2021-06-11 14:02:28 +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/world/level/block/state/BlockBehaviour.java b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
|
2024-01-12 21:58:54 +01:00
|
|
|
index a009fca54665cbc3f11cad776256fbf1fbbb18c7..2c7d025b2af3a66772c3f394620483045fb80242 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/block/state/BlockBehaviour.java
|
2023-12-05 23:12:48 +01:00
|
|
|
@@ -876,6 +876,14 @@ public abstract class BlockBehaviour implements FeatureElement {
|
2023-06-07 22:19:14 +02:00
|
|
|
this.replaceable = blockbase_info.replaceable;
|
2024-01-12 21:58:54 +01:00
|
|
|
this.conditionallyFullOpaque = this.canOcclude & this.useShapeForLightOcclusion; // Paper
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
+ // 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() {
|
2021-06-17 21:37:37 +02:00
|
|
|
+ if (cachedCraftBlockData == null) cachedCraftBlockData = org.bukkit.craftbukkit.block.data.CraftBlockData.createData(asState());
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return (org.bukkit.craftbukkit.block.data.CraftBlockData) cachedCraftBlockData.clone();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
2023-06-07 22:19:14 +02:00
|
|
|
private boolean calculateSolid() {
|
|
|
|
if (((Block) this.owner).properties.forceSolidOn) {
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
2024-01-14 10:46:04 +01:00
|
|
|
index 09b95423e66da487f48ee594ba682a4c92e347b5..85ee8a3d6db6610104f8a10d77d7cad5dc9b667e 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
2024-01-14 10:46:04 +01:00
|
|
|
@@ -570,7 +570,17 @@ public class CraftBlockData implements BlockData {
|
2021-06-11 14:02:28 +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
|
2023-06-16 12:28:31 +02:00
|
|
|
+ Block.BLOCK_STATE_REGISTRY.iterator().forEachRemaining(net.minecraft.world.level.block.state.BlockState::createCraftBlockData);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2023-06-16 12:28:31 +02:00
|
|
|
public static CraftBlockData fromData(net.minecraft.world.level.block.state.BlockState data) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return data.createCraftBlockData();
|
|
|
|
+ }
|
|
|
|
+
|
2023-06-16 12:28:31 +02:00
|
|
|
+ public static CraftBlockData createData(net.minecraft.world.level.block.state.BlockState data) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
2021-06-13 01:45:00 +02:00
|
|
|
return CraftBlockData.MAP.getOrDefault(data.getBlock().getClass(), CraftBlockData::new).apply(data);
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|