diff --git a/changelog.txt b/changelog.txt index f81b0c6..e16c35f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1 +1 @@ -- fixed an issue with biome modifier serializers not being registered (issue from very last release) \ No newline at end of file +moved gather additional flag event to the mod specific load bus. Unknown flags will also now return true \ No newline at end of file diff --git a/src/main/java/org/violetmoon/zeta/Zeta.java b/src/main/java/org/violetmoon/zeta/Zeta.java index 2d87485..0ddc239 100644 --- a/src/main/java/org/violetmoon/zeta/Zeta.java +++ b/src/main/java/org/violetmoon/zeta/Zeta.java @@ -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 loadBus; - public final ZetaEventBus playBus; + public final ZetaEventBus 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 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 diff --git a/src/main/java/org/violetmoon/zeta/config/ConfigManager.java b/src/main/java/org/violetmoon/zeta/config/ConfigManager.java index 395551e..9559864 100644 --- a/src/main/java/org/violetmoon/zeta/config/ConfigManager.java +++ b/src/main/java/org/violetmoon/zeta/config/ConfigManager.java @@ -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; @@ -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 @@ -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(); diff --git a/src/main/java/org/violetmoon/zeta/config/FlagCondition.java b/src/main/java/org/violetmoon/zeta/config/FlagCondition.java index 19367c7..965e309 100644 --- a/src/main/java/org/violetmoon/zeta/config/FlagCondition.java +++ b/src/main/java/org/violetmoon/zeta/config/FlagCondition.java @@ -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); } diff --git a/src/main/java/org/violetmoon/zeta/event/load/ZGatherAdditionalFlags.java b/src/main/java/org/violetmoon/zeta/event/load/ZGatherAdditionalFlags.java new file mode 100644 index 0000000..446bcaf --- /dev/null +++ b/src/main/java/org/violetmoon/zeta/event/load/ZGatherAdditionalFlags.java @@ -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(); +} diff --git a/src/main/java/org/violetmoon/zeta/event/play/loading/ZGatherAdditionalFlags.java b/src/main/java/org/violetmoon/zeta/event/play/loading/ZGatherAdditionalFlags.java index a1b60ce..068d3f5 100644 --- a/src/main/java/org/violetmoon/zeta/event/play/loading/ZGatherAdditionalFlags.java +++ b/src/main/java/org/violetmoon/zeta/event/play/loading/ZGatherAdditionalFlags.java @@ -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(); diff --git a/src/main/java/org/violetmoon/zetaimplforge/event/ForgeZetaEventBus.java b/src/main/java/org/violetmoon/zetaimplforge/event/ForgeZetaEventBus.java index c1b10e9..ea3e428 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/event/ForgeZetaEventBus.java +++ b/src/main/java/org/violetmoon/zetaimplforge/event/ForgeZetaEventBus.java @@ -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; @@ -82,14 +48,14 @@ public static ForgeZetaEventBus 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 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); } @@ -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 { @@ -172,14 +139,28 @@ public void registerWrapper(Class baseZetaEvent } } + public void registerWrapper(Class baseZetaEventClass, Class forgeEventClass, + Function constructor, Function unwrapper) { + synchronized (remapper) { + remapper.registerWrapper(baseZetaEventClass, forgeEventClass, constructor, unwrapper); + } + } + + public void registerWrapperWithGenerics(Class baseZetaEventClass, Class forgeEventClass, + Function constructor, Function 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 LOAD_EVENTS_REMAPPER = Util.make( + private static final ForgeEventsRemapper DEFAULT_LOAD_EVENTS_REMAPPER = Util.make( new ForgeEventsRemapper<>(IZetaLoadEvent.class, Event.class), ZetaModForge.PROXY::addKnownZetaLoadEvents ); - private static final ForgeEventsRemapper PLAY_EVENTS_REMAPPER = Util.make( + private static final ForgeEventsRemapper DEFAULT_PLAY_EVENTS_REMAPPER = Util.make( new ForgeEventsRemapper<>(IZetaPlayEvent.class, Event.class), ZetaModForge.PROXY::addKnownZetaPlayEvents ); diff --git a/src/main/java/org/violetmoon/zetaimplforge/event/load/ForgeZGatherAdditionalFlags.java b/src/main/java/org/violetmoon/zetaimplforge/event/load/ForgeZGatherAdditionalFlags.java new file mode 100644 index 0000000..22bf488 --- /dev/null +++ b/src/main/java/org/violetmoon/zetaimplforge/event/load/ForgeZGatherAdditionalFlags.java @@ -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(); + } +} diff --git a/src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZBlock.java b/src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZBlock.java index fa240f8..29a42f9 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZBlock.java +++ b/src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZBlock.java @@ -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); @@ -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); diff --git a/src/main/java/org/violetmoon/zetaimplforge/event/play/loading/ForgeZGatherAdditionalFlags.java b/src/main/java/org/violetmoon/zetaimplforge/event/play/loading/ForgeZGatherAdditionalFlags.java index 89ea34b..330bf85 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/event/play/loading/ForgeZGatherAdditionalFlags.java +++ b/src/main/java/org/violetmoon/zetaimplforge/event/play/loading/ForgeZGatherAdditionalFlags.java @@ -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; diff --git a/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModCommonProxy.java b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModCommonProxy.java index 44d65b9..4bc751d 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModCommonProxy.java +++ b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModCommonProxy.java @@ -10,6 +10,7 @@ import net.minecraftforge.event.entity.living.*; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.level.BlockEvent; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; @@ -20,6 +21,7 @@ import org.violetmoon.zeta.event.bus.IZetaLoadEvent; import org.violetmoon.zeta.event.bus.IZetaPlayEvent; import org.violetmoon.zeta.event.load.*; +import org.violetmoon.zeta.event.load.ZGatherAdditionalFlags; import org.violetmoon.zeta.event.play.*; import org.violetmoon.zeta.event.play.entity.*; import org.violetmoon.zeta.event.play.entity.living.*; @@ -34,6 +36,7 @@ import org.violetmoon.zetaimplforge.config.ConfigEventDispatcher; import org.violetmoon.zetaimplforge.event.ForgeEventsRemapper; import org.violetmoon.zetaimplforge.event.load.*; +import org.violetmoon.zetaimplforge.event.load.ForgeZGatherAdditionalFlags; import org.violetmoon.zetaimplforge.event.play.*; import org.violetmoon.zetaimplforge.event.play.entity.*; import org.violetmoon.zetaimplforge.event.play.entity.living.*; @@ -45,170 +48,176 @@ public class ZetaModCommonProxy { - public void registerEvents(Zeta zeta){ - IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); - bus.addListener(this::onSetup); - - zeta.loadBus - .subscribe(RecipeCrawlHandler.class) - .subscribe(ToolInteractionHandler.class) - .subscribe(EntitySpawnHandler.class) - .subscribe(WorldGenHandler.class) - .subscribe(ZetaGeneralConfig.class); - - zeta.playBus - .subscribe(RecipeCrawlHandler.class) - .subscribe(ToolInteractionHandler.class) - .subscribe(SyncedFlagHandler.class); - - - MinecraftForge.EVENT_BUS.register(ToolInteractionHandler.class); - ZetaBiomeModifier.registerBiomeModifier(FMLJavaModLoadingContext.get().getModEventBus()); - - } - - - public void onSetup(FMLCommonSetupEvent event) { - event.enqueueWork(ConfigEventDispatcher::dispatchAllInitialLoads); - } - - public void addKnownZetaLoadEvents(ForgeEventsRemapper r){ - - //TODO: repace all these with explicit ones - - // adds known events subclasses to the bus - r.registerWrapper(ZCommonSetup.class, FMLCommonSetupEvent.class, - ForgeZCommonSetup::new, ForgeZCommonSetup::e); - r.registerWrapper(ZEntityAttributeCreation.class, EntityAttributeCreationEvent.class, - ForgeZEntityAttributeCreation::new, ForgeZEntityAttributeCreation::e); - r.registerWrapper(ZModulesReady.class, ForgeZModulesReady.class); - r.registerWrapper(ZRegister.class, ForgeZRegister.class); - r.registerWrapper(ZRegister.Post.class, ForgeZRegister.Post.class); - r.registerWrapper(ZConfigChanged.class, ForgeZConfigChange.class); - r.registerWrapper(ZLoadComplete.class, ForgeZLoadComplete.class); - - //zeta own - r.registerWrapper(ZGatherAdvancementModifiers.class, ForgeZGatherAdvancementModifiers.class); - - } - - public void addKnownZetaPlayEvents(ForgeEventsRemapper r){ - - r.registerWrapper(ZAnvilRepair.class, ForgeZAnvilRepair.class); - r.registerWrapper(ZAnvilUpdate.Highest.class, ForgeZAnvilUpdate.Highest.class); - r.registerWrapper(ZAnvilUpdate.Lowest.class, ForgeZAnvilUpdate.Lowest.class); - r.registerWrapper(ZTagsUpdated.class, ForgeZTagsUpdated.class); - r.registerWrapper(ZBabyEntitySpawn.Lowest.class, BabyEntitySpawnEvent.class, - ForgeZBabyEntitySpawn.Lowest::new, a -> a.wrapped); - r.registerWrapper(ZBabyEntitySpawn.class, BabyEntitySpawnEvent.class, - ForgeZBabyEntitySpawn::new, a -> a.wrapped); - r.registerWrapper(ZBlock.Break.class, ForgeZBlock.Break.class); - r.registerWrapper(ZBlock.EntityPlace.class, ForgeZBlock.EntityPlace.class); - r.registerWrapper(ZBlock.BlockToolModification.class, ForgeZBlock.BlockToolModification.class); - r.registerWrapper(ZBonemeal.class, ForgeZBonemeal.class); - r.registerWrapper(ZEntityConstruct.class, ForgeZEntityConstruct.class); - r.registerWrapper(ZEntityInteract.class, PlayerInteractEvent.EntityInteract.class, - ForgeZEntityInteract::new, ForgeZEntityInteract::e); - r.registerWrapper(ZEntityItemPickup.class, ForgeZEntityItemPickup.class); - r.registerWrapper(ZEntityJoinLevel.class, ForgeZEntityJoinLevel.class); - r.registerWrapper(ZEntityMobGriefing.class, ForgeZEntityMobGriefing.class); - r.registerWrapper(ZEntityTeleport.class, ForgeZEntityTeleport.class); - r.registerWrapper(ZItemTooltip.class, ItemTooltipEvent.class, - ForgeZItemTooltip::new, ForgeZItemTooltip::e); - r.registerWrapper(ZLivingChangeTarget.class, LivingChangeTargetEvent.class, - ForgeZLivingChangeTarget::new, ForgeZLivingChangeTarget::e); - r.registerWrapper(ZLivingConversion.class, ForgeZLivingConversion.class); - r.registerWrapper(ZLivingConversion.Pre.class, ForgeZLivingConversion.Pre.class); - r.registerWrapper(ZLivingConversion.Post.class, ForgeZLivingConversion.Post.class); - r.registerWrapper(ZLivingDeath.class, ForgeZLivingDeath.class); - r.registerWrapper(ZLivingDeath.Lowest.class, ForgeZLivingDeath.Lowest.class); - r.registerWrapper(ZLivingDrops.class, LivingDropsEvent.class, - ForgeZLivingDrops::new, w -> w.e); - r.registerWrapper(ZLivingDrops.Lowest.class, LivingDropsEvent.class, - ForgeZLivingDrops.Lowest::new, w -> w.e); - r.registerWrapper(ZLivingFall.class, ForgeZLivingFall.class); - r.registerWrapper(ZLivingTick.class, LivingEvent.LivingTickEvent.class, - ForgeZLivingTick::new, ForgeZLivingTick::e); - r.registerWrapper(ZMobSpawnEvent.class, MobSpawnEvent.class, - ForgeZMobSpawnEvent::new, w -> w.e); - r.registerWrapper(ZMobSpawnEvent.CheckSpawn.class, MobSpawnEvent.FinalizeSpawn.class, - ForgeZMobSpawnEvent.FinalizeSpawn::new, w -> w.e); - r.registerWrapper(ZMobSpawnEvent.CheckSpawn.Lowest.class, MobSpawnEvent.FinalizeSpawn.class, - ForgeZMobSpawnEvent.FinalizeSpawn.Lowest::new, w -> w.e); - r.registerWrapper(ZPlayNoteBlock.class, ForgeZPlayNoteBlock.class); - r.registerWrapper(ZPlayer.BreakSpeed.class, ForgeZPlayer.BreakSpeed.class); - r.registerWrapper(ZPlayer.Clone.class, ForgeZPlayer.Clone.class); - r.registerWrapper(ZPlayerDestroyItem.class, ForgeZPlayerDestroyItem.class); - r.registerWrapper(ZPlayer.LoggedIn.class, ForgeZPlayer.LoggedIn.class); - r.registerWrapper(ZPlayer.LoggedOut.class, ForgeZPlayer.LoggedOut.class); - r.registerWrapper(ZPlayerTick.Start.class, TickEvent.PlayerTickEvent.class, - ForgeZPlayerTick.Start::new, w -> w.e); - r.registerWrapper(ZPlayerTick.End.class, TickEvent.PlayerTickEvent.class, - ForgeZPlayerTick.End::new, w -> w.e); - r.registerWrapper(ZPlayerInteract.class, ForgeZPlayerInteract.class); - r.registerWrapper(ZPlayerInteract.EntityInteractSpecific.class, ForgeZPlayerInteract.EntityInteractSpecific.class); - r.registerWrapper(ZPlayerInteract.EntityInteract.class, ForgeZPlayerInteract.EntityInteract.class); - r.registerWrapper(ZPlayerInteract.RightClickBlock.class, ForgeZPlayerInteract.RightClickBlock.class); - r.registerWrapper(ZPlayerInteract.RightClickItem.class, ForgeZPlayerInteract.RightClickItem.class); - r.registerWrapper(ZRightClickBlock.class, ForgeZRightClickBlock.class); - r.registerWrapper(ZRightClickBlock.Low.class, ForgeZRightClickBlock.Low.class); - r.registerWrapper(ZRightClickItem.class, ForgeZRightClickItem.class); - r.registerWrapper(ZLootTableLoad.class, ForgeZLootTableLoad.class); - r.registerWrapper(ZVillagerTrades.class, ForgeZVillagerTrades.class); - r.registerWrapper(ZWandererTrades.class, ForgeZWandererTrades.class); - r.registerWrapper(ZFurnaceFuelBurnTime.class, ForgeZFurnaceFuelBurnTime.class); - r.registerWrapper(ZGatherAdditionalFlags.class, ForgeZGatherAdditionalFlags.class); - r.registerWrapper(ZServerTick.Start.class, TickEvent.ServerTickEvent.class, - ForgeZServerTick.Start::new, w -> w.e); - r.registerWrapper(ZServerTick.End.class, TickEvent.ServerTickEvent.class, - ForgeZServerTick.End::new, w -> w.e); - r.registerWrapper(ZAddReloadListener.class, ForgeZAddReloadListener.class); - r.registerWrapper(ZGatherHints.class, ForgeZGatherHints.class); - r.registerWrapper(ZSleepingLocationCheck.class, ForgeZSleepingLocationCheck.class); - r.registerWrapper(ZAnimalTame.class, ForgeZAnimalTame.class); - r.registerWrapper(ZLevelTick.End.class, TickEvent.LevelTickEvent.class, - ForgeZLevelTick.End::new, w -> w.e); - r.registerWrapper(ZLevelTick.Start.class, TickEvent.LevelTickEvent.class, - ForgeZLevelTick.Start::new, w -> w.e); - - - //this is ugly. generic events here - r.registerWrapperWithGeneric(ZAttachCapabilities.BlockEntityCaps.class, - ForgeZAttachCapabilities.BlockEntityCaps.class, - (Function, ForgeZAttachCapabilities.BlockEntityCaps>) inner -> - new ForgeZAttachCapabilities.BlockEntityCaps(ForgeCapabilityManager.INSTANCE, inner), - BlockEntity.class); - r.registerWrapperWithGeneric(ZAttachCapabilities.ItemStackCaps.class, - ForgeZAttachCapabilities.ItemStackCaps.class, - (Function, ForgeZAttachCapabilities.ItemStackCaps>) inner -> - new ForgeZAttachCapabilities.ItemStackCaps(ForgeCapabilityManager.INSTANCE, inner), - ItemStack.class); - r.registerWrapperWithGeneric(ZAttachCapabilities.LevelCaps.class, - ForgeZAttachCapabilities.LevelCaps.class, - (Function, ForgeZAttachCapabilities.LevelCaps>) inner -> - new ForgeZAttachCapabilities.LevelCaps(ForgeCapabilityManager.INSTANCE, inner), - Level.class); - - // zeta specific ones - - r.registerWrapper(ZRecipeCrawl.Digest.class, ForgeZRecipeCrawl.Digest.class, - ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Digest::new); - r.registerWrapper(ZRecipeCrawl.Reset.class, ForgeZRecipeCrawl.Reset.class, - ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Reset::new); - r.registerWrapper(ZRecipeCrawl.Starting.class, ForgeZRecipeCrawl.Starting.class, - ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Starting::new); - r.registerWrapper(ZRecipeCrawl.Visit.Cooking.class, ForgeZRecipeCrawl.Visit.Cooking.class, - ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Visit.Cooking::new); - r.registerWrapper(ZRecipeCrawl.Visit.Custom.class, ForgeZRecipeCrawl.Visit.Custom.class, - ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Visit.Custom::new); - r.registerWrapper(ZRecipeCrawl.Visit.Misc.class, ForgeZRecipeCrawl.Visit.Misc.class, - ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Visit.Misc::new); - r.registerWrapper(ZRecipeCrawl.Visit.Shaped.class, ForgeZRecipeCrawl.Visit.Shaped.class, - ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Visit.Shaped::new); - r.registerWrapper(ZRecipeCrawl.Visit.Shapeless.class, ForgeZRecipeCrawl.Visit.Shapeless.class, - ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Visit.Shapeless::new); - - } + public void registerEvents(Zeta zeta) { + IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); + bus.addListener(this::onSetup); + + zeta.loadBus + .subscribe(RecipeCrawlHandler.class) + .subscribe(ToolInteractionHandler.class) + .subscribe(EntitySpawnHandler.class) + .subscribe(WorldGenHandler.class) + .subscribe(ZetaGeneralConfig.class); + + zeta.playBus + .subscribe(RecipeCrawlHandler.class) + .subscribe(ToolInteractionHandler.class) + .subscribe(SyncedFlagHandler.class); + + + MinecraftForge.EVENT_BUS.register(ToolInteractionHandler.class); + ZetaBiomeModifier.registerBiomeModifier(FMLJavaModLoadingContext.get().getModEventBus()); + + } + + + public void onSetup(FMLCommonSetupEvent event) { + event.enqueueWork(ConfigEventDispatcher::dispatchAllInitialLoads); + } + + public void addKnownZetaLoadEvents(ForgeEventsRemapper r) { + + //TODO: repace all these with explicit ones + + // adds known events subclasses to the bus + r.registerWrapper(ZCommonSetup.class, FMLCommonSetupEvent.class, + ForgeZCommonSetup::new, ForgeZCommonSetup::e); + r.registerWrapper(ZEntityAttributeCreation.class, EntityAttributeCreationEvent.class, + ForgeZEntityAttributeCreation::new, ForgeZEntityAttributeCreation::e); + r.registerWrapper(ZModulesReady.class, ForgeZModulesReady.class); + r.registerWrapper(ZRegister.class, ForgeZRegister.class); + r.registerWrapper(ZRegister.Post.class, ForgeZRegister.Post.class); + r.registerWrapper(ZConfigChanged.class, ForgeZConfigChange.class); + r.registerWrapper(ZLoadComplete.class, ForgeZLoadComplete.class); + + //zeta own + r.registerWrapper(ZGatherAdvancementModifiers.class, ForgeZGatherAdvancementModifiers.class); + r.registerWrapper(ZGatherAdditionalFlags.class, ForgeZGatherAdditionalFlags.class); + + } + + public void addKnownZetaPlayEvents(ForgeEventsRemapper r) { + + r.registerWrapper(ZAnvilRepair.class, ForgeZAnvilRepair.class); + r.registerWrapper(ZAnvilUpdate.Highest.class, ForgeZAnvilUpdate.Highest.class); + r.registerWrapper(ZAnvilUpdate.Lowest.class, ForgeZAnvilUpdate.Lowest.class); + r.registerWrapper(ZTagsUpdated.class, ForgeZTagsUpdated.class); + r.registerWrapper(ZBabyEntitySpawn.Lowest.class, BabyEntitySpawnEvent.class, + ForgeZBabyEntitySpawn.Lowest::new, a -> a.wrapped); + r.registerWrapper(ZBabyEntitySpawn.class, BabyEntitySpawnEvent.class, + ForgeZBabyEntitySpawn::new, a -> a.wrapped); + r.registerWrapper(ZBlock.Break.class, BlockEvent.BreakEvent.class, + ForgeZBlock.Break::new, w -> w.e); + r.registerWrapper(ZBlock.EntityPlace.class, BlockEvent.EntityPlaceEvent.class, + ForgeZBlock.EntityPlace::new, w -> w.e); + r.registerWrapper(ZBlock.BlockToolModification.class, ForgeZBlock.BlockToolModification.class); + r.registerWrapper(ZBonemeal.class, ForgeZBonemeal.class); + r.registerWrapper(ZEntityConstruct.class, ForgeZEntityConstruct.class); + r.registerWrapper(ZEntityInteract.class, PlayerInteractEvent.EntityInteract.class, + ForgeZEntityInteract::new, ForgeZEntityInteract::e); + r.registerWrapper(ZEntityItemPickup.class, ForgeZEntityItemPickup.class); + r.registerWrapper(ZEntityJoinLevel.class, ForgeZEntityJoinLevel.class); + r.registerWrapper(ZEntityMobGriefing.class, ForgeZEntityMobGriefing.class); + r.registerWrapper(ZEntityTeleport.class, ForgeZEntityTeleport.class); + r.registerWrapper(ZItemTooltip.class, ItemTooltipEvent.class, + ForgeZItemTooltip::new, ForgeZItemTooltip::e); + r.registerWrapper(ZLivingChangeTarget.class, LivingChangeTargetEvent.class, + ForgeZLivingChangeTarget::new, ForgeZLivingChangeTarget::e); + r.registerWrapper(ZLivingConversion.class, ForgeZLivingConversion.class); + r.registerWrapper(ZLivingConversion.Pre.class, ForgeZLivingConversion.Pre.class); + r.registerWrapper(ZLivingConversion.Post.class, ForgeZLivingConversion.Post.class); + r.registerWrapper(ZLivingDeath.class, ForgeZLivingDeath.class); + r.registerWrapper(ZLivingDeath.Lowest.class, ForgeZLivingDeath.Lowest.class); + r.registerWrapper(ZLivingDrops.class, LivingDropsEvent.class, + ForgeZLivingDrops::new, w -> w.e); + r.registerWrapper(ZLivingDrops.Lowest.class, LivingDropsEvent.class, + ForgeZLivingDrops.Lowest::new, w -> w.e); + r.registerWrapper(ZLivingFall.class, ForgeZLivingFall.class); + r.registerWrapper(ZLivingTick.class, LivingEvent.LivingTickEvent.class, + ForgeZLivingTick::new, ForgeZLivingTick::e); + r.registerWrapper(ZMobSpawnEvent.class, MobSpawnEvent.class, + ForgeZMobSpawnEvent::new, w -> w.e); + r.registerWrapper(ZMobSpawnEvent.CheckSpawn.class, MobSpawnEvent.FinalizeSpawn.class, + ForgeZMobSpawnEvent.FinalizeSpawn::new, w -> w.e); + r.registerWrapper(ZMobSpawnEvent.CheckSpawn.Lowest.class, MobSpawnEvent.FinalizeSpawn.class, + ForgeZMobSpawnEvent.FinalizeSpawn.Lowest::new, w -> w.e); + r.registerWrapper(ZPlayNoteBlock.class, ForgeZPlayNoteBlock.class); + r.registerWrapper(ZPlayer.BreakSpeed.class, ForgeZPlayer.BreakSpeed.class); + r.registerWrapper(ZPlayer.Clone.class, ForgeZPlayer.Clone.class); + r.registerWrapper(ZPlayerDestroyItem.class, ForgeZPlayerDestroyItem.class); + r.registerWrapper(ZPlayer.LoggedIn.class, ForgeZPlayer.LoggedIn.class); + r.registerWrapper(ZPlayer.LoggedOut.class, ForgeZPlayer.LoggedOut.class); + r.registerWrapper(ZPlayerTick.Start.class, TickEvent.PlayerTickEvent.class, + ForgeZPlayerTick.Start::new, w -> w.e); + r.registerWrapper(ZPlayerTick.End.class, TickEvent.PlayerTickEvent.class, + ForgeZPlayerTick.End::new, w -> w.e); + r.registerWrapper(ZPlayerInteract.class, ForgeZPlayerInteract.class); + r.registerWrapper(ZPlayerInteract.EntityInteractSpecific.class, ForgeZPlayerInteract.EntityInteractSpecific.class); + r.registerWrapper(ZPlayerInteract.EntityInteract.class, ForgeZPlayerInteract.EntityInteract.class); + r.registerWrapper(ZPlayerInteract.RightClickBlock.class, ForgeZPlayerInteract.RightClickBlock.class); + r.registerWrapper(ZPlayerInteract.RightClickItem.class, ForgeZPlayerInteract.RightClickItem.class); + r.registerWrapper(ZRightClickBlock.class, ForgeZRightClickBlock.class); + r.registerWrapper(ZRightClickBlock.Low.class, ForgeZRightClickBlock.Low.class); + r.registerWrapper(ZRightClickItem.class, ForgeZRightClickItem.class); + r.registerWrapper(ZLootTableLoad.class, ForgeZLootTableLoad.class); + r.registerWrapper(ZVillagerTrades.class, ForgeZVillagerTrades.class); + r.registerWrapper(ZWandererTrades.class, ForgeZWandererTrades.class); + r.registerWrapper(ZFurnaceFuelBurnTime.class, ForgeZFurnaceFuelBurnTime.class); + r.registerWrapper(ZServerTick.Start.class, TickEvent.ServerTickEvent.class, + ForgeZServerTick.Start::new, w -> w.e); + r.registerWrapper(ZServerTick.End.class, TickEvent.ServerTickEvent.class, + ForgeZServerTick.End::new, w -> w.e); + r.registerWrapper(ZAddReloadListener.class, ForgeZAddReloadListener.class); + r.registerWrapper(ZGatherHints.class, ForgeZGatherHints.class); + r.registerWrapper(ZSleepingLocationCheck.class, ForgeZSleepingLocationCheck.class); + r.registerWrapper(ZAnimalTame.class, ForgeZAnimalTame.class); + r.registerWrapper(ZLevelTick.End.class, TickEvent.LevelTickEvent.class, + ForgeZLevelTick.End::new, w -> w.e); + r.registerWrapper(ZLevelTick.Start.class, TickEvent.LevelTickEvent.class, + ForgeZLevelTick.Start::new, w -> w.e); + + + //this is ugly. generic events here + r.registerWrapperWithGeneric(ZAttachCapabilities.BlockEntityCaps.class, + ForgeZAttachCapabilities.BlockEntityCaps.class, + (Function, ForgeZAttachCapabilities.BlockEntityCaps>) inner -> + new ForgeZAttachCapabilities.BlockEntityCaps(ForgeCapabilityManager.INSTANCE, inner), + BlockEntity.class); + r.registerWrapperWithGeneric(ZAttachCapabilities.ItemStackCaps.class, + ForgeZAttachCapabilities.ItemStackCaps.class, + (Function, ForgeZAttachCapabilities.ItemStackCaps>) inner -> + new ForgeZAttachCapabilities.ItemStackCaps(ForgeCapabilityManager.INSTANCE, inner), + ItemStack.class); + r.registerWrapperWithGeneric(ZAttachCapabilities.LevelCaps.class, + ForgeZAttachCapabilities.LevelCaps.class, + (Function, ForgeZAttachCapabilities.LevelCaps>) inner -> + new ForgeZAttachCapabilities.LevelCaps(ForgeCapabilityManager.INSTANCE, inner), + Level.class); + + // zeta specific ones + + r.registerWrapper(ZRecipeCrawl.Digest.class, ForgeZRecipeCrawl.Digest.class, + ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Digest::new); + r.registerWrapper(ZRecipeCrawl.Reset.class, ForgeZRecipeCrawl.Reset.class, + ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Reset::new); + r.registerWrapper(ZRecipeCrawl.Starting.class, ForgeZRecipeCrawl.Starting.class, + ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Starting::new); + r.registerWrapper(ZRecipeCrawl.Visit.Cooking.class, ForgeZRecipeCrawl.Visit.Cooking.class, + ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Visit.Cooking::new); + r.registerWrapper(ZRecipeCrawl.Visit.Custom.class, ForgeZRecipeCrawl.Visit.Custom.class, + ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Visit.Custom::new); + r.registerWrapper(ZRecipeCrawl.Visit.Misc.class, ForgeZRecipeCrawl.Visit.Misc.class, + ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Visit.Misc::new); + r.registerWrapper(ZRecipeCrawl.Visit.Shaped.class, ForgeZRecipeCrawl.Visit.Shaped.class, + ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Visit.Shaped::new); + r.registerWrapper(ZRecipeCrawl.Visit.Shapeless.class, ForgeZRecipeCrawl.Visit.Shapeless.class, + ForgeZRecipeCrawl::get, ForgeZRecipeCrawl.Visit.Shapeless::new); + + r.registerWrapper(org.violetmoon.zeta.event.play.loading.ZGatherAdditionalFlags.class, + org.violetmoon.zetaimplforge.event.play.loading.ForgeZGatherAdditionalFlags.class); + + + } }