fallback to default locate logic if no API found

This commit is contained in:
Jake Potrebic 2022-06-08 13:42:54 -07:00
parent 9107753202
commit 467a16642a
No known key found for this signature in database
GPG key ID: ECE0B3C133C016C5
2 changed files with 19 additions and 17 deletions

View file

@ -72,10 +72,10 @@ index 0000000000000000000000000000000000000000..423bf87ebda7ea266dc7b48cbfadbc85
+ }
+}
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
index 0f92f2906195f5b2b70ca02a46fa111a46f8f18f..a0b21c6ffdc1a08472079db0cbfc36ec0155f2c4 100644
index 0f92f2906195f5b2b70ca02a46fa111a46f8f18f..a4e2ee3efde40c902555f982ffa546c24bc31377 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
@@ -295,6 +295,24 @@ public abstract class ChunkGenerator {
@@ -295,6 +295,26 @@ public abstract class ChunkGenerator {
@Nullable
public Pair<BlockPos, Holder<Structure>> findNearestMapStructure(ServerLevel world, HolderSet<Structure> structures, BlockPos center, int radius, boolean skipReferencedStructures) {
@ -85,17 +85,19 @@ index 0f92f2906195f5b2b70ca02a46fa111a46f8f18f..a0b21c6ffdc1a08472079db0cbfc36ec
+ final var paperRegistry = io.papermc.paper.registry.PaperRegistry.getRegistry(io.papermc.paper.registry.RegistryKey.CONFIGURED_STRUCTURE_REGISTRY);
+ final List<io.papermc.paper.world.structure.ConfiguredStructure> configuredStructures = new ArrayList<>();
+ paperRegistry.convertToApi(structures, configuredStructures::add, false); // gracefully handle missing api, use tests to check (or exclude)
+ final io.papermc.paper.event.world.StructuresLocateEvent event = new io.papermc.paper.event.world.StructuresLocateEvent(bukkitWorld, origin, configuredStructures, radius, skipReferencedStructures);
+ if (!event.callEvent()) {
+ return null;
+ if (!configuredStructures.isEmpty()) {
+ final io.papermc.paper.event.world.StructuresLocateEvent event = new io.papermc.paper.event.world.StructuresLocateEvent(bukkitWorld, origin, configuredStructures, radius, skipReferencedStructures);
+ if (!event.callEvent()) {
+ return null;
+ }
+ if (event.getResult() != null) {
+ return Pair.of(net.minecraft.server.MCUtil.toBlockPosition(event.getResult().position()), paperRegistry.getMinecraftHolder(event.getResult().configuredStructure()));
+ }
+ center = net.minecraft.server.MCUtil.toBlockPosition(event.getOrigin());
+ radius = event.getRadius();
+ skipReferencedStructures = event.shouldFindUnexplored();
+ structures = HolderSet.direct(paperRegistry::getMinecraftHolder, event.getConfiguredStructures());
+ }
+ if (event.getResult() != null) {
+ return Pair.of(net.minecraft.server.MCUtil.toBlockPosition(event.getResult().position()), paperRegistry.getMinecraftHolder(event.getResult().configuredStructure()));
+ }
+ center = net.minecraft.server.MCUtil.toBlockPosition(event.getOrigin());
+ radius = event.getRadius();
+ skipReferencedStructures = event.shouldFindUnexplored();
+ structures = HolderSet.direct(paperRegistry::getMinecraftHolder, event.getConfiguredStructures());
+ // Paper end
Map<StructurePlacement, Set<Holder<Structure>>> map = new Object2ObjectArrayMap();
Iterator iterator = structures.iterator();

View file

@ -6,10 +6,10 @@ Subject: [PATCH] Configurable feature seeds
Co-authored-by: Thonk <30448663+ExcessiveAmountsOfZombies@users.noreply.github.com>
diff --git a/src/main/java/co/aikar/timings/TimingsExport.java b/src/main/java/co/aikar/timings/TimingsExport.java
index 4092a227a540a1c5cfb95efcc2a36e049b9a979c..e2f60115370f19e935eb3b14d5de99aa4126c6b0 100644
index 46297ac0a19fd2398ab777a381eff4d0a256161e..78280fb3bcd8d792a58ece6d735e0824ea4be536 100644
--- a/src/main/java/co/aikar/timings/TimingsExport.java
+++ b/src/main/java/co/aikar/timings/TimingsExport.java
@@ -282,7 +282,7 @@ public class TimingsExport extends Thread {
@@ -283,7 +283,7 @@ public class TimingsExport extends Thread {
JSONObject object = new JSONObject();
for (String key : config.getKeys(false)) {
String fullKey = (parentKey != null ? parentKey + "." + key : key);
@ -79,10 +79,10 @@ index 5c43fe70f8c87b0a83f10f9608ddca556e99e634..28b4188cd15d297e4b89ab98f78cecd7
return getIntOrDefault(behaviorTickRates, typeName, entityType, def);
}
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
index a0b21c6ffdc1a08472079db0cbfc36ec0155f2c4..974b948513c2b2c7f2503fbed044bcea01231938 100644
index a4e2ee3efde40c902555f982ffa546c24bc31377..094846cebffd209535e436ab0269cfed11deb277 100644
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGenerator.java
@@ -528,7 +528,7 @@ public abstract class ChunkGenerator {
@@ -530,7 +530,7 @@ public abstract class ChunkGenerator {
int j = list.size();
try {
@ -91,7 +91,7 @@ index a0b21c6ffdc1a08472079db0cbfc36ec0155f2c4..974b948513c2b2c7f2503fbed044bcea
int k = Math.max(GenerationStep.Decoration.values().length, j);
for (int l = 0; l < k; ++l) {
@@ -601,7 +601,15 @@ public abstract class ChunkGenerator {
@@ -603,7 +603,15 @@ public abstract class ChunkGenerator {
return (String) optional.orElseGet(placedfeature::toString);
};