From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: lukas Date: Sun, 27 Dec 2020 17:19:51 +0100 Subject: [PATCH] Optimized tick ready check diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable { if (!tileentity.isRemoved() && tileentity.hasLevel()) { BlockPos blockposition = tileentity.getBlockPos(); - if (this.getChunkSource().isTickingChunk(blockposition) && this.getWorldBorder().isWithinBounds(blockposition)) { + LevelChunk chunk; ChunkHolder playerChunk; if ((chunk = tileentity.getCurrentChunk()) != null && (playerChunk = chunk.playerChunk) != null && playerChunk.isTickingReady() && this.getWorldBorder().isInBounds(blockposition)) { // Paper - optimized tick ready check by inlining ChunkProviderServer.a(BlockPosition). Chunk lookup is no longer required and we can use the PlayerChunk directly available through the tile entity try { gameprofilerfiller.push(() -> { return String.valueOf(BlockEntityType.getKey(tileentity.getType())); }); tileentity.tickTimer.startTiming(); // Spigot - if (tileentity.getType().isValid(this.getBlockState(blockposition).getBlock())) { + if (tileentity.getType().isValid(chunk.getBlockState(blockposition).getBlock())) { // Paper - reuse the chunk from above, do not look it up again ((TickableBlockEntity) tileentity).tick(); } else { tileentity.logInvalidState(); @@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable { this.tickableBlockEntities.remove(tileTickPosition--); // Spigot end //this.tileEntityList.remove(tileentity); // Paper - remove unused list - if (this.hasChunkAt(tileentity.getBlockPos())) { - this.getChunkAt(tileentity.getBlockPos()).removeBlockEntity(tileentity.getBlockPos()); + // Paper - prevent double chunk lookups + LevelChunk chunk; if ((chunk = this.getChunkIfLoaded(tileentity.getBlockPos())) != null) { // inlined contents of this.isLoaded(BlockPosition). Reuse the returned chunk instead of looking it up again + chunk.removeBlockEntity(tileentity.getBlockPos()); } + // Paper end } } @@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable { } // CraftBukkit end */ - if (this.hasChunkAt(tileentity1.getBlockPos())) { - LevelChunk chunk = this.getChunkAt(tileentity1.getBlockPos()); + LevelChunk chunk; if ((chunk = this.getChunkIfLoaded(tileentity1.getBlockPos())) != null) { // Paper - inlined contents of this.isLoaded(BlockPosition). Reuse the returned chunk instead of looking it up again + // Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition()); // Paper - already computed above BlockState iblockdata = chunk.getBlockState(tileentity1.getBlockPos()); chunk.setBlockEntity(tileentity1.getBlockPos(), tileentity1);