fix some stuff

This commit is contained in:
Jake Potrebic 2024-05-04 10:15:21 -07:00
parent 42b9aeb28f
commit 683fb6bcd2
No known key found for this signature in database
GPG Key ID: ECE0B3C133C016C5
7 changed files with 99 additions and 66 deletions

View File

@ -163,6 +163,28 @@ index 0000000000000000000000000000000000000000..b89e19c070f97c9662f1e16309446494
+ private RegistryAccessHolder() { + private RegistryAccessHolder() {
+ } + }
+} +}
diff --git a/src/main/java/io/papermc/paper/registry/RegistryKeyImpl.java b/src/main/java/io/papermc/paper/registry/RegistryKeyImpl.java
index 791813220b2504214b1adecc69093cd600fb0f8c..47fe5b0d5d031110c27210a0a256c260b35d9ba1 100644
--- a/src/main/java/io/papermc/paper/registry/RegistryKeyImpl.java
+++ b/src/main/java/io/papermc/paper/registry/RegistryKeyImpl.java
@@ -10,6 +10,17 @@ record RegistryKeyImpl<T>(@NotNull Key key) implements RegistryKey<T> {
static final Set<RegistryKey<?>> REGISTRY_KEYS = Sets.newIdentityHashSet();
+ // override equals and hashCode to this can be used to simulate an "identity" hashmap
+ @Override
+ public boolean equals(final Object obj) {
+ return obj == this;
+ }
+
+ @Override
+ public int hashCode() {
+ return System.identityHashCode(this);
+ }
+
static <T> RegistryKey<T> create(@Subst("some_key") final String key) {
final RegistryKey<T> registryKey = createInternal(key);
REGISTRY_KEYS.add(registryKey);
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 732ed3724e784ad659cb4411dbd73b42a8330a2c..7be6710d28dea19bd0f9054c1c2e32dacd355c45 100644 index 732ed3724e784ad659cb4411dbd73b42a8330a2c..7be6710d28dea19bd0f9054c1c2e32dacd355c45 100644
--- a/src/main/java/org/bukkit/Bukkit.java --- a/src/main/java/org/bukkit/Bukkit.java
@ -180,7 +202,7 @@ index 732ed3724e784ad659cb4411dbd73b42a8330a2c..7be6710d28dea19bd0f9054c1c2e32da
return server.getRegistry(tClass); return server.getRegistry(tClass);
} }
diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java
index a04d279561676e825905f5512c399d14a3d8f828..7aee2cee892492c523ae06902c6582b0ab827ffa 100644 index a04d279561676e825905f5512c399d14a3d8f828..91117cad12eee0bdaac8e0398a0f7f288ba27a40 100644
--- a/src/main/java/org/bukkit/Registry.java --- a/src/main/java/org/bukkit/Registry.java
+++ b/src/main/java/org/bukkit/Registry.java +++ b/src/main/java/org/bukkit/Registry.java
@@ -129,7 +129,7 @@ public interface Registry<T extends Keyed> extends Iterable<T> { @@ -129,7 +129,7 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
@ -218,7 +240,7 @@ index a04d279561676e825905f5512c399d14a3d8f828..7aee2cee892492c523ae06902c6582b0
*/ */
- Registry<Structure> STRUCTURE = Bukkit.getRegistry(Structure.class); - Registry<Structure> STRUCTURE = Bukkit.getRegistry(Structure.class);
+ @Deprecated(since = "1.20.6") // Paper + @Deprecated(since = "1.20.6") // Paper
+ Registry<Structure> STRUCTURE = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(Structure.class); // Paper + Registry<Structure> STRUCTURE = Objects.requireNonNull(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(Structure.class), "No registry present for Structure. This is a bug."); // Paper
/** /**
* Server structure types. * Server structure types.
* *
@ -237,7 +259,7 @@ index a04d279561676e825905f5512c399d14a3d8f828..7aee2cee892492c523ae06902c6582b0
*/ */
- Registry<TrimMaterial> TRIM_MATERIAL = Bukkit.getRegistry(TrimMaterial.class); - Registry<TrimMaterial> TRIM_MATERIAL = Bukkit.getRegistry(TrimMaterial.class);
+ @Deprecated(since = "1.20.6") // Paper + @Deprecated(since = "1.20.6") // Paper
+ Registry<TrimMaterial> TRIM_MATERIAL = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(TrimMaterial.class); // Paper + Registry<TrimMaterial> TRIM_MATERIAL = Objects.requireNonNull(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(TrimMaterial.class), "No registry present for TrimMaterial. This is a bug."); // Paper
/** /**
* Trim patterns. * Trim patterns.
* *
@ -246,7 +268,7 @@ index a04d279561676e825905f5512c399d14a3d8f828..7aee2cee892492c523ae06902c6582b0
*/ */
- Registry<TrimPattern> TRIM_PATTERN = Bukkit.getRegistry(TrimPattern.class); - Registry<TrimPattern> TRIM_PATTERN = Bukkit.getRegistry(TrimPattern.class);
+ @Deprecated(since = "1.20.6") + @Deprecated(since = "1.20.6")
+ Registry<TrimPattern> TRIM_PATTERN = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(TrimPattern.class); // Paper + Registry<TrimPattern> TRIM_PATTERN = Objects.requireNonNull(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(TrimPattern.class), "No registry present for TrimPattern. This is a bug."); // Paper
/** /**
* Damage types. * Damage types.
* *
@ -256,7 +278,7 @@ index a04d279561676e825905f5512c399d14a3d8f828..7aee2cee892492c523ae06902c6582b0
- @ApiStatus.Experimental - @ApiStatus.Experimental
- Registry<DamageType> DAMAGE_TYPE = Objects.requireNonNull(Bukkit.getRegistry(DamageType.class), "No registry present for DamageType. This is a bug."); - Registry<DamageType> DAMAGE_TYPE = Objects.requireNonNull(Bukkit.getRegistry(DamageType.class), "No registry present for DamageType. This is a bug.");
+ @Deprecated(since = "1.20.6") + @Deprecated(since = "1.20.6")
+ Registry<DamageType> DAMAGE_TYPE = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(DamageType.class); // Paper + Registry<DamageType> DAMAGE_TYPE = Objects.requireNonNull(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(DamageType.class), "No registry present for DamageType. This is a bug."); // Paper
/** /**
* Villager profession. * Villager profession.
* *
@ -268,7 +290,7 @@ index a04d279561676e825905f5512c399d14a3d8f828..7aee2cee892492c523ae06902c6582b0
*/ */
- Registry<Wolf.Variant> WOLF_VARIANT = Objects.requireNonNull(Bukkit.getRegistry(Wolf.Variant.class), "No registry present for Wolf Variant. This is a bug."); - Registry<Wolf.Variant> WOLF_VARIANT = Objects.requireNonNull(Bukkit.getRegistry(Wolf.Variant.class), "No registry present for Wolf Variant. This is a bug.");
+ @Deprecated(since = "1.20.6") + @Deprecated(since = "1.20.6")
+ Registry<Wolf.Variant> WOLF_VARIANT = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(Wolf.Variant.class); // Paper + Registry<Wolf.Variant> WOLF_VARIANT = Objects.requireNonNull(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(Wolf.Variant.class), "No registry present for Wolf$Variant. This is a bug."); // Paper
/** /**
* Map cursor types. * Map cursor types.
* *

View File

@ -513,7 +513,7 @@ index 0000000000000000000000000000000000000000..1e7b53f9bc13dcd5a0a4a40004591e4f
+ } + }
+} +}
diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java
index 7aee2cee892492c523ae06902c6582b0ab827ffa..3adc243fa7e1aecf8a271b38a25c7fa3ef6fcc03 100644 index 91117cad12eee0bdaac8e0398a0f7f288ba27a40..43f410326d6d68242113e2fefe31af256889ed9c 100644
--- a/src/main/java/org/bukkit/Registry.java --- a/src/main/java/org/bukkit/Registry.java
+++ b/src/main/java/org/bukkit/Registry.java +++ b/src/main/java/org/bukkit/Registry.java
@@ -292,6 +292,15 @@ public interface Registry<T extends Keyed> extends Iterable<T> { @@ -292,6 +292,15 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
@ -527,7 +527,7 @@ index 7aee2cee892492c523ae06902c6582b0ab827ffa..3adc243fa7e1aecf8a271b38a25c7fa3
+ * @deprecated use {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)} with {@link io.papermc.paper.registry.RegistryKey#STRUCTURE} + * @deprecated use {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)} with {@link io.papermc.paper.registry.RegistryKey#STRUCTURE}
+ */ + */
+ @Deprecated(forRemoval = true) + @Deprecated(forRemoval = true)
+ Registry<io.papermc.paper.world.structure.ConfiguredStructure> CONFIGURED_STRUCTURE = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(io.papermc.paper.world.structure.ConfiguredStructure.class); + Registry<io.papermc.paper.world.structure.ConfiguredStructure> CONFIGURED_STRUCTURE = Objects.requireNonNull(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(io.papermc.paper.world.structure.ConfiguredStructure.class), "No registry present for ConfiguredStructure. This is a bug.");
+ // Paper end + // Paper end
/** /**
* Get the object by its key. * Get the object by its key.

View File

@ -5,13 +5,13 @@ Subject: [PATCH] More PotionEffectType API
diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java
index 3adc243fa7e1aecf8a271b38a25c7fa3ef6fcc03..9a8be5c730802e5750de1fc31e65f254f5894e63 100644 index 43f410326d6d68242113e2fefe31af256889ed9c..90ab3bef4c5b6b6e215e9c759c886ed6d0f3302b 100644
--- a/src/main/java/org/bukkit/Registry.java --- a/src/main/java/org/bukkit/Registry.java
+++ b/src/main/java/org/bukkit/Registry.java +++ b/src/main/java/org/bukkit/Registry.java
@@ -300,6 +300,31 @@ public interface Registry<T extends Keyed> extends Iterable<T> { @@ -300,6 +300,31 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
*/ */
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
Registry<io.papermc.paper.world.structure.ConfiguredStructure> CONFIGURED_STRUCTURE = io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(io.papermc.paper.world.structure.ConfiguredStructure.class); Registry<io.papermc.paper.world.structure.ConfiguredStructure> CONFIGURED_STRUCTURE = Objects.requireNonNull(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(io.papermc.paper.world.structure.ConfiguredStructure.class), "No registry present for ConfiguredStructure. This is a bug.");
+ +
+ /** + /**
+ * Potion effect types. + * Potion effect types.

View File

@ -7208,17 +7208,24 @@ index bc91370654f5da33cbfe7d42431568915c1159d6..b43af53960978ac04bccde08544a5628
validate(REGISTRY); validate(REGISTRY);
} }
diff --git a/src/main/java/net/minecraft/server/Bootstrap.java b/src/main/java/net/minecraft/server/Bootstrap.java diff --git a/src/main/java/net/minecraft/server/Bootstrap.java b/src/main/java/net/minecraft/server/Bootstrap.java
index 15ee2f2a83bfef2f6891d9bfb2d3a8c14b24ffb1..d0d95d729853fc296c4931a2f73a3fc5f94302c9 100644 index 15ee2f2a83bfef2f6891d9bfb2d3a8c14b24ffb1..26892378d27dadce25c178333188ba093dc1617b 100644
--- a/src/main/java/net/minecraft/server/Bootstrap.java --- a/src/main/java/net/minecraft/server/Bootstrap.java
+++ b/src/main/java/net/minecraft/server/Bootstrap.java +++ b/src/main/java/net/minecraft/server/Bootstrap.java
@@ -74,7 +74,11 @@ public class Bootstrap { @@ -63,6 +63,7 @@ public class Bootstrap {
Bootstrap.isBootstrapped = true;
Instant instant = Instant.now();
+ io.papermc.paper.plugin.entrypoint.LaunchEntryPointHandler.enterBootstrappers(); // Paper - Entrypoint for bootstrapping
if (BuiltInRegistries.REGISTRY.keySet().isEmpty()) {
throw new IllegalStateException("Unable to load registries");
} else {
@@ -74,7 +75,10 @@ public class Bootstrap {
EntitySelectorOptions.bootStrap(); EntitySelectorOptions.bootStrap();
DispenseItemBehavior.bootStrap(); DispenseItemBehavior.bootStrap();
CauldronInteraction.bootStrap(); CauldronInteraction.bootStrap();
- BuiltInRegistries.bootStrap(); - BuiltInRegistries.bootStrap();
+ // Paper start + // Paper start
+ BuiltInRegistries.bootStrap(() -> { + BuiltInRegistries.bootStrap(() -> {
+ io.papermc.paper.plugin.entrypoint.LaunchEntryPointHandler.enterBootstrappers(); // Paper - Entrypoint for bootstrapping
+ }); + });
+ // Paper end + // Paper end
CreativeModeTabs.validate(); CreativeModeTabs.validate();

View File

@ -100,10 +100,10 @@ index 0000000000000000000000000000000000000000..5fc4c41ec2089d4f69861c5da17e0bef
+} +}
diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..9480dafb2de09ac883e997c41e8a16b77f5f7082 index 0000000000000000000000000000000000000000..00a49ae2f0c89b129301e226794fc9c29d4c0ddd
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java +++ b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java
@@ -0,0 +1,119 @@ @@ -0,0 +1,123 @@
+package io.papermc.paper.registry; +package io.papermc.paper.registry;
+ +
+import io.papermc.paper.registry.entry.RegistryEntry; +import io.papermc.paper.registry.entry.RegistryEntry;
@ -111,9 +111,10 @@ index 0000000000000000000000000000000000000000..9480dafb2de09ac883e997c41e8a16b7
+import io.papermc.paper.registry.legacy.DelayedRegistryEntry; +import io.papermc.paper.registry.legacy.DelayedRegistryEntry;
+import io.papermc.paper.registry.legacy.LegacyRegistryIdentifiers; +import io.papermc.paper.registry.legacy.LegacyRegistryIdentifiers;
+import java.util.Collections; +import java.util.Collections;
+import java.util.IdentityHashMap;
+import java.util.Map; +import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set; +import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceKey;
+import org.bukkit.Keyed; +import org.bukkit.Keyed;
+import org.bukkit.Registry; +import org.bukkit.Registry;
@ -132,7 +133,7 @@ index 0000000000000000000000000000000000000000..9480dafb2de09ac883e997c41e8a16b7
+ // We want to do registration there, so we have access to the nms.Registry instance in order to wrap it in a CraftRegistry instance. + // We want to do registration there, so we have access to the nms.Registry instance in order to wrap it in a CraftRegistry instance.
+ // The memoized Supplier is needed because we *can't* instantiate any CraftRegistry class until **all** the BuiltInRegistries have been added + // The memoized Supplier is needed because we *can't* instantiate any CraftRegistry class until **all** the BuiltInRegistries have been added
+ // to this map because that would class-load org.bukkit.Registry which would query this map. + // to this map because that would class-load org.bukkit.Registry which would query this map.
+ private final Map<RegistryKey<?>, RegistryHolder<?, ?>> registries = Collections.synchronizedMap(new IdentityHashMap<>()); + private final Map<RegistryKey<?>, RegistryHolder<?>> registries = new ConcurrentHashMap<>(); // is "identity" because RegistryKey overrides equals and hashCode
+ +
+ public static PaperRegistryAccess instance() { + public static PaperRegistryAccess instance() {
+ return (PaperRegistryAccess) RegistryAccessHolder.INSTANCE.orElseThrow(() -> new IllegalStateException("No RegistryAccess implementation found")); + return (PaperRegistryAccess) RegistryAccessHolder.INSTANCE.orElseThrow(() -> new IllegalStateException("No RegistryAccess implementation found"));
@ -151,7 +152,7 @@ index 0000000000000000000000000000000000000000..9480dafb2de09ac883e997c41e8a16b7
+ final @Nullable RegistryEntry<?, T, ?> entry; + final @Nullable RegistryEntry<?, T, ?> entry;
+ registryKey = requireNonNull(byType(type), () -> type + " is not a valid registry type"); + registryKey = requireNonNull(byType(type), () -> type + " is not a valid registry type");
+ entry = PaperRegistries.getEntry(registryKey); + entry = PaperRegistries.getEntry(registryKey);
+ final @Nullable RegistryHolder<T, ?> registry = (RegistryHolder<T, ?>) this.registries.get(registryKey); + final @Nullable RegistryHolder<T> registry = (RegistryHolder<T>) this.registries.get(registryKey);
+ if (registry != null) { + if (registry != null) {
+ // if the registry exists, return right away. Since this is the "legacy" method, we return DelayedRegistry + // if the registry exists, return right away. Since this is the "legacy" method, we return DelayedRegistry
+ // for the non-builtin Registry instances stored as fields in Registry. + // for the non-builtin Registry instances stored as fields in Registry.
@ -160,7 +161,7 @@ index 0000000000000000000000000000000000000000..9480dafb2de09ac883e997c41e8a16b7
+ // if the registry doesn't exist and the entry is marked as "delayed", we create a registry holder that is empty + // if the registry doesn't exist and the entry is marked as "delayed", we create a registry holder that is empty
+ // which will later be filled with the actual registry. This is so the fields on org.bukkit.Registry can be populated with + // which will later be filled with the actual registry. This is so the fields on org.bukkit.Registry can be populated with
+ // registries that don't exist at the time org.bukkit.Registry is statically initialized. + // registries that don't exist at the time org.bukkit.Registry is statically initialized.
+ final RegistryHolder<T, ?> delayedHolder = new RegistryHolder.Delayed<>(); + final RegistryHolder<T> delayedHolder = new RegistryHolder.Delayed<>();
+ this.registries.put(registryKey, delayedHolder); + this.registries.put(registryKey, delayedHolder);
+ return delayedHolder.get(); + return delayedHolder.get();
+ } else { + } else {
@ -172,9 +173,12 @@ index 0000000000000000000000000000000000000000..9480dafb2de09ac883e997c41e8a16b7
+ @SuppressWarnings("unchecked") + @SuppressWarnings("unchecked")
+ @Override + @Override
+ public <T extends Keyed> Registry<T> getRegistry(final RegistryKey<T> key) { + public <T extends Keyed> Registry<T> getRegistry(final RegistryKey<T> key) {
+ final @Nullable RegistryHolder<T, ?> registryHolder = (RegistryHolder<T, ?>) this.registries.get(key); + if (PaperRegistries.getEntry(key) == null) {
+ throw new NoSuchElementException(key + " is not a valid registry key");
+ }
+ final @Nullable RegistryHolder<T> registryHolder = (RegistryHolder<T>) this.registries.get(key);
+ if (registryHolder == null) { + if (registryHolder == null) {
+ throw new IllegalArgumentException(key + " is not a valid registry key or that registry is not available yet"); + throw new IllegalArgumentException(key + " points to a registry that is not available yet");
+ } + }
+ // since this is the getRegistry method that uses the modern RegistryKey, we unwrap any DelayedRegistry instances + // since this is the getRegistry method that uses the modern RegistryKey, we unwrap any DelayedRegistry instances
+ // that might be returned here. I don't think reference equality is required when doing getRegistry(RegistryKey.WOLF_VARIANT) == Registry.WOLF_VARIANT + // that might be returned here. I don't think reference equality is required when doing getRegistry(RegistryKey.WOLF_VARIANT) == Registry.WOLF_VARIANT
@ -202,14 +206,14 @@ index 0000000000000000000000000000000000000000..9480dafb2de09ac883e997c41e8a16b7
+ if (entry == null) { // skip registries that don't have API entries + if (entry == null) { // skip registries that don't have API entries
+ return; + return;
+ } + }
+ final @Nullable RegistryHolder<B, R> registryHolder = (RegistryHolder<B, R>) this.registries.get(entry.apiKey()); + final @Nullable RegistryHolder<B> registryHolder = (RegistryHolder<B>) this.registries.get(entry.apiKey());
+ if (registryHolder == null || replace) { + if (registryHolder == null || replace) {
+ // if the holder doesn't exist yet, or is marked as "replaceable", put it in the map. + // if the holder doesn't exist yet, or is marked as "replaceable", put it in the map.
+ this.registries.put(entry.apiKey(), entry.createRegistryHolder(registry)); + this.registries.put(entry.apiKey(), entry.createRegistryHolder(registry));
+ } else { + } else {
+ if (registryHolder instanceof final RegistryHolder.Delayed<B, R> delayedHolder && entry instanceof final DelayedRegistryEntry<M, B, R> delayedEntry) { + if (registryHolder instanceof RegistryHolder.Delayed<?, ?> && entry instanceof final DelayedRegistryEntry<M, B, R> delayedEntry) {
+ // if the registry holder is delayed, and the entry is marked as "delayed", then load the holder with the CraftRegistry instance that wraps the actual nms Registry. + // if the registry holder is delayed, and the entry is marked as "delayed", then load the holder with the CraftRegistry instance that wraps the actual nms Registry.
+ delayedHolder.loadFrom(delayedEntry, registry); + ((RegistryHolder.Delayed<B, R>) registryHolder).loadFrom(delayedEntry, registry);
+ } else { + } else {
+ throw new IllegalArgumentException(resourceKey + " has already been created"); + throw new IllegalArgumentException(resourceKey + " has already been created");
+ } + }
@ -225,13 +229,12 @@ index 0000000000000000000000000000000000000000..9480dafb2de09ac883e997c41e8a16b7
+} +}
diff --git a/src/main/java/io/papermc/paper/registry/RegistryHolder.java b/src/main/java/io/papermc/paper/registry/RegistryHolder.java diff --git a/src/main/java/io/papermc/paper/registry/RegistryHolder.java b/src/main/java/io/papermc/paper/registry/RegistryHolder.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..f750325fa980d4c49b92573ac4650f2b53c26e7b index 0000000000000000000000000000000000000000..02402ef647c3e78ed56fd6b2687bf7c67448f891
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/RegistryHolder.java +++ b/src/main/java/io/papermc/paper/registry/RegistryHolder.java
@@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
+package io.papermc.paper.registry; +package io.papermc.paper.registry;
+ +
+import com.google.common.base.Preconditions;
+import com.google.common.base.Suppliers; +import com.google.common.base.Suppliers;
+import io.papermc.paper.registry.legacy.DelayedRegistry; +import io.papermc.paper.registry.legacy.DelayedRegistry;
+import io.papermc.paper.registry.legacy.DelayedRegistryEntry; +import io.papermc.paper.registry.legacy.DelayedRegistryEntry;
@ -239,46 +242,47 @@ index 0000000000000000000000000000000000000000..f750325fa980d4c49b92573ac4650f2b
+import org.bukkit.Keyed; +import org.bukkit.Keyed;
+import org.bukkit.Registry; +import org.bukkit.Registry;
+import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.NonNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.checkerframework.framework.qual.DefaultQualifier; +import org.checkerframework.framework.qual.DefaultQualifier;
+ +
+@DefaultQualifier(NonNull.class) +@DefaultQualifier(NonNull.class)
+public class RegistryHolder<B extends Keyed, R extends Registry<B>> { +public interface RegistryHolder<B extends Keyed> {
+ +
+ private final @Nullable Supplier<R> memoizedSupplier; + Registry<B> get();
+ +
+ public RegistryHolder(final Supplier<? extends R> supplier) { + final class Memoized<B extends Keyed, R extends Registry<B>> implements RegistryHolder<B> {
+ this.memoizedSupplier = Suppliers.memoize(supplier::get); +
+ private final Supplier<R> memoizedSupplier;
+
+ public Memoized(final Supplier<? extends R> supplier) {
+ this.memoizedSupplier = Suppliers.memoize(supplier::get);
+ }
+
+ public Registry<B> get() {
+ return this.memoizedSupplier.get();
+ }
+ } + }
+ +
+ protected RegistryHolder() { + final class Delayed<B extends Keyed, R extends Registry<B>> implements RegistryHolder<B> {
+ this.memoizedSupplier = null;
+ }
+
+ public Registry<B> get() {
+ Preconditions.checkState(this.memoizedSupplier != null, "Must provide a supplier or override this method!");
+ return this.memoizedSupplier.get();
+ }
+
+ public static final class Delayed<B extends Keyed, R extends Registry<B>> extends RegistryHolder<B, R> {
+ +
+ private final DelayedRegistry<B, R> delayedRegistry = new DelayedRegistry<>(); + private final DelayedRegistry<B, R> delayedRegistry = new DelayedRegistry<>();
+ +
+ @Override + @Override
+ public Registry<B> get() { + public DelayedRegistry<B, R> get() {
+ return this.delayedRegistry; + return this.delayedRegistry;
+ } + }
+ +
+ <M> void loadFrom(final DelayedRegistryEntry<M, B, R> delayedEntry, final net.minecraft.core.Registry<M> registry) { + <M> void loadFrom(final DelayedRegistryEntry<M, B, R> delayedEntry, final net.minecraft.core.Registry<M> registry) {
+ final RegistryHolder<B, R> delegateHolder = delayedEntry.delegate().createRegistryHolder(registry); + final RegistryHolder<B> delegateHolder = delayedEntry.delegate().createRegistryHolder(registry);
+ Preconditions.checkState(delegateHolder.memoizedSupplier != null, "delegateHolder must have a memoized supplier!"); + if (!(delegateHolder instanceof RegistryHolder.Memoized<B, ?>)) {
+ this.delayedRegistry.load(delegateHolder.memoizedSupplier); + throw new IllegalArgumentException(delegateHolder + " must be a memoized holder");
+ }
+ this.delayedRegistry.load(((Memoized<B, R>) delegateHolder).memoizedSupplier);
+ } + }
+ } + }
+} +}
diff --git a/src/main/java/io/papermc/paper/registry/entry/BaseRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/BaseRegistryEntry.java diff --git a/src/main/java/io/papermc/paper/registry/entry/BaseRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/BaseRegistryEntry.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..6ce94c2399817a74771ade0bb82905763a8e9df2 index 0000000000000000000000000000000000000000..8cb8630304f2b7604f420fe9dbdee9c460ee7bda
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/entry/BaseRegistryEntry.java +++ b/src/main/java/io/papermc/paper/registry/entry/BaseRegistryEntry.java
@@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
@ -316,13 +320,13 @@ index 0000000000000000000000000000000000000000..6ce94c2399817a74771ade0bb8290576
+ } + }
+ +
+ @Override + @Override
+ public final Class<?> toPreload() { + public final Class<?> classToPreload() {
+ return this.classToPreload; + return this.classToPreload;
+ } + }
+} +}
diff --git a/src/main/java/io/papermc/paper/registry/entry/CraftRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/CraftRegistryEntry.java diff --git a/src/main/java/io/papermc/paper/registry/entry/CraftRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/CraftRegistryEntry.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..1639380c9db4249f9e49b23588720d5cec2d63fd index 0000000000000000000000000000000000000000..03ffc325c008af97e848e747d8860c58e308bdf3
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/entry/CraftRegistryEntry.java +++ b/src/main/java/io/papermc/paper/registry/entry/CraftRegistryEntry.java
@@ -0,0 +1,34 @@ @@ -0,0 +1,34 @@
@ -352,17 +356,17 @@ index 0000000000000000000000000000000000000000..1639380c9db4249f9e49b23588720d5c
+ } + }
+ +
+ @Override + @Override
+ public RegistryHolder<B, CraftRegistry<B, M>> createRegistryHolder(final Registry<M> nmsRegistry) { + public RegistryHolder<B> createRegistryHolder(final Registry<M> nmsRegistry) {
+ return new RegistryHolder<>(() -> this.createApiRegistry(nmsRegistry)); + return new RegistryHolder.Memoized<>(() -> this.createApiRegistry(nmsRegistry));
+ } + }
+ +
+ private CraftRegistry<B, M> createApiRegistry(final Registry<M> nmsRegistry) { + private CraftRegistry<B, M> createApiRegistry(final Registry<M> nmsRegistry) {
+ return new CraftRegistry<>(this.toPreload(), nmsRegistry, this.minecraftToBukkit); + return new CraftRegistry<>(this.classToPreload(), nmsRegistry, this.minecraftToBukkit);
+ } + }
+} +}
diff --git a/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java diff --git a/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..9cda87cd03a04998cb527a4be9d3950523646cd3 index 0000000000000000000000000000000000000000..8daafa1bc3c1dbbc9c902633c61e093668b2f049
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java +++ b/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java
@@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
@ -383,7 +387,7 @@ index 0000000000000000000000000000000000000000..9cda87cd03a04998cb527a4be9d39505
+@DefaultQualifier(NonNull.class) +@DefaultQualifier(NonNull.class)
+public interface RegistryEntry<M, B extends Keyed, R extends org.bukkit.Registry<B>> extends RegistryEntryInfo<M, B> { // TODO remove Keyed +public interface RegistryEntry<M, B extends Keyed, R extends org.bukkit.Registry<B>> extends RegistryEntryInfo<M, B> { // TODO remove Keyed
+ +
+ RegistryHolder<B, R> createRegistryHolder(Registry<M> nmsRegistry); + RegistryHolder<B> createRegistryHolder(Registry<M> nmsRegistry);
+ +
+ /** + /**
+ * This should only be used if the registry instance needs to exist early due to the need + * This should only be used if the registry instance needs to exist early due to the need
@ -401,7 +405,7 @@ index 0000000000000000000000000000000000000000..9cda87cd03a04998cb527a4be9d39505
+} +}
diff --git a/src/main/java/io/papermc/paper/registry/entry/RegistryEntryInfo.java b/src/main/java/io/papermc/paper/registry/entry/RegistryEntryInfo.java diff --git a/src/main/java/io/papermc/paper/registry/entry/RegistryEntryInfo.java b/src/main/java/io/papermc/paper/registry/entry/RegistryEntryInfo.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..abb24093dc81c0ba8a761700be59d4c9a67f4b00 index 0000000000000000000000000000000000000000..8b8c273b7fb60998a53cf1ce67632315e94599cd
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/entry/RegistryEntryInfo.java +++ b/src/main/java/io/papermc/paper/registry/entry/RegistryEntryInfo.java
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
@ -417,7 +421,7 @@ index 0000000000000000000000000000000000000000..abb24093dc81c0ba8a761700be59d4c9
+ +
+ RegistryKey<B> apiKey(); + RegistryKey<B> apiKey();
+ +
+ Class<?> toPreload(); + Class<?> classToPreload();
+} +}
diff --git a/src/main/java/io/papermc/paper/registry/entry/package-info.java b/src/main/java/io/papermc/paper/registry/entry/package-info.java diff --git a/src/main/java/io/papermc/paper/registry/entry/package-info.java b/src/main/java/io/papermc/paper/registry/entry/package-info.java
new file mode 100644 new file mode 100644
@ -493,7 +497,7 @@ index 0000000000000000000000000000000000000000..5562e8da5ebaef2a3add46e88d64358b
+} +}
diff --git a/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistryEntry.java b/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistryEntry.java diff --git a/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistryEntry.java b/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistryEntry.java
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..0ca04fac46b2ec6aa8481ad867264050bfda630c index 0000000000000000000000000000000000000000..aa85e32961ea258745dc8ed68328528b3458c042
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistryEntry.java +++ b/src/main/java/io/papermc/paper/registry/legacy/DelayedRegistryEntry.java
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
@ -519,12 +523,12 @@ index 0000000000000000000000000000000000000000..0ca04fac46b2ec6aa8481ad867264050
+ } + }
+ +
+ @Override + @Override
+ public Class<?> toPreload() { + public Class<?> classToPreload() {
+ return this.delegate.toPreload(); + return this.delegate.classToPreload();
+ } + }
+ +
+ @Override + @Override
+ public RegistryHolder<T, R> createRegistryHolder(final Registry<M> nmsRegistry) { + public RegistryHolder<T> createRegistryHolder(final Registry<M> nmsRegistry) {
+ return this.delegate.createRegistryHolder(nmsRegistry); + return this.delegate.createRegistryHolder(nmsRegistry);
+ } + }
+} +}

View File

@ -6,7 +6,7 @@ Subject: [PATCH] Add StructuresLocateEvent
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/src/main/java/io/papermc/paper/registry/PaperRegistries.java diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
index d45e2855f137d8708139281e8598ed34cc07ddd2..3a2b7f6f2dad856bc1499472970ba8b579df2e33 100644 index 5fc4c41ec2089d4f69861c5da17e0bef8a203401..e3c16b2aee3da74c43c52a20f52fcde066f0d90d 100644
--- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java --- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java +++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
@@ -38,6 +38,12 @@ import static io.papermc.paper.registry.entry.RegistryEntry.entry; @@ -38,6 +38,12 @@ import static io.papermc.paper.registry.entry.RegistryEntry.entry;
@ -23,10 +23,10 @@ index d45e2855f137d8708139281e8598ed34cc07ddd2..3a2b7f6f2dad856bc1499472970ba8b5
private static final Map<RegistryKey<?>, RegistryEntry<?, ?, ?>> BY_REGISTRY_KEY; private static final Map<RegistryKey<?>, RegistryEntry<?, ?, ?>> BY_REGISTRY_KEY;
private static final Map<ResourceKey<?>, RegistryEntry<?, ?, ?>> BY_RESOURCE_KEY; private static final Map<ResourceKey<?>, RegistryEntry<?, ?, ?>> BY_RESOURCE_KEY;
diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java
index 958e37a80ea486f460f495a4a6f6a55aa5f1c7ee..0de4a2cf8527a0cbdc7de4c9bdba4230047a1252 100644 index 00a49ae2f0c89b129301e226794fc9c29d4c0ddd..51c45a97503c9a863c97e75ad97b334b8c59225e 100644
--- a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java --- a/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java +++ b/src/main/java/io/papermc/paper/registry/PaperRegistryAccess.java
@@ -43,8 +43,13 @@ public class PaperRegistryAccess implements RegistryAccess { @@ -44,8 +44,13 @@ public class PaperRegistryAccess implements RegistryAccess {
public <T extends Keyed> @Nullable Registry<T> getRegistry(final Class<T> type) { public <T extends Keyed> @Nullable Registry<T> getRegistry(final Class<T> type) {
final RegistryKey<T> registryKey; final RegistryKey<T> registryKey;
final @Nullable RegistryEntry<?, T, ?> entry; final @Nullable RegistryEntry<?, T, ?> entry;
@ -39,7 +39,7 @@ index 958e37a80ea486f460f495a4a6f6a55aa5f1c7ee..0de4a2cf8527a0cbdc7de4c9bdba4230
+ registryKey = requireNonNull(byType(type), () -> type + " is not a valid registry type"); + registryKey = requireNonNull(byType(type), () -> type + " is not a valid registry type");
+ entry = PaperRegistries.getEntry(registryKey); + entry = PaperRegistries.getEntry(registryKey);
+ } + }
final @Nullable RegistryHolder<T, ?> registry = (RegistryHolder<T, ?>) this.registries.get(registryKey); final @Nullable RegistryHolder<T> registry = (RegistryHolder<T>) this.registries.get(registryKey);
if (registry != null) { if (registry != null) {
// if the registry exists, return right away. Since this is the "legacy" method, we return DelayedRegistry // if the registry exists, return right away. Since this is the "legacy" method, we return DelayedRegistry
diff --git a/src/main/java/io/papermc/paper/world/structure/PaperConfiguredStructure.java b/src/main/java/io/papermc/paper/world/structure/PaperConfiguredStructure.java diff --git a/src/main/java/io/papermc/paper/world/structure/PaperConfiguredStructure.java b/src/main/java/io/papermc/paper/world/structure/PaperConfiguredStructure.java

View File

@ -105,17 +105,17 @@ index 0000000000000000000000000000000000000000..e0d73113c937ddbcf8144f88b15a8d3d
+ } + }
+} +}
diff --git a/src/main/java/net/minecraft/server/Bootstrap.java b/src/main/java/net/minecraft/server/Bootstrap.java diff --git a/src/main/java/net/minecraft/server/Bootstrap.java b/src/main/java/net/minecraft/server/Bootstrap.java
index 05f4be8dfff37ab6804a2d990b1f8c430d42dc7c..2a49a6a6bccabf588ba67b565d8f16fda04ba0b0 100644 index a3a2097716430b30c9bac2581b9f67fe0c595bd2..6885a653bfe629c46bface19ff1eb666d74d4f1b 100644
--- a/src/main/java/net/minecraft/server/Bootstrap.java --- a/src/main/java/net/minecraft/server/Bootstrap.java
+++ b/src/main/java/net/minecraft/server/Bootstrap.java +++ b/src/main/java/net/minecraft/server/Bootstrap.java
@@ -76,6 +76,7 @@ public class Bootstrap { @@ -77,6 +77,7 @@ public class Bootstrap {
CauldronInteraction.bootStrap(); CauldronInteraction.bootStrap();
// Paper start // Paper start
BuiltInRegistries.bootStrap(() -> { BuiltInRegistries.bootStrap(() -> {
+ io.papermc.paper.world.worldgen.OptionallyFlatBedrockConditionSource.bootstrap(); // Paper - Flat bedrock generator settings + io.papermc.paper.world.worldgen.OptionallyFlatBedrockConditionSource.bootstrap(); // Paper - Flat bedrock generator settings
io.papermc.paper.plugin.entrypoint.LaunchEntryPointHandler.enterBootstrappers(); // Paper - Entrypoint for bootstrapping
}); });
// Paper end // Paper end
CreativeModeTabs.validate();
diff --git a/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java b/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java diff --git a/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java b/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java
index dc765b92cc90f5f370254e68bbbdfa5add7935ce..8ce870a5341a61fbbaf42021ef7f7f615a6a3e09 100644 index dc765b92cc90f5f370254e68bbbdfa5add7935ce..8ce870a5341a61fbbaf42021ef7f7f615a6a3e09 100644
--- a/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java --- a/src/main/java/net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator.java