mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 06:24:06 +01:00
7ae47d4eb3
Mojang fixed it in MC-63720
97 lines
4.8 KiB
Diff
97 lines
4.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Spottedleaf <spottedleaf@spottedleaf.dev>
|
|
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<IBlockData> 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<IBlockState<?>, Comparable<?>> immutablemap, MapCodec<IBlockData> 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 ff8ba545748c1065f6560d9d11a22c64d9a5347b..db1edc07e4a797280ee872168b69a0e2232529b6 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 f44fc4a95954e0745fbcd6d06b79acc37699c77a..4a9245fa5b91b894f982b29f7b87878453189cb9 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
|