diff --git a/paper-server/patches/sources/net/minecraft/world/level/block/state/BlockState.java.patch b/paper-server/patches/sources/net/minecraft/world/level/block/state/BlockState.java.patch new file mode 100644 index 0000000000..77d0d6d1c5 --- /dev/null +++ b/paper-server/patches/sources/net/minecraft/world/level/block/state/BlockState.java.patch @@ -0,0 +1,19 @@ +--- a/net/minecraft/world/level/block/state/BlockState.java ++++ b/net/minecraft/world/level/block/state/BlockState.java +@@ -10,6 +10,16 @@ + public class BlockState extends BlockBehaviour.BlockStateBase { + public static final Codec CODEC = codec(BuiltInRegistries.BLOCK.byNameCodec(), Block::defaultBlockState).stable(); + ++ // Paper start - optimise getType calls ++ org.bukkit.Material cachedMaterial; ++ ++ public final org.bukkit.Material getBukkitMaterial() { ++ if (this.cachedMaterial == null) { ++ this.cachedMaterial = org.bukkit.craftbukkit.block.CraftBlockType.minecraftToBukkit(this.getBlock()); ++ } ++ return this.cachedMaterial; ++ } ++ // Paper end - optimise getType calls + public BlockState(Block block, Reference2ObjectArrayMap, Comparable> propertyMap, MapCodec codec) { + super(block, propertyMap, codec); + } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java index a845ebd626..c88e4ba701 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java @@ -100,7 +100,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot { public Material getBlockType(int x, int y, int z) { this.validateChunkCoordinates(x, y, z); - return CraftBlockType.minecraftToBukkit(this.blockids[this.getSectionIndex(y)].get(x, y & 0xF, z).getBlock()); + return this.blockids[this.getSectionIndex(y)].get(x, y & 0xF, z).getBukkitMaterial(); // Paper - optimise getType calls } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index 3fa3de9a89..5f4dcf6d86 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -220,7 +220,7 @@ public class CraftBlock implements Block { @Override public Material getType() { - return CraftBlockType.minecraftToBukkit(this.world.getBlockState(this.position).getBlock()); + return this.world.getBlockState(this.position).getBukkitMaterial(); // Paper - optimise getType calls } @Override diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java index fabdec2d66..1002123cd0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java @@ -175,7 +175,7 @@ public class CraftBlockState implements BlockState { @Override public Material getType() { - return CraftBlockType.minecraftToBukkit(this.data.getBlock()); + return this.data.getBukkitMaterial(); // Paper - optimise getType calls } public void setFlag(int flag) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java index 22b8603a0e..4982950b13 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java @@ -63,7 +63,7 @@ public class CraftBlockData implements BlockData { @Override public Material getMaterial() { - return CraftBlockType.minecraftToBukkit(this.state.getBlock()); + return this.state.getBukkitMaterial(); // Paper - optimise getType calls } public net.minecraft.world.level.block.state.BlockState getState() { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java index c96aaa185d..0fb580530d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java @@ -96,7 +96,7 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData { @Override public Material getType(int x, int y, int z) { - return CraftBlockType.minecraftToBukkit(this.getTypeId(x, y, z).getBlock()); + return this.getTypeId(x, y, z).getBukkitMaterial(); // Paper - optimise getType calls } @Override