diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/LevelingEventHandler.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/LevelingEventHandler.java index 933a84b..0e9f797 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/LevelingEventHandler.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/LevelingEventHandler.java @@ -36,6 +36,8 @@ import tconstruct.library.TConstructRegistry; import tconstruct.library.event.ToolCraftEvent; import tconstruct.library.tools.ToolCore; import tconstruct.library.weaponry.ProjectileWeapon; +import tconstruct.weaponry.ammo.ArrowAmmo; +import tconstruct.weaponry.ammo.BoltAmmo; import tconstruct.weaponry.entity.ShurikenEntity; import tconstruct.weaponry.weapons.Shuriken; import xonin.backhand.api.core.BackhandUtils; @@ -192,9 +194,9 @@ public class LevelingEventHandler { LevelingLogic.addLevelingTags(toolTag, event.tool); // remove modifiers - toolTag.setInteger( - "Modifiers", - Math.max(toolTag.getInteger("Modifiers") - (3 - Config.toolLevelingExtraModifiers), 0)); + int toolBaseModifiers = event.tool instanceof ArrowAmmo || event.tool instanceof BoltAmmo ? 2 : 3; + int result = toolTag.getInteger("Modifiers") - (toolBaseModifiers - Config.toolLevelingExtraModifiers); + toolTag.setInteger("Modifiers", Math.max(result, 0)); } // Display XP of held tool in debug (F3) if config is set diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ModPartReplacement.java b/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ModPartReplacement.java index a372551..c9d9701 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ModPartReplacement.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ModPartReplacement.java @@ -7,6 +7,7 @@ import static iguanaman.iguanatweakstconstruct.replacing.ReplacementLogic.PartTy import static iguanaman.iguanatweakstconstruct.replacing.ReplacementLogic.PartTypes.HEAD; import static iguanaman.iguanatweakstconstruct.replacing.ReplacementLogic.detectAdditionalPartType; import static iguanaman.iguanatweakstconstruct.replacing.ReplacementLogic.exchangeToolPart; +import static iguanaman.iguanatweakstconstruct.replacing.ReplacementLogic.getResultingBoltModifierCount; import static iguanaman.iguanatweakstconstruct.replacing.ReplacementLogic.getResultingModifierCount; import static iguanaman.iguanatweakstconstruct.replacing.ReplacementLogic.getToolPartMaterial; @@ -103,6 +104,10 @@ public class ModPartReplacement extends ItemModifier { else if (recipe.validExtra(item)) partType = EXTRA; else return false; + if (partType == HEAD && tool == TinkerWeaponry.boltAmmo && item instanceof DualMaterialToolPart) { + partType = HANDLE; + } + replacementPartItem = item; partIndex = i; } @@ -133,25 +138,22 @@ public class ModPartReplacement extends ItemModifier { if (TConstructRegistry.getMaterial(newMatId).harvestLevel == 0 && LevelingLogic.hasBoostXp(tags)) return false; + boolean sameMaterial = newMatId == oldMatId; + // do we have enough modifiers left if we exchange this part? - // This probably doesn't work right for bolts (which replace two parts at a time). - modifiers = getResultingModifierCount(tool, tags, oldMatId, newMatId, partType); + // Special case for bolts, which have two materials. + if (tool == TinkerWeaponry.boltAmmo && replacementPartItem instanceof DualMaterialToolPart) { + int newHeadId = ((DualMaterialToolPart) replacementPartItem).getMaterialID2(parts[partIndex]); + int oldHeadId = getToolPartMaterial(tags, HEAD); + + modifiers = getResultingBoltModifierCount(tool, modifiers, tags, oldHeadId, newHeadId, oldMatId, newMatId); + sameMaterial = sameMaterial && newHeadId == oldHeadId; + } else { + modifiers = getResultingModifierCount(tool, modifiers, tags, oldMatId, newMatId, partType); + } if (modifiers < 0) return false; - // is it the same material as the one we want to replace? - if (newMatId == oldMatId) { - // Special case for bolts, which have two materials. - if (tool == TinkerWeaponry.boltAmmo && replacementPartItem instanceof DualMaterialToolPart) { - int newHeadMatId = ((DualMaterialToolPart) replacementPartItem).getMaterialID2(parts[partIndex]); - int oldHeadMatId = getToolPartMaterial(tags, HEAD); - - return newHeadMatId != oldHeadMatId; - } - - return false; - } - - return true; + return !sameMaterial; } @Override diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java b/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java index 113a0dc..feb1959 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java @@ -109,6 +109,26 @@ public final class ReplacementLogic { long oldRequiredXp = LevelingLogic.getRequiredXp(toolStack, tags); long oldRequiredBoostXp = LevelingLogic.getRequiredBoostXp(toolStack); + int modifiers = tags.getInteger("Modifiers"); + // special case for bolts + if (tool == TinkerWeaponry.boltAmmo && partStack.getItem() instanceof DualMaterialToolPart) { + int oldHandleId = getToolPartMaterial(tags, HANDLE); + int newHandleId = ((DualMaterialToolPart) partStack.getItem()).getMaterialID(partStack); + + modifiers = getResultingBoltModifierCount( + tool, + modifiers, + tags, + oldMaterialId, + partMaterialId, + oldHandleId, + newHandleId); + } else { + modifiers = getResultingModifierCount(tool, modifiers, tags, oldMaterialId, partMaterialId, type); + } + // Shouldn't happen, but just in case + tags.setInteger("Modifiers", Math.max(modifiers, 0)); + // update part materials and rendering updateTag(newTags, tags, "Head"); updateTag(newTags, tags, "RenderHead"); @@ -171,8 +191,6 @@ public final class ReplacementLogic { tags.setInteger("Unbreaking", newReinforced); // reinforced tooltip is handled internally by tcon automagically - // now for the scary part... handle material traits >_< - handleMaterialTraits(tool, tags, oldMaterialId, partMaterialId, type); // fiery blaze arrows has to be handled separately.. meh if (tool == TinkerWeaponry.arrowAmmo && type == HANDLE) if (oldMaterialId == 3 && partMaterialId != 3) { // remove fiery @@ -280,17 +298,6 @@ public final class ReplacementLogic { if (to.hasKey(tag)) to.setTag(tag, from.getTag(tag)); } - private static void handleMaterialTraits(ToolCore tool, NBTTagCompound tags, int oldMaterialId, int newMaterialId, - PartTypes partType) { - // nothing to do if they're the same :) - if (oldMaterialId == newMaterialId) return; - - int modifiers = getResultingModifierCount(tool, tags, oldMaterialId, newMaterialId, partType); - // Shouldn't happen, but just in case - if (modifiers < 0) modifiers = 0; - tags.setInteger("Modifiers", modifiers); - } - // 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 @@ -466,22 +473,20 @@ public final class ReplacementLogic { return true; } - public static int getResultingModifierCount(ToolCore tool, NBTTagCompound tags, int oldMatId, int newMatId, - PartTypes partType) { - int modifiers = tags.getInteger("Modifiers"); + public static int getResultingModifierCount(ToolCore tool, int modifiers, NBTTagCompound tags, int oldMatId, + int newMatId, PartTypes partType) { if (oldMatId == newMatId) return modifiers; if (hasExtraModifier(oldMatId)) modifiers--; if (hasExtraModifier(newMatId)) modifiers++; // Handle magic wood modifiers if (IguanaToolPartReplacing.extraUtilsLoaded && Config.partReplacementHandleMagicalWood) { + int magicWoodId = ExtraUtils.tcon_magical_wood_id; int extraModifiers = tool == TinkerTools.battlesign ? 11 : 8; EnumMap map = new EnumMap<>(PartTypes.class); - int magicWoodId = ExtraUtils.tcon_magical_wood_id; int oldToolMagicWoodCount = 0; for (PartTypes type : PartTypes.values()) { - // We use oldMatId as tags could be from post-tool part swapping - int partId = type == partType ? oldMatId : getToolPartMaterial(tags, type); + int partId = getToolPartMaterial(tags, type); if (partId == magicWoodId) oldToolMagicWoodCount++; map.put(type, partId); } @@ -509,6 +514,17 @@ public final class ReplacementLogic { return modifiers; } + /** + * Bolts swap head and handle at once, so the handle lookup has to see the new head. + */ + public static int getResultingBoltModifierCount(ToolCore tool, int modifiers, NBTTagCompound tags, int oldHeadId, + int newHeadId, int oldHandleId, int newHandleId) { + modifiers = getResultingModifierCount(tool, modifiers, tags, oldHeadId, newHeadId, HEAD); + NBTTagCompound swapped = (NBTTagCompound) tags.copy(); + swapped.setInteger("Head", newHeadId); + return getResultingModifierCount(tool, modifiers, swapped, oldHandleId, newHandleId, HANDLE); + } + /** * Returns the type-part of the tool. */