From 849019c24f8e692a1f78555960636657d2ec5973 Mon Sep 17 00:00:00 2001 From: DStrand1 Date: Sat, 7 Aug 2021 22:11:02 -0500 Subject: [PATCH] fix GT tools not working for some mod actions --- .../gregtech/api/items/toolitem/IToolStats.java | 11 ++++++++++- .../gregtech/api/items/toolitem/ToolMetaItem.java | 11 ++++++++++- src/main/java/gregtech/common/tools/ToolAxe.java | 10 ++++++++++ .../java/gregtech/common/tools/ToolCrowbar.java | 10 ++++++++++ src/main/java/gregtech/common/tools/ToolFile.java | 9 +++++++++ .../java/gregtech/common/tools/ToolHardHammer.java | 11 +++++++++++ src/main/java/gregtech/common/tools/ToolHoe.java | 9 +++++++++ .../java/gregtech/common/tools/ToolJackHammer.java | 13 ++++++++++--- .../java/gregtech/common/tools/ToolPickaxe.java | 9 +++++++++ src/main/java/gregtech/common/tools/ToolSaw.java | 11 +++++++++++ src/main/java/gregtech/common/tools/ToolScoop.java | 9 +++++++++ .../java/gregtech/common/tools/ToolScrewdriver.java | 10 ++++++++++ src/main/java/gregtech/common/tools/ToolShovel.java | 9 +++++++++ src/main/java/gregtech/common/tools/ToolSword.java | 9 +++++++++ .../gregtech/common/tools/ToolUniversalSpade.java | 11 +++++++++++ .../java/gregtech/common/tools/ToolWireCutter.java | 9 +++++++++ src/main/java/gregtech/common/tools/ToolWrench.java | 12 +++++++++++- 17 files changed, 167 insertions(+), 6 deletions(-) diff --git a/src/main/java/gregtech/api/items/toolitem/IToolStats.java b/src/main/java/gregtech/api/items/toolitem/IToolStats.java index 9993fa1081..4045f2bbe1 100644 --- a/src/main/java/gregtech/api/items/toolitem/IToolStats.java +++ b/src/main/java/gregtech/api/items/toolitem/IToolStats.java @@ -14,6 +14,7 @@ import java.util.Collections; import java.util.List; +import java.util.Set; /** * The Stats for GT Tools. Not including any Material Modifiers. @@ -161,4 +162,12 @@ default int getColor(ItemStack stack, int tintIndex) { SolidMaterial primaryMaterial = ToolMetaItem.getToolMaterial(stack); return tintIndex % 2 == 1 ? primaryMaterial.materialRGB : 0xFFFFFF; } -} \ No newline at end of file + + /** + * @return The MC tool classes for cross-mod compatibility. + * Default: no tool classes. + */ + default Set getToolClasses(ItemStack stack) { + return Collections.emptySet(); + } +} diff --git a/src/main/java/gregtech/api/items/toolitem/ToolMetaItem.java b/src/main/java/gregtech/api/items/toolitem/ToolMetaItem.java index ebb4ccc9fb..7570e657a6 100755 --- a/src/main/java/gregtech/api/items/toolitem/ToolMetaItem.java +++ b/src/main/java/gregtech/api/items/toolitem/ToolMetaItem.java @@ -761,7 +761,16 @@ private Map bakeEnchantmentsMap(ItemStack itemStack, Colle enchantments.keySet().removeIf(enchantment -> !enchantment.canApply(itemStack)); return enchantments; } - } + @Override + @Nonnull + public Set getToolClasses(@Nonnull ItemStack stack) { + T metaToolValueItem = getItem(stack); + if (metaToolValueItem != null) { + IToolStats toolStats = metaToolValueItem.getToolStats(); + return toolStats.getToolClasses(stack); + } + return Collections.emptySet(); + } } diff --git a/src/main/java/gregtech/common/tools/ToolAxe.java b/src/main/java/gregtech/common/tools/ToolAxe.java index ec0284c719..d92d7dfc0f 100644 --- a/src/main/java/gregtech/common/tools/ToolAxe.java +++ b/src/main/java/gregtech/common/tools/ToolAxe.java @@ -8,8 +8,13 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; +import java.util.Collections; +import java.util.Set; + public class ToolAxe extends ToolBase { + private static final Set AXE_TOOL_CLASSES = Collections.singleton("axe"); + @Override public boolean canApplyEnchantment(ItemStack stack, Enchantment enchantment) { return enchantment.type.canEnchantItem(Items.IRON_AXE); @@ -59,4 +64,9 @@ public boolean onBlockPreBreak(ItemStack stack, BlockPos blockPos, EntityPlayer } return false; } + + @Override + public Set getToolClasses(ItemStack stack) { + return AXE_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolCrowbar.java b/src/main/java/gregtech/common/tools/ToolCrowbar.java index 2e840688ba..f875d0aeb0 100644 --- a/src/main/java/gregtech/common/tools/ToolCrowbar.java +++ b/src/main/java/gregtech/common/tools/ToolCrowbar.java @@ -6,8 +6,13 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; +import java.util.Collections; +import java.util.Set; + public class ToolCrowbar extends ToolBase { + private static final Set CROWBAR_TOOL_CLASSES = Collections.singleton("crowbar"); + @Override public int getToolDamagePerBlockBreak(ItemStack stack) { return 1; @@ -39,4 +44,9 @@ public boolean canMineBlock(IBlockState block, ItemStack stack) { return (tool != null && tool.equals("crowbar")) || block.getMaterial() == Material.CIRCUITS; } + + @Override + public Set getToolClasses(ItemStack stack) { + return CROWBAR_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolFile.java b/src/main/java/gregtech/common/tools/ToolFile.java index e866c426e4..49b1e59438 100644 --- a/src/main/java/gregtech/common/tools/ToolFile.java +++ b/src/main/java/gregtech/common/tools/ToolFile.java @@ -4,8 +4,13 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; +import java.util.Collections; +import java.util.Set; + public class ToolFile extends ToolBase { + private static final Set FILE_TOOL_CLASSES = Collections.singleton("file"); + @Override public int getToolDamagePerBlockBreak(ItemStack stack) { return 1; @@ -28,4 +33,8 @@ public boolean canMineBlock(IBlockState block, ItemStack stack) { block.getMaterial() == Material.CIRCUITS; } + @Override + public Set getToolClasses(ItemStack stack) { + return FILE_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolHardHammer.java b/src/main/java/gregtech/common/tools/ToolHardHammer.java index c09ae3e32a..f6fb0cd133 100644 --- a/src/main/java/gregtech/common/tools/ToolHardHammer.java +++ b/src/main/java/gregtech/common/tools/ToolHardHammer.java @@ -15,10 +15,16 @@ import net.minecraft.world.World; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class ToolHardHammer extends ToolBase { + private static final Set HAMMER_TOOL_CLASSES = new HashSet() {{ + add("hammer"); add("pickaxe"); + }}; + @Override public boolean canApplyEnchantment(ItemStack stack, Enchantment enchantment) { return enchantment.type.canEnchantItem(Items.IRON_PICKAXE); @@ -87,4 +93,9 @@ public void convertBlockDrops(World world, BlockPos blockPos, IBlockState blockS public void addInformation(ItemStack stack, List lines, boolean isAdvanced) { lines.add(I18n.format("metaitem.tool.tooltip.hammer.extra_drop")); } + + @Override + public Set getToolClasses(ItemStack stack) { + return HAMMER_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolHoe.java b/src/main/java/gregtech/common/tools/ToolHoe.java index 7ae8e2b80b..6c53f84bc7 100644 --- a/src/main/java/gregtech/common/tools/ToolHoe.java +++ b/src/main/java/gregtech/common/tools/ToolHoe.java @@ -6,8 +6,13 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; +import java.util.Collections; +import java.util.Set; + public class ToolHoe extends ToolBase { + private static final Set HOE_TOOL_CLASSES = Collections.singleton("hoe"); + @Override public int getToolDamagePerBlockBreak(ItemStack stack) { return 1; @@ -30,4 +35,8 @@ public void onStatsAddedToTool(MetaValueItem item) { item.addComponents(new HoeBehaviour(DamageValues.DAMAGE_FOR_HOE)); } + @Override + public Set getToolClasses(ItemStack stack) { + return HOE_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolJackHammer.java b/src/main/java/gregtech/common/tools/ToolJackHammer.java index beb3cc1496..2360da823a 100644 --- a/src/main/java/gregtech/common/tools/ToolJackHammer.java +++ b/src/main/java/gregtech/common/tools/ToolJackHammer.java @@ -21,12 +21,14 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; public class ToolJackHammer extends ToolDrillLV { + private static final Set HAMMER_TOOL_CLASSES = new HashSet() {{ + add("pickaxe"); add("hammer"); + }}; + private static final ModeSwitchBehavior MODE_SWITCH_BEHAVIOR = new ModeSwitchBehavior<>(JackHammerMode.class); public enum JackHammerMode implements ILocalizationKey { @@ -202,4 +204,9 @@ private static BlockPos rotateVertical(BlockPos origin, int x, int y, EnumFacing default: return BlockPos.ORIGIN; } } + + @Override + public Set getToolClasses(ItemStack stack) { + return HAMMER_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolPickaxe.java b/src/main/java/gregtech/common/tools/ToolPickaxe.java index f7c3f14670..e2a07a3189 100644 --- a/src/main/java/gregtech/common/tools/ToolPickaxe.java +++ b/src/main/java/gregtech/common/tools/ToolPickaxe.java @@ -6,8 +6,13 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import java.util.Collections; +import java.util.Set; + public class ToolPickaxe extends ToolBase { + private static final Set PICK_TOOL_CLASSES = Collections.singleton("pickaxe"); + @Override public boolean canApplyEnchantment(ItemStack stack, Enchantment enchantment) { return enchantment.type.canEnchantItem(Items.IRON_PICKAXE); @@ -38,4 +43,8 @@ public boolean canMineBlock(IBlockState block, ItemStack stack) { block.getMaterial() == Material.GLASS; } + @Override + public Set getToolClasses(ItemStack stack) { + return PICK_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolSaw.java b/src/main/java/gregtech/common/tools/ToolSaw.java index 931731f8d7..ccc3a88cbe 100644 --- a/src/main/java/gregtech/common/tools/ToolSaw.java +++ b/src/main/java/gregtech/common/tools/ToolSaw.java @@ -20,10 +20,16 @@ import gregtech.api.items.toolitem.ToolMetaItem; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class ToolSaw extends ToolBase { + private static final Set SAW_TOOL_CLASSES = new HashSet() {{ + add("axe"); add("saw"); + }}; + @Override public boolean canApplyEnchantment(ItemStack stack, Enchantment enchantment) { return enchantment.type.canEnchantItem(Items.IRON_AXE); @@ -82,6 +88,11 @@ public void convertBlockDrops(World world, BlockPos blockPos, IBlockState blockS } } + @Override + public Set getToolClasses(ItemStack stack) { + return SAW_TOOL_CLASSES; + } + /** * Added to the world event listeners to hopefully catch and revert the ice-to-water conversion. * diff --git a/src/main/java/gregtech/common/tools/ToolScoop.java b/src/main/java/gregtech/common/tools/ToolScoop.java index 1133787cdb..1c5c95214b 100644 --- a/src/main/java/gregtech/common/tools/ToolScoop.java +++ b/src/main/java/gregtech/common/tools/ToolScoop.java @@ -5,8 +5,13 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; +import java.util.Collections; +import java.util.Set; + public class ToolScoop extends ToolBase { + private static final Set SCOOP_TOOL_CLASSES = Collections.singleton("scoop"); + @Override public int getToolDamagePerBlockBreak(ItemStack stack) { return 2; @@ -23,4 +28,8 @@ public void onStatsAddedToTool(MetaValueItem item) { item.addComponents(new ScoopBehaviour(DamageValues.DAMAGE_FOR_SCOOP)); } + @Override + public Set getToolClasses(ItemStack stack) { + return SCOOP_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolScrewdriver.java b/src/main/java/gregtech/common/tools/ToolScrewdriver.java index 175f3f041e..bdf320367b 100644 --- a/src/main/java/gregtech/common/tools/ToolScrewdriver.java +++ b/src/main/java/gregtech/common/tools/ToolScrewdriver.java @@ -5,8 +5,13 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; +import java.util.Collections; +import java.util.Set; + public class ToolScrewdriver extends ToolBase { + private static final Set DRIVER_TOOL_CLASSES = Collections.singleton("screwdriver"); + @Override public float getNormalDamageBonus(EntityLivingBase entity, ItemStack stack, EntityLivingBase attacker) { String name = entity.getClass().getName(); @@ -35,4 +40,9 @@ public boolean canMineBlock(IBlockState block, ItemStack stack) { return (tool != null && tool.equals("screwdriver")) || block.getMaterial() == Material.CIRCUITS; } + + @Override + public Set getToolClasses(ItemStack stack) { + return DRIVER_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolShovel.java b/src/main/java/gregtech/common/tools/ToolShovel.java index 98e4f1107e..52aa1c525f 100644 --- a/src/main/java/gregtech/common/tools/ToolShovel.java +++ b/src/main/java/gregtech/common/tools/ToolShovel.java @@ -6,8 +6,13 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import java.util.Collections; +import java.util.Set; + public class ToolShovel extends ToolBase { + private static final Set SHOVEL_TOOL_CLASSES = Collections.singleton("shovel"); + @Override public boolean canApplyEnchantment(ItemStack stack, Enchantment enchantment) { return enchantment.type.canEnchantItem(Items.IRON_SHOVEL); @@ -44,4 +49,8 @@ public boolean canMineBlock(IBlockState block, ItemStack stack) { block.getMaterial() == Material.CLAY; } + @Override + public Set getToolClasses(ItemStack stack) { + return SHOVEL_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolSword.java b/src/main/java/gregtech/common/tools/ToolSword.java index 38ece2b1ee..97a99b128b 100644 --- a/src/main/java/gregtech/common/tools/ToolSword.java +++ b/src/main/java/gregtech/common/tools/ToolSword.java @@ -6,8 +6,13 @@ import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import java.util.Collections; +import java.util.Set; + public class ToolSword extends ToolBase { + private static final Set SWORD_TOOL_CLASSES = Collections.singleton("sword"); + @Override public boolean canApplyEnchantment(ItemStack stack, Enchantment enchantment) { return enchantment.type.canEnchantItem(Items.IRON_SWORD); @@ -60,4 +65,8 @@ public boolean canMineBlock(IBlockState block, ItemStack stack) { block.getMaterial() == Material.SPONGE; } + @Override + public Set getToolClasses(ItemStack stack) { + return SWORD_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolUniversalSpade.java b/src/main/java/gregtech/common/tools/ToolUniversalSpade.java index fa2badaa9e..4af0c2613d 100644 --- a/src/main/java/gregtech/common/tools/ToolUniversalSpade.java +++ b/src/main/java/gregtech/common/tools/ToolUniversalSpade.java @@ -6,8 +6,15 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; +import java.util.HashSet; +import java.util.Set; + public class ToolUniversalSpade extends ToolBase { + private static final Set SPADE_TOOL_CLASSES = new HashSet() {{ + add("shovel"); add("axe"); add("saw"); add("sword"); add("crowbar"); + }}; + @Override public int getToolDamagePerBlockBreak(ItemStack stack) { return 1; @@ -67,4 +74,8 @@ public void onStatsAddedToTool(MetaValueItem item) { item.addComponents(new CrowbarBehaviour(DamageValues.DAMAGE_FOR_UNIVERSAL_SPADE)); } + @Override + public Set getToolClasses(ItemStack stack) { + return SPADE_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolWireCutter.java b/src/main/java/gregtech/common/tools/ToolWireCutter.java index 3b305d112b..48e8c73daf 100644 --- a/src/main/java/gregtech/common/tools/ToolWireCutter.java +++ b/src/main/java/gregtech/common/tools/ToolWireCutter.java @@ -3,8 +3,13 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; +import java.util.Collections; +import java.util.Set; + public class ToolWireCutter extends ToolBase { + private static final Set CUTTER_TOOL_CLASSES = Collections.singleton("cutter"); + @Override public int getToolDamagePerBlockBreak(ItemStack stack) { return 1; @@ -26,4 +31,8 @@ public boolean canMineBlock(IBlockState block, ItemStack stack) { return tool != null && tool.equals("cutter"); } + @Override + public Set getToolClasses(ItemStack stack) { + return CUTTER_TOOL_CLASSES; + } } diff --git a/src/main/java/gregtech/common/tools/ToolWrench.java b/src/main/java/gregtech/common/tools/ToolWrench.java index 25fbbebbb0..7273be0f16 100644 --- a/src/main/java/gregtech/common/tools/ToolWrench.java +++ b/src/main/java/gregtech/common/tools/ToolWrench.java @@ -9,8 +9,13 @@ import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import java.util.Collections; +import java.util.Set; + public class ToolWrench extends ToolBase { + private static final Set WRENCH_TOOL_CLASSES = Collections.singleton("wrench"); + @Override public float getNormalDamageBonus(EntityLivingBase entity, ItemStack stack, EntityLivingBase attacker) { String name = entity.getClass().getName(); @@ -44,4 +49,9 @@ public boolean canMineBlock(IBlockState blockState, ItemStack stack) { public void onStatsAddedToTool(MetaValueItem item) { item.addComponents(new WrenchBehaviour(DamageValues.DAMAGE_FOR_WRENCH)); } -} \ No newline at end of file + + @Override + public Set getToolClasses(ItemStack stack) { + return WRENCH_TOOL_CLASSES; + } +}