Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
41647af74c
We cannot put blocking network I/O onto the worldgen threads, this will crash the server if it stalls
50 Zeilen
2.6 KiB
Diff
50 Zeilen
2.6 KiB
Diff
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/world/level/block/state/BlockBehaviour.java b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
|
|
index 06525d7687fec5b37cd6020ad1bac998b194e89f..942dae5116840a2e8a992f0830574ab2a315bdf1 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
|
|
@@ -694,6 +694,14 @@ public abstract class BlockBehaviour {
|
|
this.emissiveRendering = blockbase_info.emissiveRendering;
|
|
this.offsetType = (BlockBehaviour.OffsetType) blockbase_info.offsetType.apply(this.asState());
|
|
}
|
|
+ // 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(asState());
|
|
+ return (org.bukkit.craftbukkit.block.data.CraftBlockData) cachedCraftBlockData.clone();
|
|
+ }
|
|
+ // Paper end
|
|
|
|
// Paper start
|
|
protected boolean shapeExceedsCube = true;
|
|
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 15aff39d8d68430cc35ab134c0ab55cf50575cce..8ec78b26d6bfbcdad443c9649e35f79dd336b095 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
|
@@ -533,7 +533,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.BLOCK_STATE_REGISTRY.iterator().forEachRemaining(BlockState::createCraftBlockData);
|
|
+ }
|
|
public static CraftBlockData fromData(BlockState data) {
|
|
+ return data.createCraftBlockData();
|
|
+ }
|
|
+
|
|
+ public static CraftBlockData createData(BlockState data) {
|
|
+ // Paper end
|
|
return CraftBlockData.MAP.getOrDefault(data.getBlock().getClass(), CraftBlockData::new).apply(data);
|
|
}
|
|
|