mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-27 18:33:51 -07:00
Switch Impl types to Holderable (#11662)
* Switch Impl types to Holderable * Fix compile issues * more improvements * compile fixes * remove unneeded unwrapAndConvertHolder call --------- Co-authored-by: Bjarne Koll <git@lynxplay.dev>
This commit is contained in:
@@ -20,14 +20,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
@@ -0,0 +0,0 @@ import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.entry.RegistryEntry.apiOnly;
|
||||
import static io.papermc.paper.registry.entry.RegistryEntry.entry;
|
||||
+import static io.papermc.paper.registry.entry.RegistryEntry.writable;
|
||||
|
||||
public final class PaperRegistries {
|
||||
|
||||
@@ -0,0 +0,0 @@ public final class PaperRegistries {
|
||||
return ResourceKey.create((ResourceKey<? extends Registry<M>>) PaperRegistries.registryToNms(typedKey.registryKey()), PaperAdventure.asVanilla(typedKey.key()));
|
||||
}
|
||||
@@ -81,17 +73,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ @FunctionalInterface
|
||||
+ interface Filler<M, T, B extends PaperRegistryBuilder<M, T>> {
|
||||
+
|
||||
+ B fill(Conversions conversions, TypedKey<T> key, @Nullable M nms);
|
||||
+ B fill(Conversions conversions, @Nullable M nms);
|
||||
+
|
||||
+ default Factory<M, T, B> asFactory() {
|
||||
+ return (lookup, key) -> this.fill(lookup, key, null);
|
||||
+ return (lookup) -> this.fill(lookup, null);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ @FunctionalInterface
|
||||
+ interface Factory<M, T, B extends PaperRegistryBuilder<M, T>> {
|
||||
+
|
||||
+ B create(Conversions conversions, TypedKey<T> key);
|
||||
+ B create(Conversions conversions);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java b/src/main/java/io/papermc/paper/registry/PaperRegistryListenerManager.java
|
||||
@@ -204,7 +196,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+ final RegistryEntry.Modifiable<M, T, B> modifiableEntry = RegistryEntry.Modifiable.asModifiable(entry);
|
||||
+ @SuppressWarnings("PatternValidation") final TypedKey<T> typedKey = TypedKey.create(entry.apiKey(), Key.key(key.location().getNamespace(), key.location().getPath()));
|
||||
+ final B builder = modifiableEntry.fillBuilder(conversions, typedKey, nms);
|
||||
+ final B builder = modifiableEntry.fillBuilder(conversions, nms);
|
||||
+ return this.registerWithListeners(registry, modifiableEntry, key, nms, builder, registrationInfo, registerMethod, conversions);
|
||||
+ }
|
||||
+
|
||||
@@ -324,9 +316,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+package io.papermc.paper.registry;
|
||||
+
|
||||
+import com.mojang.serialization.Lifecycle;
|
||||
+import io.papermc.paper.adventure.PaperAdventure;
|
||||
+import io.papermc.paper.registry.data.util.Conversions;
|
||||
+import io.papermc.paper.registry.entry.RegistryEntry;
|
||||
+import io.papermc.paper.registry.entry.RegistryTypeMapper;
|
||||
+import io.papermc.paper.registry.event.WritableRegistry;
|
||||
+import java.util.Optional;
|
||||
+import java.util.function.BiFunction;
|
||||
@@ -338,7 +330,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.craftbukkit.CraftRegistry;
|
||||
+import org.bukkit.craftbukkit.util.ApiVersion;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+public class WritableCraftRegistry<M, T extends Keyed, B extends PaperRegistryBuilder<M, T>> extends CraftRegistry<T, M> {
|
||||
+
|
||||
@@ -347,7 +338,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ private final RegistryEntry.BuilderHolder<M, T, B> entry;
|
||||
+ private final MappedRegistry<M> registry;
|
||||
+ private final PaperRegistryBuilder.Factory<M, T, ? extends B> builderFactory;
|
||||
+ private final BiFunction<? super NamespacedKey, M, T> minecraftToBukkit;
|
||||
+
|
||||
+ public WritableCraftRegistry(
|
||||
+ final RegistryEntry.BuilderHolder<M, T, B> entry,
|
||||
@@ -355,19 +345,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ final MappedRegistry<M> registry,
|
||||
+ final BiFunction<NamespacedKey, ApiVersion, NamespacedKey> serializationUpdater,
|
||||
+ final PaperRegistryBuilder.Factory<M, T, ? extends B> builderFactory,
|
||||
+ final BiFunction<? super NamespacedKey, M, T> minecraftToBukkit
|
||||
+ final RegistryTypeMapper<M, T> minecraftToBukkit
|
||||
+ ) {
|
||||
+ super(classToPreload, registry, null, serializationUpdater);
|
||||
+ super(classToPreload, registry, minecraftToBukkit, serializationUpdater);
|
||||
+ this.entry = entry;
|
||||
+ this.registry = registry;
|
||||
+ this.builderFactory = builderFactory;
|
||||
+ this.minecraftToBukkit = minecraftToBukkit;
|
||||
+ }
|
||||
+
|
||||
+ public void register(final TypedKey<T> key, final Consumer<? super B> value, final Conversions conversions) {
|
||||
+ final ResourceKey<M> resourceKey = ResourceKey.create(this.registry.key(), PaperAdventure.asVanilla(key.key()));
|
||||
+ final ResourceKey<M> resourceKey = PaperRegistries.toNms(key);
|
||||
+ this.registry.validateWrite(resourceKey);
|
||||
+ final B builder = this.newBuilder(conversions, key);
|
||||
+ final B builder = this.newBuilder(conversions);
|
||||
+ value.accept(builder);
|
||||
+ PaperRegistryListenerManager.INSTANCE.registerWithListeners(
|
||||
+ this.registry,
|
||||
@@ -379,24 +368,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public final @Nullable T createBukkit(final NamespacedKey namespacedKey, final @Nullable M minecraft) {
|
||||
+ if (minecraft == null) {
|
||||
+ return null;
|
||||
+ }
|
||||
+ return this.minecraftToBukkit(namespacedKey, minecraft);
|
||||
+ }
|
||||
+
|
||||
+ public WritableRegistry<T, B> createApiWritableRegistry(final Conversions conversions) {
|
||||
+ return new ApiWritableRegistry(conversions);
|
||||
+ }
|
||||
+
|
||||
+ public T minecraftToBukkit(final NamespacedKey namespacedKey, final M minecraft) {
|
||||
+ return this.minecraftToBukkit.apply(namespacedKey, minecraft);
|
||||
+ }
|
||||
+
|
||||
+ protected B newBuilder(final Conversions conversions, final TypedKey<T> key) {
|
||||
+ return this.builderFactory.create(conversions, key);
|
||||
+ protected B newBuilder(final Conversions conversions) {
|
||||
+ return this.builderFactory.create(conversions);
|
||||
+ }
|
||||
+
|
||||
+ public class ApiWritableRegistry implements WritableRegistry<T, B> {
|
||||
@@ -421,15 +398,40 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.registry.data.util;
|
||||
+
|
||||
+import com.google.common.base.Preconditions;
|
||||
+import com.mojang.serialization.JavaOps;
|
||||
+import io.papermc.paper.adventure.WrapperAwareSerializer;
|
||||
+import java.util.Optional;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import net.minecraft.core.Registry;
|
||||
+import net.minecraft.core.RegistryAccess;
|
||||
+import net.minecraft.resources.RegistryOps;
|
||||
+import net.minecraft.resources.ResourceKey;
|
||||
+import org.bukkit.craftbukkit.CraftRegistry;
|
||||
+import org.jetbrains.annotations.Contract;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+public class Conversions {
|
||||
+
|
||||
+ private static @Nullable Conversions globalInstance;
|
||||
+ public static Conversions global() {
|
||||
+ if (globalInstance == null) {
|
||||
+ final RegistryAccess globalAccess = CraftRegistry.getMinecraftRegistry();
|
||||
+ Preconditions.checkState(globalAccess != null, "Global registry access is not available");
|
||||
+ globalInstance = new Conversions(new RegistryOps.RegistryInfoLookup() {
|
||||
+ @Override
|
||||
+ public <T> Optional<RegistryOps.RegistryInfo<T>> lookup(final ResourceKey<? extends Registry<? extends T>> registryRef) {
|
||||
+ final Registry<T> registry = globalAccess.lookupOrThrow(registryRef);
|
||||
+ return Optional.of(
|
||||
+ new RegistryOps.RegistryInfo<>(registry, registry, registry.registryLifecycle())
|
||||
+ );
|
||||
+ }
|
||||
+ });
|
||||
+ }
|
||||
+ return globalInstance;
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ private final RegistryOps.RegistryInfoLookup lookup;
|
||||
+ private final WrapperAwareSerializer serializer;
|
||||
+
|
||||
@@ -473,15 +475,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import io.papermc.paper.registry.PaperRegistryBuilder;
|
||||
+import io.papermc.paper.registry.RegistryHolder;
|
||||
+import io.papermc.paper.registry.RegistryKey;
|
||||
+import io.papermc.paper.registry.TypedKey;
|
||||
+import io.papermc.paper.registry.WritableCraftRegistry;
|
||||
+import io.papermc.paper.registry.data.util.Conversions;
|
||||
+import java.util.function.BiFunction;
|
||||
+import net.minecraft.core.MappedRegistry;
|
||||
+import net.minecraft.core.Registry;
|
||||
+import net.minecraft.resources.ResourceKey;
|
||||
+import org.bukkit.Keyed;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+
|
||||
+public class AddableRegistryEntry<M, T extends Keyed, B extends PaperRegistryBuilder<M, T>> extends CraftRegistryEntry<M, T> implements RegistryEntry.Addable<M, T, B> {
|
||||
+
|
||||
@@ -491,7 +490,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ final ResourceKey<? extends Registry<M>> mcKey,
|
||||
+ final RegistryKey<T> apiKey,
|
||||
+ final Class<?> classToPreload,
|
||||
+ final BiFunction<NamespacedKey, M, T> minecraftToBukkit,
|
||||
+ final RegistryTypeMapper<M, T> minecraftToBukkit,
|
||||
+ final PaperRegistryBuilder.Filler<M, T, B> builderFiller
|
||||
+ ) {
|
||||
+ super(mcKey, apiKey, classToPreload, minecraftToBukkit);
|
||||
@@ -508,8 +507,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public B fillBuilder(final Conversions conversions, final TypedKey<T> key, final M nms) {
|
||||
+ return this.builderFiller.fill(conversions, key, nms);
|
||||
+ public B fillBuilder(final Conversions conversions, final M nms) {
|
||||
+ return this.builderFiller.fill(conversions, nms);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/ModifiableRegistryEntry.java
|
||||
@@ -522,13 +521,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+import io.papermc.paper.registry.PaperRegistryBuilder;
|
||||
+import io.papermc.paper.registry.RegistryKey;
|
||||
+import io.papermc.paper.registry.TypedKey;
|
||||
+import io.papermc.paper.registry.data.util.Conversions;
|
||||
+import java.util.function.BiFunction;
|
||||
+import net.minecraft.core.Registry;
|
||||
+import net.minecraft.resources.ResourceKey;
|
||||
+import org.bukkit.Keyed;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+
|
||||
+public class ModifiableRegistryEntry<M, T extends Keyed, B extends PaperRegistryBuilder<M, T>> extends CraftRegistryEntry<M, T> implements RegistryEntry.Modifiable<M, T, B> {
|
||||
+
|
||||
@@ -538,7 +534,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ final ResourceKey<? extends Registry<M>> mcKey,
|
||||
+ final RegistryKey<T> apiKey,
|
||||
+ final Class<?> toPreload,
|
||||
+ final BiFunction<NamespacedKey, M, T> minecraftToBukkit,
|
||||
+ final RegistryTypeMapper<M, T> minecraftToBukkit,
|
||||
+ final PaperRegistryBuilder.Filler<M, T, B> builderFiller
|
||||
+ ) {
|
||||
+ super(mcKey, apiKey, toPreload, minecraftToBukkit);
|
||||
@@ -546,8 +542,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public B fillBuilder(final Conversions conversions, final TypedKey<T> key, final M nms) {
|
||||
+ return this.builderFiller.fill(conversions, key, nms);
|
||||
+ public B fillBuilder(final Conversions conversions, final M nms) {
|
||||
+ return this.builderFiller.fill(conversions, nms);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/RegistryEntry.java
|
||||
@@ -567,8 +563,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+import io.papermc.paper.registry.event.RegistryFreezeEventImpl;
|
||||
import io.papermc.paper.registry.legacy.DelayedRegistryEntry;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Supplier;
|
||||
@@ -0,0 +0,0 @@ import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.core.Registry;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.craftbukkit.util.ApiVersion;
|
||||
@@ -577,12 +572,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
public interface RegistryEntry<M, B extends Keyed> extends RegistryEntryInfo<M, B> { // TODO remove Keyed
|
||||
|
||||
@@ -0,0 +0,0 @@ public interface RegistryEntry<M, B extends Keyed> extends RegistryEntryInfo<M,
|
||||
default RegistryEntry<M, B> delayed() {
|
||||
return new DelayedRegistryEntry<>(this);
|
||||
}
|
||||
|
||||
+
|
||||
+ interface BuilderHolder<M, T, B extends PaperRegistryBuilder<M, T>> extends RegistryEntryInfo<M, T> {
|
||||
+
|
||||
+ B fillBuilder(Conversions conversions, TypedKey<T> key, M nms);
|
||||
+ B fillBuilder(Conversions conversions, M nms);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
@@ -638,34 +634,36 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ private static <M, B extends Keyed> RegistryEntryInfo<M, B> possiblyUnwrap(final RegistryEntryInfo<M, B> entry) {
|
||||
+ return entry instanceof final DelayedRegistryEntry<M, B> delayed ? delayed.delegate() : entry;
|
||||
+ }
|
||||
}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/entry/RegistryEntryBuilder.java b/src/main/java/io/papermc/paper/registry/entry/RegistryEntryBuilder.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/io/papermc/paper/registry/entry/RegistryEntryBuilder.java
|
||||
+++ b/src/main/java/io/papermc/paper/registry/entry/RegistryEntryBuilder.java
|
||||
@@ -0,0 +0,0 @@
|
||||
package io.papermc.paper.registry.entry;
|
||||
|
||||
import com.mojang.datafixers.util.Either;
|
||||
+import io.papermc.paper.registry.PaperRegistryBuilder;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
@@ -0,0 +0,0 @@ public class RegistryEntryBuilder<M, A extends Keyed> { // TODO remove Keyed
|
||||
public RegistryEntry<M, A> build() {
|
||||
return new CraftRegistryEntry<>(this.mcKey, this.apiKey, this.classToPreload, this.minecraftToBukkit);
|
||||
}
|
||||
+
|
||||
static <M, B extends Keyed> RegistryEntry<M, B> entry(
|
||||
final ResourceKey<? extends Registry<M>> mcKey,
|
||||
final RegistryKey<B> apiKey,
|
||||
@@ -0,0 +0,0 @@ public interface RegistryEntry<M, B extends Keyed> extends RegistryEntryInfo<M,
|
||||
) {
|
||||
return new ApiRegistryEntry<>(mcKey, apiKey, apiRegistrySupplier);
|
||||
+ public <B extends PaperRegistryBuilder<M, A>> RegistryEntry<M, A> modifiable(final PaperRegistryBuilder.Filler<M, A, B> filler) {
|
||||
+ return new ModifiableRegistryEntry<>(this.mcKey, this.apiKey, this.classToPreload, this.minecraftToBukkit, filler);
|
||||
+ }
|
||||
+
|
||||
+ public <B extends PaperRegistryBuilder<M, A>> RegistryEntry<M, A> addable(final PaperRegistryBuilder.Filler<M, A, B> filler) {
|
||||
+ return new AddableRegistryEntry<>(this.mcKey, this.apiKey, this.classToPreload, this.minecraftToBukkit, filler);
|
||||
+ }
|
||||
+
|
||||
+ public <B extends PaperRegistryBuilder<M, A>> RegistryEntry<M, A> writable(final PaperRegistryBuilder.Filler<M, A, B> filler) {
|
||||
+ return new WritableRegistryEntry<>(this.mcKey, this.apiKey, this.classToPreload, this.minecraftToBukkit, filler);
|
||||
+ }
|
||||
}
|
||||
+
|
||||
+ static <M, T extends Keyed, B extends PaperRegistryBuilder<M, T>> RegistryEntry<M, T> modifiable(
|
||||
+ final ResourceKey<? extends Registry<M>> mcKey,
|
||||
+ final RegistryKey<T> apiKey,
|
||||
+ final Class<?> toPreload,
|
||||
+ final BiFunction<NamespacedKey, M, T> minecraftToBukkit,
|
||||
+ final PaperRegistryBuilder.Filler<M, T, B> filler
|
||||
+ ) {
|
||||
+ return new ModifiableRegistryEntry<>(mcKey, apiKey, toPreload, minecraftToBukkit, filler);
|
||||
+ }
|
||||
+
|
||||
+ static <M, T extends Keyed, B extends PaperRegistryBuilder<M, T>> RegistryEntry<M, T> writable(
|
||||
+ final ResourceKey<? extends Registry<M>> mcKey,
|
||||
+ final RegistryKey<T> apiKey,
|
||||
+ final Class<?> toPreload,
|
||||
+ final BiFunction<NamespacedKey, M, T> minecraftToBukkit,
|
||||
+ final PaperRegistryBuilder.Filler<M, T, B> filler
|
||||
+ ) {
|
||||
+ return new WritableRegistryEntry<>(mcKey, apiKey, toPreload, minecraftToBukkit, filler);
|
||||
+ }
|
||||
}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java b/src/main/java/io/papermc/paper/registry/entry/WritableRegistryEntry.java
|
||||
new file mode 100644
|
||||
@@ -675,9 +673,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.registry.entry;
|
||||
+
|
||||
+import com.mojang.datafixers.util.Either;
|
||||
+import io.papermc.paper.registry.PaperRegistryBuilder;
|
||||
+import io.papermc.paper.registry.RegistryKey;
|
||||
+import java.util.function.BiFunction;
|
||||
+import java.util.function.Function;
|
||||
+import net.minecraft.core.Holder;
|
||||
+import net.minecraft.core.Registry;
|
||||
+import net.minecraft.resources.ResourceKey;
|
||||
+import org.bukkit.Keyed;
|
||||
@@ -689,7 +690,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ final ResourceKey<? extends Registry<M>> mcKey,
|
||||
+ final RegistryKey<T> apiKey,
|
||||
+ final Class<?> classToPreload,
|
||||
+ final BiFunction<NamespacedKey, M, T> minecraftToBukkit,
|
||||
+ final RegistryTypeMapper<M, T> minecraftToBukkit,
|
||||
+ final PaperRegistryBuilder.Filler<M, T, B> builderFiller
|
||||
+ ) {
|
||||
+ super(mcKey, apiKey, classToPreload, minecraftToBukkit, builderFiller);
|
||||
@@ -1213,40 +1214,12 @@ diff --git a/src/main/java/net/minecraft/resources/RegistryDataLoader.java b/src
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/resources/RegistryDataLoader.java
|
||||
+++ b/src/main/java/net/minecraft/resources/RegistryDataLoader.java
|
||||
@@ -0,0 +0,0 @@ public class RegistryDataLoader {
|
||||
public static RegistryAccess.Frozen load(
|
||||
ResourceManager resourceManager, List<HolderLookup.RegistryLookup<?>> registries, List<RegistryDataLoader.RegistryData<?>> entries
|
||||
) {
|
||||
- return load((loader, infoGetter) -> loader.loadFromResources(resourceManager, infoGetter), registries, entries);
|
||||
+ return load((loader, infoGetter, conversions) -> loader.loadFromResources(resourceManager, infoGetter, conversions), registries, entries); // Paper - pass conversions
|
||||
}
|
||||
|
||||
public static RegistryAccess.Frozen load(
|
||||
@@ -0,0 +0,0 @@ public class RegistryDataLoader {
|
||||
List<HolderLookup.RegistryLookup<?>> registries,
|
||||
List<RegistryDataLoader.RegistryData<?>> entries
|
||||
) {
|
||||
- return load((loader, infoGetter) -> loader.loadFromNetwork(data, factory, infoGetter), registries, entries);
|
||||
+ return load((loader, infoGetter, conversions) -> loader.loadFromNetwork(data, factory, infoGetter, conversions), registries, entries); // Paper - pass conversions
|
||||
}
|
||||
|
||||
private static RegistryAccess.Frozen load(
|
||||
@@ -0,0 +0,0 @@ public class RegistryDataLoader {
|
||||
Map<ResourceKey<?>, Exception> map = new HashMap<>();
|
||||
List<RegistryDataLoader.Loader<?>> list = entries.stream().map(entry -> entry.create(Lifecycle.stable(), map)).collect(Collectors.toUnmodifiableList());
|
||||
RegistryOps.RegistryInfoLookup registryInfoLookup = createContext(registries, list);
|
||||
- list.forEach(loader -> loadable.apply((RegistryDataLoader.Loader<?>)loader, registryInfoLookup));
|
||||
+ final io.papermc.paper.registry.data.util.Conversions conversions = new io.papermc.paper.registry.data.util.Conversions(registryInfoLookup); // Paper - create conversions
|
||||
+ list.forEach(loader -> loadable.apply((RegistryDataLoader.Loader<?>)loader, registryInfoLookup, conversions));
|
||||
list.forEach(loader -> {
|
||||
Registry<?> registry = loader.registry();
|
||||
|
||||
@@ -0,0 +0,0 @@ public class RegistryDataLoader {
|
||||
}
|
||||
|
||||
private static <E> void loadElementFromResource(
|
||||
- WritableRegistry<E> registry, Decoder<E> decoder, RegistryOps<JsonElement> ops, ResourceKey<E> key, Resource resource, RegistrationInfo entryInfo
|
||||
+ WritableRegistry<E> registry, Decoder<E> decoder, RegistryOps<JsonElement> ops, ResourceKey<E> key, Resource resource, RegistrationInfo entryInfo, io.papermc.paper.registry.data.util.Conversions conversions
|
||||
+ WritableRegistry<E> registry, Decoder<E> decoder, RegistryOps<JsonElement> ops, ResourceKey<E> key, Resource resource, RegistrationInfo entryInfo, io.papermc.paper.registry.data.util.Conversions conversions // Paper - pass conversions
|
||||
) throws IOException {
|
||||
try (Reader reader = resource.openAsReader()) {
|
||||
JsonElement jsonElement = JsonParser.parseReader(reader);
|
||||
@@ -1258,15 +1231,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ public class RegistryDataLoader {
|
||||
RegistryOps.RegistryInfoLookup infoGetter,
|
||||
WritableRegistry<E> registry,
|
||||
Decoder<E> elementDecoder,
|
||||
- Map<ResourceKey<?>, Exception> errors
|
||||
+ Map<ResourceKey<?>, Exception> errors,
|
||||
+ io.papermc.paper.registry.data.util.Conversions conversions // Paper - pass conversions
|
||||
) {
|
||||
FileToIdConverter fileToIdConverter = FileToIdConverter.registry(registry.key());
|
||||
RegistryOps<JsonElement> registryOps = RegistryOps.create(JsonOps.INSTANCE, infoGetter);
|
||||
|
||||
+ final io.papermc.paper.registry.data.util.Conversions conversions = new io.papermc.paper.registry.data.util.Conversions(infoGetter); // Paper - create conversions
|
||||
for (Entry<ResourceLocation, Resource> entry : fileToIdConverter.listMatchingResources(resourceManager).entrySet()) {
|
||||
ResourceLocation resourceLocation = entry.getKey();
|
||||
ResourceKey<E> resourceKey = ResourceKey.create(registry.key(), fileToIdConverter.fileToId(resourceLocation));
|
||||
@@ -0,0 +0,0 @@ public class RegistryDataLoader {
|
||||
RegistrationInfo registrationInfo = REGISTRATION_INFO_CACHE.apply(resource.knownPackInfo());
|
||||
|
||||
@@ -1285,15 +1256,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ public class RegistryDataLoader {
|
||||
RegistryOps.RegistryInfoLookup infoGetter,
|
||||
WritableRegistry<E> registry,
|
||||
Decoder<E> decoder,
|
||||
- Map<ResourceKey<?>, Exception> loadingErrors
|
||||
+ Map<ResourceKey<?>, Exception> loadingErrors,
|
||||
+ io.papermc.paper.registry.data.util.Conversions conversions // Paper - pass conversions
|
||||
) {
|
||||
RegistryDataLoader.NetworkedRegistryData networkedRegistryData = data.get(registry.key());
|
||||
if (networkedRegistryData != null) {
|
||||
RegistryOps<JsonElement> registryOps2 = RegistryOps.create(JsonOps.INSTANCE, infoGetter);
|
||||
FileToIdConverter fileToIdConverter = FileToIdConverter.registry(registry.key());
|
||||
|
||||
+ final io.papermc.paper.registry.data.util.Conversions conversions = new io.papermc.paper.registry.data.util.Conversions(infoGetter); // Paper - create conversions
|
||||
for (RegistrySynchronization.PackedRegistryEntry packedRegistryEntry : networkedRegistryData.elements) {
|
||||
ResourceKey<E> resourceKey = ResourceKey.create(registry.key(), packedRegistryEntry.id());
|
||||
Optional<Tag> optional = packedRegistryEntry.data();
|
||||
@@ -0,0 +0,0 @@ public class RegistryDataLoader {
|
||||
|
||||
try {
|
||||
@@ -1303,35 +1272,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
} catch (Exception var17) {
|
||||
loadingErrors.put(resourceKey, new IllegalStateException("Failed to parse local data", var17));
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public class RegistryDataLoader {
|
||||
}
|
||||
|
||||
static record Loader<T>(RegistryDataLoader.RegistryData<T> data, WritableRegistry<T> registry, Map<ResourceKey<?>, Exception> loadingErrors) {
|
||||
- public void loadFromResources(ResourceManager resourceManager, RegistryOps.RegistryInfoLookup infoGetter) {
|
||||
- RegistryDataLoader.loadContentsFromManager(resourceManager, infoGetter, this.registry, this.data.elementCodec, this.loadingErrors);
|
||||
+ public void loadFromResources(ResourceManager resourceManager, RegistryOps.RegistryInfoLookup infoGetter, io.papermc.paper.registry.data.util.Conversions conversions) { // Paper - pass conversions
|
||||
+ RegistryDataLoader.loadContentsFromManager(resourceManager, infoGetter, this.registry, this.data.elementCodec, this.loadingErrors, conversions); // Paper - pass conversions
|
||||
}
|
||||
|
||||
public void loadFromNetwork(
|
||||
Map<ResourceKey<? extends Registry<?>>, RegistryDataLoader.NetworkedRegistryData> data,
|
||||
ResourceProvider factory,
|
||||
- RegistryOps.RegistryInfoLookup infoGetter
|
||||
+ RegistryOps.RegistryInfoLookup infoGetter,
|
||||
+ io.papermc.paper.registry.data.util.Conversions conversions // Paper
|
||||
) {
|
||||
- RegistryDataLoader.loadContentsFromNetwork(data, factory, infoGetter, this.registry, this.data.elementCodec, this.loadingErrors);
|
||||
+ RegistryDataLoader.loadContentsFromNetwork(data, factory, infoGetter, this.registry, this.data.elementCodec, this.loadingErrors, conversions); // Paper - pass conversions
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface LoadingFunction {
|
||||
- void apply(RegistryDataLoader.Loader<?> loader, RegistryOps.RegistryInfoLookup infoGetter);
|
||||
+ void apply(RegistryDataLoader.Loader<?> loader, RegistryOps.RegistryInfoLookup infoGetter, io.papermc.paper.registry.data.util.Conversions conversions); // Paper - pass conversions
|
||||
}
|
||||
|
||||
public static record NetworkedRegistryData(List<RegistrySynchronization.PackedRegistryEntry> elements, TagNetworkSerialization.NetworkPayload tags) {
|
||||
diff --git a/src/main/java/net/minecraft/server/ReloadableServerRegistries.java b/src/main/java/net/minecraft/server/ReloadableServerRegistries.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/ReloadableServerRegistries.java
|
||||
@@ -1368,20 +1308,6 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/src/main/
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
||||
@@ -0,0 +0,0 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
|
||||
private final Map<NamespacedKey, B> cache = new HashMap<>();
|
||||
private final Map<B, NamespacedKey> byValue = new java.util.IdentityHashMap<>(); // Paper - improve Registry
|
||||
private final net.minecraft.core.Registry<M> minecraftRegistry;
|
||||
- private final BiFunction<NamespacedKey, M, B> minecraftToBukkit;
|
||||
+ private final BiFunction<? super NamespacedKey, M, B> minecraftToBukkit; // Paper
|
||||
private final BiFunction<NamespacedKey, ApiVersion, NamespacedKey> serializationUpdater; // Paper - rename to make it *clear* what it is *only* for
|
||||
private boolean init;
|
||||
|
||||
- public CraftRegistry(Class<?> bukkitClass, net.minecraft.core.Registry<M> minecraftRegistry, BiFunction<NamespacedKey, M, B> minecraftToBukkit, BiFunction<NamespacedKey, ApiVersion, NamespacedKey> serializationUpdater) { // Paper - relax preload class
|
||||
+ public CraftRegistry(Class<?> bukkitClass, net.minecraft.core.Registry<M> minecraftRegistry, BiFunction<? super NamespacedKey, M, B> minecraftToBukkit, BiFunction<NamespacedKey, ApiVersion, NamespacedKey> serializationUpdater) { // Paper - relax preload class
|
||||
this.bukkitClass = bukkitClass;
|
||||
this.minecraftRegistry = minecraftRegistry;
|
||||
this.minecraftToBukkit = minecraftToBukkit;
|
||||
@@ -0,0 +0,0 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
|
||||
return this.byValue.get(value);
|
||||
}
|
||||
@@ -1452,7 +1378,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ <M, T> void testEquality(final RegistryEntry.BuilderHolder<M, T, ?> registryEntry) {
|
||||
+ final Registry<M> registry = RegistryHelper.getRegistry().lookupOrThrow(registryEntry.mcKey());
|
||||
+ for (final Map.Entry<ResourceKey<M>, M> entry : registry.entrySet()) {
|
||||
+ final M built = registryEntry.fillBuilder(new Conversions(new RegistryOps.HolderLookupAdapter(RegistryHelper.getRegistry())), PaperRegistries.fromNms(entry.getKey()), entry.getValue()).build();
|
||||
+ final M built = registryEntry.fillBuilder(new Conversions(new RegistryOps.HolderLookupAdapter(RegistryHelper.getRegistry())), entry.getValue()).build();
|
||||
+ assertEquals(entry.getValue(), built);
|
||||
+ }
|
||||
+ }
|
||||
|
Reference in New Issue
Block a user