Skip to content

Commit

Permalink
fix registry on neoforge, clean
Browse files Browse the repository at this point in the history
  • Loading branch information
TexBlock committed Aug 5, 2024
1 parent eccb4ae commit c14f18e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

@Mod(KessokuBase.MOD_ID)
public class KessokuBaseEntrypoint {
public KessokuBaseEntrypoint() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package band.kessoku.lib.event;

public class KessokuEventBase {
public static final String MOD_ID = "kessoku_event_base";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {

Expand All @@ -19,24 +19,23 @@ public interface Event<T> {

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 <T> Event<T> of(Function<List<T>, T> invokerFunc) {
return new EventImpl<>(invokerFunc);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package band.kessoku.lib.event;
package band.kessoku.lib.event.impl;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package band.kessoku.lib.event;

import net.neoforged.fml.common.Mod;

@Mod(KessokuEventBase.MOD_ID)
public class KessokuEventBaseEntrypoint {
public KessokuEventBaseEntrypoint() {

}
}
3 changes: 3 additions & 0 deletions registry-neo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<net.minecraft.registry.Registry, Set<EntryWithId>> 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
Expand Down

0 comments on commit c14f18e

Please sign in to comment.