From 1c3e5ba595bda63c7026ce4fd05acc2e0aa9bd0a Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 7 Oct 2018 12:45:28 +0200 Subject: [PATCH] Improved memory usage during asteroid generation --- .../java/cr0s/warpdrive/world/EntitySphereGen.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java b/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java index 74cbfe3f..4ba99037 100644 --- a/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java +++ b/src/main/java/cr0s/warpdrive/world/EntitySphereGen.java @@ -14,6 +14,7 @@ import net.minecraft.entity.Entity; import net.minecraft.init.Blocks; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.BlockPos.MutableBlockPos; import net.minecraft.world.World; /* @@ -101,13 +102,14 @@ public final class EntitySphereGen extends Entity { this.state = STATE_STOP; final int minY_clamped = Math.max(0, yCoord - radius); final int maxY_clamped = Math.min(255, yCoord + radius); + final MutableBlockPos mutableBlockPos = new MutableBlockPos(); for (int x = xCoord - radius; x <= xCoord + radius; x++) { for (int z = zCoord - radius; z <= zCoord + radius; z++) { for (int y = minY_clamped; y <= maxY_clamped; y++) { - BlockPos blockPos = new BlockPos(x, y, z); - IBlockState blockState = world.getBlockState(blockPos); + mutableBlockPos.setPos(x, y, z); + final IBlockState blockState = world.getBlockState(mutableBlockPos); if (blockState.getBlock() != Blocks.AIR) { - world.notifyBlockUpdate(blockPos, blockState, blockState, 3); + world.notifyBlockUpdate(mutableBlockPos, blockState, blockState, 3); } } } @@ -156,14 +158,16 @@ public final class EntitySphereGen extends Entity { final int blocksToMove = Math.min(BLOCKS_PER_TICK, blocks.size() - currentIndex); LocalProfiler.start("[EntitySphereGen] Placing blocks from " + currentIndex + " to " + (currentIndex + blocksToMove) + "/" + blocks.size()); + final MutableBlockPos mutableBlockPos = new MutableBlockPos(); for (int index = 0; index < blocksToMove; index++) { if (currentIndex >= blocks.size()) break; final JumpBlock jumpBlock = blocks.get(currentIndex); + mutableBlockPos.setPos(jumpBlock.x, jumpBlock.y, jumpBlock.z); if (isSurfaces.get(currentIndex)) { - world.setBlockState(new BlockPos(jumpBlock.x, jumpBlock.y, jumpBlock.z), jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2); + world.setBlockState(mutableBlockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2); } else { - JumpBlock.setBlockNoLight(world, new BlockPos(jumpBlock.x, jumpBlock.y, jumpBlock.z), jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2); + JumpBlock.setBlockNoLight(world, mutableBlockPos, jumpBlock.block.getStateFromMeta(jumpBlock.blockMeta), 2); } currentIndex++; }