2022-04-03 03:10:13 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
Date: Sun, 20 Mar 2022 22:06:47 -0700
|
|
|
|
Subject: [PATCH] cache resource keys
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
2022-12-15 14:19:09 +01:00
|
|
|
index 0976a1295be35dd7c053fb4ee4050011fc3d95fe..87dfc2fd1e2ff9e9449f1ce00dfb63e3e88839cd 100644
|
2022-04-03 03:10:13 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
2022-12-07 22:35:34 +01:00
|
|
|
@@ -368,12 +368,13 @@ public class CraftBlock implements Block {
|
2022-04-03 03:10:13 +02:00
|
|
|
return (biome == null) ? Biome.CUSTOM : biome;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ private static final java.util.Map<org.bukkit.block.Biome, net.minecraft.resources.ResourceKey<net.minecraft.world.level.biome.Biome>> BIOME_KEY_CACHE = Collections.synchronizedMap(new java.util.EnumMap<>(Biome.class)); // Paper
|
|
|
|
public static Holder<net.minecraft.world.level.biome.Biome> biomeToBiomeBase(net.minecraft.core.Registry<net.minecraft.world.level.biome.Biome> registry, Biome bio) {
|
|
|
|
if (bio == null || bio == Biome.CUSTOM) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-12-07 22:35:34 +01:00
|
|
|
- return registry.getHolderOrThrow(ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(bio.getKey())));
|
|
|
|
+ return registry.getHolderOrThrow(BIOME_KEY_CACHE.computeIfAbsent(bio, b -> ResourceKey.create(Registries.BIOME, CraftNamespacedKey.toMinecraft(b.getKey())))); // Paper - cache key
|
2022-04-03 03:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java b/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java
|
2022-12-07 22:35:34 +01:00
|
|
|
index e0bf615fb1b99abbab2be55a4ee345204b36e218..7b3b12b4b2f5dbd37e23a7f5a0ad2abd04d259e2 100644
|
2022-04-03 03:10:13 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/tag/CraftEntityTag.java
|
|
|
|
@@ -16,9 +16,10 @@ public class CraftEntityTag extends CraftTag<net.minecraft.world.entity.EntityTy
|
|
|
|
super(registry, tag);
|
|
|
|
}
|
|
|
|
|
2022-12-07 22:35:34 +01:00
|
|
|
+ private static final java.util.Map<org.bukkit.entity.EntityType, net.minecraft.resources.ResourceKey<net.minecraft.world.entity.EntityType<?>>> KEY_CACHE = java.util.Collections.synchronizedMap(new java.util.EnumMap<>(EntityType.class)); // Paper
|
2022-04-03 03:10:13 +02:00
|
|
|
@Override
|
|
|
|
public boolean isTagged(EntityType entity) {
|
2022-12-07 22:35:34 +01:00
|
|
|
- return registry.getHolderOrThrow(ResourceKey.create(Registries.ENTITY_TYPE, CraftNamespacedKey.toMinecraft(entity.getKey()))).is(tag);
|
|
|
|
+ return registry.getHolderOrThrow(KEY_CACHE.computeIfAbsent(entity, type -> ResourceKey.create(Registries.ENTITY_TYPE, CraftNamespacedKey.toMinecraft(type.getKey())))).is(tag); // Paper - cache key
|
2022-04-03 03:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java b/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java
|
2022-12-08 04:24:00 +01:00
|
|
|
index cdd474e9b0363641839a66d3e61fec46c735879a..1a987b3c8f044dfd217e984dc122582095367e46 100644
|
2022-04-03 03:10:13 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java
|
|
|
|
@@ -14,9 +14,10 @@ public class CraftFluidTag extends CraftTag<net.minecraft.world.level.material.F
|
|
|
|
super(registry, tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ private static final java.util.Map<Fluid, net.minecraft.resources.ResourceKey<net.minecraft.world.level.material.Fluid>> KEY_CACHE = Collections.synchronizedMap(new java.util.EnumMap<>(Fluid.class)); // Paper
|
|
|
|
@Override
|
|
|
|
public boolean isTagged(Fluid fluid) {
|
|
|
|
- return registry.getHolderOrThrow(net.minecraft.resources.ResourceKey.create(net.minecraft.core.Registry.FLUID_REGISTRY, org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(fluid.getKey()))).is(tag); // Paper
|
2022-12-08 04:24:00 +01:00
|
|
|
+ return registry.getHolderOrThrow(KEY_CACHE.computeIfAbsent(fluid, f -> net.minecraft.resources.ResourceKey.create(net.minecraft.core.registries.Registries.FLUID, org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(f.getKey())))).is(tag); // Paper - cache key
|
2022-04-03 03:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|