13
0
geforkt von Mirrors/Paper

Fix structures issues/api (#7895)

Dieser Commit ist enthalten in:
Jake Potrebic 2022-06-08 12:00:19 -07:00
Ursprung f136fe47a3
Commit f823b12e0a
3 geänderte Dateien mit 32 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -393,7 +393,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public static final Reference<ConfiguredStructure> RUINED_PORTAL_MOUNTAIN = create("ruined_portal_mountain");
+ public static final Reference<ConfiguredStructure> RUINED_PORTAL_OCEAN = create("ruined_portal_ocean");
+ public static final Reference<ConfiguredStructure> RUINED_PORTAL_NETHER = create("ruined_portal_nether");
+ public static final Reference<ConfiguredStructure> ANCIENT_CITY = create("ancient_city");
+ // public static final Reference<ConfiguredStructure> ANCIENT_CITY = create("ancient_city"); // TODO remove when upstream adds "jigsaw" StructureType
+
+ private final NamespacedKey key;
+ private final StructureType structureType;

Datei anzeigen

@ -35,6 +35,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+
+@DefaultQualifier(NonNull.class)
@ -69,13 +70,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ });
+ }
+
+ public abstract API convertToApi(NamespacedKey key, MINECRAFT nms);
+ public abstract @Nullable API convertToApi(NamespacedKey key, MINECRAFT nms);
+
+ public API convertToApi(ResourceLocation resourceLocation, MINECRAFT nms) {
+ public API convertToApiOrThrow(ResourceLocation resourceLocation, MINECRAFT nms) {
+ return Objects.requireNonNull(this.convertToApi(resourceLocation, nms), resourceLocation + " has a null api representation");
+ }
+
+ public @Nullable API convertToApi(ResourceLocation resourceLocation, MINECRAFT nms) {
+ return this.convertToApi(CraftNamespacedKey.fromMinecraft(resourceLocation), nms);
+ }
+
+ public API convertToApi(Holder<MINECRAFT> nmsHolder) {
+ public API convertToApiOrThrow(Holder<MINECRAFT> nmsHolder) {
+ return Objects.requireNonNull(this.convertToApi(nmsHolder), nmsHolder + " has a null api representation");
+ }
+
+ public @Nullable API convertToApi(Holder<MINECRAFT> nmsHolder) {
+ final Optional<ResourceKey<MINECRAFT>> key = nmsHolder.unwrapKey();
+ if (nmsHolder.isBound() && key.isPresent()) {
+ return this.convertToApi(key.get().location(), nmsHolder.value());
@ -90,6 +99,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ throw new IllegalStateException("Cannot convert " + nmsHolder + " to an API type in: " + this.registryKey);
+ }
+
+ public void convertToApi(Iterable<Holder<MINECRAFT>> holders, Consumer<API> apiConsumer, boolean throwOnNull) {
+ for (Holder<MINECRAFT> holder : holders) {
+ final @Nullable API api = this.convertToApi(holder);
+ if (api == null && throwOnNull) {
+ throw new NullPointerException(holder + " has a null api representation");
+ } else if (api != null) {
+ apiConsumer.accept(api);
+ }
+ }
+ }
+
+ public MINECRAFT getMinecraftValue(API apiValue) {
+ return this.registry.get().getOptional(CraftNamespacedKey.toMinecraft(apiValue.getKey())).orElseThrow();
+ }

Datei anzeigen

@ -39,6 +39,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+import org.bukkit.NamespacedKey;
+import org.bukkit.StructureType;
+import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.framework.qual.DefaultQualifier;
+
+import java.util.Objects;
@ -63,10 +64,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ @Override
+ public ConfiguredStructure convertToApi(NamespacedKey key, Structure nms) {
+ public @Nullable ConfiguredStructure convertToApi(NamespacedKey key, Structure nms) {
+ final ResourceLocation structureTypeLoc = Objects.requireNonNull(Registry.STRUCTURE_TYPES.getKey(nms.type()), "unexpected structure type " + nms.type());
+ final StructureType structureType = Objects.requireNonNull(StructureType.getStructureTypes().get(structureTypeLoc.getPath()), structureTypeLoc + " could not be converted to an API type"); // TODO this is just not gonna work until upstream fixes their StructureType pseudo-enum
+ return new ConfiguredStructure(key, structureType);
+ final @Nullable StructureType structureType = StructureType.getStructureTypes().get(structureTypeLoc.getPath());
+ return structureType == null ? null : new ConfiguredStructure(key, structureType);
+ }
+ }
+}
@ -83,9 +84,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ final org.bukkit.Location origin = net.minecraft.server.MCUtil.toLocation(world, center);
+ 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<>();
+ for (Holder<Structure> holder : structures) {
+ configuredStructures.add(paperRegistry.convertToApi(holder));
+ }
+ 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;
@ -178,6 +177,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ for (Structure feature : BuiltinRegistries.STRUCTURES) {
+ final ResourceLocation key = BuiltinRegistries.STRUCTURES.getKey(feature);
+ assertNotNull("Missing built-in registry key", key);
+ if (key.equals(BuiltinStructures.ANCIENT_CITY.location())) {
+ continue; // TODO remove when upstream adds "jigsaw" StructureType
+ }
+ if (DEFAULT_CONFIGURED_STRUCTURES.get(CraftNamespacedKey.fromMinecraft(key)) == null) {
+ missing.put(key, feature);
+ }