2013-08-28 08:32:01 +00:00
|
|
|
package thaumcraft.api;
|
|
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-09-01 09:36:19 +00:00
|
|
|
import thaumcraft.api.aspects.Aspect;
|
2013-08-28 08:32:01 +00:00
|
|
|
import thaumcraft.api.aspects.AspectList;
|
|
|
|
import cpw.mods.fml.common.FMLLog;
|
|
|
|
|
|
|
|
public class ThaumcraftApiHelper {
|
|
|
|
|
|
|
|
public static AspectList cullTags(AspectList temp) {
|
2013-09-01 09:36:19 +00:00
|
|
|
AspectList temp2 = new AspectList();
|
|
|
|
for (Aspect tag:temp.getAspects()) {
|
|
|
|
if (tag!=null)
|
|
|
|
temp2.add(tag, temp.getAmount(tag));
|
|
|
|
}
|
|
|
|
while (temp2!=null && temp2.size()>10) {
|
|
|
|
Aspect lowest = null;
|
|
|
|
int low = Integer.MAX_VALUE;
|
|
|
|
for (Aspect tag:temp2.getAspects()) {
|
|
|
|
if (tag==null) continue;
|
|
|
|
if (temp2.getAmount(tag)<low) {
|
|
|
|
low = temp2.getAmount(tag);
|
|
|
|
lowest = tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
temp2.aspects.remove(lowest);
|
|
|
|
}
|
|
|
|
return temp2;
|
2013-08-28 08:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean areItemsEqual(ItemStack s1,ItemStack s2)
|
|
|
|
{
|
|
|
|
if (s1.isItemStackDamageable() && s2.isItemStackDamageable())
|
|
|
|
{
|
|
|
|
return s1.itemID == s2.itemID;
|
|
|
|
} else
|
|
|
|
return s1.itemID == s2.itemID && s1.getItemDamage() == s2.getItemDamage();
|
|
|
|
}
|
|
|
|
|
|
|
|
static Method isResearchComplete;
|
|
|
|
static Method getObjectTags;
|
|
|
|
static Method getBonusTags;
|
|
|
|
static Method generateTags;
|
|
|
|
public static boolean isResearchComplete(String username, String researchkey) {
|
|
|
|
boolean ot = false;
|
|
|
|
try {
|
|
|
|
if(isResearchComplete == null) {
|
|
|
|
Class fake = Class.forName("thaumcraft.common.lib.research.ResearchManager");
|
|
|
|
isResearchComplete = fake.getMethod("isResearchComplete", String.class, String.class);
|
|
|
|
}
|
|
|
|
ot = (Boolean) isResearchComplete.invoke(null, username, researchkey);
|
|
|
|
} catch(Exception ex) {
|
|
|
|
FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.lib.research.ResearchManager method isResearchComplete");
|
|
|
|
}
|
|
|
|
return ot;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ItemStack getStackInRowAndColumn(Object instance, int row, int column) {
|
|
|
|
ItemStack ot = null;
|
|
|
|
try {
|
|
|
|
Class fake = Class.forName("thaumcraft.common.tiles.TileMagicWorkbench");
|
|
|
|
Method getStackInRowAndColumn = fake.getMethod("getStackInRowAndColumn", int.class, int.class);
|
|
|
|
ot = (ItemStack) getStackInRowAndColumn.invoke(instance, row, column);
|
|
|
|
} catch(Exception ex) {
|
|
|
|
FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.tiles.TileMagicWorkbench method getStackInRowAndColumn");
|
|
|
|
}
|
|
|
|
return ot;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AspectList getObjectAspects(ItemStack is) {
|
|
|
|
AspectList ot = null;
|
|
|
|
try {
|
|
|
|
if(getObjectTags == null) {
|
|
|
|
Class fake = Class.forName("thaumcraft.common.lib.ThaumcraftCraftingManager");
|
|
|
|
getObjectTags = fake.getMethod("getObjectTags", ItemStack.class);
|
|
|
|
}
|
|
|
|
ot = (AspectList) getObjectTags.invoke(null, is);
|
|
|
|
} catch(Exception ex) {
|
|
|
|
FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.lib.ThaumcraftCraftingManager method getObjectTags");
|
|
|
|
}
|
|
|
|
return ot;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AspectList getBonusObjectTags(ItemStack is,AspectList ot) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
if(getBonusTags == null) {
|
|
|
|
Class fake = Class.forName("thaumcraft.common.lib.ThaumcraftCraftingManager");
|
|
|
|
getBonusTags = fake.getMethod("getBonusTags", ItemStack.class, AspectList.class);
|
|
|
|
}
|
|
|
|
ot = (AspectList) getBonusTags.invoke(null, is, ot);
|
|
|
|
} catch(Exception ex) {
|
|
|
|
FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.lib.ThaumcraftCraftingManager method getBonusTags");
|
|
|
|
}
|
|
|
|
return ot;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AspectList generateTags(int id, int meta) {
|
|
|
|
try {
|
|
|
|
if(generateTags == null) {
|
|
|
|
Class fake = Class.forName("thaumcraft.common.lib.ThaumcraftCraftingManager");
|
|
|
|
generateTags = fake.getMethod("generateTags", int.class, int.class);
|
|
|
|
}
|
|
|
|
return (AspectList) generateTags.invoke(null, id, meta);
|
|
|
|
} catch(Exception ex) {
|
|
|
|
FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.lib.ThaumcraftCraftingManager method generateTags");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|