Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 12:30:06 +01:00
36f34f01c0
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: da9ef3c5 #496: Add methods to get/set ItemStacks in EquipmentSlots 3abebc9f #492: Let Tameable extend Animals rather than Entity 941111a0 #495: Expose ItemStack and hand used in PlayerShearEntityEvent 4fe19cae #494: InventoryView - Add missing Brewing FUEL_TIME CraftBukkit Changes:933e9094
#664: Add methods to get/set ItemStacks in EquipmentSlots18722312
#662: Expose ItemStack and hand used in PlayerShearEntityEvent
60 Zeilen
2.6 KiB
Diff
60 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/server/IBlockData.java b/src/main/java/net/minecraft/server/IBlockData.java
|
|
index 9ab57be8500bf5106e32671b8d5fb11d8e9b1c60..c1ff62aa52595decd7ed8278eb63e7c6e46feefe 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().k(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 683b17a0c9f09d90c2fc30aad6516b4d01d2f34f..a0746a1694a01996eab44a91b078ba14996f3d13 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/data/CraftBlockData.java
|
|
@@ -549,7 +549,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);
|
|
}
|
|
}
|