From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Fri, 25 Oct 2024 22:27:07 -0400 Subject: [PATCH] Cache tile entity position Dreeam TODO: Check if there is a way to cache isRemoved without problem diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java index 290163335cf3967e2745442fd7d4d4fa16fb7bc0..238e015d4ff5fabb99e569118f253366d545d269 100644 --- a/net/minecraft/world/level/chunk/LevelChunk.java +++ b/net/minecraft/world/level/chunk/LevelChunk.java @@ -936,10 +936,12 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p private final T blockEntity; private final BlockEntityTicker ticker; private boolean loggedInvalidBlockState; + private final BlockPos cachedPos; // Leaf - Cache tile entity position BoundTickingBlockEntity(final T blockEntity, final BlockEntityTicker ticker) { this.blockEntity = blockEntity; this.ticker = ticker; + this.cachedPos = this.blockEntity.getBlockPos(); // Leaf - Cache tile entity position } @Override @@ -980,7 +982,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p @Override public BlockPos getPos() { - return this.blockEntity.getBlockPos(); + return this.cachedPos; // Leaf - Cache tile entity position } @Override @@ -1007,13 +1009,16 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p static class RebindableTickingBlockEntityWrapper implements TickingBlockEntity { private TickingBlockEntity ticker; + private BlockPos cachedPos; // Leaf - Cache tile entity position RebindableTickingBlockEntityWrapper(TickingBlockEntity ticker) { this.ticker = ticker; + this.cachedPos = this.ticker.getPos(); // Leaf - Cache tile entity position } void rebind(TickingBlockEntity ticker) { this.ticker = ticker; + this.cachedPos = this.ticker.getPos(); // Leaf - Cache tile entity position } @Override @@ -1028,7 +1033,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p @Override public BlockPos getPos() { - return this.ticker.getPos(); + return this.cachedPos; // Leaf - Cache tile entity position } @Override