Fix Cocoon

This commit is contained in:
Nedelosk committed 2017-02-19 21:59:28 +01:00
1 parent e93633d999
commit 56a907dbec
1 file changed
+20 -7
@@ -188,7 +188,7 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot {
BlockRegistryLepidopterology blocks = PluginLepidopterology.getBlocks();
BlockPos pos = getNextPos(world, nursery.getCoordinates());
BlockPos pos = getNextValidPos(world, nursery.getCoordinates());
IBlockState state = blocks.cocoon.getDefaultState();
boolean placed = world.setBlockState(pos, state);
if (!placed) {
@@ -215,12 +215,25 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot {
return pos;
}
private BlockPos getNextPos(World world, BlockPos pos) {
IBlockState blockState;
do {
pos = pos.down();
blockState = world.getBlockState(pos);
} while (!BlockUtil.canReplace(blockState, world, pos));
private BlockPos getNextValidPos(World world, BlockPos pos) {
for(int x = -2;x < 2;x++){
for(int z = -2;z < 2;z++){
for(int y = 1;y < 7;y++){
BlockPos coordinate = pos.add(x, -y, z);
TileEntity tile = world.getTileEntity(coordinate);
IBlockState blockState = world.getBlockState(coordinate);
if(tile instanceof IButterflyNursery){
IButterflyNursery nursery = (IButterflyNursery) tile;
if(nursery.getCaterpillar() != null){
break;
}
}
if(BlockUtil.canReplace(blockState, world, coordinate)){
return coordinate;
}
}
}
}
return pos;
}