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
|
2023-12-05 23:12:48 +01:00
|
|
|
index bf42cead5fa040d87da28d7be521b109724da19b..b4241ccdf972feec3dc2802ceafeef4f004c62d5 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;
|
2022-09-26 10:02:51 +02:00
|
|
|
this.conditionallyFullOpaque = this.isOpaque() & this.isTransparentOnSomeFaces(); // 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
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear 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:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
index 02b10005e7c6ac735de932fd12cff5579939c4d7..cf379f7da8d8e6db0d74f1ca0e4b42e017a8191e 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
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear 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:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -569,7 +569,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
|
|
|
}
|
|
|
|
|