Skip to content

Commit

Permalink
moved gather additional flag event to the mod specific load bus. Unkn…
Browse files Browse the repository at this point in the history
…own flags will also now return true
  • Loading branch information
MehVahdJukaar committed Aug 4, 2024
1 parent dd38934 commit 5394658
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 215 deletions.
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- fixed an issue with biome modifier serializers not being registered (issue from very last release)
moved gather additional flag event to the mod specific load bus. Unknown flags will also now return true
5 changes: 3 additions & 2 deletions src/main/java/org/violetmoon/zeta/Zeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public Zeta(String modid, Logger log, ZetaSide side, boolean isProduction) {
public final String modid;
public final ZetaSide side;
public final boolean isProduction;
public final ZetaEventBus<IZetaLoadEvent> loadBus;
public final ZetaEventBus<IZetaPlayEvent> playBus;
public final ZetaEventBus<IZetaLoadEvent> loadBus; //zeta specific bus
// Be careful when using this. Load bus will only fire stuff to this zeta events. Play bus however will not as it delegate to forge bus
public final ZetaEventBus<IZetaPlayEvent> playBus; //common mod event bus. Each zeta will have their own object for now but internally they all delegate to the same internal bus
public final ZetaModuleManager modules;

//registry
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/violetmoon/zeta/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.jetbrains.annotations.Nullable;
import org.violetmoon.zeta.Zeta;
import org.violetmoon.zeta.event.play.loading.ZGatherAdditionalFlags;
import org.violetmoon.zeta.event.load.ZGatherAdditionalFlags;
import org.violetmoon.zeta.module.ZetaCategory;
import org.violetmoon.zeta.module.ZetaModule;
import org.violetmoon.zeta.module.ZetaModuleManager;
Expand Down Expand Up @@ -103,8 +103,8 @@ public ConfigManager(Zeta z, Object rootPojo) {
}));
}

//grab any extra flags
z.playBus.fire(() -> cfm, ZGatherAdditionalFlags.class);
//grab any extra flags. Fires on the load event of that mod
z.loadBus.fire(() -> cfm, ZGatherAdditionalFlags.class);

//managing module enablement in one go
//adding this to the *start* of the list so modules are enabled before anything else runs
Expand All @@ -118,7 +118,7 @@ public ConfigManager(Zeta z, Object rootPojo) {
});

//update extra flags
z.playBus.fire(() -> cfm, ZGatherAdditionalFlags.class);
z.loadBus.fire(() -> cfm, ZGatherAdditionalFlags.class);
});

