Skip to content

Commit

Permalink
address jmp's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Mar 3, 2022
1 parent 6e28c98 commit d358851
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
10 changes: 8 additions & 2 deletions patches/api/0256-Add-PaperRegistry.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Subject: [PATCH] Add PaperRegistry

diff --git a/src/main/java/io/papermc/paper/registry/Reference.java b/src/main/java/io/papermc/paper/registry/Reference.java
new file mode 100644
index 0000000000000000000000000000000000000000..ec1bc3ea8345b24f39c507ed45165319b5153f91
index 0000000000000000000000000000000000000000..d880810cbf05bc45051fe29515054211572e33b4
--- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/Reference.java
@@ -0,0 +1,37 @@
@@ -0,0 +1,43 @@
+package io.papermc.paper.registry;
+
+import org.bukkit.Keyed;
Expand All @@ -18,6 +18,12 @@ index 0000000000000000000000000000000000000000..ec1bc3ea8345b24f39c507ed45165319
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Represents a reference to a server-backed registry value that may
+ * change.
+ *
+ * @param <T> type of the value
+ */
+public interface Reference<T extends Keyed> extends Keyed {
+
+ /**
Expand Down
15 changes: 3 additions & 12 deletions patches/api/0257-Add-StructuresLocateEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ index 0000000000000000000000000000000000000000..566f9df8f615142e14330965f3491f4e
+}
diff --git a/src/main/java/io/papermc/paper/world/structure/ConfiguredStructure.java b/src/main/java/io/papermc/paper/world/structure/ConfiguredStructure.java
new file mode 100644
index 0000000000000000000000000000000000000000..ef5dd6822178c2b795e411454a0ebc977183b6aa
index 0000000000000000000000000000000000000000..280febf7482418734558c50c22688248ac2b14f3
--- /dev/null
+++ b/src/main/java/io/papermc/paper/world/structure/ConfiguredStructure.java
@@ -0,0 +1,106 @@
@@ -0,0 +1,97 @@
+package io.papermc.paper.world.structure;
+
+import io.papermc.paper.registry.Reference;
Expand All @@ -352,10 +352,7 @@ index 0000000000000000000000000000000000000000..ef5dd6822178c2b795e411454a0ebc97
+import org.bukkit.Registry;
+import org.bukkit.StructureType;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.VisibleForTesting;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
Expand All @@ -365,9 +362,6 @@ index 0000000000000000000000000000000000000000..ef5dd6822178c2b795e411454a0ebc97
+ */
+public final class ConfiguredStructure implements Keyed {
+
+ @VisibleForTesting
+ static final Map<NamespacedKey, Reference<ConfiguredStructure>> DEFAULTS = new HashMap<>();
+
+ public static final Reference<ConfiguredStructure> PILLAGER_OUTPOST = create("pillager_outpost");
+ public static final Reference<ConfiguredStructure> MINESHAFT = create("mineshaft");
+ public static final Reference<ConfiguredStructure> MINESHAFT_MESA = create("mineshaft_mesa");
Expand Down Expand Up @@ -444,10 +438,7 @@ index 0000000000000000000000000000000000000000..ef5dd6822178c2b795e411454a0ebc97
+ }
+
+ private static @NotNull Reference<ConfiguredStructure> create(@NotNull String name) {
+ final NamespacedKey key = NamespacedKey.minecraft(name);
+ final Reference<ConfiguredStructure> reference = Reference.create(Registry.CONFIGURED_STRUCTURE, key);
+ DEFAULTS.put(key, reference);
+ return reference;
+ return Reference.create(Registry.CONFIGURED_STRUCTURE, NamespacedKey.minecraft(name));
+ }
+}
diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java
Expand Down
26 changes: 13 additions & 13 deletions patches/server/0580-Add-StructuresLocateEvent.patch
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,20 @@ index af9ef29f5c5a600e4544ba735c833699cc93f93a..473a54963fbe08beeff26a828827f9f7
this.feature = feature;
diff --git a/src/test/java/io/papermc/paper/world/structure/ConfiguredStructureTest.java b/src/test/java/io/papermc/paper/world/structure/ConfiguredStructureTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..e44822771a04549da63360d0e64467ea685e18eb
index 0000000000000000000000000000000000000000..29c0209327374d5a4dad4e3bacdba7fa56d80749
--- /dev/null
+++ b/src/test/java/io/papermc/paper/world/structure/ConfiguredStructureTest.java
@@ -0,0 +1,89 @@
+package io.papermc.paper.world.structure;
+
+import io.papermc.paper.registry.Reference;
+import net.minecraft.data.BuiltinRegistries;
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.Bootstrap;
+import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
+import net.minecraft.world.level.levelgen.structure.BuiltinStructures;
+import org.bukkit.NamespacedKey;
+import org.bukkit.StructureType;
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
+import org.bukkit.support.AbstractTestingBase;
+import org.junit.AfterClass;
Expand All @@ -135,9 +135,9 @@ index 0000000000000000000000000000000000000000..e44822771a04549da63360d0e64467ea
+
+import java.io.PrintStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.StringJoiner;
+
+import static org.junit.Assert.assertEquals;
Expand All @@ -147,36 +147,36 @@ index 0000000000000000000000000000000000000000..e44822771a04549da63360d0e64467ea
+public class ConfiguredStructureTest extends AbstractTestingBase {
+
+ private static final Map<ResourceLocation, String> BUILT_IN_STRUCTURES = new LinkedHashMap<>();
+ private static final Map<StructureType, String> API_STRUCTURE_TYPES = new LinkedHashMap<>();
+ private static final Map<NamespacedKey, Reference<?>> DEFAULT_CONFIGURED_STRUCTURES = new LinkedHashMap<>();
+
+ private static PrintStream out;
+
+ @BeforeClass
+ public static void collectStructures() throws ReflectiveOperationException {
+ out = System.out;
+ System.setOut(Bootstrap.STDOUT);
+ for (Field field : BuiltinStructures.class.getDeclaredFields()) {
+ if (field.getType().equals(ResourceKey.class)) {
+ BUILT_IN_STRUCTURES.put(((ResourceKey<ConfiguredStructureFeature<?, ?>>) field.get(null)).location(), field.getName());
+ if (field.getType().equals(ResourceKey.class) && Modifier.isStatic(field.getModifiers())) {
+ BUILT_IN_STRUCTURES.put(((ResourceKey<?>) field.get(null)).location(), field.getName());
+ }
+ }
+
+ for (Field field : StructureType.class.getDeclaredFields()) {
+ if (field.getType().equals(StructureType.class)) {
+ API_STRUCTURE_TYPES.put((StructureType) field.get(null), field.getName());
+ for (Field field : ConfiguredStructure.class.getDeclaredFields()) {
+ if (field.getType().equals(Reference.class) && Modifier.isStatic(field.getModifiers())) {
+ final Reference<?> ref = (Reference<?>) field.get(null);
+ DEFAULT_CONFIGURED_STRUCTURES.put(ref.getKey(), ref);
+ }
+ }
+ }
+
+ @Test
+ public void testMinecraftToApi() {
+ assertEquals("configured structure maps should be the same size", BUILT_IN_STRUCTURES.size(), BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.size());
+ assertEquals("api structure types map should be the same size", API_STRUCTURE_TYPES.size(), StructureType.getStructureTypes().size());
+
+ Map<ResourceLocation, ConfiguredStructureFeature<?, ?>> missing = new LinkedHashMap<>();
+ for (ConfiguredStructureFeature<?, ?> feature : BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE) {
+ final ResourceLocation key = BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getKey(feature);
+ assertNotNull("Missing built-in registry key", key);
+ if (ConfiguredStructure.DEFAULTS.get(CraftNamespacedKey.fromMinecraft(key)) == null) {
+ if (DEFAULT_CONFIGURED_STRUCTURES.get(CraftNamespacedKey.fromMinecraft(key)) == null) {
+ missing.put(key, feature);
+ }
+ }
Expand All @@ -186,7 +186,7 @@ index 0000000000000000000000000000000000000000..e44822771a04549da63360d0e64467ea
+
+ @Test
+ public void testApiToMinecraft() {
+ for (NamespacedKey apiKey : ConfiguredStructure.DEFAULTS.keySet()) {
+ for (NamespacedKey apiKey : DEFAULT_CONFIGURED_STRUCTURES.keySet()) {
+ assertTrue(apiKey + " does not have a minecraft counterpart", BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.containsKey(CraftNamespacedKey.toMinecraft(apiKey)));
+ }
+ }
Expand Down

0 comments on commit d358851

Please sign in to comment.