mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
@@ -78,6 +78,12 @@ public final class RegistrarManager {
|
|||||||
return this.provider.builder((Class<T>) typeGetter.getClass().getComponentType(), registryId);
|
return this.provider.builder((Class<T>) typeGetter.getClass().getComponentType(), registryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public final <T> RegistrarBuilder<T> builderDefaulted(ResourceLocation registryId, ResourceLocation defaultId, T... typeGetter) {
|
||||||
|
if (typeGetter.length != 0) throw new IllegalStateException("array must be empty!");
|
||||||
|
return this.provider.builderDefaulted((Class<T>) typeGetter.getClass().getComponentType(), registryId, defaultId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a non-synced dynamic registry.
|
* Registers a non-synced dynamic registry.
|
||||||
*
|
*
|
||||||
@@ -174,6 +180,8 @@ public final class RegistrarManager {
|
|||||||
|
|
||||||
<T> RegistrarBuilder<T> builder(Class<T> type, ResourceLocation registryId);
|
<T> RegistrarBuilder<T> builder(Class<T> type, ResourceLocation registryId);
|
||||||
|
|
||||||
|
<T> RegistrarBuilder<T> builderDefaulted(Class<T> type, ResourceLocation registryId, ResourceLocation defaultId);
|
||||||
|
|
||||||
<T> void registerDynamicRegistry(ResourceKey<Registry<T>> key, Codec<T> dataCodec);
|
<T> void registerDynamicRegistry(ResourceKey<Registry<T>> key, Codec<T> dataCodec);
|
||||||
|
|
||||||
<T> void registerDynamicRegistrySynced(ResourceKey<Registry<T>> key, Codec<T> dataCodec, Codec<T> networkCodec);
|
<T> void registerDynamicRegistrySynced(ResourceKey<Registry<T>> key, Codec<T> dataCodec, Codec<T> networkCodec);
|
||||||
|
|||||||
@@ -97,6 +97,11 @@ public class RegistrarManagerImpl {
|
|||||||
return new RegistrarBuilderWrapper<>(modId, FabricRegistryBuilder.createSimple(type, registryId));
|
return new RegistrarBuilderWrapper<>(modId, FabricRegistryBuilder.createSimple(type, registryId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> RegistrarBuilder<T> builderDefaulted(Class<T> type, ResourceLocation registryId, ResourceLocation defaultId) {
|
||||||
|
return new RegistrarBuilderWrapper<>(modId, FabricRegistryBuilder.createDefaulted(type, registryId, defaultId));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> void registerDynamicRegistry(ResourceKey<Registry<T>> key, Codec<T> dataCodec) {
|
public <T> void registerDynamicRegistry(ResourceKey<Registry<T>> key, Codec<T> dataCodec) {
|
||||||
DynamicRegistries.register(key, dataCodec);
|
DynamicRegistries.register(key, dataCodec);
|
||||||
@@ -133,9 +138,9 @@ public class RegistrarManagerImpl {
|
|||||||
|
|
||||||
public static class RegistrarBuilderWrapper<T> implements RegistrarBuilder<T> {
|
public static class RegistrarBuilderWrapper<T> implements RegistrarBuilder<T> {
|
||||||
private final String modId;
|
private final String modId;
|
||||||
private FabricRegistryBuilder<T, MappedRegistry<T>> builder;
|
private FabricRegistryBuilder<T, ? extends MappedRegistry<T>> builder;
|
||||||
|
|
||||||
public RegistrarBuilderWrapper(String modId, FabricRegistryBuilder<T, MappedRegistry<T>> builder) {
|
public RegistrarBuilderWrapper(String modId, FabricRegistryBuilder<T, ? extends MappedRegistry<T>> builder) {
|
||||||
this.modId = modId;
|
this.modId = modId;
|
||||||
this.builder = builder;
|
this.builder = builder;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,6 +181,12 @@ public class RegistrarManagerImpl {
|
|||||||
.setName(registryId), registryId);
|
.setName(registryId), registryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> RegistrarBuilder<T> builderDefaulted(Class<T> type, ResourceLocation registryId, ResourceLocation defaultId) {
|
||||||
|
return new RegistryBuilderWrapper<>(this, new net.minecraftforge.registries.RegistryBuilder<>()
|
||||||
|
.setName(registryId).setDefaultKey(defaultId), registryId);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> void registerDynamicRegistry(ResourceKey<Registry<T>> key, Codec<T> dataCodec) {
|
public <T> void registerDynamicRegistry(ResourceKey<Registry<T>> key, Codec<T> dataCodec) {
|
||||||
if (newDynamicRegistries == null) {
|
if (newDynamicRegistries == null) {
|
||||||
|
|||||||
@@ -143,6 +143,11 @@ public class RegistrarManagerImpl {
|
|||||||
return new RegistryBuilderWrapper<>(this, new RegistryBuilder<>(ResourceKey.createRegistryKey(registryId)));
|
return new RegistryBuilderWrapper<>(this, new RegistryBuilder<>(ResourceKey.createRegistryKey(registryId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> RegistrarBuilder<T> builderDefaulted(Class<T> type, ResourceLocation registryId, ResourceLocation defaultId) {
|
||||||
|
return new RegistryBuilderWrapper<>(this, new RegistryBuilder<T>(ResourceKey.createRegistryKey(registryId)).defaultKey(defaultId));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> void registerDynamicRegistry(ResourceKey<Registry<T>> key, Codec<T> dataCodec) {
|
public <T> void registerDynamicRegistry(ResourceKey<Registry<T>> key, Codec<T> dataCodec) {
|
||||||
if (newDynamicRegistries == null) {
|
if (newDynamicRegistries == null) {
|
||||||
|
|||||||
@@ -75,9 +75,18 @@ public class TestRegistries {
|
|||||||
public TestInt(int value) {
|
public TestInt(int value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Integer.toString(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Registrar<TestInt> INTS = RegistrarManager.get(TestMod.MOD_ID).<TestInt>builder(new ResourceLocation(TestMod.MOD_ID, "ints"))
|
public static final Registrar<TestInt> INTS = RegistrarManager.get(TestMod.MOD_ID)
|
||||||
|
.<TestInt>builderDefaulted(
|
||||||
|
new ResourceLocation(TestMod.MOD_ID, "ints"),
|
||||||
|
new ResourceLocation(TestMod.MOD_ID, "test_no_int")
|
||||||
|
)
|
||||||
.syncToClients()
|
.syncToClients()
|
||||||
.build();
|
.build();
|
||||||
public static final DeferredRegister<CreativeModeTab> TABS = DeferredRegister.create(TestMod.MOD_ID, Registries.CREATIVE_MODE_TAB);
|
public static final DeferredRegister<CreativeModeTab> TABS = DeferredRegister.create(TestMod.MOD_ID, Registries.CREATIVE_MODE_TAB);
|
||||||
@@ -101,6 +110,7 @@ public class TestRegistries {
|
|||||||
.bucketItemSupplier(() -> TestRegistries.TEST_FLUID_BUCKET)
|
.bucketItemSupplier(() -> TestRegistries.TEST_FLUID_BUCKET)
|
||||||
.color(0xFF0000);
|
.color(0xFF0000);
|
||||||
|
|
||||||
|
public static final RegistrySupplier<TestInt> TEST_NO_INT = INTS.register(new ResourceLocation(TestMod.MOD_ID, "test_no_int"), () -> new TestInt(0));
|
||||||
public static final RegistrySupplier<TestInt> TEST_INT = INTS.register(new ResourceLocation(TestMod.MOD_ID, "test_int"), () -> new TestInt(1));
|
public static final RegistrySupplier<TestInt> TEST_INT = INTS.register(new ResourceLocation(TestMod.MOD_ID, "test_int"), () -> new TestInt(1));
|
||||||
public static final RegistrySupplier<TestInt> TEST_INT_2 = INTS.register(new ResourceLocation(TestMod.MOD_ID, "test_int_2"), () -> new TestInt(2));
|
public static final RegistrySupplier<TestInt> TEST_INT_2 = INTS.register(new ResourceLocation(TestMod.MOD_ID, "test_int_2"), () -> new TestInt(2));
|
||||||
|
|
||||||
@@ -223,5 +233,8 @@ public class TestRegistries {
|
|||||||
TEST_RECIPE_TYPE.listen(type -> {
|
TEST_RECIPE_TYPE.listen(type -> {
|
||||||
System.out.println("Registered recipe type!");
|
System.out.println("Registered recipe type!");
|
||||||
});
|
});
|
||||||
|
INTS.listen(TEST_INT_2, i -> {
|
||||||
|
System.out.println("Non-existent int: " + INTS.get(new ResourceLocation("non_existent")));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user