Skip to content

Commit

Permalink
clean up tool classes impl
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Aug 11, 2021
1 parent 41ff7ce commit d1a5619
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/tools/ToolAxe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/tools/ToolCrowbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/tools/ToolFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 3 additions & 6 deletions src/main/java/gregtech/common/tools/ToolHardHammer.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String> HAMMER_TOOL_CLASSES = new HashSet<String>() {{
add("hammer");
add("pickaxe");
}};
private static final Set<String> HAMMER_TOOL_CLASSES = ImmutableSet.of("hammer", "pickaxe");

@Override
public boolean canApplyEnchantment(ItemStack stack, Enchantment enchantment) {
Expand Down Expand Up @@ -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 ||
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/tools/ToolHoe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/gregtech/common/tools/ToolMiningHammer.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,10 +21,7 @@

public class ToolMiningHammer extends ToolBase {

private static final Set<String> HAMMER_TOOL_CLASSES = new HashSet<String>() {{
add("pickaxe");
add("hammer");
}};
private static final Set<String> 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),
Expand Down Expand Up @@ -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 ||
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/tools/ToolPickaxe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/gregtech/common/tools/ToolSaw.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String> SAW_TOOL_CLASSES = new HashSet<String>() {{
add("axe");
add("saw");
}};
private static final Set<String> SAW_TOOL_CLASSES = ImmutableSet.of("axe", "saw");

@Override
public boolean canApplyEnchantment(ItemStack stack, Enchantment enchantment) {
Expand All @@ -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 ||
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/tools/ToolScoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/tools/ToolScrewdriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/tools/ToolShovel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/tools/ToolSword.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
16 changes: 3 additions & 13 deletions src/main/java/gregtech/common/tools/ToolUniversalSpade.java
Original file line number Diff line number Diff line change
@@ -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<String> SPADE_TOOL_CLASSES = new HashSet<String>() {{
add("shovel");
add("axe");
add("saw");
add("sword");
add("crowbar");
}};
private static final Set<String> SPADE_TOOL_CLASSES = ImmutableSet.of("shovel", "axe", "saw", "sword", "crowbar");

@Override
public int getToolDamagePerBlockBreak(ItemStack stack) {
Expand Down Expand Up @@ -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 ||
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/tools/ToolWireCutter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/common/tools/ToolWrench.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d1a5619

Please sign in to comment.