From f52a4014b8a2e84d5bf5c534e09b5f6178664501 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 1 Mar 2022 14:40:34 -0800 Subject: [PATCH] Fix various 1.18.2 update issues (#7523) --- .../Fix-Fluid-tags-isTagged-method.patch | 32 ++++++++ .../Fix-World-locateNearestStructure.patch | 74 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 patches/server/Fix-Fluid-tags-isTagged-method.patch create mode 100644 patches/server/Fix-World-locateNearestStructure.patch diff --git a/patches/server/Fix-Fluid-tags-isTagged-method.patch b/patches/server/Fix-Fluid-tags-isTagged-method.patch new file mode 100644 index 0000000000..00ef77f8b6 --- /dev/null +++ b/patches/server/Fix-Fluid-tags-isTagged-method.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jake Potrebic +Date: Tue, 1 Mar 2022 12:45:50 -0800 +Subject: [PATCH] Fix Fluid tags isTagged method + + +diff --git a/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java b/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java ++++ b/src/main/java/org/bukkit/craftbukkit/tag/CraftFluidTag.java +@@ -0,0 +0,0 @@ public class CraftFluidTag extends CraftTag +Date: Tue, 1 Mar 2022 14:12:17 -0800 +Subject: [PATCH] Fix World#locateNearestStructure + +1.18.2 switched to TagKeys to reference tags of objects, and this method + impl needs to be changed to reflect that + +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -0,0 +0,0 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop>> pair = this.getChunkSource().getGenerator().findNearestMapFeature(this, (HolderSet) optional.get(), pos, radius, skipExistingChunks); ++ // Paper start ++ return this.findNearestMapFeature(optional.get(), pos, radius, skipExistingChunks); ++ } ++ } ++ } ++ public @Nullable BlockPos findNearestMapFeature(HolderSet> holderSet, BlockPos pos, int radius, boolean skipExistingChunks) { ++ { ++ { ++ Pair>> pair = this.getChunkSource().getGenerator().findNearestMapFeature(this, holderSet, pos, radius, skipExistingChunks); ++ // Paper end + + return pair != null ? (BlockPos) pair.getFirst() : null; + } +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +@@ -0,0 +0,0 @@ public class CraftWorld extends CraftRegionAccessor implements World { + + } + ++ public final Map>>> structureCache = new java.util.HashMap<>(); // Paper + @Override + public Location locateNearestStructure(Location origin, StructureType structureType, int radius, boolean findUnexplored) { + BlockPos originPos = new BlockPos(origin.getX(), origin.getY(), origin.getZ()); +- BlockPos nearest = this.getHandle().findNearestMapFeature(TagKey.create(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY, CraftNamespacedKey.toMinecraft(structureType.getKey())), originPos, radius, findUnexplored); ++ // Paper start - fix because you can't just create random TagKeys ++ if (!this.getHandle().serverLevelData.worldGenSettings().generateFeatures()) { // from ServerLevel#findNearestMapFeature ++ return null; ++ } ++ final List>> features = this.structureCache.computeIfAbsent(structureType, (type) -> { ++ final Registry> structureFeatureRegistry = this.getHandle().registryAccess().registryOrThrow(Registry.STRUCTURE_FEATURE_REGISTRY); ++ return this.getHandle().registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).holders().filter(holder -> { ++ return structureType.getKey().equals(org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(Objects.requireNonNull(structureFeatureRegistry.getKey(holder.value().feature)))); ++ }).toList(); ++ }); ++ BlockPos nearest = this.getHandle().findNearestMapFeature(net.minecraft.core.HolderSet.direct(features), originPos, radius, findUnexplored); ++ // Paper end + return (nearest == null) ? null : new Location(this, nearest.getX(), nearest.getY(), nearest.getZ()); + } +