diff --git a/src/main/java/gregtech/api/items/toolitem/IGTTool.java b/src/main/java/gregtech/api/items/toolitem/IGTTool.java index 94ae45effb9..fa59429a1a5 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; @@ -150,6 +151,10 @@ default ItemStack getRaw() { return stack; } + /** + * @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 stack = new ItemStack(get()); @@ -170,35 +175,38 @@ default ItemStack get(Material material) { AoESymmetrical aoeDefinition = getToolStats().getAoEDefinition(stack); // Set other tool stats (durability) - ToolProperty toolProperty = 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 // 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(); + // 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 *= toolStats.getDurabilityMultiplier(stack); + durability = (int) (durability * toolStats.getDurabilityMultiplier(stack)); } else { - durability += toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack); + durability += (int) (toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack)); } - toolTag.setInteger(MAX_DURABILITY_KEY, durability - 1); + durability -= 1; // Finally adjust for MC + toolTag.setInteger(MAX_DURABILITY_KEY, durability); toolTag.setInteger(DURABILITY_KEY, 0); - if (toolProperty.getUnbreakable()) { + + if (finalToolProperty.getUnbreakable()) { 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()))); + finalToolProperty.getEnchantments().forEach((enchantment, level) -> enchantments.put(enchantment, + level.getLevel(finalToolProperty.getToolHarvestLevel()))); toolStats.getDefaultEnchantments(stack).forEach((enchantment, level) -> enchantments.put(enchantment, - level.getLevel(toolProperty.getToolHarvestLevel()))); + level.getLevel(finalToolProperty.getToolHarvestLevel()))); enchantments.forEach((enchantment, level) -> { if (stack.getItem().canApplyAtEnchantingTable(stack, enchantment)) { stack.addEnchantment(enchantment, level); @@ -218,7 +226,7 @@ default ItemStack get(Material material) { behaviourTag.setInteger(AOE_LAYER_KEY, aoeDefinition.layer); } - if (toolProperty.isMagnetic()) { + if (finalToolProperty.isMagnetic()) { behaviourTag.setBoolean(RELOCATE_MINED_BLOCKS_KEY, true); } @@ -253,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 @@ -263,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(); } @@ -849,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 diff --git a/src/main/java/gregtech/api/unification/material/Material.java b/src/main/java/gregtech/api/unification/material/Material.java index 29c4c9fd9e4..66871358bee 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 toolId, ExtraToolProperty.OverrideToolProperty toolProperty) { + properties.ensureSet(PropertyKey.EXTRATOOL); + properties.getProperty(PropertyKey.EXTRATOOL).setOverrideProperty(toolId, 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/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..a348ecb76ed --- /dev/null +++ b/src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java @@ -0,0 +1,39 @@ +package gregtech.api.unification.material.materials; + +import gregtech.api.items.toolitem.ToolClasses; +import gregtech.api.recipes.ModHandler; +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 { + + public static final Material[] softMaterials = new Material[] { + Materials.Wood, Materials.Rubber, Materials.Polyethylene, + Materials.Polytetrafluoroethylene, Materials.Polybenzimidazole + }; + + public static void register() { + for (int i = 0; i < softMaterials.length; i++) { + + Material material = softMaterials[i]; + + if (ModHandler.isMaterialWood(material)) { + 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 { + 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, + ExtraToolProperty.Builder.of(4F, 0F, 128 * (1 << i), 1).build()); + } + } + } +} 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..1e7a42c6b11 --- /dev/null +++ b/src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java @@ -0,0 +1,164 @@ +package gregtech.api.unification.material.properties; + +import net.minecraft.enchantment.Enchantment; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +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); + this.setToolHarvestLevel(-1); + this.setToolEnchantability(-1); + this.setDurabilityMultiplier(-1); + } + + // It does not make much sense to set these overrides: + public void setShouldIgnoreCraftingTools(boolean ignore) { + throw new UnsupportedOperationException(); + } + + public void setUnbreakable(boolean isUnbreakable) { + throw new UnsupportedOperationException(); + } + + public boolean isMagnetic() { + throw new UnsupportedOperationException(); + } + + 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())) + result.setToolSpeed(this.getToolSpeed()); + if (!Float.isNaN(this.getToolAttackSpeed())) + result.setToolAttackSpeed(this.getToolAttackSpeed()); + if (!Float.isNaN(this.getToolAttackDamage())) + result.setToolAttackDamage(this.getToolAttackDamage()); + + // Set the integer fields + if (this.getToolDurability() != -1) + result.setToolDurability(this.getToolDurability()); + if (this.getToolHarvestLevel() != -1) + result.setToolHarvestLevel(this.getToolHarvestLevel()); + if (this.getToolEnchantability() != -1) + result.setToolEnchantability(this.getToolEnchantability()); + if (this.getDurabilityMultiplier() != -1) + result.setDurabilityMultiplier(this.getDurabilityMultiplier()); + + // Merge the enchantment map + result.getEnchantments().putAll(this.getEnchantments()); + return result; + } + } + + public ExtraToolProperty() { + this.overrideMap = new HashMap<>(); + } + + public void setOverrideProperty(String toolId, OverrideToolProperty overrideProperty) { + this.overrideMap.put(toolId, overrideProperty); + } + + @Nullable + public OverrideToolProperty getOverrideProperty(String toolId) { + return this.overrideMap.get(toolId); + } + + public boolean hasOverrideProperty(String toolId) { + return getOverrideProperty(toolId) != null; + } + + public SimpleToolProperty getOverriddenResult(String toolId, @Nullable ToolProperty toolProperty) { + if (toolProperty == null) toolProperty = new ToolProperty(); + return overrideMap.getOrDefault(toolId, new OverrideToolProperty()) + .override(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 Builder { + + private final OverrideToolProperty toolProperty; + + public static Builder of() { + return new Builder(); + } + + public static Builder of(int durability) { + Builder builder = new Builder(); + builder.durability(durability); + return builder; + } + + 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 Builder() { + this.toolProperty = new OverrideToolProperty(); + } + + public Builder harvestSpeed(float harvestSpeed) { + toolProperty.setToolSpeed(harvestSpeed); + return this; + } + + public Builder attackDamage(float attackDamage) { + toolProperty.setToolAttackDamage(attackDamage); + return this; + } + + public Builder durability(int durability) { + toolProperty.setToolDurability(durability); + return this; + } + + public Builder attackSpeed(float attackSpeed) { + toolProperty.setToolAttackSpeed(attackSpeed); + return this; + } + + public Builder harvestLevel(int harvestLevel) { + toolProperty.setToolHarvestLevel(harvestLevel); + return this; + } + + public Builder enchantment(Enchantment enchantment, int level) { + toolProperty.addEnchantmentForTools(enchantment, level); + return this; + } + + public Builder durabilityMultiplier(int multiplier) { + toolProperty.setDurabilityMultiplier(multiplier); + return this; + } + + public OverrideToolProperty build() { + return this.toolProperty; + } + } +} 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..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,6 +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 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..c672f726298 --- /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 net.minecraft.enchantment.Enchantment; + +import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; + +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..e1c4de1f0a0 100644 --- a/src/main/java/gregtech/api/unification/material/properties/ToolProperty.java +++ b/src/main/java/gregtech/api/unification/material/properties/ToolProperty.java @@ -1,191 +1,24 @@ 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 class ToolProperty extends SimpleToolProperty implements IMaterialProperty { public ToolProperty(float harvestSpeed, float attackDamage, int durability, int harvestLevel) { - this.harvestSpeed = harvestSpeed; - this.attackDamage = attackDamage; - this.durability = durability; - this.harvestLevel = harvestLevel; + super(harvestSpeed, attackDamage, durability, harvestLevel); + this.setToolEnchantability(10); + this.setDurabilityMultiplier(1); } 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; - } - - 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; - } - @Override 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; 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) 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..e8acd54b925 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 toolId, + ExtraToolProperty.Builder overrideBuilder) { + return builder.overrideToolStats(toolId, 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..2e13841470d 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 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(toolId, overrideBuilder.build()); + } else logError(m, "change tool stats", "Tool"); + } + // Wire/Item Pipe/Fluid Pipe stuff? //////////////////////////////////// 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);