this.rootConfig = rootConfigBuilder.build();
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/violetmoon/zeta/config/FlagCondition.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public boolean test(IContext context) {
if(flag.contains("%"))
throw new RuntimeException("Illegal flag: " + flag);

if(!cfm.isValidFlag(flag))
cfm.zeta.log.warn("Non-existent flag " + flag + " being used");
if(!cfm.isValidFlag(flag)) {
cfm.zeta.log.warn("Non-existent flag {} being used", flag);
// return true for unknown flags
return true;
}

return extraCondition.getAsBoolean() && cfm.getFlag(flag);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.violetmoon.zeta.event.load;

import org.violetmoon.zeta.config.ConfigFlagManager;
import org.violetmoon.zeta.event.bus.IZetaLoadEvent;
import org.violetmoon.zeta.event.bus.IZetaPlayEvent;

public interface ZGatherAdditionalFlags extends IZetaLoadEvent {

ConfigFlagManager flagManager();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.violetmoon.zeta.config.ConfigFlagManager;
import org.violetmoon.zeta.event.bus.IZetaPlayEvent;

//use load event instead
@Deprecated(forRemoval = true)
public interface ZGatherAdditionalFlags extends IZetaPlayEvent {

ConfigFlagManager flagManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,16 @@

import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.Util;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGuiOverlayEvent;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.client.event.ScreenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.EntityAttributeCreationEvent;
import net.minecraftforge.event.entity.living.*;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLEnvironment;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.zeta.Zeta;
import org.violetmoon.zeta.client.event.load.*;
import org.violetmoon.zeta.client.event.play.*;
import org.violetmoon.zeta.event.bus.*;
import org.violetmoon.zeta.event.load.*;
import org.violetmoon.zeta.event.play.*;
import org.violetmoon.zeta.event.play.entity.*;
import org.violetmoon.zeta.event.play.entity.living.*;
import org.violetmoon.zeta.event.play.entity.player.*;
import org.violetmoon.zeta.event.play.loading.*;
import org.violetmoon.zetaimplforge.api.ForgeZGatherAdvancementModifiers;
import org.violetmoon.zetaimplforge.capability.ForgeCapabilityManager;
import org.violetmoon.zetaimplforge.client.event.load.*;
import org.violetmoon.zetaimplforge.client.event.play.*;
import org.violetmoon.zetaimplforge.event.load.*;
import org.violetmoon.zetaimplforge.event.play.*;
import org.violetmoon.zetaimplforge.event.play.entity.*;
import org.violetmoon.zetaimplforge.event.play.entity.living.*;
import org.violetmoon.zetaimplforge.event.play.entity.player.*;
import org.violetmoon.zetaimplforge.event.play.loading.*;
import org.violetmoon.zetaimplforge.mod.ZetaModClientProxy;
import org.violetmoon.zeta.event.play.loading.ZGatherAdditionalFlags;
import org.violetmoon.zetaimplforge.mod.ZetaModForge;

import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -82,14 +48,14 @@ public static ForgeZetaEventBus<IZetaLoadEvent, Event> ofLoadBus(@Nullable Logge
return new ForgeZetaEventBus<>(
LoadEvent.class, IZetaLoadEvent.class,
logSpam, FMLJavaModLoadingContext.get().getModEventBus(), Event.class,
ofZeta, LOAD_EVENTS_REMAPPER);
ofZeta, DEFAULT_LOAD_EVENTS_REMAPPER);
}

public static ForgeZetaEventBus<IZetaPlayEvent, Event> ofPlayBus(@Nullable Logger logSpam, Zeta ofZeta) {
return new ForgeZetaEventBus<>(
PlayEvent.class, IZetaPlayEvent.class,
logSpam, MinecraftForge.EVENT_BUS, Event.class,
ofZeta, PLAY_EVENTS_REMAPPER);
ofZeta, DEFAULT_PLAY_EVENTS_REMAPPER);
}


Expand All @@ -101,8 +67,9 @@ protected void subscribeMethod(Method method, Object receiver, Class<?> owningCl
Class<?> zetaEventClass = method.getParameterTypes()[0];

//check if it's already a forge event, or it's a zeta event
if (!eventRoot.isAssignableFrom(zetaEventClass) && !forgeEventRoot.isAssignableFrom(zetaEventClass))
if (!eventRoot.isAssignableFrom(zetaEventClass) && !forgeEventRoot.isAssignableFrom(zetaEventClass)) {
throw typeERR(method);
}

MethodHandle handle;
try {
Expand Down Expand Up @@ -172,14 +139,28 @@ public <ZF extends Z, ZB extends Z> void registerWrapper(Class<ZB> baseZetaEvent
}
}

public <ZF extends Z, ZB extends Z, F2 extends F> void registerWrapper(Class<ZB> baseZetaEventClass, Class<F2> forgeEventClass,
Function<F2, ZF> constructor, Function<ZF, ? extends F> unwrapper) {
synchronized (remapper) {
remapper.registerWrapper(baseZetaEventClass, forgeEventClass, constructor, unwrapper);
}
}

public <ZF extends Z, ZB extends Z, F2 extends F> void registerWrapperWithGenerics(Class<ZB> baseZetaEventClass, Class<F2> forgeEventClass,
Function<F2, ZF> constructor, Function<ZF, ? extends F> unwrapper, Class<?> generic) {
synchronized (remapper) {
remapper.registerWrapperWithGenerics(baseZetaEventClass, forgeEventClass, constructor, unwrapper, generic);
}
}

// I would love to put this code in the mod proxy but that needs to do event setup stuff which requires these busses to be fully initialized

// instances so we don't create multiple as reflections take time and memory
private static final ForgeEventsRemapper<IZetaLoadEvent, Event> LOAD_EVENTS_REMAPPER = Util.make(
private static final ForgeEventsRemapper<IZetaLoadEvent, Event> DEFAULT_LOAD_EVENTS_REMAPPER = Util.make(
new ForgeEventsRemapper<>(IZetaLoadEvent.class, Event.class), ZetaModForge.PROXY::addKnownZetaLoadEvents
);

private static final ForgeEventsRemapper<IZetaPlayEvent, Event> PLAY_EVENTS_REMAPPER = Util.make(
private static final ForgeEventsRemapper<IZetaPlayEvent, Event> DEFAULT_PLAY_EVENTS_REMAPPER = Util.make(
new ForgeEventsRemapper<>(IZetaPlayEvent.class, Event.class), ZetaModForge.PROXY::addKnownZetaPlayEvents
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.violetmoon.zetaimplforge.event.load;

import net.minecraftforge.eventbus.api.Event;
import org.violetmoon.zeta.config.ConfigFlagManager;
import org.violetmoon.zeta.event.load.ZGatherAdditionalFlags;

public class ForgeZGatherAdditionalFlags extends Event implements ZGatherAdditionalFlags {

private final ZGatherAdditionalFlags wrapped;

public ForgeZGatherAdditionalFlags(ZGatherAdditionalFlags wrapped) {
this.wrapped = wrapped;
}

@Override
public ConfigFlagManager flagManager() {
return wrapped.flagManager();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public BlockState getState() {
}

public static class Break extends ForgeZBlock implements ZBlock.Break {
private final BlockEvent.BreakEvent e;
public final BlockEvent.BreakEvent e;

public Break(BlockEvent.BreakEvent e) {
super(e);
Expand All @@ -47,7 +47,7 @@ public Player getPlayer() {
}

public static class EntityPlace extends ForgeZBlock implements ZBlock.EntityPlace {
private final BlockEvent.EntityPlaceEvent e;
public final BlockEvent.EntityPlaceEvent e;

public EntityPlace(BlockEvent.EntityPlaceEvent e) {
super(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.violetmoon.zeta.config.ConfigFlagManager;
import org.violetmoon.zeta.event.play.loading.ZGatherAdditionalFlags;

@Deprecated(forRemoval = true)
public class ForgeZGatherAdditionalFlags extends Event implements ZGatherAdditionalFlags {

private final ZGatherAdditionalFlags wrapped;
Expand Down
Loading

0 comments on commit 5394658

Please sign in to comment.