diff --git a/base-neo/src/main/java/band/kessoku/lib/base/KessokuBaseEntrypoint.java b/base-neo/src/main/java/band/kessoku/lib/base/KessokuBaseEntrypoint.java index 9445004a..ad6baac4 100644 --- a/base-neo/src/main/java/band/kessoku/lib/base/KessokuBaseEntrypoint.java +++ b/base-neo/src/main/java/band/kessoku/lib/base/KessokuBaseEntrypoint.java @@ -4,4 +4,7 @@ @Mod(KessokuBase.MOD_ID) public class KessokuBaseEntrypoint { + public KessokuBaseEntrypoint() { + + } } diff --git a/event-base-common/src/main/java/band/kessoku/lib/event/KessokuEventBase.java b/event-base-common/src/main/java/band/kessoku/lib/event/KessokuEventBase.java new file mode 100644 index 00000000..33685817 --- /dev/null +++ b/event-base-common/src/main/java/band/kessoku/lib/event/KessokuEventBase.java @@ -0,0 +1,5 @@ +package band.kessoku.lib.event; + +public class KessokuEventBase { + public static final String MOD_ID = "kessoku_event_base"; +} diff --git a/event-base-common/src/main/java/band/kessoku/lib/event/api/Event.java b/event-base-common/src/main/java/band/kessoku/lib/event/api/Event.java index 40a5a90f..fb30f815 100644 --- a/event-base-common/src/main/java/band/kessoku/lib/event/api/Event.java +++ b/event-base-common/src/main/java/band/kessoku/lib/event/api/Event.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.function.Function; -import band.kessoku.lib.event.EventImpl; +import band.kessoku.lib.event.impl.EventImpl; public interface Event { @@ -19,24 +19,23 @@ public interface Event { default void register(T listener) { register(listener, EventPhase.DEFAULT); - }; + } default void unregister(T listener) { unregister(listener, EventPhase.DEFAULT); - }; + } default boolean isRegistered(T listener) { return isRegistered(listener, EventPhase.DEFAULT); - }; + } default void clearAllListeners() { for (EventPhase phase : EventPhase.values()) { clearListeners(phase); } - }; + } static Event of(Function, T> invokerFunc) { return new EventImpl<>(invokerFunc); } - } diff --git a/event-base-common/src/main/java/band/kessoku/lib/event/EventImpl.java b/event-base-common/src/main/java/band/kessoku/lib/event/impl/EventImpl.java similarity index 97% rename from event-base-common/src/main/java/band/kessoku/lib/event/EventImpl.java rename to event-base-common/src/main/java/band/kessoku/lib/event/impl/EventImpl.java index 4f23eb80..8fa27816 100644 --- a/event-base-common/src/main/java/band/kessoku/lib/event/EventImpl.java +++ b/event-base-common/src/main/java/band/kessoku/lib/event/impl/EventImpl.java @@ -1,4 +1,4 @@ -package band.kessoku.lib.event; +package band.kessoku.lib.event.impl; import java.util.ArrayList; import java.util.HashMap; diff --git a/event-base-neo/src/main/java/band/kessoku/lib/event/KessokuEventBaseEntrypoint.java b/event-base-neo/src/main/java/band/kessoku/lib/event/KessokuEventBaseEntrypoint.java index b206d012..cbdea0fd 100644 --- a/event-base-neo/src/main/java/band/kessoku/lib/event/KessokuEventBaseEntrypoint.java +++ b/event-base-neo/src/main/java/band/kessoku/lib/event/KessokuEventBaseEntrypoint.java @@ -1,4 +1,10 @@ package band.kessoku.lib.event; +import net.neoforged.fml.common.Mod; + +@Mod(KessokuEventBase.MOD_ID) public class KessokuEventBaseEntrypoint { + public KessokuEventBaseEntrypoint() { + + } } diff --git a/registry-neo/build.gradle b/registry-neo/build.gradle index 12487321..7ea5bbb3 100644 --- a/registry-neo/build.gradle +++ b/registry-neo/build.gradle @@ -34,6 +34,9 @@ configurations { dependencies { neoForge libs.neo + + implementation(project(":event-base-neo")) + common(project(path: ':registry-common', configuration: 'namedElements')) { transitive false } shadowBundle project(path: ':registry-common', configuration: 'transformProductionNeoForge') } diff --git a/registry-neo/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java b/registry-neo/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java index cf9bce74..11cbdda0 100644 --- a/registry-neo/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java +++ b/registry-neo/src/main/java/band/kessoku/lib/registry/KessokuRegistryEntrypoint.java @@ -1,7 +1,12 @@ package band.kessoku.lib.registry; +import band.kessoku.lib.registry.impl.RegistryImpl; +import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.common.Mod; @Mod(KessokuRegistry.MOD_ID) public class KessokuRegistryEntrypoint { + public KessokuRegistryEntrypoint(IEventBus modEventBus) { + new RegistryImpl().registerEvent(modEventBus); + } } diff --git a/registry-neo/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java b/registry-neo/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java index a37f9115..99c3c9d7 100644 --- a/registry-neo/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java +++ b/registry-neo/src/main/java/band/kessoku/lib/registry/impl/RegistryImpl.java @@ -3,29 +3,29 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; -import band.kessoku.lib.registry.KessokuRegistry; +import band.kessoku.lib.event.util.NeoEventUtils; import band.kessoku.lib.registry.api.Registry; import com.google.auto.service.AutoService; import net.minecraft.util.Identifier; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.EventBusSubscriber; +import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.registries.RegisterEvent; @AutoService(Registry.class) -@EventBusSubscriber(modid = KessokuRegistry.MOD_ID) @SuppressWarnings("unchecked") public class RegistryImpl implements Registry { private static final Map> map = new ConcurrentHashMap<>(); - @SubscribeEvent - public void register(RegisterEvent event) { - map.forEach((registry, entryWithIds) -> - entryWithIds.forEach(entryWithId -> - event.register(registry.getKey(), entryWithId.id(), () -> entryWithId.entry()) - ) - ); + // THIS NOT A PUBLIC API METHOD + public void registerEvent(IEventBus modEventBus) { + NeoEventUtils.registerEvent(modEventBus, RegisterEvent.class, event -> { + map.forEach((registry, entryWithIds) -> + entryWithIds.forEach(entryWithId -> + event.register(registry.getKey(), entryWithId.id(), () -> entryWithId.entry()) + ) + ); + }); } @Override