From 6d4aa5968568ce6350caf13db569c4f1e01244e9 Mon Sep 17 00:00:00 2001 From: Hea3veN Date: Mon, 22 Dec 2014 08:24:05 -0300 Subject: [PATCH] fix miner robot's harvest level being reset on world close/unload. make sure blocks harvest tools are being initialized by forge before using them. --- .../core/robots/boards/BoardRobotMiner.java | 15 ++++++++++----- .../buildcraft/core/utils/WorldPropertyIsOre.java | 9 +++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/common/buildcraft/core/robots/boards/BoardRobotMiner.java b/common/buildcraft/core/robots/boards/BoardRobotMiner.java index 32cfc308..3c1dc44f 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotMiner.java +++ b/common/buildcraft/core/robots/boards/BoardRobotMiner.java @@ -24,6 +24,7 @@ public class BoardRobotMiner extends BoardRobotGenericBreakBlock { public BoardRobotMiner(EntityRobotBase iRobot) { super(iRobot); + detectHarvestLevel(); } @Override @@ -31,13 +32,17 @@ public class BoardRobotMiner extends BoardRobotGenericBreakBlock { super.delegateAIEnded(ai); if (ai instanceof AIRobotFetchAndEquipItemStack) { - ItemStack stack = robot.getHeldItem(); + detectHarvestLevel(); + } + } - if (stack != null && stack.getItem() instanceof ItemPickaxe) { - ItemPickaxe pickaxe = (ItemPickaxe) stack.getItem(); + private void detectHarvestLevel() { + ItemStack stack = robot.getHeldItem(); - harvestLevel = pickaxe.getHarvestLevel(stack, "pickaxe"); - } + if (stack != null && stack.getItem() instanceof ItemPickaxe) { + ItemPickaxe pickaxe = (ItemPickaxe) stack.getItem(); + + harvestLevel = pickaxe.getHarvestLevel(stack, "pickaxe"); } } diff --git a/common/buildcraft/core/utils/WorldPropertyIsOre.java b/common/buildcraft/core/utils/WorldPropertyIsOre.java index ab2d0bff..54d86bbf 100755 --- a/common/buildcraft/core/utils/WorldPropertyIsOre.java +++ b/common/buildcraft/core/utils/WorldPropertyIsOre.java @@ -12,9 +12,12 @@ import java.util.ArrayList; import java.util.HashSet; import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.world.IBlockAccess; +import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.oredict.OreDictionary; public class WorldPropertyIsOre extends WorldProperty { @@ -22,6 +25,7 @@ public class WorldPropertyIsOre extends WorldProperty { public HashSet ores = new HashSet(); public WorldPropertyIsOre(int harvestLevel) { + initBlockHarvestTools(); for (String oreName : OreDictionary.getOreNames()) { if (oreName.startsWith("ore")) { ArrayList oreStacks = OreDictionary.getOres(oreName); @@ -43,6 +47,11 @@ public class WorldPropertyIsOre extends WorldProperty { } } + private void initBlockHarvestTools() { + // Make sure the static code block in the ForgeHooks class is run + ForgeHooks.canToolHarvestBlock(Blocks.coal_ore, 0, new ItemStack(Items.diamond_pickaxe)); + } + @Override public boolean get(IBlockAccess blockAccess, Block block, int meta, int x, int y, int z) { if (block == null) {