2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2022-09-26 10:02:51 +02:00
|
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
2021-06-11 14:02:28 +02:00
|
|
|
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
|
2022-12-07 21:16:54 +01:00
|
|
|
index da878e180c6b94f98dc82c6e8395f63ecc9b2c1e..a9b0f5950b6f97ea4c2a1075946b92008b62c9d9 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 {
|
2022-12-07 21:16:54 +01:00
|
|
|
public static final Codec<BlockState> CODEC = codec(BuiltInRegistries.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
|
2023-04-07 20:39:13 +02:00
|
|
|
index eebac2ea211f58c385b2ceb36ab911ac5e115296..d1aaca5de055fd5e3bf2c6d39ef397bbb2deeaae 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
|
2023-02-07 16:55:53 +01:00
|
|
|
@@ -98,7 +98,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
|
2023-06-08 01:44:11 +02:00
|
|
|
index f92b0151d9e2655191a3a7a009c5da66022dddc1..cd39ec0e87974be616f10321d953fd2f3af194f7 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
|
2023-05-12 13:10:08 +02:00
|
|
|
@@ -225,7 +225,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
|
2023-05-12 13:10:08 +02:00
|
|
|
index 843a166e43f05fe987e62329593b23656c6a2abb..9068557ac50cfb26e7e3ec4ac64bac583baa582e 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
|
2023-05-12 13:10:08 +02:00
|
|
|
@@ -167,7 +167,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
|
2023-06-08 01:44:11 +02:00
|
|
|
index cd40c4c86b1f5de37fea9c0cd71b2e7b30b9136f..58d10e8909fea652810e30bbd4b24aaa5e038277 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
|
2023-05-12 13:10:08 +02:00
|
|
|
@@ -57,7 +57,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
|