From bf49687ab66557aa65429861d3edbb09a70a3009 Mon Sep 17 00:00:00 2001 From: opfromthestart Date: Thu, 10 Jun 2021 12:50:51 -0400 Subject: [PATCH] Better performance maybe? -Changed as many of the ClientState statements to context as I could. -Only looks for a sand based update once per block update(I think it was twice before) --- .../test/TestEntityLogicFallingBlock.java | 13 +++++++------ .../progressia/test/gen/TestWorldGenerator.java | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java index 2c52c73..cff6b24 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java @@ -44,7 +44,7 @@ public class TestEntityLogicFallingBlock extends EntityLogic { } @Override - public void tick(EntityData entity, TickContext context) { + public void tick(EntityData entity, TickContext context) { //context.getWorldData() ClientState.getInstance().getWorld().getData() if (entity == null) { return; @@ -58,7 +58,7 @@ public class TestEntityLogicFallingBlock extends EntityLogic { vel = new Vec3(vel.x*friction,vel.y*friction,vel.z); entity.setVelocity(vel); - TestEntityDataFallingBlock fallBlock = (TestEntityDataFallingBlock) ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); + TestEntityDataFallingBlock fallBlock = (TestEntityDataFallingBlock) ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); //ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); //fallBlock = (TestEntityDataFallingBlock) entity; if (fallBlock.isDone() || !context.getWorld().isBlockLoaded(fallBlock.getBlockInWorld(null))) @@ -76,12 +76,13 @@ public class TestEntityLogicFallingBlock extends EntityLogic { //LogManager.getLogger().info("FallingBlock is at "+String.valueOf(occupiedBlock.x)+" "+String.valueOf(occupiedBlock.y)+" "+String.valueOf(occupiedBlock.z)); //LogManager.getLogger().info("Block is of type " + context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId()); - if (ClientState.getInstance().getWorld().getData().getChunk(chunkCoords).getBlock(inChunkCoords) + if (context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords) .getId() != "Test:Air") { LogManager.getLogger().info("Deleting FallingBlock at " + String.valueOf(occupiedBlock.x)); - ClientState.getInstance().getWorld().getData().setBlock(occupiedBlock, fallBlock.getBlock(),true); - fallBlock.setInvisible(); //Until I know how to properly delete it. - //ClientState.getInstance().getWorld().getData().removeEntity(entity.getEntityId()); + //ClientState.getInstance().getWorld().getData().setBlock(occupiedBlock, fallBlock.getBlock(),true); + context.getAccessor().setBlock(occupiedBlock, fallBlock.getBlock()); + //fallBlock.setInvisible(); //Until I know how to properly delete it. + context.getWorldData().removeEntity(entity.getEntityId()); } } } diff --git a/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java b/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java index 6ec975f..6702856 100644 --- a/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java +++ b/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java @@ -27,7 +27,6 @@ import org.apache.logging.log4j.LogManager; import glm.vec._3.Vec3; import glm.vec._3.i.Vec3i; -import ru.windcorp.progressia.client.ClientState; import ru.windcorp.progressia.common.util.VectorUtil; import ru.windcorp.progressia.common.util.Vectors; import ru.windcorp.progressia.common.world.ChunkData; @@ -58,7 +57,7 @@ public class TestWorldGenerator extends AbstractWorldGenerator { @Override public void onChunkLoaded(WorldData world, ChunkData chunk) { findAndPopulate(chunk.getPosition(), world); - chunk.addListener(new ChunkDataListener() { + chunk.addListener(new ChunkDataListener() { //Falling Block spawning logic @Override public void onChunkBlockChanged(ChunkData chunk, Vec3i blockInChunk, BlockData previous, BlockData current) { @@ -79,10 +78,11 @@ public class TestWorldGenerator extends AbstractWorldGenerator { + String.valueOf(new Random().nextFloat())).hashCode()); chunk.getWorld().addEntity(fallingBlock); - chunk.setBlock(blockInChunk, previous, true); + + chunk.setBlock(blockInChunk, previous, false); Vec3i chunkWorldPos = chunk.getPosition().mul_(16).add_(blockInChunk); LogManager.getLogger().info(String.valueOf(chunkWorldPos.x)+" "+String.valueOf(chunkWorldPos.y)+" "+String.valueOf(chunkWorldPos.z)); - ClientState.getInstance().getWorld().getData().setBlock(chunkWorldPos, BlockDataRegistry.getInstance().get("Test:Glass"), true); + world.setBlock(chunkWorldPos, BlockDataRegistry.getInstance().get("Test:Glass"), false); } } });