Skip to content

Commit

Permalink
Clean up registration.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnuecke committed Jan 6, 2023
1 parent b554e3d commit 452479d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Optional<Document> getDocument(final String path, final String language)
private String compileLinkList() {
final StringBuilder sb = new StringBuilder();
final Set<SerialProtocolDocumentationReference> references = new HashSet<>();
for (final SerialInterfaceProvider provider : SerialInterfaceProviders.MODULE_PROVIDER_REGISTRY) {
for (final SerialInterfaceProvider provider : SerialInterfaceProviders.REGISTRAR.get()) {
final Optional<SerialProtocolDocumentationReference> reference = provider.getDocumentationReference();
reference.ifPresent(references::add);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package li.cil.tis3d.common.provider;

import com.google.common.base.Suppliers;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.Registrar;
import dev.architectury.registry.registries.Registries;
import dev.architectury.registry.registries.RegistrySupplier;
import li.cil.tis3d.api.API;
import li.cil.tis3d.api.machine.Casing;
import li.cil.tis3d.api.machine.Face;
import li.cil.tis3d.api.module.Module;
Expand All @@ -16,19 +19,20 @@

import java.util.Optional;
import java.util.function.BiFunction;
import java.util.function.Supplier;

public final class ModuleProviders {
private static final DeferredRegister<ModuleProvider> MODULE_PROVIDERS = RegistryUtils.get(ModuleProvider.REGISTRY);

// --------------------------------------------------------------------- //

public static final Registrar<ModuleProvider> MODULE_PROVIDER_REGISTRY = MODULE_PROVIDERS.getRegistries()
.<ModuleProvider>builder(ModuleProvider.REGISTRY.location())
.build();
private static final Supplier<Registrar<ModuleProvider>> REGISTRAR = Suppliers.memoize(() -> Registries.get(API.MOD_ID).get(ModuleProvider.REGISTRY));

// --------------------------------------------------------------------- //

public static void initialize() {
RegistryUtils.builder(ModuleProvider.REGISTRY).build();

register(Items.AUDIO_MODULE, AudioModule::new);
register(Items.DISPLAY_MODULE, DisplayModule::new);
register(Items.EXECUTION_MODULE, ExecutionModule::new);
Expand All @@ -50,7 +54,7 @@ public static void initialize() {
}

public static Optional<ModuleProvider> getProviderFor(final ItemStack stack, final Casing casing, final Face face) {
for (final ModuleProvider provider : MODULE_PROVIDER_REGISTRY) {
for (final ModuleProvider provider : REGISTRAR.get()) {
if (provider.matches(stack, casing, face)) {
return Optional.of(provider);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package li.cil.tis3d.common.provider;

import com.google.common.base.Suppliers;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.Registrar;
import dev.architectury.registry.registries.Registries;
import li.cil.tis3d.api.API;
import li.cil.tis3d.api.machine.Face;
import li.cil.tis3d.api.module.Module;
import li.cil.tis3d.api.module.RedstoneInputProvider;
Expand All @@ -10,18 +13,18 @@
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;

import java.util.function.Supplier;

public final class RedstoneInputProviders {
private static final DeferredRegister<RedstoneInputProvider> REDSTONE_INPUT_PROVIDERS = RegistryUtils.get(RedstoneInputProvider.REGISTRY);

// --------------------------------------------------------------------- //

public static final Registrar<RedstoneInputProvider> REDSTONE_INPUT_PROVIDER_REGISTRY = REDSTONE_INPUT_PROVIDERS.getRegistries()
.<RedstoneInputProvider>builder(RedstoneInputProvider.REGISTRY.location())
.build();
private static final Supplier<Registrar<RedstoneInputProvider>> REGISTRAR = Suppliers.memoize(() -> Registries.get(API.MOD_ID).get(RedstoneInputProvider.REGISTRY));

// --------------------------------------------------------------------- //

public static void initialize() {
RegistryUtils.builder(RedstoneInputProvider.REGISTRY).build();

REDSTONE_INPUT_PROVIDERS.register("minecraft", MinecraftRedstoneInputProvider::new);

REDSTONE_INPUT_PROVIDERS.register();
Expand All @@ -31,7 +34,7 @@ public static int getRedstoneInput(final Module module) {
int maxSignal = 0;
final Level level = module.getCasing().getCasingLevel();
final BlockPos position = module.getCasing().getPosition();
for (final RedstoneInputProvider provider : REDSTONE_INPUT_PROVIDER_REGISTRY) {
for (final RedstoneInputProvider provider : REGISTRAR.get()) {
final int signal = provider.getInput(level, position, Face.toDirection(module.getFace()));
if (signal > maxSignal) {
maxSignal = signal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package li.cil.tis3d.common.provider;

import com.google.common.base.Suppliers;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.Registrar;
import dev.architectury.registry.registries.Registries;
import li.cil.tis3d.api.API;
import li.cil.tis3d.api.serial.SerialInterfaceProvider;
import li.cil.tis3d.common.provider.serial.SerialInterfaceProviderFurnace;
import li.cil.tis3d.util.RegistryUtils;
Expand All @@ -10,26 +13,27 @@
import net.minecraft.world.level.Level;

import java.util.Optional;
import java.util.function.Supplier;

public final class SerialInterfaceProviders {
private static final DeferredRegister<SerialInterfaceProvider> MODULE_PROVIDERS = RegistryUtils.get(SerialInterfaceProvider.REGISTRY);

// --------------------------------------------------------------------- //

public static final Registrar<SerialInterfaceProvider> MODULE_PROVIDER_REGISTRY = MODULE_PROVIDERS.getRegistries()
.<SerialInterfaceProvider>builder(SerialInterfaceProvider.REGISTRY.location())
.build();
public static final Supplier<Registrar<SerialInterfaceProvider>> REGISTRAR = Suppliers.memoize(() -> Registries.get(API.MOD_ID).get(SerialInterfaceProvider.REGISTRY));

// --------------------------------------------------------------------- //

public static void initialize() {
RegistryUtils.builder(SerialInterfaceProvider.REGISTRY).build();

MODULE_PROVIDERS.register("furnace", SerialInterfaceProviderFurnace::new);

MODULE_PROVIDERS.register();
}

public static Optional<SerialInterfaceProvider> getProviderFor(final Level level, final BlockPos position, final Direction face) {
for (final SerialInterfaceProvider provider : MODULE_PROVIDER_REGISTRY) {
for (final SerialInterfaceProvider provider : REGISTRAR.get()) {
if (provider.matches(level, position, face)) {
return Optional.of(provider);
}
Expand Down

0 comments on commit 452479d

Please sign in to comment.