2020-06-26 06:29:44 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: miclebrick <miclebrick@outlook.com>
|
|
|
|
Date: Thu, 23 Aug 2018 11:45:32 -0400
|
|
|
|
Subject: [PATCH] Optimize CraftBlockData Creation
|
|
|
|
|
|
|
|
Avoids a hashmap lookup by cacheing a reference to the CraftBlockData
|
|
|
|
and cloning it when one is needed.
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/state/BlockBase.java b/src/main/java/net/minecraft/world/level/block/state/BlockBase.java
|
|
|
|
index 61e2da8d8b2ebf50b28362c5c89bf5c32dbba1ba..58c9f11bda5b8a0d80739d7c243e8e5cba4fe0af 100644
|
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBase.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBase.java
|
|
|
|
@@ -374,6 +374,14 @@ public abstract class BlockBase {
|
2020-06-26 06:29:44 +00:00
|
|
|
this.o = blockbase_info.t;
|
|
|
|
this.p = blockbase_info.u;
|
|
|
|
}
|
|
|
|
+ // Paper start - impl cached craft block data, lazy load to fix issue with loading at the wrong time
|
|
|
|
+ private org.bukkit.craftbukkit.block.data.CraftBlockData cachedCraftBlockData;
|
|
|
|
+
|
|
|
|
+ public org.bukkit.craftbukkit.block.data.CraftBlockData createCraftBlockData() {
|
|
|
|
+ if (cachedCraftBlockData == null) cachedCraftBlockData = org.bukkit.craftbukkit.block.data.CraftBlockData.createData(getBlockData());
|
|
|
|
+ return (org.bukkit.craftbukkit.block.data.CraftBlockData) cachedCraftBlockData.clone();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
public void a() {
|
|
|
|
if (!this.getBlock().o()) {
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
2021-03-16 07:19:45 +00:00
|
|
|
index 76fd1fea386d0e65c63c529dba772f01d9888407..ed88da727feddc319a650fb35710d16727f6dbd7 100644
|
2020-06-26 06:29:44 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
2020-11-03 07:27:09 +00:00
|
|
|
@@ -509,7 +509,17 @@ public class CraftBlockData implements BlockData {
|
2020-06-26 06:29:44 +00:00
|
|
|
return craft;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - optimize creating BlockData to not need a map lookup
|
|
|
|
+ static {
|
|
|
|
+ // Initialize cached data for all IBlockData instances after registration
|
|
|
|
+ Block.REGISTRY_ID.iterator().forEachRemaining(IBlockData::createCraftBlockData);
|
|
|
|
+ }
|
|
|
|
public static CraftBlockData fromData(IBlockData data) {
|
|
|
|
+ return data.createCraftBlockData();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static CraftBlockData createData(IBlockData data) {
|
|
|
|
+ // Paper end
|
|
|
|
return MAP.getOrDefault(data.getBlock().getClass(), CraftBlockData::new).apply(data);
|
|
|
|
}
|
2020-11-25 23:49:06 +00:00
|
|
|
|