Fix #1470 Prevent bees from loading new chunks

This commit is contained in:
mezz committed 2016-10-18 16:15:44 -07:00
1 parent 41ab1ea374
commit 4f85236475
13 files changed
+50 -24

No files matched your search

@@ -167,6 +167,9 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
List<BlockPos> flowerCoords = new ArrayList<>();
for (BlockPos.MutableBlockPos posBlock : VectUtil.getAllInBoxFromCenterMutable(world, minPos, beeHousing.getCoordinates(), maxPos)) {
if (!world.isBlockLoaded(posBlock)) {
continue;
}
IBlockState blockState = world.getBlockState(posBlock);
if (blockState.getBlock().isAir(blockState, world, posBlock)) {
continue;
@@ -194,6 +197,9 @@ public final class FlowerRegistry implements IFlowerRegistry, IFlowerGrowthHelpe
@Override
public boolean isAcceptedFlower(String flowerType, World world, BlockPos pos) {
if (!world.isBlockLoaded(pos)) {
return true; // Avoid actually checking until the flower's position is loaded.
}
IBlockState blockState = world.getBlockState(pos);
Set<IFlowerAcceptableRule> acceptedCustom = this.registeredRules.get(flowerType);
for (IFlowerAcceptableRule acceptableFlower : acceptedCustom) {
@@ -22,7 +22,7 @@ public class GrowthRuleDirtGrass implements IFlowerGrowthRule {
@Override
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos) {
if (!world.isAirBlock(pos)) {
if (!world.isBlockLoaded(pos) || !world.isAirBlock(pos)) {
return false;
}
@@ -35,6 +35,10 @@ public class GrowthRuleFertilize implements IFlowerGrowthRule {
}
private boolean growFlower(World world, BlockPos pos) {
if (!world.isBlockLoaded(pos)) {
return false;
}
IBlockState state = world.getBlockState(pos);
Block ground = state.getBlock();
int groundMeta;
@@ -22,7 +22,7 @@ public class GrowthRuleMycelium implements IFlowerGrowthRule {
@Override
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos) {
if (!world.isAirBlock(pos)) {
if (!world.isBlockLoaded(pos) || !world.isAirBlock(pos)) {
return false;
}
@@ -22,7 +22,7 @@ public class GrowthRuleSnow implements IFlowerGrowthRule {
@Override
public boolean growFlower(IFlowerGrowthHelper helper, String flowerType, World world, BlockPos pos) {
if (world.getBlockState(pos).getBlock() != Blocks.SNOW) {
if (!world.isBlockLoaded(pos) || world.getBlockState(pos).getBlock() != Blocks.SNOW) {
return false;
}
@@ -45,11 +45,13 @@ public class AlleleEffectFertile extends AlleleEffectThrottled {
int blockMinY = housingCoordinates.getY() - area.getY() / 2 - 1;
for (int attempt = 0; attempt < MAX_BLOCK_FIND_TRIES; ++attempt) {
if (tryTickColumn(world, blockX, blockZ, blockMaxY, blockMinY)) {
break;
if (world.getChunkProvider().getLoadedChunk(blockX >> 4, blockZ >> 4) != null) {
if (tryTickColumn(world, blockX, blockZ, blockMaxY, blockMinY)) {
break;
}
blockX = getRandomOffset(world.rand, housingCoordinates.getX(), area.getX());
blockZ = getRandomOffset(world.rand, housingCoordinates.getZ(), area.getZ());
}
blockX = getRandomOffset(world.rand, housingCoordinates.getX(), area.getX());
blockZ = getRandomOffset(world.rand, housingCoordinates.getZ(), area.getZ());
}
return storedData;
@@ -61,12 +61,14 @@ public class AlleleEffectFungification extends AlleleEffectThrottled {
for (int attempt = 0; attempt < MAX_BLOCK_FIND_TRIES; ++attempt) {
BlockPos pos = VectUtil.getRandomPositionInArea(world.rand, area).subtract(halfArea).add(housingCoordinates);
IBlockState blockState = world.getBlockState(pos);
if (world.isBlockLoaded(pos)) {
IBlockState blockState = world.getBlockState(pos);
if (convertToMycelium(world, blockState, pos)) {
return;
} else if (growGiantMushroom(world, blockState, pos)) {
return;
if (convertToMycelium(world, blockState, pos)) {
return;
} else if (growGiantMushroom(world, blockState, pos)) {
return;
}
}
}
}
@@ -52,16 +52,14 @@ public class AlleleEffectGlacial extends AlleleEffectThrottled {
BlockPos posBlock = VectUtil.add(randomPos, housingCoords, offset);
// Freeze water
Block block = world.getBlockState(posBlock).getBlock();
if (block != Blocks.WATER) {
continue;
if (world.isBlockLoaded(posBlock)) {
Block block = world.getBlockState(posBlock).getBlock();
if (block == Blocks.WATER) {
if (world.isAirBlock(new BlockPos(posBlock.getX(), posBlock.getY() + 1, posBlock.getZ()))) {
world.setBlockState(posBlock, Blocks.ICE.getDefaultState());
}
}
}
if (!world.isAirBlock(new BlockPos(posBlock.getX(), posBlock.getY() + 1, posBlock.getZ()))) {
continue;
}
world.setBlockState(posBlock, Blocks.ICE.getDefaultState());
}
return storedData;
@@ -84,7 +84,7 @@ public class AlleleEffectRadioactive extends AlleleEffectThrottled {
continue;
}
if (world.isAirBlock(posBlock)) {
if (!world.isBlockLoaded(posBlock) || world.isAirBlock(posBlock)) {
continue;
}
@@ -55,6 +55,9 @@ public class AlleleEffectSnowing extends AlleleEffectThrottled {
BlockPos posBlock = randomPos.add(housing.getCoordinates());
posBlock = posBlock.add(offset);
if (!world.isBlockLoaded(posBlock)) {
continue;
}
// Put snow on the ground
if (!world.isSideSolid(new BlockPos(posBlock.getX(), posBlock.getY() - 1, posBlock.getZ()), EnumFacing.UP, false)) {
@@ -57,12 +57,16 @@ public abstract class AIButterflyBase extends EntityAIBase {
if (dest.yCoord < 1) {
return false;
}
IBlockState blockState = entity.worldObj.getBlockState(new BlockPos(dest));
BlockPos pos = new BlockPos(dest);
if (!entity.worldObj.isBlockLoaded(pos)) {
return false;
}
IBlockState blockState = entity.worldObj.getBlockState(pos);
Block block = blockState.getBlock();
if (!allowFluids && block.getMaterial(blockState).isLiquid()) {
return false;
}
if (!block.isPassable(entity.worldObj, new BlockPos(dest))) {
if (!block.isPassable(entity.worldObj, pos)) {
return false;
}
return entity.getButterfly().isAcceptedEnvironment(entity.worldObj, dest.xCoord, dest.yCoord, dest.zCoord);
@@ -84,6 +84,9 @@ public class AIButterflyRest extends AIButterflyBase {
}
private boolean canLand(BlockPos pos) {
if (!entity.worldObj.isBlockLoaded(pos)) {
return false;
}
IBlockState blockState = entity.worldObj.getBlockState(pos);
Block block = blockState.getBlock();
if (!block.isPassable(entity.worldObj, pos)) {
@@ -204,6 +204,10 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly
@Override
public float getBlockPathWeight(BlockPos pos) {
if (!worldObj.isBlockLoaded(pos)) {
return -100f;
}
float weight = 0.0f;
if (!getButterfly().isAcceptedEnvironment(worldObj, pos.getX(), pos.getY(), pos.getZ())) {