Paper/Spigot-Server-Patches/0292-Optimize-CraftBlockData-Creation.patch
Spottedleaf 5c7081fecc Update upstream & fix some chunk related issues (#2177)
* Updated Upstream (Bukkit/CraftBukkit)

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:
45690fe9 SPIGOT-5047: Correct slot types for 1.14 inventories

CraftBukkit Changes:
4090d01f SPIGOT-5047: Correct slot types for 1.14 inventories
e8c08362 SPIGOT-5046: World#getLoadedChunks returning inaccessible cached chunks.
d445af3b SPIGOT-5067: Add item meta for 1.14 spawn eggs

* Bring Chunk load checks in-line with spigot

As of the last upstream merge spigot now checks ticket level status
when returning loaded chunks for a world from api. Now our checks
will respect that decision.

* Fix spawn ticket levels

Vanilla would keep the inner chunks of spawn available for ticking,
however my changes made all chunks non-ticking. Resolve by changing
ticket levels for spawn chunks inside the border to respect this
behavior.


* Make World#getChunkIfLoadedImmediately return only entity ticking chunks

Mojang appears to be using chunks with level > 33 (non-ticking chunks)
as cached chunks and not actually loaded chunks.

* Bring all loaded checks in line with spigot

Loaded chunks must be at least border  chunks, or level <= 33
2019-06-14 03:27:40 +01:00

63 lines
2.5 KiB
Diff

From 1d500b69a89b640cba6fd9857e353f2159f5264d 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/IBlockData.java b/src/main/java/net/minecraft/server/IBlockData.java
index 0f4aa698aa..c66cabe82f 100644
--- a/src/main/java/net/minecraft/server/IBlockData.java
+++ b/src/main/java/net/minecraft/server/IBlockData.java
@@ -4,6 +4,8 @@ import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.Dynamic;
import com.mojang.datafixers.types.DynamicOps;
import com.mojang.datafixers.util.Pair;
+import org.bukkit.craftbukkit.block.data.CraftBlockData;
+
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@@ -38,6 +40,15 @@ public class IBlockData extends BlockDataAbstract<Block, IBlockData> implements
return (Block) this.a;
}
+ // Paper start - impl cached craft block data, lazy load to fix issue with loading at the wrong time
+ private CraftBlockData cachedCraftBlockData;
+
+ public CraftBlockData createCraftBlockData() {
+ if(cachedCraftBlockData == null) cachedCraftBlockData = CraftBlockData.createData(this);
+ return (CraftBlockData) cachedCraftBlockData.clone();
+ }
+ // Paper end
+
public Material getMaterial() {
return this.getBlock().l(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 c1666a9baf..3c29abd525 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
@@ -539,7 +539,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.21.0