Make BlockData creation thread safe again (#6876)

This commit is contained in:
Pierre Maurice Schwang 2022-01-02 18:29:21 +01:00 committed by GitHub
parent d3f3429d03
commit 19bc612483
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 14 deletions

View file

@ -17,23 +17,15 @@ index 95842327aa08d4717f86e9dcc0519ab24c41ca14..135b3e44fb6054d360327a0ce46decc4
if (this.isSameThread()) {
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 3594f432a25b580173e8577bf324be954f5eddd1..6dc8f9f269db6971b8b46819e017357899ccd118 100644
index 3594f432a25b580173e8577bf324be954f5eddd1..d62ba8d02228b2a00202190ff16a0efc342c7b83 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
@@ -13,6 +13,7 @@ import net.minecraft.commands.arguments.blocks.BlockStateParser;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
@@ -494,9 +495,39 @@ public class CraftBlockData implements BlockData {
@@ -494,9 +494,39 @@ public class CraftBlockData implements BlockData {
Preconditions.checkState(CraftBlockData.MAP.put(nms, bukkit) == null, "Duplicate mapping %s->%s", nms, bukkit);
}
+ // Paper start - cache block data strings
+ private static Map<String, CraftBlockData> stringDataCache = new HashMap<>();
+ private static Map<String, CraftBlockData> stringDataCache = new java.util.concurrent.ConcurrentHashMap<>();
+
+ static {
+ // cache all of the default states at startup, will not cache ones with the custom states inside of the
@ -54,7 +46,7 @@ index 3594f432a25b580173e8577bf324be954f5eddd1..6dc8f9f269db6971b8b46819e0173578
+ if (material != null) {
+ Block block = CraftMagicNumbers.getBlock(material);
+ if (block != null) {
+ ResourceLocation key = Registry.BLOCK.getKey(block);
+ net.minecraft.resources.ResourceLocation key = Registry.BLOCK.getKey(block);
+ data = data == null ? key.toString() : key + data;
+ }
+ }