2021-06-11 14:02:28 +02:00
|
|
|
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/world/level/block/state/BlockState.java b/src/main/java/net/minecraft/world/level/block/state/BlockState.java
|
2021-11-24 17:39:04 +01:00
|
|
|
index 76133c77e8ebce7c9e5402e3e7cd50b30aa1c2e0..348a91a760bd728f8e732e1a35c86ab75d8fc0f1 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/state/BlockState.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockState.java
|
2021-06-14 18:58:00 +02:00
|
|
|
@@ -10,6 +10,17 @@ import net.minecraft.world.level.block.state.properties.Property;
|
|
|
|
public class BlockState extends BlockBehaviour.BlockStateBase {
|
2021-11-24 17:39:04 +01:00
|
|
|
public static final Codec<BlockState> CODEC = codec(Registry.BLOCK.byNameCodec(), Block::defaultBlockState).stable();
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
+ // 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
|
2021-06-14 18:58:00 +02:00
|
|
|
public BlockState(Block block, ImmutableMap<Property<?>, Comparable<?>> propertyMap, MapCodec<BlockState> codec) {
|
|
|
|
super(block, propertyMap, codec);
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java b/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
|
2022-03-11 21:13:46 +01:00
|
|
|
index 8001245c4ba619cd357a194d60fdc2efe186efb3..07fa4e4ae5f2cfb4447a608dc645c0b7b0a217dd 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunkSnapshot.java
|
2022-03-01 06:43:03 +01:00
|
|
|
@@ -83,7 +83,7 @@ public class CraftChunkSnapshot implements ChunkSnapshot {
|
2021-06-11 14:02:28 +02:00
|
|
|
public Material getBlockType(int x, int y, int z) {
|
2021-06-14 18:58:00 +02:00
|
|
|
this.validateChunkCoordinates(x, y, z);
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-06-14 18:58:00 +02:00
|
|
|
- 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
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
2022-03-13 08:47:54 +01:00
|
|
|
index e116ccfa4878636073cc4cdcf680683cda88d314..4bbaf22f449af42eba1307604e3860ea8b60a38c 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
2022-03-13 08:47:54 +01:00
|
|
|
@@ -224,7 +224,7 @@ public class CraftBlock implements Block {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Material getType() {
|
2021-06-14 18:58:00 +02:00
|
|
|
- return CraftMagicNumbers.getMaterial(this.world.getBlockState(position).getBlock());
|
|
|
|
+ return this.world.getBlockState(this.position).getBukkitMaterial(); // Paper - optimise getType calls
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
|
2021-11-24 17:39:04 +01:00
|
|
|
index 0a755f38fae9dc84440f43113920c5b4c6d8218b..7b9e943b391c061782fccd2b8d705ceec8db50fe 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
|
2021-10-15 13:43:19 +02:00
|
|
|
@@ -166,7 +166,7 @@ public class CraftBlockState implements BlockState {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Material getType() {
|
2021-06-14 18:58:00 +02:00
|
|
|
- return CraftMagicNumbers.getMaterial(this.data.getBlock());
|
|
|
|
+ return this.data.getBukkitMaterial(); // Paper - optimise getType calls
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2022-03-01 06:43:03 +01:00
|
|
|
index afc69b0077f180c3e7ace3db11aa0eccc602516f..4cc67caac2be8c75cd60be5ac63c9aefcc6e2c9c 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
2022-01-02 18:29:21 +01:00
|
|
|
@@ -44,7 +44,7 @@ public class CraftBlockData implements BlockData {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Material getMaterial() {
|
2021-06-14 18:58:00 +02:00
|
|
|
- return CraftMagicNumbers.getMaterial(this.state.getBlock());
|
|
|
|
+ return this.state.getBukkitMaterial(); // Paper - optimise getType calls
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2021-11-24 17:39:04 +01:00
|
|
|
index ee88ff2ee86bbd3ccf3e4a0b2310f020f137ef4f..5e15feb408b8a05ec5ee393a604c8d39a91ff106 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/generator/CraftChunkData.java
|
2021-11-24 17:39:04 +01:00
|
|
|
@@ -96,7 +96,7 @@ public final class CraftChunkData implements ChunkGenerator.ChunkData {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Material getType(int x, int y, int z) {
|
2021-06-14 18:58:00 +02:00
|
|
|
- return CraftMagicNumbers.getMaterial(this.getTypeId(x, y, z).getBlock());
|
|
|
|
+ return this.getTypeId(x, y, z).getBukkitMaterial(); // Paper - optimise getType calls
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|