From f28c84287f8756c6943d940d787c234cc32bbef4 Mon Sep 17 00:00:00 2001 From: Krepyn <38840498+Krepyn@users.noreply.github.com> Date: Mon, 18 May 2026 21:37:55 +0300 Subject: [PATCH] Swapping parts instead of AmmoItem repair (#30) --- .../replacing/ModPartReplacement.java | 4 ++++ .../iguanatweakstconstruct/replacing/ReplacementLogic.java | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ModPartReplacement.java b/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ModPartReplacement.java index 4f9abd8..bf18bf2 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ModPartReplacement.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ModPartReplacement.java @@ -24,6 +24,7 @@ import tconstruct.library.modifier.ItemModifier; import tconstruct.library.tools.DualMaterialToolPart; import tconstruct.library.tools.ToolCore; import tconstruct.library.util.IToolPart; +import tconstruct.library.weaponry.AmmoItem; import tconstruct.tools.TinkerTools; import tconstruct.weaponry.TinkerWeaponry; @@ -50,6 +51,9 @@ public class ModPartReplacement extends ItemModifier { if (tags.getBoolean("Special")) return false; if (tags.getInteger("Damage") > 0) return false; + // Durability is written on "Ammo" tag instead of "Damage" tag for AmmoWeapons + if (tool instanceof AmmoItem && ((AmmoItem) tool).getMaxAmmo(tags) != ((AmmoItem) tool).getAmmoCount(itemStack)) + return false; // check if any of the tools parts contain stone. we have to prevent exchanging that with disabled stone tools // because otherwise the replacement-logic would not be able to obtain necessary information and crash. diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java b/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java index 75fc1dc..05b4648 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/replacing/ReplacementLogic.java @@ -140,7 +140,7 @@ public final class ReplacementLogic { updateTag(newTags, tags, "HarvestLevelHandle"); updateTag(newTags, tags, "HarvestLevelExtra"); - // ranged weapons have have additional tags to consider + // ranged weapons have additional tags to consider updateTag(newTags, tags, "DrawSpeed"); updateTag(newTags, tags, "BaseDrawSpeed"); updateTag(newTags, tags, "FlightSpeed"); @@ -224,7 +224,7 @@ public final class ReplacementLogic { xp *= (100.0f - Config.partReplacementXpPenality) / 100.0f; } - tags.setInteger(LevelingLogic.TAG_EXP, Math.round(xp)); + tags.setLong(LevelingLogic.TAG_EXP, Math.round(xp)); } // handle boost leveling/xp @@ -245,7 +245,7 @@ public final class ReplacementLogic { xp *= (100.0f - Config.partReplacementBoostXpPenality) / 100.0f; } - tags.setInteger(LevelingLogic.TAG_BOOST_EXP, Math.round(xp)); + tags.setLong(LevelingLogic.TAG_BOOST_EXP, Math.round(xp)); // already full xp? if (LevelingLogic.isBoosted(tags)) tags.setInteger("HarvestLevel", tags.getInteger("HarvestLevel") + 1);