Paper/Spigot-Server-Patches/0335-Optimize-CraftBlockData-Creation.patch
Shane Freeder ac66acab27
Updated Upstream (Bukkit/CraftBukkit/Spigot)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
78568d11 Tweak Block.getTemperature to return actual block temperature
9ad459ca SPIGOT-2151: Add support for getting simple bounding box of a block
ad28b19f Add BlockData#getAsString(boolean) to hide unspecified states

CraftBukkit Changes:
1b982fd6 Tweak Block.getTemperature to return actual block temperature
f55c8191 SPIGOT-2151: Add support for getting simple bounding box of a block
4b843638 Add BlockData#getAsString(boolean) to hide unspecified states

Spigot Changes:
573cdf2c BUILDTOOLS-425: Disable commit.gpgSign in applyPatches.sh
667bdd6b Deprecate Spigot version of Entity.isInvulnerable
2018-12-21 16:09:17 +00:00

74 lines
3.1 KiB
Diff

From 282209ce7be1433a8ce6153e59ba0a56737fc9d7 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/BlockData.java b/src/main/java/net/minecraft/server/BlockData.java
index fbe181c1f..bd86cd2e5 100644
--- a/src/main/java/net/minecraft/server/BlockData.java
+++ b/src/main/java/net/minecraft/server/BlockData.java
@@ -1,6 +1,7 @@
package net.minecraft.server;
import com.google.common.collect.ImmutableMap;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
public class BlockData extends BlockDataAbstract<Block, IBlockData> implements IBlockData {
public BlockData(Block block, ImmutableMap<IBlockState<?>, Comparable<?>> immutablemap) {
@@ -10,4 +11,14 @@ public class BlockData extends BlockDataAbstract<Block, IBlockData> implements I
public Block getBlock() {
return this.e_;
}
+
+ // Paper start - impl cached craft block data, lazy load to fix issue with loading at the wrong time
+ private CraftBlockData cachedCraftBlockData;
+
+ @Override
+ public CraftBlockData createCraftBlockData() {
+ if(cachedCraftBlockData == null) cachedCraftBlockData = CraftBlockData.createData(this);
+ return (CraftBlockData) cachedCraftBlockData.clone();
+ }
+ // Paper end
}
diff --git a/src/main/java/net/minecraft/server/IBlockData.java b/src/main/java/net/minecraft/server/IBlockData.java
index 1423419b9..2d855aae6 100644
--- a/src/main/java/net/minecraft/server/IBlockData.java
+++ b/src/main/java/net/minecraft/server/IBlockData.java
@@ -23,6 +23,8 @@ public interface IBlockData extends IBlockDataHolder<IBlockData> {
Block getBlock();
+ org.bukkit.craftbukkit.block.data.CraftBlockData createCraftBlockData(); // Paper - property for converting IBlockData to CraftBlockData, should only be used by CraftBlockData#fromData and should return a clone
+
default Material getMaterial() {
return this.getBlock().n(this);
}
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 57f483367..8ac8969e2 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
@@ -531,7 +531,17 @@ public class CraftBlockData implements BlockData {
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);
}
}
--
2.20.1