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.
This commit is contained in:
Hea3veN 2014-12-22 08:24:05 -03:00
parent b3a72ed545
commit 6d4aa59685
2 changed files with 19 additions and 5 deletions

View file

@ -24,6 +24,7 @@ public class BoardRobotMiner extends BoardRobotGenericBreakBlock {
public BoardRobotMiner(EntityRobotBase iRobot) { public BoardRobotMiner(EntityRobotBase iRobot) {
super(iRobot); super(iRobot);
detectHarvestLevel();
} }
@Override @Override
@ -31,6 +32,11 @@ public class BoardRobotMiner extends BoardRobotGenericBreakBlock {
super.delegateAIEnded(ai); super.delegateAIEnded(ai);
if (ai instanceof AIRobotFetchAndEquipItemStack) { if (ai instanceof AIRobotFetchAndEquipItemStack) {
detectHarvestLevel();
}
}
private void detectHarvestLevel() {
ItemStack stack = robot.getHeldItem(); ItemStack stack = robot.getHeldItem();
if (stack != null && stack.getItem() instanceof ItemPickaxe) { if (stack != null && stack.getItem() instanceof ItemPickaxe) {
@ -39,7 +45,6 @@ public class BoardRobotMiner extends BoardRobotGenericBreakBlock {
harvestLevel = pickaxe.getHarvestLevel(stack, "pickaxe"); harvestLevel = pickaxe.getHarvestLevel(stack, "pickaxe");
} }
} }
}
@Override @Override
public RedstoneBoardRobotNBT getNBTHandler() { public RedstoneBoardRobotNBT getNBTHandler() {

View file

@ -12,9 +12,12 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
public class WorldPropertyIsOre extends WorldProperty { public class WorldPropertyIsOre extends WorldProperty {
@ -22,6 +25,7 @@ public class WorldPropertyIsOre extends WorldProperty {
public HashSet<Integer> ores = new HashSet<Integer>(); public HashSet<Integer> ores = new HashSet<Integer>();
public WorldPropertyIsOre(int harvestLevel) { public WorldPropertyIsOre(int harvestLevel) {
initBlockHarvestTools();
for (String oreName : OreDictionary.getOreNames()) { for (String oreName : OreDictionary.getOreNames()) {
if (oreName.startsWith("ore")) { if (oreName.startsWith("ore")) {
ArrayList<ItemStack> oreStacks = OreDictionary.getOres(oreName); ArrayList<ItemStack> 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 @Override
public boolean get(IBlockAccess blockAccess, Block block, int meta, int x, int y, int z) { public boolean get(IBlockAccess blockAccess, Block block, int meta, int x, int y, int z) {
if (block == null) { if (block == null) {