From 26c0c890c1855be3447fa186628a95cb7ed7cd52 Mon Sep 17 00:00:00 2001 From: LittleCube Date: Mon, 30 Dec 2024 02:49:03 +0800 Subject: [PATCH 01/11] Added repairing recipe workaround for specially registered tools This fix will eliminate the NullPointerException caused from repairing tools without toolProperty properly set for the material. Therefore, the current soft-mallet/plumber duplications will be fixed since they are separately registered currently. --- .../gregtech/api/items/toolitem/IGTTool.java | 76 +++++++++++++------ .../asm/hooks/RecipeRepairItemHooks.java | 2 +- .../minecraft/RecipeRepairItemMixin.java | 2 +- 3 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/main/java/gregtech/api/items/toolitem/IGTTool.java b/src/main/java/gregtech/api/items/toolitem/IGTTool.java index 94ae45effb9..0b891ee8816 100644 --- a/src/main/java/gregtech/api/items/toolitem/IGTTool.java +++ b/src/main/java/gregtech/api/items/toolitem/IGTTool.java @@ -150,13 +150,20 @@ default ItemStack getRaw() { return stack; } - default ItemStack get(Material material) { + /** + * This is a safer wrapper for materials without toolProperty properly set. In this case, the missing data is + * inferred from the referenceStack. This method supports specially made tools that is registered separately. + * + * @return A tool made from the given material + */ + default ItemStack get(Material material, ItemStack referenceStack) { ItemStack stack = new ItemStack(get()); NBTTagCompound stackCompound = GTUtility.getOrCreateNbtCompound(stack); stackCompound.setBoolean(DISALLOW_CONTAINER_ITEM_KEY, false); NBTTagCompound toolTag = getToolTag(stack); + NBTTagCompound referenceToolTag = getToolTag(referenceStack); IGTToolDefinition toolStats = getToolStats(); // don't show the normal vanilla damage and attack speed tooltips, @@ -177,33 +184,47 @@ default ItemStack get(Material material) { // definition durability multiplier) - 1 // Subtracts 1 internally since Minecraft treats "0" as a valid durability, but we don't want to display this. - int durability = toolProperty.getToolDurability() * toolProperty.getDurabilityMultiplier(); - - // Most Tool Definitions do not set a base durability, which will lead to ignoring the multiplier if present. So - // apply the multiplier to the material durability if that would happen - if (toolStats.getBaseDurability(stack) == 0) { - durability *= toolStats.getDurabilityMultiplier(stack); + int durability; + boolean isUnbreakable; + if (toolProperty != null) { + // Tool material modifiers. + durability = toolProperty.getToolDurability() * toolProperty.getDurabilityMultiplier(); + + // Tool type modifiers. + // Most Tool Definitions do not set a base durability, which will lead to ignoring the multiplier if present. So + // apply the multiplier to the material durability if that would happen + if (toolStats.getBaseDurability(stack) == 0) { + durability = (int) (durability * toolStats.getDurabilityMultiplier(stack)); + } else { + durability += (int) (toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack)); + } + durability--; // Adjust for MC + + // Get unbreakability + isUnbreakable = toolProperty.getUnbreakable(); + + // Set tool and material enchantments + Object2IntMap enchantments = new Object2IntOpenHashMap<>(); + toolProperty.getEnchantments().forEach((enchantment, level) -> enchantments.put(enchantment, + level.getLevel(toolProperty.getToolHarvestLevel()))); + toolStats.getDefaultEnchantments(stack).forEach((enchantment, level) -> enchantments.put(enchantment, + level.getLevel(toolProperty.getToolHarvestLevel()))); + enchantments.forEach((enchantment, level) -> { + if (stack.getItem().canApplyAtEnchantingTable(stack, enchantment)) { + stack.addEnchantment(enchantment, level); + } + }); } else { - durability += toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack); + // In this case, simply get from the reference tool + durability = referenceToolTag.getInteger(MAX_DURABILITY_KEY); + isUnbreakable = referenceToolTag.getBoolean(UNBREAKABLE_KEY); } - toolTag.setInteger(MAX_DURABILITY_KEY, durability - 1); - toolTag.setInteger(DURABILITY_KEY, 0); - if (toolProperty.getUnbreakable()) { + if (isUnbreakable) { stackCompound.setBoolean(UNBREAKABLE_KEY, true); } - - // Set tool and material enchantments - Object2IntMap enchantments = new Object2IntOpenHashMap<>(); - toolProperty.getEnchantments().forEach((enchantment, level) -> enchantments.put(enchantment, - level.getLevel(toolProperty.getToolHarvestLevel()))); - toolStats.getDefaultEnchantments(stack).forEach((enchantment, level) -> enchantments.put(enchantment, - level.getLevel(toolProperty.getToolHarvestLevel()))); - enchantments.forEach((enchantment, level) -> { - if (stack.getItem().canApplyAtEnchantingTable(stack, enchantment)) { - stack.addEnchantment(enchantment, level); - } - }); + toolTag.setInteger(MAX_DURABILITY_KEY, durability); + toolTag.setInteger(DURABILITY_KEY, 0); // Set behaviours NBTTagCompound behaviourTag = getBehaviorsTag(stack); @@ -218,13 +239,20 @@ default ItemStack get(Material material) { behaviourTag.setInteger(AOE_LAYER_KEY, aoeDefinition.layer); } - if (toolProperty.isMagnetic()) { + if (toolProperty != null && toolProperty.isMagnetic()) { behaviourTag.setBoolean(RELOCATE_MINED_BLOCKS_KEY, true); } return stack; } + /** + * @return A tool made from the given material. The tool property for the material must be set. + */ + default ItemStack get(Material material) { + return get(material, ItemStack.EMPTY); + } + default ItemStack get(Material material, long defaultCharge, long defaultMaxCharge) { ItemStack stack = get(material); if (isElectric()) { diff --git a/src/main/java/gregtech/asm/hooks/RecipeRepairItemHooks.java b/src/main/java/gregtech/asm/hooks/RecipeRepairItemHooks.java index 7956c412a68..a00ec3da35a 100644 --- a/src/main/java/gregtech/asm/hooks/RecipeRepairItemHooks.java +++ b/src/main/java/gregtech/asm/hooks/RecipeRepairItemHooks.java @@ -96,7 +96,7 @@ public static ItemStack getCraftingResult(InventoryCrafting inv) { // two GT tools, so use own logic to produce the correct output IGTTool tool = (IGTTool) first.getItem(); - ItemStack output = tool.get(tool.getToolMaterial(first)); + ItemStack output = tool.get(tool.getToolMaterial(first), first); NBTTagCompound outputTag = ToolHelper.getToolTag(output); outputTag.setInteger(ToolHelper.DURABILITY_KEY, i1); diff --git a/src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java b/src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java index 5cd275b6cf8..461a5216a16 100644 --- a/src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java +++ b/src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java @@ -76,7 +76,7 @@ public class RecipeRepairItemMixin { if (itemstack2.getItemDamage() == 0 && itemstack3.getItemDamage() == 0) { return ItemStack.EMPTY; } else { - ItemStack output = first.get(first.getToolMaterial(itemstack2)); + ItemStack output = first.get(first.getToolMaterial(itemstack2), itemstack2); NBTTagCompound outputTag = ToolHelper.getToolTag(output); outputTag.setInteger(ToolHelper.DURABILITY_KEY, itemDamage); return output; From e9089958137f6f9b094f041e3701dc69991a244c Mon Sep 17 00:00:00 2001 From: LittleCube Date: Wed, 1 Jan 2025 15:53:27 +0800 Subject: [PATCH 02/11] add ExtraToolProperty --- .../properties/ExtraToolProperty.java | 145 +++++++++++++ .../material/properties/PropertyKey.java | 1 + .../properties/SimpleToolProperty.java | 197 ++++++++++++++++++ .../material/properties/ToolProperty.java | 181 +--------------- 4 files changed, 353 insertions(+), 171 deletions(-) create mode 100644 src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java create mode 100644 src/main/java/gregtech/api/unification/material/properties/SimpleToolProperty.java diff --git a/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java b/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java new file mode 100644 index 00000000000..ee88442a699 --- /dev/null +++ b/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java @@ -0,0 +1,145 @@ +package gregtech.api.unification.material.properties; + +import net.minecraft.enchantment.Enchantment; + +import org.jetbrains.annotations.Nullable; + +import javax.tools.Tool; +import java.util.HashMap; +import java.util.Map; + +public class ExtraToolProperty implements IMaterialProperty { + + /** + * Special override for certain kinds of tools. + */ + private final Map overrideMap; + + public static class OverrideToolProperty extends SimpleToolProperty { + + public OverrideToolProperty() { + this.setToolSpeed(Float.NaN); + this.setToolAttackSpeed(Float.NaN); + this.setToolAttackDamage(Float.NaN); + this.setToolDurability(-1); + super.setToolHarvestLevel(-1); + this.setToolEnchantability(-1); + this.setDurabilityMultiplier(-1); + } + + // It does not make much sense to set these overrides: + public void setToolHarvestLevel(int harvestLevel) { + throw new UnsupportedOperationException(); + } + + public void setShouldIgnoreCraftingTools(boolean ignore) { + throw new UnsupportedOperationException(); + } + + public void setUnbreakable(boolean isUnbreakable) { + throw new UnsupportedOperationException(); + } + + public boolean isMagnetic() { + throw new UnsupportedOperationException(); + } + + public SimpleToolProperty override(SimpleToolProperty property) { + // Set the floating point number fields + if (!Float.isNaN(this.getToolSpeed())) + property.setToolSpeed(this.getToolSpeed()); + if (!Float.isNaN(this.getToolAttackSpeed())) + property.setToolAttackSpeed(this.getToolAttackSpeed()); + if (!Float.isNaN(this.getToolAttackDamage())) + property.setToolAttackDamage(this.getToolAttackDamage()); + + // Set the integer fields + if (this.getToolDurability() != -1) + property.setToolDurability(this.getToolDurability()); + if (this.getToolEnchantability() != -1) + property.setToolEnchantability(this.getToolEnchantability()); + if (this.getDurabilityMultiplier() != -1) + property.setDurabilityMultiplier(this.getDurabilityMultiplier()); + + // Merge the enchantment map + property.getEnchantments().putAll(this.getEnchantments()); + return property; + } + } + + public ExtraToolProperty() { + this.overrideMap = new HashMap<>(); + } + + public void setOverrideProperty(String toolClass, OverrideToolProperty overrideProperty) { + this.overrideMap.put(toolClass, overrideProperty); + } + + @Nullable + public OverrideToolProperty getOverrideProperty(String toolClass) { + return this.overrideMap.get(toolClass); + } + + public boolean hasOverrideProperty(String toolClass) { + return getOverrideProperty(toolClass) != null; + } + + public SimpleToolProperty getOverriddenResult(ToolProperty toolProperty, String toolClass){ + return overrideMap.getOrDefault(toolClass, new OverrideToolProperty()).override((SimpleToolProperty) toolProperty); + } + + @Override + public void verifyProperty(MaterialProperties properties) { + // No check here, since these recipes should be self-generated. + // If they are overriding ToolProperty, then it is already generated. + } + + public static class Overrider { + + private final OverrideToolProperty toolProperty; + + public static Overrider of() { + return new Overrider(); + } + + public static Overrider of(float harvestSpeed, float attackDamage, int durability) { + Overrider overrider = new Overrider(); + overrider.harvestSpeed(harvestSpeed).attackDamage(attackDamage).durability(durability); + return overrider; + } + + public Overrider() { + this.toolProperty = new OverrideToolProperty(); + } + + public Overrider harvestSpeed(float harvestSpeed) { + toolProperty.setToolSpeed(harvestSpeed); + return this; + } + + public Overrider attackDamage(float attackDamage) { + toolProperty.setToolAttackDamage(attackDamage); + return this; + } + + public Overrider durability(int durability) { + toolProperty.setToolDurability(durability); + return this; + } + + public Overrider attackSpeed(float attackSpeed) { + toolProperty.setToolAttackSpeed(attackSpeed); + return this; + } + + public Overrider enchantment(Enchantment enchantment, int level) { + toolProperty.addEnchantmentForTools(enchantment, level); + return this; + } + + public Overrider durabilityMultiplier(int multiplier) { + toolProperty.setDurabilityMultiplier(multiplier); + return this; + } + } +} diff --git a/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java b/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java index 5dc2234a40e..05e24d16651 100644 --- a/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java +++ b/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java @@ -14,6 +14,7 @@ public class PropertyKey { ItemPipeProperties.class); public static final PropertyKey ORE = new PropertyKey<>("ore", OreProperty.class); public static final PropertyKey TOOL = new PropertyKey<>("tool", ToolProperty.class); + public static final PropertyKey EXTRATOOL = new PropertyKey<>("extra_tool", ExtraToolProperty.class); public static final PropertyKey ROTOR = new PropertyKey<>("rotor", RotorProperty.class); public static final PropertyKey WIRE = new PropertyKey<>("wire", WireProperties.class); public static final PropertyKey WOOD = new PropertyKey<>("wood", WoodProperty.class); diff --git a/src/main/java/gregtech/api/unification/material/properties/SimpleToolProperty.java b/src/main/java/gregtech/api/unification/material/properties/SimpleToolProperty.java new file mode 100644 index 00000000000..894ad7aec50 --- /dev/null +++ b/src/main/java/gregtech/api/unification/material/properties/SimpleToolProperty.java @@ -0,0 +1,197 @@ +package gregtech.api.unification.material.properties; + +import gregtech.api.items.toolitem.EnchantmentLevel; + +import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; + +import net.minecraft.enchantment.Enchantment; + +public class SimpleToolProperty { + + /** + * Harvest speed of tools made from this Material. + *

+ * Default: 1.0F + */ + private float harvestSpeed; + + /** + * Attack damage of tools made from this Material + *

+ * Default: 1.0F + */ + private float attackDamage; + + /** + * Attack speed of tools made from this Material + *

+ * Default: 0.0F + */ + private float attackSpeed; + + /** + * Durability of tools made from this Material. + *

+ * Default: 100 + */ + private int durability; + + /** + * Harvest level of tools made of this Material. + *

+ * Default: 2 (Iron). + */ + private int harvestLevel; + + /** + * Enchantability of tools made from this Material. + *

+ * Default: 10 + */ + private int enchantability; + + /** + * A multiplier to the base durability for this material Mostly for modpack makers + */ + private int durabilityMultiplier; + + /** + * If crafting tools should not be made from this material + */ + private boolean ignoreCraftingTools; + + /** + * If tools made of this material should be unbreakable and ignore durability checks. + */ + private boolean isUnbreakable; + + /** + * If tools made of this material should be "magnetic," meaning items go directly into the player's inventory + * instead of dropping on the ground. + */ + private boolean isMagnetic; + + /** + * Enchantment to be applied to tools made from this Material. + */ + private final Object2ObjectMap enchantments; + + public SimpleToolProperty(float harvestSpeed, float attackDamage, int durability, int harvestLevel) { + this.harvestSpeed = harvestSpeed; + this.attackDamage = attackDamage; + this.durability = durability; + this.harvestLevel = harvestLevel; + enchantments = new Object2ObjectArrayMap<>(); + } + + public SimpleToolProperty() { + this(1.0F, 1.0F, 100, 2); + } + + public SimpleToolProperty(SimpleToolProperty property) { + harvestSpeed = property.harvestSpeed; + attackDamage = property.attackDamage; + attackSpeed = property.attackSpeed; + durability = property.durability; + harvestLevel = property.harvestLevel; + enchantability = property.enchantability; + durabilityMultiplier = property.durabilityMultiplier; + ignoreCraftingTools = property.ignoreCraftingTools; + isUnbreakable = property.isUnbreakable; + isMagnetic = property.isMagnetic; + enchantments = new Object2ObjectArrayMap<>(property.enchantments); + } + + public float getToolSpeed() { + return harvestSpeed; + } + + public void setToolSpeed(float toolSpeed) { + this.harvestSpeed = toolSpeed; + } + + public float getToolAttackDamage() { + return attackDamage; + } + + public void setToolAttackDamage(float toolAttackDamage) { + this.attackDamage = toolAttackDamage; + } + + public float getToolAttackSpeed() { + return attackSpeed; + } + + public void setToolAttackSpeed(float toolAttackSpeed) { + this.attackSpeed = toolAttackSpeed; + } + + public int getToolDurability() { + return durability; + } + + public void setToolDurability(int toolDurability) { + this.durability = toolDurability; + } + + public int getToolHarvestLevel() { + return this.harvestLevel; + } + + public void setToolHarvestLevel(int toolHarvestLevel) { + this.harvestLevel = toolHarvestLevel; + } + + public int getToolEnchantability() { + return enchantability; + } + + public void setToolEnchantability(int toolEnchantability) { + this.enchantability = toolEnchantability; + } + + public boolean getShouldIgnoreCraftingTools() { + return ignoreCraftingTools; + } + + public void setShouldIgnoreCraftingTools(boolean ignore) { + this.ignoreCraftingTools = ignore; + } + + public boolean getUnbreakable() { + return isUnbreakable; + } + + public void setUnbreakable(boolean isUnbreakable) { + this.isUnbreakable = isUnbreakable; + } + + public Object2ObjectMap getEnchantments() { + return enchantments; + } + + public void setMagnetic(boolean isMagnetic) { + this.isMagnetic = isMagnetic; + } + + public boolean isMagnetic() { + return isMagnetic; + } + + public void setDurabilityMultiplier(int multiplier) { + this.durabilityMultiplier = multiplier; + } + + public int getDurabilityMultiplier() { + return durabilityMultiplier; + } + + public void addEnchantmentForTools(Enchantment enchantment, int level) { + this.addEnchantmentForTools(enchantment, level, 0); + } + + public void addEnchantmentForTools(Enchantment enchantment, double level, double levelGrowth) { + enchantments.put(enchantment, new EnchantmentLevel(level, levelGrowth)); + } +} diff --git a/src/main/java/gregtech/api/unification/material/properties/ToolProperty.java b/src/main/java/gregtech/api/unification/material/properties/ToolProperty.java index 99264c592e4..fefa498ac07 100644 --- a/src/main/java/gregtech/api/unification/material/properties/ToolProperty.java +++ b/src/main/java/gregtech/api/unification/material/properties/ToolProperty.java @@ -1,176 +1,23 @@ package gregtech.api.unification.material.properties; -import gregtech.api.items.toolitem.EnchantmentLevel; - import net.minecraft.enchantment.Enchantment; -import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; -import it.unimi.dsi.fastutil.objects.Object2ObjectMap; - -public class ToolProperty implements IMaterialProperty { - - /** - * Harvest speed of tools made from this Material. - *

- * Default: 1.0F - */ - private float harvestSpeed; - - /** - * Attack damage of tools made from this Material - *

- * Default: 1.0F - */ - private float attackDamage; - - /** - * Attack speed of tools made from this Material - *

- * Default: 0.0F - */ - private float attackSpeed; - - /** - * Durability of tools made from this Material. - *

- * Default: 100 - */ - private int durability; - - /** - * Harvest level of tools made of this Material. - *

- * Default: 2 (Iron). - */ - private int harvestLevel; - - /** - * Enchantability of tools made from this Material. - *

- * Default: 10 - */ - private int enchantability = 10; - - /** - * If crafting tools should not be made from this material - */ - private boolean ignoreCraftingTools; - - /** - * If tools made of this material should be unbreakable and ignore durability checks. - */ - private boolean isUnbreakable; - - /** - * If tools made of this material should be "magnetic," meaning items go - * directly into the player's inventory instead of dropping on the ground. - */ - private boolean isMagnetic; - - /** - * A multiplier to the base durability for this material - * Mostly for modpack makers - */ - private int durabilityMultiplier = 1; - - /** - * Enchantment to be applied to tools made from this Material. - */ - private final Object2ObjectMap enchantments = new Object2ObjectArrayMap<>(); - - public ToolProperty(float harvestSpeed, float attackDamage, int durability, int harvestLevel) { - this.harvestSpeed = harvestSpeed; - this.attackDamage = attackDamage; - this.durability = durability; - this.harvestLevel = harvestLevel; - } - - public ToolProperty() { - this(1.0F, 1.0F, 100, 2); - } - - public float getToolSpeed() { - return harvestSpeed; - } - - public void setToolSpeed(float toolSpeed) { - this.harvestSpeed = toolSpeed; - } - - public float getToolAttackDamage() { - return attackDamage; - } - - public void setToolAttackDamage(float toolAttackDamage) { - this.attackDamage = toolAttackDamage; - } - - public float getToolAttackSpeed() { - return attackSpeed; - } - - public void setToolAttackSpeed(float toolAttackSpeed) { - this.attackSpeed = toolAttackSpeed; - } - - public int getToolDurability() { - return durability; - } - - public void setToolDurability(int toolDurability) { - this.durability = toolDurability; - } - - public int getToolHarvestLevel() { - return this.harvestLevel; - } +import org.jetbrains.annotations.Nullable; - public void setToolHarvestLevel(int toolHarvestLevel) { - this.harvestLevel = toolHarvestLevel; - } +import java.util.HashMap; +import java.util.Map; - public int getToolEnchantability() { - return enchantability; - } +public class ToolProperty extends SimpleToolProperty implements IMaterialProperty { - public void setToolEnchantability(int toolEnchantability) { - this.enchantability = toolEnchantability; - } - public boolean getShouldIgnoreCraftingTools() { - return ignoreCraftingTools; - } - - public void setShouldIgnoreCraftingTools(boolean ignore) { - this.ignoreCraftingTools = ignore; - } - - public boolean getUnbreakable() { - return isUnbreakable; - } - - public void setUnbreakable(boolean isUnbreakable) { - this.isUnbreakable = isUnbreakable; - } - - public Object2ObjectMap getEnchantments() { - return enchantments; - } - - public void setMagnetic(boolean isMagnetic) { - this.isMagnetic = isMagnetic; - } - - public boolean isMagnetic() { - return isMagnetic; - } - - public void setDurabilityMultiplier(int multiplier) { - this.durabilityMultiplier = multiplier; + public ToolProperty(float harvestSpeed, float attackDamage, int durability, int harvestLevel) { + super(harvestSpeed, attackDamage, durability, harvestLevel); + this.setToolEnchantability(10); + this.setDurabilityMultiplier(1); } - public int getDurabilityMultiplier() { - return durabilityMultiplier; + public ToolProperty() { + this(1.0F, 1.0F, 100, 2); } @Override @@ -178,14 +25,6 @@ public void verifyProperty(MaterialProperties properties) { if (!properties.hasProperty(PropertyKey.GEM)) properties.ensureSet(PropertyKey.INGOT, true); } - public void addEnchantmentForTools(Enchantment enchantment, int level) { - this.addEnchantmentForTools(enchantment, level, 0); - } - - public void addEnchantmentForTools(Enchantment enchantment, double level, double levelGrowth) { - enchantments.put(enchantment, new EnchantmentLevel(level, levelGrowth)); - } - public static class Builder { private final ToolProperty toolProperty; From b180442ff03929714422885829e2284b629b77ea Mon Sep 17 00:00:00 2001 From: LittleCube Date: Wed, 1 Jan 2025 17:12:46 +0800 Subject: [PATCH 03/11] Fixed overriding issue --- .../properties/ExtraToolProperty.java | 80 ++++++++++++------- .../asm/hooks/RecipeRepairItemHooks.java | 2 +- .../minecraft/RecipeRepairItemMixin.java | 2 +- 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java b/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java index ee88442a699..ac2172cdd22 100644 --- a/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java +++ b/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java @@ -2,9 +2,9 @@ import net.minecraft.enchantment.Enchantment; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.tools.Tool; import java.util.HashMap; import java.util.Map; @@ -22,16 +22,12 @@ public OverrideToolProperty() { this.setToolAttackSpeed(Float.NaN); this.setToolAttackDamage(Float.NaN); this.setToolDurability(-1); - super.setToolHarvestLevel(-1); + this.setToolHarvestLevel(-1); this.setToolEnchantability(-1); this.setDurabilityMultiplier(-1); } // It does not make much sense to set these overrides: - public void setToolHarvestLevel(int harvestLevel) { - throw new UnsupportedOperationException(); - } - public void setShouldIgnoreCraftingTools(boolean ignore) { throw new UnsupportedOperationException(); } @@ -44,26 +40,31 @@ public boolean isMagnetic() { throw new UnsupportedOperationException(); } - public SimpleToolProperty override(SimpleToolProperty property) { + private SimpleToolProperty override(@NotNull SimpleToolProperty property) { + // copy to prevent the previous map is produced + SimpleToolProperty result = new SimpleToolProperty(property); + // Set the floating point number fields if (!Float.isNaN(this.getToolSpeed())) - property.setToolSpeed(this.getToolSpeed()); + result.setToolSpeed(this.getToolSpeed()); if (!Float.isNaN(this.getToolAttackSpeed())) - property.setToolAttackSpeed(this.getToolAttackSpeed()); + result.setToolAttackSpeed(this.getToolAttackSpeed()); if (!Float.isNaN(this.getToolAttackDamage())) - property.setToolAttackDamage(this.getToolAttackDamage()); + result.setToolAttackDamage(this.getToolAttackDamage()); // Set the integer fields if (this.getToolDurability() != -1) - property.setToolDurability(this.getToolDurability()); + result.setToolDurability(this.getToolDurability()); + if (this.getToolHarvestLevel() != -1) + result.setToolHarvestLevel(this.getToolHarvestLevel()); if (this.getToolEnchantability() != -1) - property.setToolEnchantability(this.getToolEnchantability()); + result.setToolEnchantability(this.getToolEnchantability()); if (this.getDurabilityMultiplier() != -1) - property.setDurabilityMultiplier(this.getDurabilityMultiplier()); + result.setDurabilityMultiplier(this.getDurabilityMultiplier()); // Merge the enchantment map - property.getEnchantments().putAll(this.getEnchantments()); - return property; + result.getEnchantments().putAll(this.getEnchantments()); + return result; } } @@ -84,8 +85,10 @@ public boolean hasOverrideProperty(String toolClass) { return getOverrideProperty(toolClass) != null; } - public SimpleToolProperty getOverriddenResult(ToolProperty toolProperty, String toolClass){ - return overrideMap.getOrDefault(toolClass, new OverrideToolProperty()).override((SimpleToolProperty) toolProperty); + public SimpleToolProperty getOverriddenResult(String toolClass, @Nullable ToolProperty toolProperty) { + if (toolProperty == null) toolProperty = new ToolProperty(); + return overrideMap.getOrDefault(toolClass, new OverrideToolProperty()) + .override(toolProperty); } @Override @@ -94,52 +97,67 @@ public void verifyProperty(MaterialProperties properties) { // If they are overriding ToolProperty, then it is already generated. } - public static class Overrider { + public static class Builder { private final OverrideToolProperty toolProperty; - public static Overrider of() { - return new Overrider(); + public static Builder of() { + return new Builder(); + } + + public static Builder of(int durability) { + Builder builder = new Builder(); + builder.durability(durability); + return builder; } - public static Overrider of(float harvestSpeed, float attackDamage, int durability) { - Overrider overrider = new Overrider(); - overrider.harvestSpeed(harvestSpeed).attackDamage(attackDamage).durability(durability); - return overrider; + public static Builder of(float harvestSpeed, float attackDamage, int durability, int harvestLevel) { + Builder builder = new Builder(); + builder.harvestSpeed(harvestSpeed).attackDamage(attackDamage).durability(durability).harvestLevel(harvestLevel); + return builder; } - public Overrider() { + public Builder() { this.toolProperty = new OverrideToolProperty(); } - public Overrider harvestSpeed(float harvestSpeed) { + public Builder harvestSpeed(float harvestSpeed) { toolProperty.setToolSpeed(harvestSpeed); return this; } - public Overrider attackDamage(float attackDamage) { + public Builder attackDamage(float attackDamage) { toolProperty.setToolAttackDamage(attackDamage); return this; } - public Overrider durability(int durability) { + public Builder durability(int durability) { toolProperty.setToolDurability(durability); return this; } - public Overrider attackSpeed(float attackSpeed) { + public Builder attackSpeed(float attackSpeed) { toolProperty.setToolAttackSpeed(attackSpeed); return this; } - public Overrider enchantment(Enchantment enchantment, int level) { + public Builder harvestLevel(int harvestLevel) { + toolProperty.setToolHarvestLevel(harvestLevel); + return this; + } + + public Builder enchantment(Enchantment enchantment, int level) { toolProperty.addEnchantmentForTools(enchantment, level); return this; } - public Overrider durabilityMultiplier(int multiplier) { + public Builder durabilityMultiplier(int multiplier) { toolProperty.setDurabilityMultiplier(multiplier); return this; } + + public OverrideToolProperty build() { + return this.toolProperty; + } } } diff --git a/src/main/java/gregtech/asm/hooks/RecipeRepairItemHooks.java b/src/main/java/gregtech/asm/hooks/RecipeRepairItemHooks.java index a00ec3da35a..7956c412a68 100644 --- a/src/main/java/gregtech/asm/hooks/RecipeRepairItemHooks.java +++ b/src/main/java/gregtech/asm/hooks/RecipeRepairItemHooks.java @@ -96,7 +96,7 @@ public static ItemStack getCraftingResult(InventoryCrafting inv) { // two GT tools, so use own logic to produce the correct output IGTTool tool = (IGTTool) first.getItem(); - ItemStack output = tool.get(tool.getToolMaterial(first), first); + ItemStack output = tool.get(tool.getToolMaterial(first)); NBTTagCompound outputTag = ToolHelper.getToolTag(output); outputTag.setInteger(ToolHelper.DURABILITY_KEY, i1); diff --git a/src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java b/src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java index 461a5216a16..5cd275b6cf8 100644 --- a/src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java +++ b/src/main/java/gregtech/mixins/minecraft/RecipeRepairItemMixin.java @@ -76,7 +76,7 @@ public class RecipeRepairItemMixin { if (itemstack2.getItemDamage() == 0 && itemstack3.getItemDamage() == 0) { return ItemStack.EMPTY; } else { - ItemStack output = first.get(first.getToolMaterial(itemstack2), itemstack2); + ItemStack output = first.get(first.getToolMaterial(itemstack2)); NBTTagCompound outputTag = ToolHelper.getToolTag(output); outputTag.setInteger(ToolHelper.DURABILITY_KEY, itemDamage); return output; From 05e56fcbc575ba6b351be27d948ac4f1f2b8eeca Mon Sep 17 00:00:00 2001 From: LittleCube Date: Wed, 1 Jan 2025 17:13:38 +0800 Subject: [PATCH 04/11] Integrated soft tools using the new ExtraToolProperty --- .../gregtech/api/items/toolitem/IGTTool.java | 96 +++++++++---------- .../api/unification/material/Materials.java | 3 + .../material/materials/SoftToolAddition.java | 42 ++++++++ .../recipe/handlers/ToolRecipeHandler.java | 20 ++-- 4 files changed, 95 insertions(+), 66 deletions(-) create mode 100644 src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java diff --git a/src/main/java/gregtech/api/items/toolitem/IGTTool.java b/src/main/java/gregtech/api/items/toolitem/IGTTool.java index 0b891ee8816..713a7b90af7 100644 --- a/src/main/java/gregtech/api/items/toolitem/IGTTool.java +++ b/src/main/java/gregtech/api/items/toolitem/IGTTool.java @@ -20,6 +20,7 @@ import gregtech.api.unification.material.Materials; import gregtech.api.unification.material.properties.DustProperty; import gregtech.api.unification.material.properties.PropertyKey; +import gregtech.api.unification.material.properties.SimpleToolProperty; import gregtech.api.unification.material.properties.ToolProperty; import gregtech.api.unification.ore.OrePrefix; import gregtech.api.unification.stack.UnificationEntry; @@ -151,19 +152,16 @@ default ItemStack getRaw() { } /** - * This is a safer wrapper for materials without toolProperty properly set. In this case, the missing data is - * inferred from the referenceStack. This method supports specially made tools that is registered separately. - * - * @return A tool made from the given material + * @return A tool made from the given material. The tool property (at least overriding) for the material must be + * set. */ - default ItemStack get(Material material, ItemStack referenceStack) { + default ItemStack get(Material material) { ItemStack stack = new ItemStack(get()); NBTTagCompound stackCompound = GTUtility.getOrCreateNbtCompound(stack); stackCompound.setBoolean(DISALLOW_CONTAINER_ITEM_KEY, false); NBTTagCompound toolTag = getToolTag(stack); - NBTTagCompound referenceToolTag = getToolTag(referenceStack); IGTToolDefinition toolStats = getToolStats(); // don't show the normal vanilla damage and attack speed tooltips, @@ -177,55 +175,56 @@ default ItemStack get(Material material, ItemStack referenceStack) { AoESymmetrical aoeDefinition = getToolStats().getAoEDefinition(stack); // Set other tool stats (durability) - ToolProperty toolProperty = material.getProperty(PropertyKey.TOOL); - + System.out.println(this.getToolId()); + SimpleToolProperty finalToolProperty; + { + ToolProperty toolProperty = material.getProperty(PropertyKey.TOOL); + if (material.hasProperty(PropertyKey.EXTRATOOL)) { + System.out.println("Find Override Property!"); + System.out.println(material); + finalToolProperty = material.getProperty(PropertyKey.EXTRATOOL) + .getOverriddenResult(this.getToolId(), toolProperty); + } else { + finalToolProperty = material.getProperty(PropertyKey.TOOL); + } + } // Durability formula we are working with: // Final Durability = (material durability * material durability multiplier) + (tool definition durability * // definition durability multiplier) - 1 // Subtracts 1 internally since Minecraft treats "0" as a valid durability, but we don't want to display this. - int durability; - boolean isUnbreakable; - if (toolProperty != null) { - // Tool material modifiers. - durability = toolProperty.getToolDurability() * toolProperty.getDurabilityMultiplier(); - - // Tool type modifiers. - // Most Tool Definitions do not set a base durability, which will lead to ignoring the multiplier if present. So - // apply the multiplier to the material durability if that would happen - if (toolStats.getBaseDurability(stack) == 0) { - durability = (int) (durability * toolStats.getDurabilityMultiplier(stack)); - } else { - durability += (int) (toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack)); - } - durability--; // Adjust for MC - - // Get unbreakability - isUnbreakable = toolProperty.getUnbreakable(); - - // Set tool and material enchantments - Object2IntMap enchantments = new Object2IntOpenHashMap<>(); - toolProperty.getEnchantments().forEach((enchantment, level) -> enchantments.put(enchantment, - level.getLevel(toolProperty.getToolHarvestLevel()))); - toolStats.getDefaultEnchantments(stack).forEach((enchantment, level) -> enchantments.put(enchantment, - level.getLevel(toolProperty.getToolHarvestLevel()))); - enchantments.forEach((enchantment, level) -> { - if (stack.getItem().canApplyAtEnchantingTable(stack, enchantment)) { - stack.addEnchantment(enchantment, level); - } - }); + // Tool material modifiers. + int durability = finalToolProperty.getToolDurability() * finalToolProperty.getDurabilityMultiplier(); + + // Tool type modifiers. + // Most Tool Definitions do not set a base durability, which will lead to ignoring the multiplier if present. So + // apply the multiplier to the material durability if that would happen + if (toolStats.getBaseDurability(stack) == 0) { + durability = (int) (durability * toolStats.getDurabilityMultiplier(stack)); } else { - // In this case, simply get from the reference tool - durability = referenceToolTag.getInteger(MAX_DURABILITY_KEY); - isUnbreakable = referenceToolTag.getBoolean(UNBREAKABLE_KEY); + durability += (int) (toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack)); } - if (isUnbreakable) { - stackCompound.setBoolean(UNBREAKABLE_KEY, true); - } + durability -= 1; // Finally adjust for MC toolTag.setInteger(MAX_DURABILITY_KEY, durability); toolTag.setInteger(DURABILITY_KEY, 0); + if (finalToolProperty.getUnbreakable()) { + stackCompound.setBoolean(UNBREAKABLE_KEY, true); + } + + // Set tool and material enchantments + Object2IntMap enchantments = new Object2IntOpenHashMap<>(); + finalToolProperty.getEnchantments().forEach((enchantment, level) -> enchantments.put(enchantment, + level.getLevel(finalToolProperty.getToolHarvestLevel()))); + toolStats.getDefaultEnchantments(stack).forEach((enchantment, level) -> enchantments.put(enchantment, + level.getLevel(finalToolProperty.getToolHarvestLevel()))); + enchantments.forEach((enchantment, level) -> { + if (stack.getItem().canApplyAtEnchantingTable(stack, enchantment)) { + stack.addEnchantment(enchantment, level); + } + }); + // Set behaviours NBTTagCompound behaviourTag = getBehaviorsTag(stack); getToolStats().getBehaviors().forEach(behavior -> behavior.addBehaviorNBT(stack, behaviourTag)); @@ -239,20 +238,13 @@ default ItemStack get(Material material, ItemStack referenceStack) { behaviourTag.setInteger(AOE_LAYER_KEY, aoeDefinition.layer); } - if (toolProperty != null && toolProperty.isMagnetic()) { + if (finalToolProperty.isMagnetic()) { behaviourTag.setBoolean(RELOCATE_MINED_BLOCKS_KEY, true); } return stack; } - /** - * @return A tool made from the given material. The tool property for the material must be set. - */ - default ItemStack get(Material material) { - return get(material, ItemStack.EMPTY); - } - default ItemStack get(Material material, long defaultCharge, long defaultMaxCharge) { ItemStack stack = get(material); if (isElectric()) { diff --git a/src/main/java/gregtech/api/unification/material/Materials.java b/src/main/java/gregtech/api/unification/material/Materials.java index 30174ce8f44..086952d93d9 100644 --- a/src/main/java/gregtech/api/unification/material/Materials.java +++ b/src/main/java/gregtech/api/unification/material/Materials.java @@ -110,6 +110,9 @@ public static void register() { Materials.DyeRed, Materials.DyeBlack }; + // Register soft tools + SoftToolAddition.register(); + OrePrefix.init(); } diff --git a/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java b/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java new file mode 100644 index 00000000000..a849e4de317 --- /dev/null +++ b/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java @@ -0,0 +1,42 @@ +package gregtech.api.unification.material.materials; + +import gregtech.api.items.toolitem.ToolClasses; +import gregtech.api.recipes.ModHandler; +import gregtech.api.unification.material.properties.ExtraToolProperty; +import gregtech.api.unification.material.properties.PropertyKey; + +import gregtech.api.unification.material.Material; +import gregtech.api.unification.material.Materials; + +public class SoftToolAddition { + + public static final Material[] softMaterials = new Material[] { + Materials.Wood, Materials.Rubber, Materials.Polyethylene, + Materials.Polytetrafluoroethylene, Materials.Polybenzimidazole + }; + + private static ExtraToolProperty ensureExtraToolProperty(Material material) { + if (material.getProperty(PropertyKey.EXTRATOOL) == null) + material.setProperty(PropertyKey.EXTRATOOL, new ExtraToolProperty()); + return material.getProperty(PropertyKey.EXTRATOOL); + } + + + public static void register() { + for (int i = 0; i < softMaterials.length; i++) { + + Material material = softMaterials[i]; + + if (ModHandler.isMaterialWood(material)) { + ensureExtraToolProperty(material).setOverrideProperty(ToolClasses.SOFT_MALLET, + ExtraToolProperty.Builder.of(4F, 1F, 48, 1).build()); + } else { + ExtraToolProperty extraToolProperty = ensureExtraToolProperty(material); + extraToolProperty.setOverrideProperty(ToolClasses.SOFT_MALLET, + ExtraToolProperty.Builder.of(4F, 1F, 128 * (1 << i), 1).build()); + extraToolProperty.setOverrideProperty(ToolClasses.PLUNGER, + ExtraToolProperty.Builder.of(4F, 0F, 128 * (1 << i), 1).build()); + } + } + } +} diff --git a/src/main/java/gregtech/loaders/recipe/handlers/ToolRecipeHandler.java b/src/main/java/gregtech/loaders/recipe/handlers/ToolRecipeHandler.java index 1997631a38c..d84ba659893 100644 --- a/src/main/java/gregtech/loaders/recipe/handlers/ToolRecipeHandler.java +++ b/src/main/java/gregtech/loaders/recipe/handlers/ToolRecipeHandler.java @@ -5,12 +5,12 @@ import gregtech.api.capability.IElectricItem; import gregtech.api.items.metaitem.MetaItem.MetaValueItem; import gregtech.api.items.toolitem.IGTTool; -import gregtech.api.items.toolitem.ToolHelper; import gregtech.api.recipes.ModHandler; import gregtech.api.unification.OreDictUnifier; import gregtech.api.unification.material.MarkerMaterials; import gregtech.api.unification.material.Material; import gregtech.api.unification.material.Materials; +import gregtech.api.unification.material.materials.SoftToolAddition; import gregtech.api.unification.material.properties.PropertyKey; import gregtech.api.unification.material.properties.ToolProperty; import gregtech.api.unification.ore.OrePrefix; @@ -406,31 +406,23 @@ private static void registerMortarRecipes() { } private static void registerSoftToolRecipes() { - final Material[] softMaterials = new Material[] { - Materials.Wood, Materials.Rubber, Materials.Polyethylene, - Materials.Polytetrafluoroethylene, Materials.Polybenzimidazole - }; + final Material[] softMaterials = SoftToolAddition.softMaterials; final UnificationEntry stick = new UnificationEntry(OrePrefix.stick, Materials.Wood); - for (int i = 0; i < softMaterials.length; i++) { - Material material = softMaterials[i]; - + for (Material material : softMaterials) { if (ModHandler.isMaterialWood(material)) { - ModHandler.addMirroredShapedRecipe(String.format("soft_mallet_%s", material), - ToolHelper.getAndSetToolData(ToolItems.SOFT_MALLET, material, 47, 1, 4F, 1F), + addToolRecipe(material, ToolItems.SOFT_MALLET, true, "II ", "IIS", "II ", 'I', new UnificationEntry(OrePrefix.plank, material), 'S', stick); } else { - ModHandler.addMirroredShapedRecipe(String.format("soft_mallet_%s", material), - ToolHelper.getAndSetToolData(ToolItems.SOFT_MALLET, material, 128 * (1 << i) - 1, 1, 4F, 1F), + addToolRecipe(material, ToolItems.SOFT_MALLET, true, "II ", "IIS", "II ", 'I', new UnificationEntry(OrePrefix.ingot, material), 'S', stick); - ModHandler.addMirroredShapedRecipe(String.format("plunger_%s", material), - ToolHelper.getAndSetToolData(ToolItems.PLUNGER, material, 128 * (i << 1) - 1, 1, 4F, 0F), + addToolRecipe(material, ToolItems.PLUNGER, true, "xPP", " SP", "S f", 'P', new UnificationEntry(OrePrefix.plate, material), 'S', stick); From 912776525f1d1ad2ced480d1061acf9a68dc796f Mon Sep 17 00:00:00 2001 From: LittleCube Date: Wed, 1 Jan 2025 18:34:06 +0800 Subject: [PATCH 05/11] Obtain markerItem of mallets and plungers from its own get method --- src/main/java/gregtech/common/items/ToolItems.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/common/items/ToolItems.java b/src/main/java/gregtech/common/items/ToolItems.java index 5545387ef7c..d824442ff92 100644 --- a/src/main/java/gregtech/common/items/ToolItems.java +++ b/src/main/java/gregtech/common/items/ToolItems.java @@ -115,7 +115,7 @@ public static void init() { .sound(GTSoundEvents.SOFT_MALLET_TOOL) .symbol('r') .toolClasses(ToolClasses.SOFT_MALLET) - .markerItem(() -> ToolHelper.getAndSetToolData(SOFT_MALLET, Materials.Wood, 47, 1, 4F, 1F))); + .markerItem(() -> SOFT_MALLET.get(Materials.Wood))); MINING_HAMMER = register(ItemGTTool.Builder.of(GTValues.MODID, "mining_hammer") .toolStats(b -> b.blockBreaking().aoe(1, 1, 0) .efficiencyMultiplier(0.4F).attackDamage(1.5F).attackSpeed(-3.2F) @@ -321,7 +321,7 @@ public static void init() { .sound(GTSoundEvents.PLUNGER_TOOL) .oreDict(ToolOreDict.toolPlunger) .toolClasses(ToolClasses.PLUNGER) - .markerItem(() -> ToolHelper.getAndSetToolData(PLUNGER, Materials.Rubber, 255, 1, 4F, 0F))); + .markerItem(() -> PLUNGER.get(Materials.Rubber))); WIRECUTTER_LV = register(ItemGTTool.Builder.of(GTValues.MODID, "wire_cutter_lv") .toolStats(b -> b.blockBreaking().crafting().damagePerCraftingAction(4) .efficiencyMultiplier(2.0F) From 2cfcfdbb86ce117c30cc23ee1811b784817b3a32 Mon Sep 17 00:00:00 2001 From: LittleCube Date: Mon, 6 Jan 2025 20:49:48 +0800 Subject: [PATCH 06/11] Spotless formatting --- src/main/java/gregtech/api/items/toolitem/IGTTool.java | 2 +- .../unification/material/materials/SoftToolAddition.java | 6 ++---- .../unification/material/properties/ExtraToolProperty.java | 3 ++- .../api/unification/material/properties/PropertyKey.java | 3 ++- .../unification/material/properties/SimpleToolProperty.java | 4 ++-- .../api/unification/material/properties/ToolProperty.java | 6 ------ 6 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/main/java/gregtech/api/items/toolitem/IGTTool.java b/src/main/java/gregtech/api/items/toolitem/IGTTool.java index 713a7b90af7..81d5459b595 100644 --- a/src/main/java/gregtech/api/items/toolitem/IGTTool.java +++ b/src/main/java/gregtech/api/items/toolitem/IGTTool.java @@ -153,7 +153,7 @@ default ItemStack getRaw() { /** * @return A tool made from the given material. The tool property (at least overriding) for the material must be - * set. + * set. */ default ItemStack get(Material material) { ItemStack stack = new ItemStack(get()); diff --git a/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java b/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java index a849e4de317..c8672d92c89 100644 --- a/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java +++ b/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java @@ -2,11 +2,10 @@ import gregtech.api.items.toolitem.ToolClasses; import gregtech.api.recipes.ModHandler; -import gregtech.api.unification.material.properties.ExtraToolProperty; -import gregtech.api.unification.material.properties.PropertyKey; - import gregtech.api.unification.material.Material; import gregtech.api.unification.material.Materials; +import gregtech.api.unification.material.properties.ExtraToolProperty; +import gregtech.api.unification.material.properties.PropertyKey; public class SoftToolAddition { @@ -21,7 +20,6 @@ private static ExtraToolProperty ensureExtraToolProperty(Material material) { return material.getProperty(PropertyKey.EXTRATOOL); } - public static void register() { for (int i = 0; i < softMaterials.length; i++) { diff --git a/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java b/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java index ac2172cdd22..d8c6eca4872 100644 --- a/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java +++ b/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java @@ -113,7 +113,8 @@ public static Builder of(int durability) { public static Builder of(float harvestSpeed, float attackDamage, int durability, int harvestLevel) { Builder builder = new Builder(); - builder.harvestSpeed(harvestSpeed).attackDamage(attackDamage).durability(durability).harvestLevel(harvestLevel); + builder.harvestSpeed(harvestSpeed).attackDamage(attackDamage).durability(durability) + .harvestLevel(harvestLevel); return builder; } diff --git a/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java b/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java index 05e24d16651..4306d000ba7 100644 --- a/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java +++ b/src/main/java/gregtech/api/unification/material/properties/PropertyKey.java @@ -14,7 +14,8 @@ public class PropertyKey { ItemPipeProperties.class); public static final PropertyKey ORE = new PropertyKey<>("ore", OreProperty.class); public static final PropertyKey TOOL = new PropertyKey<>("tool", ToolProperty.class); - public static final PropertyKey EXTRATOOL = new PropertyKey<>("extra_tool", ExtraToolProperty.class); + public static final PropertyKey EXTRATOOL = new PropertyKey<>("extra_tool", + ExtraToolProperty.class); public static final PropertyKey ROTOR = new PropertyKey<>("rotor", RotorProperty.class); public static final PropertyKey WIRE = new PropertyKey<>("wire", WireProperties.class); public static final PropertyKey WOOD = new PropertyKey<>("wood", WoodProperty.class); diff --git a/src/main/java/gregtech/api/unification/material/properties/SimpleToolProperty.java b/src/main/java/gregtech/api/unification/material/properties/SimpleToolProperty.java index 894ad7aec50..c672f726298 100644 --- a/src/main/java/gregtech/api/unification/material/properties/SimpleToolProperty.java +++ b/src/main/java/gregtech/api/unification/material/properties/SimpleToolProperty.java @@ -2,11 +2,11 @@ import gregtech.api.items.toolitem.EnchantmentLevel; +import net.minecraft.enchantment.Enchantment; + import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; -import net.minecraft.enchantment.Enchantment; - public class SimpleToolProperty { /** diff --git a/src/main/java/gregtech/api/unification/material/properties/ToolProperty.java b/src/main/java/gregtech/api/unification/material/properties/ToolProperty.java index fefa498ac07..e1c4de1f0a0 100644 --- a/src/main/java/gregtech/api/unification/material/properties/ToolProperty.java +++ b/src/main/java/gregtech/api/unification/material/properties/ToolProperty.java @@ -2,14 +2,8 @@ import net.minecraft.enchantment.Enchantment; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.Map; - public class ToolProperty extends SimpleToolProperty implements IMaterialProperty { - public ToolProperty(float harvestSpeed, float attackDamage, int durability, int harvestLevel) { super(harvestSpeed, attackDamage, durability, harvestLevel); this.setToolEnchantability(10); From c38866d9d242c1b22cb72dfc3a4a82a9527acad7 Mon Sep 17 00:00:00 2001 From: LittleCube Date: Mon, 6 Jan 2025 21:46:11 +0800 Subject: [PATCH 07/11] Change soft tool property registration to already existing method (ensureSet) --- .../material/materials/SoftToolAddition.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java b/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java index c8672d92c89..a348ecb76ed 100644 --- a/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java +++ b/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java @@ -14,22 +14,21 @@ public class SoftToolAddition { Materials.Polytetrafluoroethylene, Materials.Polybenzimidazole }; - private static ExtraToolProperty ensureExtraToolProperty(Material material) { - if (material.getProperty(PropertyKey.EXTRATOOL) == null) - material.setProperty(PropertyKey.EXTRATOOL, new ExtraToolProperty()); - return material.getProperty(PropertyKey.EXTRATOOL); - } - public static void register() { for (int i = 0; i < softMaterials.length; i++) { Material material = softMaterials[i]; if (ModHandler.isMaterialWood(material)) { - ensureExtraToolProperty(material).setOverrideProperty(ToolClasses.SOFT_MALLET, + material.getProperties().ensureSet(PropertyKey.EXTRATOOL); + ExtraToolProperty extraToolProperty = material.getProperty(PropertyKey.EXTRATOOL); + + extraToolProperty.setOverrideProperty(ToolClasses.SOFT_MALLET, ExtraToolProperty.Builder.of(4F, 1F, 48, 1).build()); } else { - ExtraToolProperty extraToolProperty = ensureExtraToolProperty(material); + material.getProperties().ensureSet(PropertyKey.EXTRATOOL); + ExtraToolProperty extraToolProperty = material.getProperty(PropertyKey.EXTRATOOL); + extraToolProperty.setOverrideProperty(ToolClasses.SOFT_MALLET, ExtraToolProperty.Builder.of(4F, 1F, 128 * (1 << i), 1).build()); extraToolProperty.setOverrideProperty(ToolClasses.PLUNGER, From 09df4b3c432714c50bd05c9ed6b601baf92b8165 Mon Sep 17 00:00:00 2001 From: LittleCube Date: Mon, 6 Jan 2025 22:20:31 +0800 Subject: [PATCH 08/11] Remove accidentally left debugging output --- src/main/java/gregtech/api/items/toolitem/IGTTool.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/gregtech/api/items/toolitem/IGTTool.java b/src/main/java/gregtech/api/items/toolitem/IGTTool.java index 81d5459b595..ee59cd55f3d 100644 --- a/src/main/java/gregtech/api/items/toolitem/IGTTool.java +++ b/src/main/java/gregtech/api/items/toolitem/IGTTool.java @@ -175,13 +175,10 @@ default ItemStack get(Material material) { AoESymmetrical aoeDefinition = getToolStats().getAoEDefinition(stack); // Set other tool stats (durability) - System.out.println(this.getToolId()); SimpleToolProperty finalToolProperty; { ToolProperty toolProperty = material.getProperty(PropertyKey.TOOL); if (material.hasProperty(PropertyKey.EXTRATOOL)) { - System.out.println("Find Override Property!"); - System.out.println(material); finalToolProperty = material.getProperty(PropertyKey.EXTRATOOL) .getOverriddenResult(this.getToolId(), toolProperty); } else { From d61efe3ee5fe5cc89339c9bb485b111679eb8126 Mon Sep 17 00:00:00 2001 From: LittleCube Date: Mon, 6 Jan 2025 23:10:59 +0800 Subject: [PATCH 09/11] Fix many properties are not properly overridden --- .../gregtech/api/items/toolitem/IGTTool.java | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/java/gregtech/api/items/toolitem/IGTTool.java b/src/main/java/gregtech/api/items/toolitem/IGTTool.java index ee59cd55f3d..fa59429a1a5 100644 --- a/src/main/java/gregtech/api/items/toolitem/IGTTool.java +++ b/src/main/java/gregtech/api/items/toolitem/IGTTool.java @@ -175,16 +175,7 @@ default ItemStack get(Material material) { AoESymmetrical aoeDefinition = getToolStats().getAoEDefinition(stack); // Set other tool stats (durability) - SimpleToolProperty finalToolProperty; - { - ToolProperty toolProperty = material.getProperty(PropertyKey.TOOL); - if (material.hasProperty(PropertyKey.EXTRATOOL)) { - finalToolProperty = material.getProperty(PropertyKey.EXTRATOOL) - .getOverriddenResult(this.getToolId(), toolProperty); - } else { - finalToolProperty = material.getProperty(PropertyKey.TOOL); - } - } + SimpleToolProperty finalToolProperty = getToolProperty(material); // Durability formula we are working with: // Final Durability = (material durability * material durability multiplier) + (tool definition durability * // definition durability multiplier) - 1 @@ -270,8 +261,23 @@ default Material getToolMaterial(ItemStack stack) { } @Nullable - default ToolProperty getToolProperty(ItemStack stack) { - return getToolMaterial(stack).getProperty(PropertyKey.TOOL); + default SimpleToolProperty getToolProperty(Material material) { + SimpleToolProperty finalToolProperty; + { + ToolProperty toolProperty = material.getProperty(PropertyKey.TOOL); + if (material.hasProperty(PropertyKey.EXTRATOOL)) { + finalToolProperty = material.getProperty(PropertyKey.EXTRATOOL) + .getOverriddenResult(this.getToolId(), toolProperty); + } else { + finalToolProperty = toolProperty; + } + } + return finalToolProperty; + } + + @Nullable + default SimpleToolProperty getToolProperty(ItemStack stack) { + return getToolProperty(getToolMaterial(stack)); } @Nullable @@ -280,32 +286,32 @@ default DustProperty getDustProperty(ItemStack stack) { } default float getMaterialToolSpeed(ItemStack stack) { - ToolProperty toolProperty = getToolProperty(stack); + SimpleToolProperty toolProperty = getToolProperty(stack); return toolProperty == null ? 0F : toolProperty.getToolSpeed(); } default float getMaterialAttackDamage(ItemStack stack) { - ToolProperty toolProperty = getToolProperty(stack); + SimpleToolProperty toolProperty = getToolProperty(stack); return toolProperty == null ? 0F : toolProperty.getToolAttackDamage(); } default float getMaterialAttackSpeed(ItemStack stack) { - ToolProperty toolProperty = getToolProperty(stack); + SimpleToolProperty toolProperty = getToolProperty(stack); return toolProperty == null ? 0F : toolProperty.getToolAttackSpeed(); } default int getMaterialDurability(ItemStack stack) { - ToolProperty toolProperty = getToolProperty(stack); + SimpleToolProperty toolProperty = getToolProperty(stack); return toolProperty == null ? 0 : toolProperty.getToolDurability() * toolProperty.getDurabilityMultiplier(); } default int getMaterialEnchantability(ItemStack stack) { - ToolProperty toolProperty = getToolProperty(stack); + SimpleToolProperty toolProperty = getToolProperty(stack); return toolProperty == null ? 0 : toolProperty.getToolEnchantability(); } default int getMaterialHarvestLevel(ItemStack stack) { - ToolProperty toolProperty = getToolProperty(stack); + SimpleToolProperty toolProperty = getToolProperty(stack); return toolProperty == null ? 0 : toolProperty.getToolHarvestLevel(); } @@ -866,7 +872,7 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) { } } - ToolProperty property = getToolProperty(stack); + SimpleToolProperty property = getToolProperty(stack); if (property == null) return false; // Check for any special enchantments specified by the material of this Tool From 7169eb896b4c54f9fa2fee0d3440235bfba0a077 Mon Sep 17 00:00:00 2001 From: LittleCube Date: Mon, 6 Jan 2025 23:11:49 +0800 Subject: [PATCH 10/11] Add GroovyScript integration --- .../api/unification/material/Material.java | 10 ++++++++++ .../integration/groovy/GroovyExpansions.java | 11 +++++++++++ .../groovy/GroovyMaterialBuilderExpansion.java | 6 ++++++ .../integration/groovy/GroovyScriptModule.java | 2 ++ .../integration/groovy/MaterialExpansion.java | 14 ++++++++++++++ 5 files changed, 43 insertions(+) diff --git a/src/main/java/gregtech/api/unification/material/Material.java b/src/main/java/gregtech/api/unification/material/Material.java index 29c4c9fd9e4..72e3990a37d 100644 --- a/src/main/java/gregtech/api/unification/material/Material.java +++ b/src/main/java/gregtech/api/unification/material/Material.java @@ -12,6 +12,7 @@ import gregtech.api.unification.material.info.MaterialIconSet; import gregtech.api.unification.material.properties.BlastProperty; import gregtech.api.unification.material.properties.DustProperty; +import gregtech.api.unification.material.properties.ExtraToolProperty; import gregtech.api.unification.material.properties.FluidPipeProperties; import gregtech.api.unification.material.properties.FluidProperty; import gregtech.api.unification.material.properties.GemProperty; @@ -936,6 +937,15 @@ public Builder toolStats(ToolProperty toolProperty) { return this; } + /** + * Use {@link ExtraToolProperty.Builder} to create a Tool Property Override. + */ + public Builder overrideToolStats(String toolClass, ExtraToolProperty.OverrideToolProperty toolProperty) { + properties.ensureSet(PropertyKey.EXTRATOOL); + properties.getProperty(PropertyKey.EXTRATOOL).setOverrideProperty(toolClass, toolProperty); + return this; + } + public Builder rotorStats(float speed, float damage, int durability) { properties.setProperty(PropertyKey.ROTOR, new RotorProperty(speed, damage, durability)); return this; diff --git a/src/main/java/gregtech/integration/groovy/GroovyExpansions.java b/src/main/java/gregtech/integration/groovy/GroovyExpansions.java index bd7e01ca643..1a2305f09e4 100644 --- a/src/main/java/gregtech/integration/groovy/GroovyExpansions.java +++ b/src/main/java/gregtech/integration/groovy/GroovyExpansions.java @@ -7,6 +7,7 @@ import gregtech.api.unification.Elements; import gregtech.api.unification.material.Material; import gregtech.api.unification.material.event.MaterialEvent; +import gregtech.api.unification.material.properties.ExtraToolProperty; import gregtech.api.unification.material.properties.ToolProperty; import net.minecraft.util.ResourceLocation; @@ -54,6 +55,16 @@ public static ToolProperty.Builder toolBuilder(MaterialEvent event) { return toolBuilder(event, 1.0F, 1.0F, 100, 2); } + public static ExtraToolProperty.Builder overrideToolBuilder(MaterialEvent event) { + return ExtraToolProperty.Builder.of(); + } + + public static ExtraToolProperty.Builder overrideToolBuilder(MaterialEvent event, float harvestSpeed, + float attackDamage, + int durability, int harvestLevel) { + return ExtraToolProperty.Builder.of(harvestSpeed, attackDamage, durability, harvestLevel); + } + public static FluidBuilder fluidBuilder(MaterialEvent event) { return new FluidBuilder(); } diff --git a/src/main/java/gregtech/integration/groovy/GroovyMaterialBuilderExpansion.java b/src/main/java/gregtech/integration/groovy/GroovyMaterialBuilderExpansion.java index f132c8ea481..6a097d8db92 100644 --- a/src/main/java/gregtech/integration/groovy/GroovyMaterialBuilderExpansion.java +++ b/src/main/java/gregtech/integration/groovy/GroovyMaterialBuilderExpansion.java @@ -8,6 +8,7 @@ import gregtech.api.unification.material.info.MaterialFlag; import gregtech.api.unification.material.info.MaterialIconSet; import gregtech.api.unification.material.properties.BlastProperty; +import gregtech.api.unification.material.properties.ExtraToolProperty; import gregtech.api.unification.material.properties.ToolProperty; import gregtech.api.unification.stack.MaterialStack; @@ -131,4 +132,9 @@ public static Material.Builder toolStats(Material.Builder builder, float harvest int durability, int harvestLevel) { return builder.toolStats(ToolProperty.Builder.of(harvestSpeed, attackDamage, durability, harvestLevel).build()); } + + public static Material.Builder overrideToolStats(Material.Builder builder, String toolClass, + ExtraToolProperty.Builder overrideBuilder) { + return builder.overrideToolStats(toolClass, overrideBuilder.build()); + } } diff --git a/src/main/java/gregtech/integration/groovy/GroovyScriptModule.java b/src/main/java/gregtech/integration/groovy/GroovyScriptModule.java index 96aa2b92cd1..0e2f3b9e801 100644 --- a/src/main/java/gregtech/integration/groovy/GroovyScriptModule.java +++ b/src/main/java/gregtech/integration/groovy/GroovyScriptModule.java @@ -313,9 +313,11 @@ public void onCompatLoaded(GroovyContainer container) { ExpansionHelper.mixinMethod(RecipeBuilder.class, GroovyExpansions.class, "property"); ExpansionHelper.mixinMethod(MaterialEvent.class, GroovyExpansions.class, "materialBuilder"); ExpansionHelper.mixinMethod(MaterialEvent.class, GroovyExpansions.class, "toolBuilder"); + ExpansionHelper.mixinMethod(MaterialEvent.class, GroovyExpansions.class, "overrideToolBuilder"); ExpansionHelper.mixinMethod(MaterialEvent.class, GroovyExpansions.class, "fluidBuilder"); ExpansionHelper.mixinMethod(MaterialEvent.class, GroovyExpansions.class, "addElement"); ExpansionHelper.mixinMethod(PostMaterialEvent.class, GroovyExpansions.class, "toolBuilder"); + ExpansionHelper.mixinMethod(PostMaterialEvent.class, GroovyExpansions.class, "overrideToolBuilder"); ExpansionHelper.mixinMethod(PostMaterialEvent.class, GroovyExpansions.class, "fluidBuilder"); ExpansionHelper.mixinMethod(FluidBuilder.class, GroovyExpansions.class, "acidic"); } diff --git a/src/main/java/gregtech/integration/groovy/MaterialExpansion.java b/src/main/java/gregtech/integration/groovy/MaterialExpansion.java index 6d5f5e7ac2f..652277bc3e2 100644 --- a/src/main/java/gregtech/integration/groovy/MaterialExpansion.java +++ b/src/main/java/gregtech/integration/groovy/MaterialExpansion.java @@ -6,6 +6,7 @@ import gregtech.api.unification.material.info.MaterialIconSet; import gregtech.api.unification.material.properties.BlastProperty; import gregtech.api.unification.material.properties.DustProperty; +import gregtech.api.unification.material.properties.ExtraToolProperty; import gregtech.api.unification.material.properties.FluidProperty; import gregtech.api.unification.material.properties.OreProperty; import gregtech.api.unification.material.properties.PropertyKey; @@ -186,6 +187,19 @@ public static void setToolStats(Material m, float toolSpeed, float toolAttackDam } else logError(m, "change tool stats", "Tool"); } + //////////////////////////////////// + // Extra Tool Property // + //////////////////////////////////// + + public static void setOverrideToolStats(Material m, String toolClass, ExtraToolProperty.Builder overrideBuilder) { + if (checkFrozen("set overriding tool stats")) return; + m.getProperties().ensureSet(PropertyKey.EXTRATOOL); + ExtraToolProperty prop = m.getProperty(PropertyKey.EXTRATOOL); + if (prop != null) { + prop.setOverrideProperty(toolClass, overrideBuilder.build()); + } else logError(m, "change tool stats", "Tool"); + } + // Wire/Item Pipe/Fluid Pipe stuff? //////////////////////////////////// From f1237eb9db0c16371f438e34b05b1aaa77cbfe12 Mon Sep 17 00:00:00 2001 From: LittleCube Date: Tue, 7 Jan 2025 00:25:09 +0800 Subject: [PATCH 11/11] Fix misleading variable name (toolClass -> toolId) --- .../api/unification/material/Material.java | 4 ++-- .../material/properties/ExtraToolProperty.java | 16 ++++++++-------- .../groovy/GroovyMaterialBuilderExpansion.java | 4 ++-- .../integration/groovy/MaterialExpansion.java | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/gregtech/api/unification/material/Material.java b/src/main/java/gregtech/api/unification/material/Material.java index 72e3990a37d..66871358bee 100644 --- a/src/main/java/gregtech/api/unification/material/Material.java +++ b/src/main/java/gregtech/api/unification/material/Material.java @@ -940,9 +940,9 @@ public Builder toolStats(ToolProperty toolProperty) { /** * Use {@link ExtraToolProperty.Builder} to create a Tool Property Override. */ - public Builder overrideToolStats(String toolClass, ExtraToolProperty.OverrideToolProperty toolProperty) { + public Builder overrideToolStats(String toolId, ExtraToolProperty.OverrideToolProperty toolProperty) { properties.ensureSet(PropertyKey.EXTRATOOL); - properties.getProperty(PropertyKey.EXTRATOOL).setOverrideProperty(toolClass, toolProperty); + properties.getProperty(PropertyKey.EXTRATOOL).setOverrideProperty(toolId, toolProperty); return this; } diff --git a/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java b/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java index d8c6eca4872..1e7a42c6b11 100644 --- a/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java +++ b/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java @@ -72,22 +72,22 @@ public ExtraToolProperty() { this.overrideMap = new HashMap<>(); } - public void setOverrideProperty(String toolClass, OverrideToolProperty overrideProperty) { - this.overrideMap.put(toolClass, overrideProperty); + public void setOverrideProperty(String toolId, OverrideToolProperty overrideProperty) { + this.overrideMap.put(toolId, overrideProperty); } @Nullable - public OverrideToolProperty getOverrideProperty(String toolClass) { - return this.overrideMap.get(toolClass); + public OverrideToolProperty getOverrideProperty(String toolId) { + return this.overrideMap.get(toolId); } - public boolean hasOverrideProperty(String toolClass) { - return getOverrideProperty(toolClass) != null; + public boolean hasOverrideProperty(String toolId) { + return getOverrideProperty(toolId) != null; } - public SimpleToolProperty getOverriddenResult(String toolClass, @Nullable ToolProperty toolProperty) { + public SimpleToolProperty getOverriddenResult(String toolId, @Nullable ToolProperty toolProperty) { if (toolProperty == null) toolProperty = new ToolProperty(); - return overrideMap.getOrDefault(toolClass, new OverrideToolProperty()) + return overrideMap.getOrDefault(toolId, new OverrideToolProperty()) .override(toolProperty); } diff --git a/src/main/java/gregtech/integration/groovy/GroovyMaterialBuilderExpansion.java b/src/main/java/gregtech/integration/groovy/GroovyMaterialBuilderExpansion.java index 6a097d8db92..e8acd54b925 100644 --- a/src/main/java/gregtech/integration/groovy/GroovyMaterialBuilderExpansion.java +++ b/src/main/java/gregtech/integration/groovy/GroovyMaterialBuilderExpansion.java @@ -133,8 +133,8 @@ public static Material.Builder toolStats(Material.Builder builder, float harvest return builder.toolStats(ToolProperty.Builder.of(harvestSpeed, attackDamage, durability, harvestLevel).build()); } - public static Material.Builder overrideToolStats(Material.Builder builder, String toolClass, + public static Material.Builder overrideToolStats(Material.Builder builder, String toolId, ExtraToolProperty.Builder overrideBuilder) { - return builder.overrideToolStats(toolClass, overrideBuilder.build()); + return builder.overrideToolStats(toolId, overrideBuilder.build()); } } diff --git a/src/main/java/gregtech/integration/groovy/MaterialExpansion.java b/src/main/java/gregtech/integration/groovy/MaterialExpansion.java index 652277bc3e2..2e13841470d 100644 --- a/src/main/java/gregtech/integration/groovy/MaterialExpansion.java +++ b/src/main/java/gregtech/integration/groovy/MaterialExpansion.java @@ -191,12 +191,12 @@ public static void setToolStats(Material m, float toolSpeed, float toolAttackDam // Extra Tool Property // //////////////////////////////////// - public static void setOverrideToolStats(Material m, String toolClass, ExtraToolProperty.Builder overrideBuilder) { + public static void setOverrideToolStats(Material m, String toolId, ExtraToolProperty.Builder overrideBuilder) { if (checkFrozen("set overriding tool stats")) return; m.getProperties().ensureSet(PropertyKey.EXTRATOOL); ExtraToolProperty prop = m.getProperty(PropertyKey.EXTRATOOL); if (prop != null) { - prop.setOverrideProperty(toolClass, overrideBuilder.build()); + prop.setOverrideProperty(toolId, overrideBuilder.build()); } else logError(m, "change tool stats", "Tool"); }