2020-06-26 08:29:44 +02: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.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/BlockBase.java b/src/main/java/net/minecraft/server/BlockBase.java
|
2020-11-03 08:27:09 +01:00
|
|
|
index 8bcca73ae48ee822d32a6d23be2e1056a376e5f6..62e7c6cb1b363d1ee626c4405f8c30e74aba03e9 100644
|
2020-06-26 08:29:44 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/BlockBase.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/BlockBase.java
|
|
|
|
@@ -323,6 +323,14 @@ public abstract class BlockBase {
|
|
|
|
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
|
2020-11-26 00:49:06 +01:00
|
|
|
index 0a377b2026d147abe3d0ec44ed605a20d4664fea..41a32f2c77f2e7b79a067a0ce15c894e53ed8709 100644
|
2020-06-26 08:29:44 +02: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 08:27:09 +01:00
|
|
|
@@ -509,7 +509,17 @@ public class CraftBlockData implements BlockData {
|
2020-06-26 08:29:44 +02: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-26 00:49:06 +01:00
|
|
|
|