mirror of
https://github.com/architectury/architectury-api.git
synced 2026-04-01 21:17:45 -05:00
Registry API to create modded registries, close #21
This commit is contained in:
@@ -20,9 +20,16 @@
|
||||
package me.shedaniel.architectury.registry.fabric;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import me.shedaniel.architectury.core.RegistryEntry;
|
||||
import me.shedaniel.architectury.registry.Registries;
|
||||
import me.shedaniel.architectury.registry.Registry;
|
||||
import me.shedaniel.architectury.registry.RegistrySupplier;
|
||||
import me.shedaniel.architectury.registry.registries.RegistryBuilder;
|
||||
import me.shedaniel.architectury.registry.registries.RegistryOption;
|
||||
import me.shedaniel.architectury.registry.registries.StandardRegistryOption;
|
||||
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
|
||||
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
|
||||
import net.minecraft.core.MappedRegistry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.LazyLoadedValue;
|
||||
@@ -64,6 +71,36 @@ public class RegistriesImpl {
|
||||
public <T> Registry<T> get(net.minecraft.core.Registry<T> registry) {
|
||||
return new RegistryImpl<>(registry);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public <T extends RegistryEntry<T>> RegistryBuilder<T> builder(Class<T> type, ResourceLocation registryId) {
|
||||
return new RegistryBuilderWrapper<>(FabricRegistryBuilder.createSimple(type, registryId));
|
||||
}
|
||||
}
|
||||
|
||||
public static class RegistryBuilderWrapper<T extends RegistryEntry<T>> implements RegistryBuilder<T> {
|
||||
@NotNull
|
||||
private FabricRegistryBuilder<T, MappedRegistry<T>> builder;
|
||||
|
||||
public RegistryBuilderWrapper(@NotNull FabricRegistryBuilder<T, MappedRegistry<T>> builder) {
|
||||
this.builder = builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Registry<T> build() {
|
||||
return RegistryProviderImpl.INSTANCE.get(builder.buildAndRegister());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull RegistryBuilder<T> option(@NotNull RegistryOption option) {
|
||||
if (option == StandardRegistryOption.SAVE_TO_DISC) {
|
||||
this.builder.attribute(RegistryAttribute.PERSISTED);
|
||||
} else if (option == StandardRegistryOption.SYNC_TO_CLIENTS) {
|
||||
this.builder.attribute(RegistryAttribute.SYNCED);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RegistryImpl<T> implements Registry<T> {
|
||||
|
||||
Reference in New Issue
Block a user