fix a ConcurrentModificationException on the planter, fixes #2566

This commit is contained in:
Hea3veN 2015-03-21 10:22:29 -03:00
parent 45882961ca
commit e1135ed183

View file

@ -87,8 +87,7 @@ public class BoardRobotPlanter extends RedstoneBoardRobot {
blockFilter = new IBlockFilter() { blockFilter = new IBlockFilter() {
@Override @Override
public boolean matches(World world, int x, int y, int z) { public boolean matches(World world, int x, int y, int z) {
return world.getBlock(x, y, z).canSustainPlant(world, x, y, z, ForgeDirection.UP, (IPlantable) Blocks.reeds) return isPlantable((IPlantable) Blocks.reeds, Blocks.reeds, world, x, y, z)
&& world.getBlock(x, y, z) != Blocks.reeds
&& !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z)) && !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z))
&& isAirAbove(world, x, y, z); && isAirAbove(world, x, y, z);
} }
@ -98,17 +97,17 @@ public class BoardRobotPlanter extends RedstoneBoardRobot {
blockFilter = new IBlockFilter() { blockFilter = new IBlockFilter() {
@Override @Override
public boolean matches(World world, int x, int y, int z) { public boolean matches(World world, int x, int y, int z) {
return world.getBlock(x, y, z).canSustainPlant(world, x, y, z, ForgeDirection.UP, (IPlantable) plantBlock) return isPlantable((IPlantable) plantBlock, plantBlock, world, x, y, z)
&& world.getBlock(x, y, z) != plantBlock
&& !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z)) && !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z))
&& isAirAbove(world, x, y, z); && isAirAbove(world, x, y, z);
} }
}; };
} else { } else {
blockFilter = new IBlockFilter() { blockFilter = new IBlockFilter() {
@Override @Override
public boolean matches(World world, int x, int y, int z) { public boolean matches(World world, int x, int y, int z) {
return world.getBlock(x, y, z).canSustainPlant(world, x, y, z, ForgeDirection.UP, (IPlantable) itemStack.getItem()) return isPlantable((IPlantable) itemStack.getItem(), null, world, x, y, z)
&& !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z)) && !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z))
&& isAirAbove(world, x, y, z); && isAirAbove(world, x, y, z);
} }
@ -172,6 +171,13 @@ public class BoardRobotPlanter extends RedstoneBoardRobot {
} }
} }
private boolean isPlantable(IPlantable plant, Block block, World world, int x, int y, int z) {
synchronized (world) {
return world.getBlock(x, y, z).canSustainPlant(world, x, y, z, ForgeDirection.UP, plant)
&& (block == null || world.getBlock(x, y, z) != block);
}
}
private boolean isAirAbove(World world, int x, int y, int z) { private boolean isAirAbove(World world, int x, int y, int z) {
synchronized (world) { synchronized (world) {
return world.isAirBlock(x, y + 1, z); return world.isAirBlock(x, y + 1, z);