From 448c1ff2b585dd6b0b73103b64186eb2a7ad15bb Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Tue, 29 Jul 2014 23:36:39 +0200 Subject: [PATCH] Add Quartz/Attac Modifier Support to Part Replacement --- .../replacing/ReplacementLogic.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java b/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java index 75f0c4b..914c251 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java @@ -15,6 +15,7 @@ import tconstruct.library.crafting.ToolRecipe; import tconstruct.library.modifier.ItemModifier; import tconstruct.library.tools.ToolCore; import tconstruct.library.tools.ToolMaterial; +import tconstruct.modifiers.tools.ModAttack; import tconstruct.modifiers.tools.ModRedstone; import tconstruct.tools.items.ToolPart; @@ -155,6 +156,8 @@ public abstract class ReplacementLogic { // redstone modifier reapplyRedstone(tags, toolStack); + // quartz/attack modifier + reapplyAttack(tags, toolStack); } // update tag if it already exists. @@ -202,6 +205,7 @@ public abstract class ReplacementLogic { // tasty - handled per ActiveToolMod, no NBT required } + // strips the redstone modifier off a tool and reapplies it (to get the correct mining level modification) private static void reapplyRedstone(NBTTagCompound tags, ItemStack itemStack) { // only do if we actually have redstone @@ -234,6 +238,39 @@ public abstract class ReplacementLogic { } } + // same as reapplyRedstone but for Attack modifier + private static void reapplyAttack(NBTTagCompound tags, ItemStack itemStack) + { + // only do if we actually have attack modifier + if(!tags.hasKey("ModAttack")) + return; + + // find the redstone modifier + for(ItemModifier mod : ModifyBuilder.instance.itemModifiers) + if(mod.key.equals("ModAttack")) + { + ModAttack modAttack = (ModAttack)mod; + int[] keyPair = tags.getIntArray("ModAttack"); + // get amount of redstone applied + int qLvl = keyPair[0]; + // reset redstone modifier + tags.removeTag("ModAttack"); + + // remove the old tooltip + int tipIndex = keyPair[2]; + tags.removeTag("Tooltip" + tipIndex); + tags.removeTag("ModifierTip" + tipIndex); + + + // reapply redstone + while(qLvl-- > 0) + modAttack.modify(new ItemStack[]{new ItemStack(Items.quartz)}, itemStack); // tags belong to oldTool + + // check if it actually used the same tipindex + Log.info(tipIndex + " " + tags.getIntArray("ModAttack")[2]); + } + } + // todo: remove this function stub :D private static void adjustModifierTag(NBTTagCompound tags, String tag, boolean decrease) {