Skip to content

Commit 5cd68b0

Browse files
committed
chore: add NeoEventHelper#registerCancellableNeoEventPoster
1 parent e31120f commit 5cd68b0

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

neoforge/src/main/java/dev/ftb/mods/ftblibrary/neoforge/FTBLibraryNeoForgeClient.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import dev.ftb.mods.ftblibrary.api.neoforge.FTBLibraryEvent;
88
import dev.ftb.mods.ftblibrary.client.FTBLibraryClient;
99
import dev.ftb.mods.ftblibrary.platform.event.NativeEventPosting;
10+
import dev.ftb.mods.ftblibrary.util.neoforge.NeoEventHelper;
1011
import net.neoforged.api.distmarker.Dist;
1112
import net.neoforged.bus.api.IEventBus;
1213
import net.neoforged.fml.common.Mod;
@@ -36,14 +37,9 @@ public FTBLibraryNeoForgeClient(IEventBus modEventBus) {
3637
}
3738

3839
private static void registerNeoEventPosters(IEventBus bus) {
39-
NativeEventPosting.INSTANCE.registerEvent(SidebarButtonCreatedEvent.Data.class,
40-
data -> bus.post(new FTBLibraryEvent.SidebarButtonCreated(data)));
41-
42-
NativeEventPosting.INSTANCE.registerEventWithResult(CustomClickEvent.TYPE, data -> {
43-
FTBLibraryEvent.CustomClick event = new FTBLibraryEvent.CustomClick(data);
44-
bus.post(event);
45-
return !event.isCanceled();
46-
});
40+
NeoEventHelper.registerNeoEventPoster(bus, SidebarButtonCreatedEvent.Data.class, FTBLibraryEvent.SidebarButtonCreated::new);
41+
42+
NeoEventHelper.registerCancellableNeoEventPoster(bus, CustomClickEvent.TYPE, FTBLibraryEvent.CustomClick::new);
4743

4844
NativeEventPosting.INSTANCE.registerEventWithResult(AllowChatCommandEvent.TYPE, data ->
4945
!ClientHooks.onClientSendMessage(data.message()).isEmpty());
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package dev.ftb.mods.ftblibrary.util.neoforge;
22

33
import dev.ftb.mods.ftblibrary.platform.event.NativeEventPosting;
4+
import dev.ftb.mods.ftblibrary.platform.event.TypedEvent;
45
import net.neoforged.bus.api.Event;
6+
import net.neoforged.bus.api.ICancellableEvent;
57
import net.neoforged.bus.api.IEventBus;
68

79
import java.util.function.Function;
@@ -10,8 +12,12 @@ public class NeoEventHelper {
1012
public static <T, R extends Event> void registerNeoEventPoster(IEventBus bus, Class<T> cls, Function<T, R> factory) {
1113
NativeEventPosting.INSTANCE.registerEvent(cls, data -> bus.post(factory.apply(data)));
1214
}
13-
//
14-
// public static <T, R extends Event> void registerNeoEventPosterWithResult(IEventBus bus, Class<T> cls, Function<T, R> factory) {
15-
// EventPostingHandler.INSTANCE.registerEventWithResult(cls, data -> bus.post(factory.apply(data)));
16-
// }
15+
16+
public static <T, R extends Event & ICancellableEvent> void registerCancellableNeoEventPoster(IEventBus bus, TypedEvent<T, Boolean> type, Function<T, R> factory) {
17+
NativeEventPosting.INSTANCE.registerEventWithResult(type, data -> {
18+
R event = factory.apply(data);
19+
bus.post(event);
20+
return !event.isCanceled();
21+
});
22+
}
1723
}

0 commit comments

Comments
 (0)