From e1135ed1838c394adf5ac4f88818ef925e697f48 Mon Sep 17 00:00:00 2001 From: Hea3veN Date: Sat, 21 Mar 2015 10:22:29 -0300 Subject: [PATCH] fix a ConcurrentModificationException on the planter, fixes #2566 --- .../robots/boards/BoardRobotPlanter.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/common/buildcraft/robots/boards/BoardRobotPlanter.java b/common/buildcraft/robots/boards/BoardRobotPlanter.java index f636de55..3313b642 100644 --- a/common/buildcraft/robots/boards/BoardRobotPlanter.java +++ b/common/buildcraft/robots/boards/BoardRobotPlanter.java @@ -87,8 +87,7 @@ public class BoardRobotPlanter extends RedstoneBoardRobot { blockFilter = new IBlockFilter() { @Override 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) - && world.getBlock(x, y, z) != Blocks.reeds + return isPlantable((IPlantable) Blocks.reeds, Blocks.reeds, world, x, y, z) && !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z)) && isAirAbove(world, x, y, z); } @@ -98,17 +97,17 @@ public class BoardRobotPlanter extends RedstoneBoardRobot { blockFilter = new IBlockFilter() { @Override 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) - && world.getBlock(x, y, z) != plantBlock + return isPlantable((IPlantable) plantBlock, plantBlock, world, x, y, z) && !robot.getRegistry().isTaken(new ResourceIdBlock(x, y, z)) && isAirAbove(world, x, y, z); } + }; } else { blockFilter = new IBlockFilter() { @Override 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)) && 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) { synchronized (world) { return world.isAirBlock(x, y + 1, z);