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:
parent
b3a72ed545
commit
6d4aa59685
2 changed files with 19 additions and 5 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Integer> ores = new HashSet<Integer>();
|
||||
|
||||
public WorldPropertyIsOre(int harvestLevel) {
|
||||
initBlockHarvestTools();
|
||||
for (String oreName : OreDictionary.getOreNames()) {
|
||||
if (oreName.startsWith("ore")) {
|
||||
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
|
||||
public boolean get(IBlockAccess blockAccess, Block block, int meta, int x, int y, int z) {
|
||||
if (block == null) {
|
||||
|
|
Loading…
Reference in a new issue