From a344011486cc7b5b2608566749334cec0907f965 Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Fri, 12 Jun 2020 14:34:31 +0100 Subject: [PATCH] Limit the number of blocks black hole can unhook per tick --- .../wizardry/entity/construct/EntityBlackHole.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/electroblob/wizardry/entity/construct/EntityBlackHole.java b/src/main/java/electroblob/wizardry/entity/construct/EntityBlackHole.java index 8f7075f0..16059b8a 100644 --- a/src/main/java/electroblob/wizardry/entity/construct/EntityBlackHole.java +++ b/src/main/java/electroblob/wizardry/entity/construct/EntityBlackHole.java @@ -27,8 +27,10 @@ import net.minecraftforge.fml.relauncher.SideOnly; import java.util.List; public class EntityBlackHole extends EntityMagicConstruct { - + private static final double SUCTION_STRENGTH = 0.075; + /** The maximum number of blocks that can be unhooked each tick, reduces lag from excessive numbers of entities. */ + private static final int BLOCK_UNHOOK_LIMIT = 3; public int[] randomiser; public int[] randomiser2; @@ -97,6 +99,8 @@ public class EntityBlackHole extends EntityMagicConstruct { List sphere = WizardryUtilities.getBlockSphere(new BlockPos(this), radius); + int blocksUnhooked = 0; + for(BlockPos pos : sphere){ if(rand.nextInt(Math.max(1, (int)this.getDistanceSq(pos) * 3)) == 0){ @@ -112,6 +116,8 @@ public class EntityBlackHole extends EntityMagicConstruct { fallingBlock.fallTime = 1; // Prevent it from trying to delete the block itself world.spawnEntity(fallingBlock); world.setBlockToAir(pos); + + if(++blocksUnhooked >= BLOCK_UNHOOK_LIMIT) break; // Lag prevention } } }