From d1a5619d58cc4d0046c4e3edef3f353317eaaf8b Mon Sep 17 00:00:00 2001 From: DStrand1 Date: Tue, 10 Aug 2021 23:58:21 -0500 Subject: [PATCH] clean up tool classes impl --- src/main/java/gregtech/common/tools/ToolAxe.java | 2 +- .../java/gregtech/common/tools/ToolCrowbar.java | 2 +- .../java/gregtech/common/tools/ToolFile.java | 2 +- .../gregtech/common/tools/ToolHardHammer.java | 9 +++------ src/main/java/gregtech/common/tools/ToolHoe.java | 2 +- .../gregtech/common/tools/ToolMiningHammer.java | 8 +++----- .../java/gregtech/common/tools/ToolPickaxe.java | 2 +- src/main/java/gregtech/common/tools/ToolSaw.java | 9 +++------ .../java/gregtech/common/tools/ToolScoop.java | 2 +- .../gregtech/common/tools/ToolScrewdriver.java | 2 +- .../java/gregtech/common/tools/ToolShovel.java | 2 +- .../java/gregtech/common/tools/ToolSword.java | 2 +- .../common/tools/ToolUniversalSpade.java | 16 +++------------- .../gregtech/common/tools/ToolWireCutter.java | 2 +- .../java/gregtech/common/tools/ToolWrench.java | 2 +- 15 files changed, 23 insertions(+), 41 deletions(-) diff --git a/src/main/java/gregtech/common/tools/ToolAxe.java b/src/main/java/gregtech/common/tools/ToolAxe.java index d1a3f0f6cb0..d1c373afb9e 100644 --- a/src/main/java/gregtech/common/tools/ToolAxe.java +++ b/src/main/java/gregtech/common/tools/ToolAxe.java @@ -53,7 +53,7 @@ public float getAttackSpeed(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return (tool != null && tool.equals("axe")) || + return (tool != null && AXE_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.WOOD; } diff --git a/src/main/java/gregtech/common/tools/ToolCrowbar.java b/src/main/java/gregtech/common/tools/ToolCrowbar.java index 7f4bd1a6ed0..902cad98cf5 100644 --- a/src/main/java/gregtech/common/tools/ToolCrowbar.java +++ b/src/main/java/gregtech/common/tools/ToolCrowbar.java @@ -41,7 +41,7 @@ public void onStatsAddedToTool(MetaValueItem item) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return (tool != null && tool.equals("crowbar")) || + return (tool != null && CROWBAR_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.CIRCUITS; } diff --git a/src/main/java/gregtech/common/tools/ToolFile.java b/src/main/java/gregtech/common/tools/ToolFile.java index cd0e5eb7d4d..7346e72760a 100644 --- a/src/main/java/gregtech/common/tools/ToolFile.java +++ b/src/main/java/gregtech/common/tools/ToolFile.java @@ -29,7 +29,7 @@ public float getBaseDamage(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return (tool != null && tool.equals("file")) || + return (tool != null && FILE_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.CIRCUITS; } diff --git a/src/main/java/gregtech/common/tools/ToolHardHammer.java b/src/main/java/gregtech/common/tools/ToolHardHammer.java index 811877422b5..4dfe1db1116 100644 --- a/src/main/java/gregtech/common/tools/ToolHardHammer.java +++ b/src/main/java/gregtech/common/tools/ToolHardHammer.java @@ -1,5 +1,6 @@ package gregtech.common.tools; +import com.google.common.collect.ImmutableSet; import gregtech.api.recipes.MatchingMode; import gregtech.api.recipes.RecipeMaps; import net.minecraft.block.material.Material; @@ -16,16 +17,12 @@ 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"); - }}; + private static final Set HAMMER_TOOL_CLASSES = ImmutableSet.of("hammer", "pickaxe"); @Override public boolean canApplyEnchantment(ItemStack stack, Enchantment enchantment) { @@ -78,7 +75,7 @@ public float getAttackSpeed(ItemStack stack) { public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); ItemStack itemStack = new ItemStack(block.getBlock(), 1, block.getBlock().getMetaFromState(block)); - return (tool != null && (tool.equals("hammer") || tool.equals("pickaxe"))) || + return (tool != null && HAMMER_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.ROCK || block.getMaterial() == Material.GLASS || block.getMaterial() == Material.ICE || diff --git a/src/main/java/gregtech/common/tools/ToolHoe.java b/src/main/java/gregtech/common/tools/ToolHoe.java index c05261643b5..f0cbff2fb1c 100644 --- a/src/main/java/gregtech/common/tools/ToolHoe.java +++ b/src/main/java/gregtech/common/tools/ToolHoe.java @@ -26,7 +26,7 @@ public float getBaseDamage(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return (tool != null && tool.equals("hoe")) || + return (tool != null && HOE_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.GROUND; } diff --git a/src/main/java/gregtech/common/tools/ToolMiningHammer.java b/src/main/java/gregtech/common/tools/ToolMiningHammer.java index fc5cb42a4ba..71aff587583 100644 --- a/src/main/java/gregtech/common/tools/ToolMiningHammer.java +++ b/src/main/java/gregtech/common/tools/ToolMiningHammer.java @@ -1,5 +1,6 @@ package gregtech.common.tools; +import com.google.common.collect.ImmutableSet; import gregtech.api.items.toolitem.ToolMetaItem; import gregtech.api.util.GTUtility; import gregtech.common.items.behaviors.ModeSwitchBehavior; @@ -20,10 +21,7 @@ public class ToolMiningHammer extends ToolBase { - private static final Set HAMMER_TOOL_CLASSES = new HashSet() {{ - add("pickaxe"); - add("hammer"); - }}; + private static final Set HAMMER_TOOL_CLASSES = ImmutableSet.of("pickaxe", "hammer"); public enum MiningHammerMode implements ModeSwitchBehavior.ILocalizationKey { THREE_BY_THREE("metaitem.drill.mode.three_by_three", 3, 3, 0.75f), @@ -89,7 +87,7 @@ public float getMaxDurabilityMultiplier(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return (tool != null && (tool.equals("hammer") || tool.equals("pickaxe"))) || + return (tool != null && HAMMER_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.ROCK || block.getMaterial() == Material.GLASS || block.getMaterial() == Material.ICE || diff --git a/src/main/java/gregtech/common/tools/ToolPickaxe.java b/src/main/java/gregtech/common/tools/ToolPickaxe.java index 947d4c9126f..7ea64387c49 100644 --- a/src/main/java/gregtech/common/tools/ToolPickaxe.java +++ b/src/main/java/gregtech/common/tools/ToolPickaxe.java @@ -36,7 +36,7 @@ public float getDigSpeedMultiplier(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return (tool != null && tool.equals("pickaxe")) || + return (tool != null && PICK_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.ROCK || block.getMaterial() == Material.IRON || block.getMaterial() == Material.ANVIL || diff --git a/src/main/java/gregtech/common/tools/ToolSaw.java b/src/main/java/gregtech/common/tools/ToolSaw.java index a5ab1cb7ee3..0aa85345053 100644 --- a/src/main/java/gregtech/common/tools/ToolSaw.java +++ b/src/main/java/gregtech/common/tools/ToolSaw.java @@ -1,5 +1,6 @@ package gregtech.common.tools; +import com.google.common.collect.ImmutableSet; import gregtech.api.items.toolitem.ToolMetaItem; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -18,16 +19,12 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; -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"); - }}; + private static final Set SAW_TOOL_CLASSES = ImmutableSet.of("axe", "saw"); @Override public boolean canApplyEnchantment(ItemStack stack, Enchantment enchantment) { @@ -52,7 +49,7 @@ public float getBaseDamage(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return (tool != null && (tool.equals("axe") || tool.equals("saw"))) || + return (tool != null && SAW_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.LEAVES || block.getMaterial() == Material.VINE || block.getMaterial() == Material.WOOD || diff --git a/src/main/java/gregtech/common/tools/ToolScoop.java b/src/main/java/gregtech/common/tools/ToolScoop.java index 1c5c95214b0..e5e74af64d0 100644 --- a/src/main/java/gregtech/common/tools/ToolScoop.java +++ b/src/main/java/gregtech/common/tools/ToolScoop.java @@ -20,7 +20,7 @@ public int getToolDamagePerBlockBreak(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return tool != null && tool.equals("scoop"); + return tool != null && SCOOP_TOOL_CLASSES.contains(tool); } @Override diff --git a/src/main/java/gregtech/common/tools/ToolScrewdriver.java b/src/main/java/gregtech/common/tools/ToolScrewdriver.java index ec1319aa306..434a101dbe3 100644 --- a/src/main/java/gregtech/common/tools/ToolScrewdriver.java +++ b/src/main/java/gregtech/common/tools/ToolScrewdriver.java @@ -37,7 +37,7 @@ public float getBaseDamage(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return (tool != null && tool.equals("screwdriver")) || + return (tool != null && DRIVER_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.CIRCUITS; } diff --git a/src/main/java/gregtech/common/tools/ToolShovel.java b/src/main/java/gregtech/common/tools/ToolShovel.java index ac8e64213cb..54b5a477ead 100644 --- a/src/main/java/gregtech/common/tools/ToolShovel.java +++ b/src/main/java/gregtech/common/tools/ToolShovel.java @@ -41,7 +41,7 @@ public float getDigSpeedMultiplier(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return (tool != null && tool.equals("shovel")) || + return (tool != null && SHOVEL_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.SAND || block.getMaterial() == Material.GRASS || block.getMaterial() == Material.GROUND || diff --git a/src/main/java/gregtech/common/tools/ToolSword.java b/src/main/java/gregtech/common/tools/ToolSword.java index 056fbddf197..b3b3a753294 100644 --- a/src/main/java/gregtech/common/tools/ToolSword.java +++ b/src/main/java/gregtech/common/tools/ToolSword.java @@ -51,7 +51,7 @@ public boolean canPerformSweepAttack(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return (tool != null && tool.equals("sword")) || + return (tool != null && SWORD_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.LEAVES || block.getMaterial() == Material.GOURD || block.getMaterial() == Material.VINE || diff --git a/src/main/java/gregtech/common/tools/ToolUniversalSpade.java b/src/main/java/gregtech/common/tools/ToolUniversalSpade.java index e83853e231e..3add2207871 100644 --- a/src/main/java/gregtech/common/tools/ToolUniversalSpade.java +++ b/src/main/java/gregtech/common/tools/ToolUniversalSpade.java @@ -1,23 +1,17 @@ package gregtech.common.tools; +import com.google.common.collect.ImmutableSet; import gregtech.api.items.metaitem.MetaItem.MetaValueItem; import gregtech.common.items.behaviors.CrowbarBehaviour; import net.minecraft.block.material.Material; 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"); - }}; + private static final Set SPADE_TOOL_CLASSES = ImmutableSet.of("shovel", "axe", "saw", "sword", "crowbar"); @Override public int getToolDamagePerBlockBreak(ItemStack stack) { @@ -47,11 +41,7 @@ public float getDigSpeedMultiplier(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return (tool != null && (tool.equals("shovel") || - tool.equals("axe") || - tool.equals("saw") || - tool.equals("sword") || - tool.equals("crowbar"))) || + return (tool != null && SPADE_TOOL_CLASSES.contains(tool)) || block.getMaterial() == Material.SAND || block.getMaterial() == Material.GRASS || block.getMaterial() == Material.GROUND || diff --git a/src/main/java/gregtech/common/tools/ToolWireCutter.java b/src/main/java/gregtech/common/tools/ToolWireCutter.java index 48e8c73dafb..0e15fe598e7 100644 --- a/src/main/java/gregtech/common/tools/ToolWireCutter.java +++ b/src/main/java/gregtech/common/tools/ToolWireCutter.java @@ -28,7 +28,7 @@ public float getBaseDamage(ItemStack stack) { @Override public boolean canMineBlock(IBlockState block, ItemStack stack) { String tool = block.getBlock().getHarvestTool(block); - return tool != null && tool.equals("cutter"); + return tool != null && CUTTER_TOOL_CLASSES.contains(tool); } @Override diff --git a/src/main/java/gregtech/common/tools/ToolWrench.java b/src/main/java/gregtech/common/tools/ToolWrench.java index 68170b8fb64..efce22a1377 100644 --- a/src/main/java/gregtech/common/tools/ToolWrench.java +++ b/src/main/java/gregtech/common/tools/ToolWrench.java @@ -39,7 +39,7 @@ public float getBaseDamage(ItemStack stack) { public boolean canMineBlock(IBlockState blockState, ItemStack stack) { Block block = blockState.getBlock(); String tool = block.getHarvestTool(blockState); - return (tool != null && tool.equals("wrench")) + return (tool != null && WRENCH_TOOL_CLASSES.contains(tool)) || blockState.getMaterial() == Material.PISTON || block == Blocks.HOPPER || block == Blocks.DISPENSER