From 4803a727d0cbee0a1b4bab24b88ce407a4d45018 Mon Sep 17 00:00:00 2001 From: MehVahdJukaar Date: Mon, 5 Aug 2024 03:50:40 +0200 Subject: [PATCH] fixed missing anvil event. Added workaround to prevent invalidly placed client events from crashing server --- .../violetmoon/zetaimplforge/EventTest.java | 15 ++++++++++ .../event/ForgeEventsRemapper.java | 30 +++++++++++++++++-- .../zetaimplforge/mod/ZetaModCommonProxy.java | 1 + .../zetaimplforge/mod/ZetaModForge.java | 6 ++++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/violetmoon/zetaimplforge/EventTest.java diff --git a/src/main/java/org/violetmoon/zetaimplforge/EventTest.java b/src/main/java/org/violetmoon/zetaimplforge/EventTest.java new file mode 100644 index 0000000..8f174e3 --- /dev/null +++ b/src/main/java/org/violetmoon/zetaimplforge/EventTest.java @@ -0,0 +1,15 @@ +package org.violetmoon.zetaimplforge; + +import org.violetmoon.zeta.event.bus.PlayEvent; +import org.violetmoon.zeta.event.play.ZAnvilUpdate; + +//remove me later +public class EventTest { + + + @PlayEvent + public static void a(ZAnvilUpdate e){ + + } + +} diff --git a/src/main/java/org/violetmoon/zetaimplforge/event/ForgeEventsRemapper.java b/src/main/java/org/violetmoon/zetaimplforge/event/ForgeEventsRemapper.java index 9718cf4..5e8de89 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/event/ForgeEventsRemapper.java +++ b/src/main/java/org/violetmoon/zetaimplforge/event/ForgeEventsRemapper.java @@ -11,7 +11,7 @@ import org.apache.commons.lang3.text.WordUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.violetmoon.zeta.client.event.play.ZRenderGuiOverlay; +import org.violetmoon.zeta.mod.ZetaMod; import java.lang.invoke.MethodHandle; import java.lang.reflect.Constructor; @@ -64,6 +64,7 @@ protected F remapEvent(@NotNull Z2 zetaEvent, Class firedAs) { /** * Given a MethodHandle of a method which takes a Zeta event, remaps it to a method which takes a Forge event, so we can register it with Forge event bus */ + @Nullable protected Consumer remapMethod(MethodHandle originalEventConsumer, Class zetaEventBaseClass, Class forgeEventClass) { Function forgeToZetaFunc = forgeToZetaMap.get(zetaEventBaseClass); if (forgeToZetaFunc == null) { @@ -76,8 +77,9 @@ protected Consumer remapMethod(MethodHandle originalEventConsumer, throw new RuntimeException(e); } }; - } else - throw new RuntimeException("Could not convert Zeta event class " + zetaEventBaseClass + " to Forge event. You must register its subclass using registerSubclass."); + } else { + return null; + } } return createForgeConsumer(originalEventConsumer, forgeToZetaFunc, zetaEventBaseClass, forgeEventClass); } @@ -374,11 +376,33 @@ public Object remapAndRegister(IEventBus forgeBus, Class owningClazz, MethodH Consumer consumer = this.remapMethod(handle, zetaEventClass, forgeEventClass); + if (consumer == null) { + + //check for client hack + if (isClientEvent(zetaEventClass)) { + if (ZetaMod.ZETA.isProduction) { + ZetaMod.LOGGER.error("Client event {} was found in a non client only class!", zetaEventClass); + return new Object(); + } + throw new RuntimeException("Client event " + zetaEventClass + " was found in a non client only class!"); + } + + throw new RuntimeException("Could not convert Zeta event class " + zetaEventClass + " to Forge event " + + "(in class " + owningClazz + "). You must register its subclass using registerSubclass."); + } + registerListenerToForgeWithPriorityAndGenerics(forgeBus, owningClazz, consumer, zetaEventClass, forgeEventClass); return consumer; } + //remove once all zeta client events are moved to client replacement module as they should + @Deprecated(forRemoval = true) + private boolean isClientEvent(Class zetaEventClass) { + String path = zetaEventClass.getPackageName(); + return path.startsWith("org.violetmoon.zeta.client.event"); + } + private enum Phase { NONE, START, END; diff --git a/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModCommonProxy.java b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModCommonProxy.java index 4bc751d..a2ad69e 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModCommonProxy.java +++ b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModCommonProxy.java @@ -99,6 +99,7 @@ public void addKnownZetaLoadEvents(ForgeEventsRemapper r) public void addKnownZetaPlayEvents(ForgeEventsRemapper r) { r.registerWrapper(ZAnvilRepair.class, ForgeZAnvilRepair.class); + r.registerWrapper(ZAnvilUpdate.class, ForgeZAnvilUpdate.class); r.registerWrapper(ZAnvilUpdate.Highest.class, ForgeZAnvilUpdate.Highest.class); r.registerWrapper(ZAnvilUpdate.Lowest.class, ForgeZAnvilUpdate.Lowest.class); r.registerWrapper(ZTagsUpdated.class, ForgeZTagsUpdated.class); diff --git a/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModForge.java b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModForge.java index a5118fd..71e56f5 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModForge.java +++ b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModForge.java @@ -1,6 +1,7 @@ package org.violetmoon.zetaimplforge.mod; import org.violetmoon.zeta.mod.ZetaMod; +import org.violetmoon.zetaimplforge.EventTest; import org.violetmoon.zetaimplforge.ForgeZeta; import net.minecraftforge.fml.DistExecutor; @@ -23,6 +24,11 @@ public ZetaModForge() { // creates 2 dist specific objects that will handle zeta specific & loader specific events needed for zeta to work PROXY.registerEvents(ZETA); + + if(!ZETA.isProduction) { + ZETA.loadBus.subscribe(EventTest.class); + ZETA.playBus.subscribe(EventTest.class); + } }