From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Wed, 3 Jun 2020 11:37:13 -0700 Subject: [PATCH] Optimise getType calls Remove the map lookup for converting from Block->Bukkit Material diff --git a/src/main/java/net/minecraft/server/IBlockData.java b/src/main/java/net/minecraft/server/IBlockData.java index 10a5901db1e0efe0b7d6958098bb0ae492a9e76f..e7aa8aca2458a7fea7bc3bf1335b04daeaba98c2 100644 --- a/src/main/java/net/minecraft/server/IBlockData.java +++ b/src/main/java/net/minecraft/server/IBlockData.java @@ -8,6 +8,19 @@ public class IBlockData extends BlockBase.BlockData { public static final Codec b = a((Codec) IRegistry.BLOCK, Block::getBlockData).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.util.CraftMagicNumbers.getMaterial(this.getBlock()); + } + + return this.cachedMaterial; + } + // Paper end - optimise getType calls + public IBlockData(Block block, ImmutableMap, Comparable> immutablemap, MapCodec mapcodec) { super(block, immutablemap, mapcodec); } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java b/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java index 6cd662c9130e6282ab520d0d471f56d9a66da5ea..0160bf9e64f0a3befe60d9945648cb4dfd297877 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java @@ -79,7 +79,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot { public Material getBlockType(int x, int y, int z) { CraftChunk.validateChunkCoordinates(x, y, z); - return CraftMagicNumbers.getMaterial(blockids[y >> 4].a(x, y & 0xF, z).getBlock()); + return blockids[y >> 4].a(x, y & 0xF, z).getBukkitMaterial(); // Paper - optimise getType calls } @Override diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index 3524b677525bf2bb529b797fe1f258efb34ac3fc..3baf7b75c65c9beba40945ba904315251b5b7a64 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -214,7 +214,7 @@ public class CraftBlock implements Block { @Override public Material getType() { - return CraftMagicNumbers.getMaterial(world.getType(position).getBlock()); + return world.getType(position).getBukkitMaterial(); // Paper - optimise getType calls } @Override diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java index 0f89e776816ad4ecb6c3e54c2549692f1b5b6aae..36d7de6e6540e156499edb4b69b8bbaeb0d6dc54 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java @@ -135,7 +135,7 @@ public class CraftBlockState implements BlockState { @Override public Material getType() { - return CraftMagicNumbers.getMaterial(data.getBlock()); + return data.getBukkitMaterial(); // Paper - optimise getType calls } public void setFlag(int flag) { diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java index 590236ccc6c15f8c4ad15913fb3ac36d28414318..5207e58670b25d60886bfd66dfb9e8acd1552f5f 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java +++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java @@ -44,7 +44,7 @@ public class CraftBlockData implements BlockData { @Override public Material getMaterial() { - return CraftMagicNumbers.getMaterial(state.getBlock()); + return state.getBukkitMaterial(); // Paper - optimise getType calls } public IBlockData getState() { diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java b/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java index 948a59217cca0f8dfa9d3befb61e679a67bf29bc..1510d80891156ba97ae59e39f928b97d0226b057 100644 --- a/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java +++ b/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java @@ -73,7 +73,7 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData { @Override public Material getType(int x, int y, int z) { - return CraftMagicNumbers.getMaterial(getTypeId(x, y, z).getBlock()); + return getTypeId(x, y, z).getBukkitMaterial(); // Paper - optimise getType calls } @Override