Skip to content

Commit

Permalink
improved the tool detection algorithm (closes #4) 1.0.3 jar build
Browse files Browse the repository at this point in the history
  • Loading branch information
Trcx528 committed Mar 19, 2015
1 parent deed201 commit bc3224b
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/main/java/com/trcx/swapper/Common/Item/Swapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import net.minecraftforge.event.entity.player.EntityItemPickupEvent;
import net.minecraftforge.oredict.ShapedOreRecipe;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
Expand All @@ -54,6 +56,14 @@ public class Swapper extends Item implements IEnergyContainerItem{

public static final int swapperSlots = 5;

private static final HashMap<String, ItemStack> testTools = new HashMap<String, ItemStack>();
static
{
testTools.put("pickaxe", new ItemStack(Items.wooden_pickaxe));
testTools.put("shovel", new ItemStack(Items.wooden_shovel));
testTools.put("axe", new ItemStack(Items.wooden_axe));
}

public Swapper(){
super();
setCreativeTab(CreativeTabs.tabTools);
Expand Down Expand Up @@ -124,6 +134,17 @@ public boolean onBlockStartBreak(ItemStack swapper, int X, int Y, int Z, EntityP
public float getDigSpeed(ItemStack swapper, Block block, int metadata) {
String effTool = block.getHarvestTool(metadata);
ItemStack is;
if (effTool == null){
for (Map.Entry<String, ItemStack> testToolEntry : testTools.entrySet())
{
ItemStack testTool = testToolEntry.getValue();
if (testTool != null && testTool.getItem() instanceof ItemTool && testTool.func_150997_a(block) >= ((ItemTool) testTool.getItem()).func_150913_i().getEfficiencyOnProperMaterial())
{
effTool = testToolEntry.getKey();
break;
}
}
}
if (effTool != null) {
if (effTool.equals("shovel")) {
is = getStack(slotSHOVEL, swapper);
Expand All @@ -137,8 +158,6 @@ public float getDigSpeed(ItemStack swapper, Block block, int metadata) {
} else { // have to handle vanilla not properly registering some blocks...
if (block == Blocks.web) {
is = getStack(slotSword, swapper);
} else if (block == Blocks.wooden_door || block == Blocks.trapdoor || block == Blocks.ladder || block == Blocks.fence || block == Blocks.fence_gate) {
is = getStack(slotAXE, swapper);
} else {
is = getStack(slotPICK, swapper);
}
Expand All @@ -153,16 +172,7 @@ public float getDigSpeed(ItemStack swapper, Block block, int metadata) {

@Override
public int getHarvestLevel(ItemStack swapper, String toolClass) {
ItemStack is;
if (toolClass.equals("shovel")){
is = getStack(slotSHOVEL,swapper);
} else if (toolClass.equals("axe")) {
is = getStack(slotAXE, swapper);
} else if (toolClass.equals("sword")) {
is = getStack(slotSword, swapper);
} else {
is = getStack(slotPICK, swapper);
}
ItemStack is = getLastStack(swapper);
if (is != null) {
int ret = is.getItem().getHarvestLevel(is, toolClass);
putLastStack(swapper,is);
Expand Down

0 comments on commit bc3224b

Please sign in to comment.