Skip to content

Commit

Permalink
better support for future direct buildables
Browse files Browse the repository at this point in the history
  • Loading branch information
Machine-Maker committed Dec 25, 2024
1 parent c7d0436 commit 6f7cabf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.papermc.paper.adventure.PaperAdventure;
import io.papermc.paper.registry.data.util.Conversions;
import io.papermc.paper.registry.entry.RegistryEntryMeta;
import java.util.function.Function;
import net.minecraft.resources.ResourceLocation;
import org.bukkit.Keyed;
Expand All @@ -11,13 +10,13 @@
public class PaperRegistryBuilderFactory<M, A extends Keyed, B extends PaperRegistryBuilder<M, A>> implements RegistryBuilderFactory<A, B> { // TODO remove Keyed

private final Conversions conversions;
private final RegistryEntryMeta.Buildable<M, A, B> meta;
private final PaperRegistryBuilder.Filler<M, A, B> builderFiller;
private final Function<? super ResourceLocation, ? extends @Nullable M> existingValueGetter;
private @Nullable B builder;

public PaperRegistryBuilderFactory(final Conversions conversions, final RegistryEntryMeta.Buildable<M, A, B> meta, final Function<? super ResourceLocation, ? extends @Nullable M> existingValueGetter) {
public PaperRegistryBuilderFactory(final Conversions conversions, final PaperRegistryBuilder.Filler<M, A, B> builderFiller, final Function<? super ResourceLocation, ? extends @Nullable M> existingValueGetter) {
this.conversions = conversions;
this.meta = meta;
this.builderFiller = builderFiller;
this.existingValueGetter = existingValueGetter;
}

Expand All @@ -37,7 +36,7 @@ public B requireBuilder() {
@Override
public B empty() {
this.validate();
return this.builder = this.meta.builderFiller().create(this.conversions);
return this.builder = this.builderFiller.create(this.conversions);
}

@Override
Expand All @@ -47,6 +46,6 @@ public B copyOf(final TypedKey<A> key) {
if (existing == null) {
throw new IllegalArgumentException("Key " + key + " doesn't exist");
}
return this.builder = this.meta.builderFiller().fill(this.conversions, existing);
return this.builder = this.builderFiller.fill(this.conversions, existing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public WritableCraftRegistry(
public void register(final TypedKey<T> key, final Consumer<RegistryBuilderFactory<T, B>> value, final Conversions conversions) {
final ResourceKey<M> resourceKey = PaperRegistries.toNms(key);
this.registry.validateWrite(resourceKey);
final PaperRegistryBuilderFactory<M, T, B> builderFactory = new PaperRegistryBuilderFactory<>(conversions, this.meta, this.registry.temporaryUnfrozenMap::get);
final PaperRegistryBuilderFactory<M, T, B> builderFactory = new PaperRegistryBuilderFactory<>(conversions, this.meta.builderFiller(), this.registry.temporaryUnfrozenMap::get);
value.accept(builderFactory);
PaperRegistryListenerManager.INSTANCE.registerWithListeners(
this.registry,
Expand Down

0 comments on commit 6f7cabf

Please sign in to comment.