Skip to content

Commit

Permalink
fixed missing anvil event. Added workaround to prevent invalidly plac…
Browse files Browse the repository at this point in the history
…ed client events from crashing server
  • Loading branch information
MehVahdJukaar committed Aug 5, 2024
1 parent 6502e27 commit 4803a72
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/main/java/org/violetmoon/zetaimplforge/EventTest.java
Original file line number Diff line number Diff line change
@@ -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){

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,6 +64,7 @@ protected <Z2 extends Z> 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<? extends F> remapMethod(MethodHandle originalEventConsumer, Class<?> zetaEventBaseClass, Class<?> forgeEventClass) {
Function<? extends F, ? extends Z> forgeToZetaFunc = forgeToZetaMap.get(zetaEventBaseClass);
if (forgeToZetaFunc == null) {
Expand All @@ -76,8 +77,9 @@ protected Consumer<? extends F> 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);
}
Expand Down Expand Up @@ -374,11 +376,33 @@ public Object remapAndRegister(IEventBus forgeBus, Class<?> owningClazz, MethodH

Consumer<? extends F> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void addKnownZetaLoadEvents(ForgeEventsRemapper<IZetaLoadEvent, Event> r)
public void addKnownZetaPlayEvents(ForgeEventsRemapper<IZetaPlayEvent, Event> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}


Expand Down

0 comments on commit 4803a72

Please sign in to comment.