13
0
geforkt von Mirrors/Paper
Paper/patches/server/0242-Optimize-CraftBlockData-Creation.patch

50 Zeilen
2.9 KiB
Diff

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-04-26 05:15:07 +02:00
index e8815210405152696a9f7ddae64f87ff456fa9bd..3e76f1baa321f1c2551a027a705bbeed48936e2b 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
2024-04-24 04:46:06 +02:00
@@ -807,6 +807,14 @@ public abstract class BlockBehaviour implements FeatureElement {
this.instrument = blockbase_info.instrument;
2023-06-07 22:19:14 +02:00
this.replaceable = blockbase_info.replaceable;
2021-06-11 14:02:28 +02:00
}
+ // Paper start - Perf: impl cached craft block data, lazy load to fix issue with loading at the wrong time
2021-06-11 14:02:28 +02:00
+ 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 - Perf: impl cached craft block data, lazy load to fix issue with loading at the wrong time
2021-06-11 14:02:28 +02:00
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-04-24 04:46:06 +02:00
index d2ec2d11736a74f8d568e25e9b560605518af987..19fab0d8d8a6211782df1fd99b5d60681aecd2f5 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-04-24 04:46:06 +02:00
@@ -571,7 +571,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
+ Block.BLOCK_STATE_REGISTRY.iterator().forEachRemaining(net.minecraft.world.level.block.state.BlockState::createCraftBlockData);
2021-06-11 14:02:28 +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();
+ }
+
+ 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
}