From febcabdde93702e4ab309f61835973f4e3d3a8cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 11 Oct 2014 20:20:50 +0200 Subject: [PATCH] Updated Thaumcraft API and, as per request, added converter for items including apsect info. Keeping TC converters disabled by default, though, because this seems kind of cheaty to me (usually you'd have to research aspects to see them on items). --- build.properties | 2 +- src/api/java/thaumcraft/api/IRunicArmor.java | 1 - .../thaumcraft/api/ThaumcraftApiHelper.java | 70 ++++++++++++++++++- .../thaumcraft/api/aspects/AspectList.java | 26 ++++++- .../damagesource/DamageSourceThaumcraft.java | 1 + .../api/potions/PotionFluxTaint.java | 2 +- src/main/resources/mcmod.info | 1 + .../integration/mfr/ConverterSafariNet.scala | 2 +- .../thaumcraft/ConverterAspectItem.scala | 19 +++++ .../thaumcraft/ConverterIAspectContainer.java | 8 +-- .../thaumcraft/ModThaumcraft.scala | 2 + 11 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 src/main/scala/li/cil/oc/integration/thaumcraft/ConverterAspectItem.scala diff --git a/build.properties b/build.properties index 087e35842..303784dd8 100644 --- a/build.properties +++ b/build.properties @@ -1,5 +1,5 @@ minecraft.version=1.7.10 -forge.version=10.13.1.1217 +forge.version=10.13.1.1224 oc.version=1.4.0 oc.subversion=dev diff --git a/src/api/java/thaumcraft/api/IRunicArmor.java b/src/api/java/thaumcraft/api/IRunicArmor.java index 89d3c379d..5dd311006 100644 --- a/src/api/java/thaumcraft/api/IRunicArmor.java +++ b/src/api/java/thaumcraft/api/IRunicArmor.java @@ -1,6 +1,5 @@ package thaumcraft.api; -import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; /** diff --git a/src/api/java/thaumcraft/api/ThaumcraftApiHelper.java b/src/api/java/thaumcraft/api/ThaumcraftApiHelper.java index b5feb068a..8487a2099 100644 --- a/src/api/java/thaumcraft/api/ThaumcraftApiHelper.java +++ b/src/api/java/thaumcraft/api/ThaumcraftApiHelper.java @@ -2,6 +2,7 @@ package thaumcraft.api; import java.lang.reflect.Method; import java.util.HashMap; +import java.util.Iterator; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; @@ -133,6 +134,29 @@ public class ThaumcraftApiHelper { } return false; } + + public static boolean areItemStackTagsEqualForCrafting(ItemStack slotItem,ItemStack recipeItem) + { + if (recipeItem == null || slotItem == null) return false; + if (recipeItem.stackTagCompound!=null && slotItem.stackTagCompound==null ) return false; + if (recipeItem.stackTagCompound==null ) return true; + + Iterator iterator = recipeItem.stackTagCompound.func_150296_c().iterator(); + while (iterator.hasNext()) + { + String s = (String)iterator.next(); + if (slotItem.stackTagCompound.hasKey(s)) { + if (!slotItem.stackTagCompound.getTag(s).toString().equals( + recipeItem.stackTagCompound.getTag(s).toString())) { + return false; + } + } else { + return false; + } + + } + return true; + } public static boolean itemMatches(ItemStack target, ItemStack input, boolean strict) { @@ -140,7 +164,8 @@ public class ThaumcraftApiHelper { { return false; } - return (target.getItem() == input.getItem() && ((target.getItemDamage() == OreDictionary.WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage())); + return (target.getItem() == input.getItem() && + ((target.getItemDamage() == OreDictionary.WILDCARD_VALUE && !strict) || target.getItemDamage() == input.getItemDamage())); } @@ -265,4 +290,47 @@ public class ThaumcraftApiHelper { } return ot; } + + + static Method addWarpToPlayer; + /** + * This adds permanents or temporary warp to a player. It will automatically be synced clientside + * @param player the player using the wand + * @param amount how much warp to add. Negative amounts are only valid for temporary warp + * @param temporary add temporary warp instead of permanent + */ + public static void addWarpToPlayer(EntityPlayer player, int amount, boolean temporary) { + boolean ot = false; + try { + if(addWarpToPlayer == null) { + Class fake = Class.forName("thaumcraft.common.Thaumcraft"); + addWarpToPlayer = fake.getMethod("addWarpToPlayer", + EntityPlayer.class, int.class, boolean.class); + } + addWarpToPlayer.invoke(null, player, amount, temporary); + } catch(Exception ex) { + FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.Thaumcraft method addWarpToPlayer"); + } + } + + static Method addStickyWarpToPlayer; + /** + * This "sticky" warp to a player. Sticky warp is permanent warp that can be removed. + * It will automatically be synced clientside + * @param player the player using the wand + * @param amount how much warp to add. Can have negative amounts. + */ + public static void addStickyWarpToPlayer(EntityPlayer player, int amount) { + boolean ot = false; + try { + if(addStickyWarpToPlayer == null) { + Class fake = Class.forName("thaumcraft.common.Thaumcraft"); + addStickyWarpToPlayer = fake.getMethod("addStickyWarpToPlayer", + EntityPlayer.class, int.class); + } + addStickyWarpToPlayer.invoke(null, player, amount); + } catch(Exception ex) { + FMLLog.warning("[Thaumcraft API] Could not invoke thaumcraft.common.Thaumcraft method addStickyWarpToPlayer"); + } + } } diff --git a/src/api/java/thaumcraft/api/aspects/AspectList.java b/src/api/java/thaumcraft/api/aspects/AspectList.java index 6b9dfcef8..6fcfe9841 100644 --- a/src/api/java/thaumcraft/api/aspects/AspectList.java +++ b/src/api/java/thaumcraft/api/aspects/AspectList.java @@ -233,6 +233,19 @@ public class AspectList implements Serializable { } } + public void readFromNBT(NBTTagCompound nbttagcompound, String label) + { + aspects.clear(); + NBTTagList tlist = nbttagcompound.getTagList(label,(byte)10); + for (int j = 0; j < tlist.tagCount(); j++) { + NBTTagCompound rs = (NBTTagCompound) tlist.getCompoundTagAt(j); + if (rs.hasKey("key")) { + add( Aspect.getAspect(rs.getString("key")), + rs.getInteger("amount")); + } + } + } + /** * Writes the list of aspects to nbt * @param nbttagcompound @@ -251,6 +264,17 @@ public class AspectList implements Serializable { } } - + public void writeToNBT(NBTTagCompound nbttagcompound, String label) + { + NBTTagList tlist = new NBTTagList(); + nbttagcompound.setTag(label, tlist); + for (Aspect aspect : getAspects()) + if (aspect != null) { + NBTTagCompound f = new NBTTagCompound(); + f.setString("key", aspect.getTag()); + f.setInteger("amount", getAmount(aspect)); + tlist.appendTag(f); + } + } } diff --git a/src/api/java/thaumcraft/api/damagesource/DamageSourceThaumcraft.java b/src/api/java/thaumcraft/api/damagesource/DamageSourceThaumcraft.java index 7c277f28e..bb55672b7 100644 --- a/src/api/java/thaumcraft/api/damagesource/DamageSourceThaumcraft.java +++ b/src/api/java/thaumcraft/api/damagesource/DamageSourceThaumcraft.java @@ -10,6 +10,7 @@ public class DamageSourceThaumcraft extends DamageSource public static DamageSource taint = new DamageSourceThaumcraft("taint").setDamageBypassesArmor().setMagicDamage(); public static DamageSource tentacle = new DamageSourceThaumcraft("tentacle"); public static DamageSource swarm = new DamageSourceThaumcraft("swarm"); + public static DamageSource dissolve = new DamageSourceThaumcraft("dissolve").setDamageBypassesArmor(); protected DamageSourceThaumcraft(String par1Str) { super(par1Str); diff --git a/src/api/java/thaumcraft/api/potions/PotionFluxTaint.java b/src/api/java/thaumcraft/api/potions/PotionFluxTaint.java index b718de4b7..b950de0ef 100644 --- a/src/api/java/thaumcraft/api/potions/PotionFluxTaint.java +++ b/src/api/java/thaumcraft/api/potions/PotionFluxTaint.java @@ -40,7 +40,7 @@ public class PotionFluxTaint extends Potion return super.getStatusIconIndex(); } - ResourceLocation rl = new ResourceLocation("thaumcraft","textures/misc/potions.png"); + static final ResourceLocation rl = new ResourceLocation("thaumcraft","textures/misc/potions.png"); @Override public void performEffect(EntityLivingBase target, int par2) { diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 4b166add9..bb1d5910f 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -20,6 +20,7 @@ "ProjRed|Transmission", "RedLogic", "StargateTech2", + "Thaumcraft", "ThermalExpansion", "UniversalElectricity" ], diff --git a/src/main/scala/li/cil/oc/integration/mfr/ConverterSafariNet.scala b/src/main/scala/li/cil/oc/integration/mfr/ConverterSafariNet.scala index 39d453937..0a103ca7a 100644 --- a/src/main/scala/li/cil/oc/integration/mfr/ConverterSafariNet.scala +++ b/src/main/scala/li/cil/oc/integration/mfr/ConverterSafariNet.scala @@ -15,7 +15,7 @@ object ConverterSafariNet extends Converter { "MineFactoryReloaded:item.mfr.safarinet.singleuse", "MineFactoryReloaded:item.mfr.safarinet.jailer") - override def convert(value: scala.Any, output: util.Map[AnyRef, AnyRef]) = value match { + override def convert(value: scala.Any, output: util.Map[AnyRef, AnyRef]): Unit = value match { case stack: ItemStack => val name = Item.itemRegistry.getNameForObject(stack.getItem) if (SafariNetNames.contains(name)) { diff --git a/src/main/scala/li/cil/oc/integration/thaumcraft/ConverterAspectItem.scala b/src/main/scala/li/cil/oc/integration/thaumcraft/ConverterAspectItem.scala new file mode 100644 index 000000000..d6c87a188 --- /dev/null +++ b/src/main/scala/li/cil/oc/integration/thaumcraft/ConverterAspectItem.scala @@ -0,0 +1,19 @@ +package li.cil.oc.integration.thaumcraft + +import java.util + +import li.cil.oc.api.driver.Converter +import net.minecraft.item.ItemStack +import thaumcraft.api.aspects.AspectList + +import scala.collection.convert.WrapAsScala._ + +object ConverterAspectItem extends Converter { + override def convert(value: scala.Any, output: util.Map[AnyRef, AnyRef]): Unit = value match { + case stack: ItemStack if stack.hasTagCompound => + val aspects = new AspectList() + aspects.readFromNBT(stack.getTagCompound) + output += "aspects" -> aspects + case _ => + } +} diff --git a/src/main/scala/li/cil/oc/integration/thaumcraft/ConverterIAspectContainer.java b/src/main/scala/li/cil/oc/integration/thaumcraft/ConverterIAspectContainer.java index 294a1e1dd..8a407389b 100644 --- a/src/main/scala/li/cil/oc/integration/thaumcraft/ConverterIAspectContainer.java +++ b/src/main/scala/li/cil/oc/integration/thaumcraft/ConverterIAspectContainer.java @@ -14,17 +14,17 @@ public class ConverterIAspectContainer implements Converter { public void convert(final Object value, final Map output) { if (value instanceof IAspectContainer) { final IAspectContainer container = (IAspectContainer) value; - output.put("aspectList", container.getAspects()); + output.put("aspects", container.getAspects()); } if (value instanceof AspectList) { - final AspectList aspectList = (AspectList) value; + final AspectList aspects = (AspectList) value; int i = 0; - for (Aspect aspect : aspectList.getAspects()) { + for (Aspect aspect : aspects.getAspects()) { if (aspect == null) continue; final HashMap aspectMap = Maps.newHashMap(); aspectMap.put("name", aspect.getName()); - aspectMap.put("quantity", aspectList.getAmount(aspect)); + aspectMap.put("amount", aspects.getAmount(aspect)); output.put(++i, aspectMap); } } diff --git a/src/main/scala/li/cil/oc/integration/thaumcraft/ModThaumcraft.scala b/src/main/scala/li/cil/oc/integration/thaumcraft/ModThaumcraft.scala index 11d6c847f..dd1bbfb21 100644 --- a/src/main/scala/li/cil/oc/integration/thaumcraft/ModThaumcraft.scala +++ b/src/main/scala/li/cil/oc/integration/thaumcraft/ModThaumcraft.scala @@ -9,6 +9,8 @@ object ModThaumcraft extends ModProxy { override def initialize() { Driver.add(new DriverAspectContainer) + Driver.add(new ConverterIAspectContainer) + Driver.add(ConverterAspectItem) } } \ No newline at end of file