Prevent loading chunks while ticking blocks (#110)

This commit is contained in:
Alexdoru authored and GitHub committed 2026-03-12 21:33:00 +01:00
1 parent 1083f52a30
commit 3bc6720dec
4 files changed
+56 -66

No files matched your search

@@ -36,29 +36,29 @@ public class BlockFruitPod extends BlockCocoa {
}
public static TileFruitPod getPodTile(IBlockAccess world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if (!(tile instanceof TileFruitPod)) {
return null;
final TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileFruitPod) {
return (TileFruitPod) tile;
}
return (TileFruitPod) tile;
return null;
}
@Override
public void updateTick(World world, int x, int y, int z, Random rand) {
if (!world.checkChunksExist(x - 1, y, z - 1, x + 1, y, z + 1)) {
return;
}
if (!canBlockStay(world, x, y, z)) {
dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
final int meta = world.getBlockMetadata(x, y, z);
this.dropBlockAsItem(world, x, y, z, meta, 0);
world.setBlockToAir(x, y, z);
return;
}
TileFruitPod tile = getPodTile(world, x, y, z);
if (tile == null) {
return;
final TileFruitPod tile = getPodTile(world, x, y, z);
if (tile != null) {
tile.onBlockTick();
}
tile.onBlockTick();
}
@SuppressWarnings("deprecation")
@@ -84,31 +84,26 @@ public class BlockSoil extends Block implements IItemTyped {
}
@Override
public void updateTick(World world, int i, int j, int k, Random random) {
public void updateTick(World world, int x, int y, int z, Random random) {
if (world.isRemote) {
return;
}
int meta = world.getBlockMetadata(i, j, k);
int meta = world.getBlockMetadata(x, y, z);
SoilType type = getTypeFromMeta(meta);
if (type == SoilType.HUMUS) {
updateTickHumus(world, i, j, k);
if (world.checkChunksExist(x - 1, y + 1, z - 1, x + 1, y + 1, z + 1)) {
if (isEnrooted(world, x, y, z)) {
degradeSoil(world, x, y, z);
}
}
} else if (type == SoilType.BOG_EARTH) {
updateTickBogEarth(world, i, j, k);
}
}
private static void updateTickHumus(World world, int i, int j, int k) {
if (isEnrooted(world, i, j, k)) {
degradeSoil(world, i, j, k);
}
}
private static void updateTickBogEarth(World world, int i, int j, int k) {
if (isMoistened(world, i, j, k)) {
matureBog(world, i, j, k);
if (world.checkChunksExist(x - 2, y, z - 2, x + 2, y, z + 2)) {
if (isMoistened(world, x, y, z)) {
matureBog(world, x, y, z);
}
}
}
}
@@ -122,7 +117,6 @@ public class BlockSoil extends Block implements IItemTyped {
}
}
}
return false;
}
@@ -156,7 +150,6 @@ public class BlockSoil extends Block implements IItemTyped {
}
private static boolean isMoistened(World world, int x, int y, int z) {
for (int i = -2; i < 3; i++) {
for (int j = -2; j < 3; j++) {
Block block = world.getBlock(x + i, y, z + j);
@@ -165,7 +158,6 @@ public class BlockSoil extends Block implements IItemTyped {
}
}
}
return false;
}
@@ -193,7 +193,7 @@ public class BlockForestryFluid extends BlockFluidClassic {
super.updateTick(world, x, y, z, rand);
// Start fires if the fluid is lava-like
if (getMaterial() == Material.lava) {
if (getMaterial() == Material.lava && world.checkChunksExist(x - 4, y, z - 4, x + 4, y, z + 4)) {
int rangeUp = rand.nextInt(3);
for (int i = 0; i < rangeUp; ++i) {
@@ -72,51 +72,54 @@ public class BlockMushroom extends BlockSapling implements IItemTyped {
}
@Override
public void updateTick(World world, int i, int j, int k, Random random) {
public void updateTick(World world, int x, int y, int z, Random random) {
if (world.isRemote) {
return;
}
int meta = world.getBlockMetadata(i, j, k);
MushroomType type = getTypeFromMeta(meta);
int maturity = meta >> 2;
final int meta = world.getBlockMetadata(x, y, z);
final MushroomType type = getTypeFromMeta(meta);
final int maturity = meta >> 2;
tickGermling(world, i, j, k, random, type, maturity);
tickGermling(world, x, y, z, random, type, maturity);
}
private void tickGermling(World world, int i, int j, int k, Random random, MushroomType type, int maturity) {
int lightvalue = world.getBlockLightValue(i, j + 1, k);
private void tickGermling(World world, int x, int y, int z, Random random, MushroomType type, int maturity) {
if (random.nextInt(2) != 0) {
return;
}
if (maturity != 3) {
maturity = 3;
int matX = maturity << 2;
int meta = (matX | type.ordinal());
world.setBlockMetadataWithNotify(i, j, k, meta, Constants.FLAG_BLOCK_SYNCH);
} else if (lightvalue <= 7) {
func_149878_d(world, i, j, k, random);
final int matX = maturity << 2;
final int meta = (matX | type.ordinal());
world.setBlockMetadataWithNotify(x, y, z, meta, Constants.FLAG_BLOCK_SYNCH);
} else {
if (world.checkChunksExist(x - 1, y, z - 1, x + 1, y, z + 1)) {
final int lightvalue = world.getBlockLightValue(x, y + 1, z);
if (lightvalue <= 7) {
func_149878_d(world, x, y, z, random);
}
}
}
}
@Override
public void func_149878_d(World world, int i, int j, int k, Random random) {
MushroomType type = getTypeFromMeta(world.getBlockMetadata(i, j, k));
public void func_149878_d(World world, int x, int y, int z, Random random) {
MushroomType type = getTypeFromMeta(world.getBlockMetadata(x, y, z));
world.setBlockToAir(i, j, k);
if (!generators[type.ordinal()].generate(world, random, i, j, k)) {
world.setBlock(i, j, k, this, type.ordinal(), 0);
world.setBlockToAir(x, y, z);
if (!generators[type.ordinal()].generate(world, random, x, y, z)) {
world.setBlock(x, y, z, this, type.ordinal(), 0);
}
}
@Override
public MushroomType getTypeFromMeta(int meta) {
meta %= MushroomType.values().length;
return MushroomType.values()[meta];
return switch (meta % 2) {
case 0 -> MushroomType.BROWN;
case 1 -> MushroomType.RED;
default -> throw new IllegalStateException("Unexpected value: " + meta);
};
}
/* ICONS */
@@ -135,15 +138,10 @@ public class BlockMushroom extends BlockSapling implements IItemTyped {
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta) {
MushroomType type = getTypeFromMeta(meta);
switch (type) {
case BROWN:
return Blocks.brown_mushroom.getIcon(side, meta);
case RED:
return Blocks.red_mushroom.getIcon(side, meta);
default:
return null;
}
final MushroomType type = getTypeFromMeta(meta);
return switch (type) {
case BROWN -> Blocks.brown_mushroom.getIcon(side, meta);
case RED -> Blocks.red_mushroom.getIcon(side, meta);
};
}
}