PaperMC/patches/server/0487-Optimise-getType-calls.patch
Jake Potrebic 03a4e7ac75
Updated Upstream (Bukkit/CraftBukkit) (#8832)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
37262de8 PR-812: Add Registry#match(String)
d6b40162 SPIGOT-4569: Add more BlockData API
f9691891 PR-809: Throw a more clear error for BlockIterators with zero direction, add Vector#isZero()
91e79e19 PR-804: Added methods to get translation keys for materials, itemstacks and more
426b00d3 PR-795: Add new BiomeParameterPoint passed to BiomeProvider#getBiome
0e91ea52 SPIGOT-7224: Add events for brewing stands and campfires starting their actions

CraftBukkit Changes:
a50301aa5 Fix issues with fluid tag conversion and fluid #isTagged
6aeb5e4c3 SPIGOT-4569: Implement more BlockData API
7dbf862c2 PR-1131: Added methods to get translation keys for materials, itemstacks and more
7167588b1 PR-1117: Add new BiomeParameterPoint passed to BiomeProvider#getBiome
7c44152eb SPIGOT-7224: Add events for brewing stands and campfires starting their actions
2023-02-15 14:10:14 -08:00

94 lines
5.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
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/world/level/block/state/BlockState.java b/src/main/java/net/minecraft/world/level/block/state/BlockState.java
index da878e180c6b94f98dc82c6e8395f63ecc9b2c1e..a9b0f5950b6f97ea4c2a1075946b92008b62c9d9 100644
--- a/src/main/java/net/minecraft/world/level/block/state/BlockState.java
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockState.java
@@ -10,6 +10,17 @@ import net.minecraft.world.level.block.state.properties.Property;
public class BlockState extends BlockBehaviour.BlockStateBase {
public static final Codec<BlockState> 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.util.CraftMagicNumbers.getMaterial(this.getBlock());
+ }
+
+ return this.cachedMaterial;
+ }
+ // Paper end - optimise getType calls
public BlockState(Block block, ImmutableMap<Property<?>, Comparable<?>> propertyMap, MapCodec<BlockState> codec) {
super(block, propertyMap, codec);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java b/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
index 484e5d5a2793d18eb49b73898d944776a1ec48e8..05512cc19eb213b6be5c869e133376ee42827806 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
@@ -98,7 +98,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
public Material getBlockType(int x, int y, int z) {
this.validateChunkCoordinates(x, y, z);
- return CraftMagicNumbers.getMaterial(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/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
index 1f780a326f4982d4be1855516fb1461b4d90bcc6..998cb47c4d3d1c67467469e661f80d231d17c04a 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
@@ -226,7 +226,7 @@ public class CraftBlock implements Block {
@Override
public Material getType() {
- return CraftMagicNumbers.getMaterial(this.world.getBlockState(position).getBlock());
+ return this.world.getBlockState(this.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 0a755f38fae9dc84440f43113920c5b4c6d8218b..7b9e943b391c061782fccd2b8d705ceec8db50fe 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
@@ -166,7 +166,7 @@ public class CraftBlockState implements BlockState {
@Override
public Material getType() {
- return CraftMagicNumbers.getMaterial(this.data.getBlock());
+ return this.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 14b8d0754955747d5a755eaf628e861929f5f47f..7acf213194f61d04cffabaaee6c1372bfa2e1933 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
@@ -53,7 +53,7 @@ public class CraftBlockData implements BlockData {
@Override
public Material getMaterial() {
- return CraftMagicNumbers.getMaterial(this.state.getBlock());
+ return this.state.getBukkitMaterial(); // Paper - optimise getType calls
}
public BlockState getState() {
diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java b/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java
index ee88ff2ee86bbd3ccf3e4a0b2310f020f137ef4f..5e15feb408b8a05ec5ee393a604c8d39a91ff106 100644
--- a/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java
+++ b/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 CraftMagicNumbers.getMaterial(this.getTypeId(x, y, z).getBlock());
+ return this.getTypeId(x, y, z).getBukkitMaterial(); // Paper - optimise getType calls
}
@Override