From 9fad6d1d90195a5d7280f58bc99e5d20b843892b Mon Sep 17 00:00:00 2001 From: MehVahdJukaar Date: Wed, 31 Jul 2024 16:08:59 +0200 Subject: [PATCH] zeta proxy refactor --- .../violetmoon/zeta/client/ZetaClient.java | 2 - .../violetmoon/zeta/config/ConfigManager.java | 364 +++++++++--------- .../zeta/event/bus/ForgeZetaEventBus.java | 116 ++++-- .../zeta/event/bus/ZetaEventBus.java | 2 +- .../violetmoon/zeta/mod/ZetaClientProxy.java | 26 -- .../java/org/violetmoon/zeta/mod/ZetaMod.java | 10 +- .../org/violetmoon/zeta/mod/ZetaModProxy.java | 32 -- .../zeta/util/handler/RecipeCrawlHandler.java | 6 + .../zeta/util/zetalist/ZetaList.java | 5 +- .../violetmoon/zetaimplforge/ForgeZeta.java | 15 +- .../zetaimplforge/client/ForgeZetaClient.java | 65 ---- .../event/play/ForgeZRenderGuiOverlay.java | 3 +- .../zetaimplforge/event/NotAForgeWrapper.java | 9 + .../zetaimplforge/mod/ZetaModClientProxy.java | 80 ++++ ...aForgeMod.java => ZetaModCommonProxy.java} | 56 +-- .../zetaimplforge/mod/ZetaModForge.java | 24 ++ 16 files changed, 417 insertions(+), 398 deletions(-) delete mode 100644 src/main/java/org/violetmoon/zeta/mod/ZetaClientProxy.java delete mode 100644 src/main/java/org/violetmoon/zeta/mod/ZetaModProxy.java create mode 100644 src/main/java/org/violetmoon/zetaimplforge/event/NotAForgeWrapper.java create mode 100644 src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModClientProxy.java rename src/main/java/org/violetmoon/zetaimplforge/mod/{ZetaForgeMod.java => ZetaModCommonProxy.java} (51%) create mode 100644 src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModForge.java diff --git a/src/main/java/org/violetmoon/zeta/client/ZetaClient.java b/src/main/java/org/violetmoon/zeta/client/ZetaClient.java index 83a6328..eea0198 100644 --- a/src/main/java/org/violetmoon/zeta/client/ZetaClient.java +++ b/src/main/java/org/violetmoon/zeta/client/ZetaClient.java @@ -87,8 +87,6 @@ public void sendToServer(IZetaMessage msg) { // The name is unwieldy on purpose, usages of this function should stick out. public abstract @Nullable RegistryAccess hackilyGetCurrentClientLevelRegistryAccess(); - public abstract void start(); - @Override public Zeta asZeta() { return zeta; diff --git a/src/main/java/org/violetmoon/zeta/config/ConfigManager.java b/src/main/java/org/violetmoon/zeta/config/ConfigManager.java index 0783265..395551e 100644 --- a/src/main/java/org/violetmoon/zeta/config/ConfigManager.java +++ b/src/main/java/org/violetmoon/zeta/config/ConfigManager.java @@ -1,196 +1,190 @@ package org.violetmoon.zeta.config; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Consumer; - import org.jetbrains.annotations.Nullable; import org.violetmoon.zeta.Zeta; import org.violetmoon.zeta.event.play.loading.ZGatherAdditionalFlags; import org.violetmoon.zeta.module.ZetaCategory; import org.violetmoon.zeta.module.ZetaModule; import org.violetmoon.zeta.module.ZetaModuleManager; -import org.violetmoon.zetaimplforge.event.play.loading.ForgeZGatherAdditionalFlags; + +import java.util.*; +import java.util.function.Consumer; public class ConfigManager { - private final Zeta z; - private final ConfigFlagManager cfm; - private final SectionDefinition rootConfig; - - //for updating the values of @Config annotations to match the current state of the config - // and other "listening for config load" purposes - private final List> databindings = new ArrayList<>(); - private Consumer onConfigReloadJEI; - - //ummmmmmm i think my abstraction isn't very good - private final @Nullable SectionDefinition generalSection; - private final Map categoriesToSections = new HashMap<>(); - - private final Map> categoryEnabledOptions = new HashMap<>(); - private final Map> ignoreAntiOverlapOptions = new HashMap<>(); - private final Map> moduleEnabledOptions = new HashMap<>(); - - //state - private final Set enabledCategories = new HashSet<>(); - - public ConfigManager(Zeta z, Object rootPojo) { - this.z = z; - this.cfm = new ConfigFlagManager(z); - ZetaModuleManager modules = z.modules; - - //all modules are enabled by default - enabledCategories.addAll(modules.getCategories()); - - SectionDefinition.Builder rootConfigBuilder = new SectionDefinition.Builder().name(""); - - // "general" section - if(rootPojo == null) - generalSection = null; - else { - //TODO: where to put this lol - z.loadBus.subscribe(rootPojo).subscribe(rootPojo.getClass()); - z.playBus.subscribe(rootPojo).subscribe(rootPojo.getClass()); - - generalSection = rootConfigBuilder.addSubsection(general -> ConfigObjectMapper.readInto(general.name("general"), rootPojo, databindings, cfm)); - } - - // "categories" section, holding the category enablement options - rootConfigBuilder.addSubsection(categories -> { - categories.name("categories"); - for(ZetaCategory category : modules.getInhabitedCategories()) - categoryEnabledOptions.put(category, categories.addValue(b -> b.name(category.name).defaultValue(true))); - }); - - // per-category options - for(ZetaCategory category : modules.getInhabitedCategories()) { - categoriesToSections.put(category, rootConfigBuilder.addSubsection(categorySectionBuilder -> { - categorySectionBuilder.name(category.name); - for(ZetaModule module : modules.modulesInCategory(category)) { - // module flag - cfm.putModuleFlag(module); - - // module enablement option - moduleEnabledOptions.put(module, categorySectionBuilder.addValue(moduleEnabledOptionBuilder -> moduleEnabledOptionBuilder - .name(module.displayName) - .englishDisplayName(module.displayName) - .comment(module.description) - .defaultValue(module.enabledByDefault))); - - // per-module options - categorySectionBuilder.addSubsection(moduleSectionBuilder -> { - moduleSectionBuilder - .name(module.lowercaseName) - .englishDisplayName(module.displayName) - .comment(module.description); - - // @Config options - ConfigObjectMapper.readInto(moduleSectionBuilder, module, databindings, cfm); - - // anti overlap option - if(!module.antiOverlap.isEmpty()) { - ignoreAntiOverlapOptions.put(module, moduleSectionBuilder.addValue(antiOverlapOptionBuilder -> { - antiOverlapOptionBuilder.name("Ignore Anti Overlap") - .comment("This feature disables itself if any of the following mods are loaded:") - .defaultValue(false); - - for(String modid : module.antiOverlap) - antiOverlapOptionBuilder.comment(" - " + modid); - - antiOverlapOptionBuilder.comment("This is done to prevent content overlap.") - .comment("You can turn this on to force the feature to be loaded even if the above mods are also loaded."); - })); - } - }); - } - })); - } - - //grab any extra flags - z.playBus.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 - //Its Janky ! - databindings.add(0, i -> { - categoryEnabledOptions.forEach((category, option) -> setCategoryEnabled(category, i.get(option))); - ignoreAntiOverlapOptions.forEach((module, option) -> module.ignoreAntiOverlap = !ZetaGeneralConfig.useAntiOverlap || i.get(option)); - moduleEnabledOptions.forEach((module, option) -> { - setModuleEnabled(module, i.get(option)); - cfm.putModuleFlag(module); - }); - - //update extra flags - z.playBus.fire(() -> cfm,ZGatherAdditionalFlags.class); - }); - - this.rootConfig = rootConfigBuilder.build(); - rootConfig.finish(); - } - - public SectionDefinition getRootConfig() { - return rootConfig; - } - - // mapping between internal and external representations of the config (??????) - - public @Nullable SectionDefinition getGeneralSection() { - return generalSection; - } - - public SectionDefinition getCategorySection(ZetaCategory cat) { - return categoriesToSections.get(cat); - } - - public ValueDefinition getCategoryEnabledOption(ZetaCategory cat) { - return categoryEnabledOptions.get(cat); - } - - public ValueDefinition getModuleEnabledOption(ZetaModule module) { - return moduleEnabledOptions.get(module); - } - - // support for the options added by this class - - private void setCategoryEnabled(ZetaCategory cat, boolean enabled) { - if(enabled) - enabledCategories.add(cat); - else - enabledCategories.remove(cat); - - //TODO: hacky, just forcing setEnabled to rerun since it checks category enablement - for(ZetaModule mod : z.modules.modulesInCategory(cat)) { - mod.setEnabled(z, mod.enabled); - } - } - - private void setModuleEnabled(ZetaModule module, boolean enabled) { - module.setEnabled(z, enabled); - } - - public boolean isCategoryEnabled(ZetaCategory cat) { - return enabledCategories.contains(cat); - } - - // ummm - - public ConfigFlagManager getConfigFlagManager() { - return cfm; - } - - public void onReload() { - IZetaConfigInternals internals = z.configInternals; - databindings.forEach(c -> c.accept(internals)); - - if(onConfigReloadJEI != null) - onConfigReloadJEI.accept(internals); - } - - public void setJeiReloadListener(Consumer consumer) { - this.onConfigReloadJEI = consumer; - consumer.accept(z.configInternals); //run it now as well - } + private final Zeta z; + private final ConfigFlagManager cfm; + private final SectionDefinition rootConfig; + + //for updating the values of @Config annotations to match the current state of the config + // and other "listening for config load" purposes + private final List> databindings = new ArrayList<>(); + private Consumer onConfigReloadJEI; + + //ummmmmmm i think my abstraction isn't very good + private final @Nullable SectionDefinition generalSection; + private final Map categoriesToSections = new HashMap<>(); + + private final Map> categoryEnabledOptions = new HashMap<>(); + private final Map> ignoreAntiOverlapOptions = new HashMap<>(); + private final Map> moduleEnabledOptions = new HashMap<>(); + + //state + private final Set enabledCategories = new HashSet<>(); + + public ConfigManager(Zeta z, Object rootPojo) { + this.z = z; + this.cfm = new ConfigFlagManager(z); + ZetaModuleManager modules = z.modules; + + //all modules are enabled by default + enabledCategories.addAll(modules.getCategories()); + + SectionDefinition.Builder rootConfigBuilder = new SectionDefinition.Builder().name(""); + + // "general" section + if (rootPojo == null) + generalSection = null; + else { + //TODO: where to put this lol + z.loadBus.subscribe(rootPojo).subscribe(rootPojo.getClass()); + z.playBus.subscribe(rootPojo).subscribe(rootPojo.getClass()); + + generalSection = rootConfigBuilder.addSubsection(general -> ConfigObjectMapper.readInto(general.name("general"), rootPojo, databindings, cfm)); + } + + // "categories" section, holding the category enablement options + rootConfigBuilder.addSubsection(categories -> { + categories.name("categories"); + for (ZetaCategory category : modules.getInhabitedCategories()) + categoryEnabledOptions.put(category, categories.addValue(b -> b.name(category.name).defaultValue(true))); + }); + + // per-category options + for (ZetaCategory category : modules.getInhabitedCategories()) { + categoriesToSections.put(category, rootConfigBuilder.addSubsection(categorySectionBuilder -> { + categorySectionBuilder.name(category.name); + for (ZetaModule module : modules.modulesInCategory(category)) { + // module flag + cfm.putModuleFlag(module); + + // module enablement option + moduleEnabledOptions.put(module, categorySectionBuilder.addValue(moduleEnabledOptionBuilder -> moduleEnabledOptionBuilder + .name(module.displayName) + .englishDisplayName(module.displayName) + .comment(module.description) + .defaultValue(module.enabledByDefault))); + + // per-module options + categorySectionBuilder.addSubsection(moduleSectionBuilder -> { + moduleSectionBuilder + .name(module.lowercaseName) + .englishDisplayName(module.displayName) + .comment(module.description); + + // @Config options + ConfigObjectMapper.readInto(moduleSectionBuilder, module, databindings, cfm); + + // anti overlap option + if (!module.antiOverlap.isEmpty()) { + ignoreAntiOverlapOptions.put(module, moduleSectionBuilder.addValue(antiOverlapOptionBuilder -> { + antiOverlapOptionBuilder.name("Ignore Anti Overlap") + .comment("This feature disables itself if any of the following mods are loaded:") + .defaultValue(false); + + for (String modid : module.antiOverlap) + antiOverlapOptionBuilder.comment(" - " + modid); + + antiOverlapOptionBuilder.comment("This is done to prevent content overlap.") + .comment("You can turn this on to force the feature to be loaded even if the above mods are also loaded."); + })); + } + }); + } + })); + } + + //grab any extra flags + z.playBus.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 + //Its Janky ! + databindings.add(0, i -> { + categoryEnabledOptions.forEach((category, option) -> setCategoryEnabled(category, i.get(option))); + ignoreAntiOverlapOptions.forEach((module, option) -> module.ignoreAntiOverlap = !ZetaGeneralConfig.useAntiOverlap || i.get(option)); + moduleEnabledOptions.forEach((module, option) -> { + setModuleEnabled(module, i.get(option)); + cfm.putModuleFlag(module); + }); + + //update extra flags + z.playBus.fire(() -> cfm, ZGatherAdditionalFlags.class); + }); + + this.rootConfig = rootConfigBuilder.build(); + rootConfig.finish(); + } + + public SectionDefinition getRootConfig() { + return rootConfig; + } + + // mapping between internal and external representations of the config (??????) + + public @Nullable SectionDefinition getGeneralSection() { + return generalSection; + } + + public SectionDefinition getCategorySection(ZetaCategory cat) { + return categoriesToSections.get(cat); + } + + public ValueDefinition getCategoryEnabledOption(ZetaCategory cat) { + return categoryEnabledOptions.get(cat); + } + + public ValueDefinition getModuleEnabledOption(ZetaModule module) { + return moduleEnabledOptions.get(module); + } + + // support for the options added by this class + + private void setCategoryEnabled(ZetaCategory cat, boolean enabled) { + if (enabled) + enabledCategories.add(cat); + else + enabledCategories.remove(cat); + + //TODO: hacky, just forcing setEnabled to rerun since it checks category enablement + for (ZetaModule mod : z.modules.modulesInCategory(cat)) { + mod.setEnabled(z, mod.enabled); + } + } + + private void setModuleEnabled(ZetaModule module, boolean enabled) { + module.setEnabled(z, enabled); + } + + public boolean isCategoryEnabled(ZetaCategory cat) { + return enabledCategories.contains(cat); + } + + // ummm + + public ConfigFlagManager getConfigFlagManager() { + return cfm; + } + + public void onReload() { + IZetaConfigInternals internals = z.configInternals; + databindings.forEach(c -> c.accept(internals)); + + if (onConfigReloadJEI != null) + onConfigReloadJEI.accept(internals); + } + + public void setJeiReloadListener(Consumer consumer) { + this.onConfigReloadJEI = consumer; + consumer.accept(z.configInternals); //run it now as well + } } diff --git a/src/main/java/org/violetmoon/zeta/event/bus/ForgeZetaEventBus.java b/src/main/java/org/violetmoon/zeta/event/bus/ForgeZetaEventBus.java index 7d14346..487639d 100644 --- a/src/main/java/org/violetmoon/zeta/event/bus/ForgeZetaEventBus.java +++ b/src/main/java/org/violetmoon/zeta/event/bus/ForgeZetaEventBus.java @@ -9,9 +9,9 @@ import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.violetmoon.zeta.client.event.load.ZAddBlockColorHandlers; -import org.violetmoon.zeta.event.load.ZRegister; -import org.violetmoon.zetaimplforge.event.load.ForgeZRegister; +import org.violetmoon.zeta.event.load.ZModulesReady; +import org.violetmoon.zetaimplforge.event.NotAForgeWrapper; +import org.violetmoon.zetaimplforge.event.load.ForgeZConfigChange; import java.lang.annotation.Annotation; import java.lang.invoke.MethodHandle; @@ -25,7 +25,7 @@ import java.util.function.Function; import java.util.function.Predicate; -// this is quite jank. Basically converts all zeta events to forge ones, then delegates to the forge bus directly +// this is super jank. Basically converts all zeta events to forge ones, then delegates to the forge bus directly public class ForgeZetaEventBus extends ZetaEventBus { private final Map, Function> forgeToZetaMap = new HashMap<>(); @@ -106,37 +106,47 @@ public T fire(@NotNull T event, Class firedAs) { // good thing is most of this can be removed in 1.21 since Event is an interface there so we can pass zeta events directly. Just need to make zeta event extend Event + /** + * Given an event object which is NOT a subtype of Event class, remap it to a forge event + */ private F remapEvent(@NotNull Z2 zetaEvent, Class firedAs) { Function zetaToForgeFunc = zetaToForgeMap.get(firedAs); if (zetaToForgeFunc == null) { // remap is null. no checks because micro optimization. It means it must be a forge event already return (F) zetaEvent; - //throw new RuntimeException("No wrapped forge Event found for Zeta event class. You must register its subclass using registerSubclass. " + firedAs); } return createForgeEvent(zetaEvent, zetaToForgeFunc); } // takes a method that takes a zeta event and turns into one that takes a forge event - private Consumer remapMethod(MethodHandle originalEventConsumer, Class zetaEventClass) { - Function forgeToZetaFunc = forgeToZetaMap.get(zetaEventClass); + + /** + * 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 + */ + private Consumer remapMethod(MethodHandle originalEventConsumer, Class zetaEventBaseClass) { + Function forgeToZetaFunc = forgeToZetaMap.get(zetaEventBaseClass); if (forgeToZetaFunc == null) { // no remap needed - if (forgeEventRoot.isAssignableFrom(zetaEventClass)) { + if (forgeEventRoot.isAssignableFrom(zetaEventBaseClass)) { forgeToZetaFunc = event -> (Z) event; } else - throw new RuntimeException("No forge-Event-wrapping constructor found for Zeta event class. You must register its subclass using registerSubclass. " + zetaEventClass); + throw new RuntimeException("No forge-Event-wrapping constructor found for Zeta event class. You must register its subclass using registerSubclass. " + zetaEventBaseClass); } - return createForgeConsumer(originalEventConsumer, forgeToZetaFunc, zetaEventClass); + return createForgeConsumer(originalEventConsumer, forgeToZetaFunc, zetaEventBaseClass); } + + // generic bs private F createForgeEvent(@NotNull Z event, Function function) { return function.apply((T) event); } + // generic bs + // Creates the Forge Event Consumer that will be registered with Forge Event Bus private Consumer createForgeConsumer(MethodHandle zetaEventConsumer, Function forgeToZetaFunc, - Class zetaEventClass) { + Class zetaEventBaseClass) { //hack for tick events - Phase phase = Phase.guessFromClassName(zetaEventClass); + Phase phase = Phase.guessFromClassName(zetaEventBaseClass); return event -> { try { //luckily this phase madness will go away with new neoforge @@ -152,52 +162,74 @@ private Consumer createForgeConsumer(MethodHand } // for generic events - public void registerSubClass(Class eventClass, Class zetaEventClass, Class genericClass) { - registerSubClass(eventClass, zetaEventClass); - generics.put(eventClass, genericClass); + public void registerSubClassWithGeneric(Class baseZetaEventClass, Class forgeZetaEventClass, Class genericClass) { + registerSubClass(baseZetaEventClass, forgeZetaEventClass); + generics.put(baseZetaEventClass, genericClass); } - public void registerSubClass(Class eventClass, Class zetaEventClass) { + public void registerSubClass(Class baseZetaEventClass, Class forgeZetaEventClass) { - Function wrappingConstructor = findForgeWrapper(zetaEventClass, eventClass); - registerSubClass(eventClass, zetaEventClass, wrappingConstructor); + registerSubClass(baseZetaEventClass, forgeZetaEventClass, null); } - public void registerSubClass(Class eventClass, Class zetaEventClass, - Function constructor, Class genericClass) { - registerSubClass(eventClass, zetaEventClass, constructor); - generics.put(eventClass, genericClass); + public void registerSubClassWithGeneric(Class baseZetaEventClass, Class forgeZetaEventClass, + Function constructor, Class genericClass) { + registerSubClass(baseZetaEventClass, forgeZetaEventClass, constructor); + generics.put(baseZetaEventClass, genericClass); } - public void registerSubClass(Class eventClass, Class zetaEventClass, - @Nullable Function constructor) { + public void registerSubClass(Class baseZetaEventClass, Class forgeZetaEventClass, + @Nullable Function constructor) { Object old1 = null; Object old2 = null; - if (constructor != null) { - old1 = forgeToZetaMap.put(eventClass, constructor); + boolean isNoWrapper = false; + if (constructor == null) { + // if it's an Event already just returns the no argument constructor + if (forgeEventRoot.isAssignableFrom(forgeZetaEventClass)) { + zetaToForgeEventClass.put(baseZetaEventClass, forgeZetaEventClass); + constructor = event -> (ZF) event; + isNoWrapper = true; + } + else constructor = findForgeWrapper(forgeZetaEventClass); + } + if (constructor == null) { + throw new RuntimeException("No forge-Event-wrapping constructor found for Zeta event class " + forgeZetaEventClass); + } else { + old1 = forgeToZetaMap.put(baseZetaEventClass, constructor); + } + + Function zetaToForge = null; + if (!isNoWrapper) { + zetaToForge = findWrappedForgeEvent(forgeZetaEventClass, baseZetaEventClass); } - Function zetaToForge = findWrappedForgeEvent(zetaEventClass, eventClass); + if (zetaToForge == null) { - zetaToForge = findZetaWrapper(zetaEventClass); + zetaToForge = findZetaWrapper(forgeZetaEventClass); } if (zetaToForge != null) { - old2 = zetaToForgeMap.put(eventClass, zetaToForge); + old2 = zetaToForgeMap.put(baseZetaEventClass, zetaToForge); } if (old1 != null || old2 != null) { - throw new RuntimeException("Event class " + eventClass + " already registered"); + throw new RuntimeException("Event class " + baseZetaEventClass + " already registered"); } } + // This is where the magic happens - private Function findForgeWrapper(Class zetaEventClass, Class baseZetaEventClass) { + // Explanation: + // The whole point of these methods is to automatically convert a Zeta event to a Forge event, and vice versa. + // This is done since we can only have zeta event consumer methods in our common code, however we can only register to the forge bus a consumer of the forge Event class. + // For this reason here we have some functions that, with a lot of assumptions, try to find wrappers and unwrapper functions for each Forge-Zeta classes pair - // if it's an Event already ust returns the no argument constructor - if (forgeEventRoot.isAssignableFrom(zetaEventClass)) { - zetaToForgeEventClass.put(baseZetaEventClass, zetaEventClass); - return event -> (Z2) event; - } + /** + * @param zetaEventClass i.e: ForgeZClientSetup.class + *

+ * Attempts to find a constructor of zetaEventClass which takes an Event as a parameter. This is used for simple forge Event wrappers + * in this example the one found will be new ForgeZClientSetup(FMLClientSetupEvent event) + */ + private Function findForgeWrapper(Class zetaEventClass) { // Find the constructor that takes a single parameter of type A for (Constructor constructor : zetaEventClass.getConstructors()) { @@ -212,12 +244,18 @@ private Function findForgeWrapper(Class }; } } - throw new RuntimeException("No forge-Event-wrapping constructor found for Zeta event class " + zetaEventClass); + return null; } + /** + * @param zetaEventClass i.e: ForgeZRegister.class + *

+ * Tries to find a constructor that takes a single parameter with type of Zeta event. This convention is used to create Zeta specific event. + * The wrapper pattern is used here to provide platform specific implementation. + * In this example the one returned would be new ForgeZRegister(ZRegister event) + * If no wrapper constructor is found and the provided class implements Event already returns null. Exception otherwise. + */ private Function findZetaWrapper(Class zetaEventClass) { - // if it's an Event already ust returns the no argument constructor - // Find the constructor that takes a single parameter of type A for (Constructor constructor : zetaEventClass.getConstructors()) { Class[] parameterTypes = constructor.getParameterTypes(); diff --git a/src/main/java/org/violetmoon/zeta/event/bus/ZetaEventBus.java b/src/main/java/org/violetmoon/zeta/event/bus/ZetaEventBus.java index 38c4066..e10100b 100644 --- a/src/main/java/org/violetmoon/zeta/event/bus/ZetaEventBus.java +++ b/src/main/java/org/violetmoon/zeta/event/bus/ZetaEventBus.java @@ -5,6 +5,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.violetmoon.zeta.Zeta; +import org.violetmoon.zeta.util.handler.RecipeCrawlHandler; import java.lang.annotation.Annotation; import java.lang.reflect.Method; @@ -47,7 +48,6 @@ public ZetaEventBus subscribe(@NotNull Object target) { receiver = target; owningClazz = target.getClass(); } - streamAnnotatedMethods(owningClazz, receiver == null) .forEach(m -> subscribeMethod(m, receiver, owningClazz)); return this; diff --git a/src/main/java/org/violetmoon/zeta/mod/ZetaClientProxy.java b/src/main/java/org/violetmoon/zeta/mod/ZetaClientProxy.java deleted file mode 100644 index 706b2ea..0000000 --- a/src/main/java/org/violetmoon/zeta/mod/ZetaClientProxy.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.violetmoon.zeta.mod; - -import org.violetmoon.zeta.Zeta; -import org.violetmoon.zeta.client.TopLayerTooltipHandler; -import org.violetmoon.zeta.client.ZetaClient; -import org.violetmoon.zeta.util.handler.RequiredModTooltipHandler; - -public class ZetaClientProxy extends ZetaModProxy { - - public static ZetaClient ZETA_CLIENT; - - @Override - public void registerEvents(Zeta zeta) { - super.registerEvents(zeta); - - zeta.playBus - .subscribe(TopLayerTooltipHandler.class) - .subscribe(new RequiredModTooltipHandler.Client(zeta)); - } - - @Override - public void setClientZeta(Object obj) { - ZETA_CLIENT = (ZetaClient) obj; - } - -} diff --git a/src/main/java/org/violetmoon/zeta/mod/ZetaMod.java b/src/main/java/org/violetmoon/zeta/mod/ZetaMod.java index bea5684..7bcfc15 100644 --- a/src/main/java/org/violetmoon/zeta/mod/ZetaMod.java +++ b/src/main/java/org/violetmoon/zeta/mod/ZetaMod.java @@ -2,25 +2,19 @@ import org.violetmoon.zeta.Zeta; import org.violetmoon.zeta.config.ZetaGeneralConfig; -import org.violetmoon.zeta.event.bus.LoadEvent; -import org.violetmoon.zeta.event.load.ZCommonSetup; import org.violetmoon.zeta.network.ZetaModInternalNetwork; -import org.violetmoon.zetaimplforge.config.ConfigEventDispatcher; public class ZetaMod { public static Zeta ZETA; - public static ZetaModProxy proxy; - - public static void start(Zeta zeta, ZetaModProxy proxy) { + + public static void start(Zeta zeta) { ZetaMod.ZETA = zeta; - ZetaMod.proxy = proxy; ZETA.start(); ZETA.loadModules(null, null, ZetaGeneralConfig.INSTANCE); ZetaModInternalNetwork.init(); - proxy.registerEvents(zeta); } } diff --git a/src/main/java/org/violetmoon/zeta/mod/ZetaModProxy.java b/src/main/java/org/violetmoon/zeta/mod/ZetaModProxy.java deleted file mode 100644 index 1ed6586..0000000 --- a/src/main/java/org/violetmoon/zeta/mod/ZetaModProxy.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.violetmoon.zeta.mod; - -import org.violetmoon.zeta.Zeta; -import org.violetmoon.zeta.config.SyncedFlagHandler; -import org.violetmoon.zeta.config.ZetaGeneralConfig; -import org.violetmoon.zeta.util.handler.RecipeCrawlHandler; -import org.violetmoon.zeta.util.handler.ToolInteractionHandler; -import org.violetmoon.zeta.world.EntitySpawnHandler; -import org.violetmoon.zeta.world.WorldGenHandler; - -public class ZetaModProxy { - - public void registerEvents(Zeta zeta) { - 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); - } - - // Cast up obj to ZetaClient on the client proxy - public void setClientZeta(Object obj) { - // NO-OP - } - -} diff --git a/src/main/java/org/violetmoon/zeta/util/handler/RecipeCrawlHandler.java b/src/main/java/org/violetmoon/zeta/util/handler/RecipeCrawlHandler.java index 48fe47c..860bb9c 100644 --- a/src/main/java/org/violetmoon/zeta/util/handler/RecipeCrawlHandler.java +++ b/src/main/java/org/violetmoon/zeta/util/handler/RecipeCrawlHandler.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import org.violetmoon.zeta.Zeta; +import org.violetmoon.zeta.client.event.play.ZRenderGuiOverlay; import org.violetmoon.zeta.event.bus.IZetaPlayEvent; import org.violetmoon.zeta.event.bus.LoadEvent; import org.violetmoon.zeta.event.bus.PlayEvent; @@ -128,6 +129,11 @@ else if (recipe instanceof AbstractCookingRecipe acr) } } + @PlayEvent + public static void a (ZRenderGuiOverlay.ArmorLevel.Pre aa){ + int aaa = 1; + } + @PlayEvent public static void onTick(ZServerTick.Start tick) { synchronized (mutex) { diff --git a/src/main/java/org/violetmoon/zeta/util/zetalist/ZetaList.java b/src/main/java/org/violetmoon/zeta/util/zetalist/ZetaList.java index 280b474..e424f11 100644 --- a/src/main/java/org/violetmoon/zeta/util/zetalist/ZetaList.java +++ b/src/main/java/org/violetmoon/zeta/util/zetalist/ZetaList.java @@ -5,7 +5,6 @@ import org.violetmoon.zeta.Zeta; import org.violetmoon.zeta.event.bus.IZetaLoadEvent; -import org.violetmoon.zeta.event.bus.IZetaPlayEvent; public class ZetaList { @@ -19,11 +18,11 @@ public void register(T z) { knownZetas.add(z); } - public void fireEvent(E event) { + public void fireLoadEvent(E event) { knownZetas.forEach(z -> z.asZeta().loadBus.fire(event)); } - public void fireEvent(E event, Class eventClass) { + public void fireLoadEvent(E event, Class eventClass) { knownZetas.forEach(z -> z.asZeta().loadBus.fire(event, eventClass)); } diff --git a/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java b/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java index 8e007de..0d23211 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java +++ b/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java @@ -31,6 +31,7 @@ import org.violetmoon.zeta.client.ZetaClient; import org.violetmoon.zeta.client.event.load.*; import org.violetmoon.zeta.client.event.play.*; +import org.violetmoon.zeta.config.ConfigManager; import org.violetmoon.zeta.config.IZetaConfigInternals; import org.violetmoon.zeta.config.SectionDefinition; import org.violetmoon.zeta.event.bus.*; @@ -48,6 +49,7 @@ import org.violetmoon.zetaimplforge.api.ForgeZGatherAdvancementModifiers; import org.violetmoon.zetaimplforge.block.IForgeBlockBlockExtensions; import org.violetmoon.zetaimplforge.capability.ForgeCapabilityManager; +import org.violetmoon.zetaimplforge.client.ForgeZetaClient; import org.violetmoon.zetaimplforge.client.event.load.*; import org.violetmoon.zetaimplforge.client.event.play.*; import org.violetmoon.zetaimplforge.config.ConfigEventDispatcher; @@ -81,8 +83,6 @@ protected ZetaEventBus createLoadBus() { if (false) return new FabricZetaEventBus<>(LoadEvent.class, IZetaLoadEvent.class, log); - // thanks forge and your dumb Event + IModEvent classes and hacky runtime generic stuff. I cant get this to work - var bus = new ForgeZetaEventBus<>(LoadEvent.class, IZetaLoadEvent.class, log, FMLJavaModLoadingContext.get().getModEventBus(), Event.class); @@ -183,7 +183,6 @@ protected ZetaEventBus createLoadBus() { bus.registerSubClass(ZInput.Key.class, ForgeZInput.Key.class); bus.registerSubClass(ZInputUpdate.class, ForgeZInputUpdate.class); bus.registerSubClass(ZRenderContainerScreen.class, ForgeZRenderContainerScreen.class); - //bus.registerSubClass(ZRenderGuiOverlay.class, ForgeZRenderGuiOverlay.class); bus.registerSubClass(ZRenderLiving.class, ForgeZRenderLiving.class); bus.registerSubClass(ZRenderPlayer.class, ForgeZRenderPlayer.class); bus.registerSubClass(ZRenderTick.class, ForgeZRenderTick.class); @@ -195,20 +194,22 @@ protected ZetaEventBus createLoadBus() { bus.registerSubClass(ZScreen.MouseScrolled.class, ForgeZScreen.MouseScrolled.class); bus.registerSubClass(ZScreen.MouseButtonPressed.class, ForgeZScreen.MouseButtonPressed.class); bus.registerSubClass(ZScreen.Render.class, ForgeZScreen.Render.class); + bus.registerSubClass(ZRenderGuiOverlay.ArmorLevel.Pre.class, ForgeZRenderGuiOverlay.ArmorLevel.Pre.class); + bus.registerSubClass(ZRenderGuiOverlay.ArmorLevel.Post.class, ForgeZRenderGuiOverlay.ArmorLevel.Post.class); //this is ugly. generic events here Zeta zeta = this; - bus.registerSubClass(ZAttachCapabilities.BlockEntityCaps.class, + bus.registerSubClassWithGeneric(ZAttachCapabilities.BlockEntityCaps.class, ForgeZAttachCapabilities.BlockEntityCaps.class, (Function, ForgeZAttachCapabilities.BlockEntityCaps>) inner -> new ForgeZAttachCapabilities.BlockEntityCaps(zeta.capabilityManager, inner), BlockEntity.class); - bus.registerSubClass(ZAttachCapabilities.ItemStackCaps.class, + bus.registerSubClassWithGeneric(ZAttachCapabilities.ItemStackCaps.class, ForgeZAttachCapabilities.ItemStackCaps.class, (Function, ForgeZAttachCapabilities.ItemStackCaps>) inner -> new ForgeZAttachCapabilities.ItemStackCaps(zeta.capabilityManager, inner), ItemStack.class); - bus.registerSubClass(ZAttachCapabilities.LevelCaps.class, + bus.registerSubClassWithGeneric(ZAttachCapabilities.LevelCaps.class, ForgeZAttachCapabilities.LevelCaps.class, (Function, ForgeZAttachCapabilities.LevelCaps>) inner -> new ForgeZAttachCapabilities.LevelCaps(zeta.capabilityManager, inner), @@ -311,8 +312,6 @@ public void start() { modbus.addListener(ConfigEventDispatcher::configChanged); modbus.addListener(EventPriority.HIGHEST, this::registerHighest); - //why is this load? - //MinecraftForge.EVENT_BUS.addListener(this::addReloadListener); } private boolean registerDone = false; diff --git a/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java b/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java index 9f0deef..444206e 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java +++ b/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java @@ -136,70 +136,5 @@ public RegistryAccess hackilyGetCurrentClientLevelRegistryAccess() { return conn == null ? null : conn.registryAccess(); } - @Override - public void start() { - IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); - - MinecraftForge.EVENT_BUS.addListener(this::clientTick); - - - MinecraftForge.EVENT_BUS.addListener(this::renderGameOverlayNeitherPreNorPost); - MinecraftForge.EVENT_BUS.addListener(this::renderGuiOverlayPre); - MinecraftForge.EVENT_BUS.addListener(this::renderGuiOverlayPost); - } - - boolean clientTicked = false; - public void clientTick(TickEvent.ClientTickEvent e) { - if(!clientTicked) { - loadBus.fire(new ZFirstClientTick()); - clientTicked = true; - } - - playBus.fire(new ForgeZClientTick(e), ZClientTick.class); - } - - - //TODO: This probably should have been a PRE/POST event (just copying quark here) - public void renderGameOverlayNeitherPreNorPost(RenderGuiOverlayEvent e) { - if(e.getOverlay() == VanillaGuiOverlay.CROSSHAIR.type()) - playBus.fire(new ForgeZRenderGuiOverlay.Crosshair(e), ZRenderGuiOverlay.Crosshair.class); - else if(e.getOverlay() == VanillaGuiOverlay.HOTBAR.type()) - playBus.fire(new ForgeZRenderGuiOverlay.Hotbar(e), ZRenderGuiOverlay.Hotbar.class); - } - - public void renderGuiOverlayPre(RenderGuiOverlayEvent.Pre e) { - if (e.getOverlay() == VanillaGuiOverlay.HOTBAR.type()) - playBus.fire(new ForgeZRenderGuiOverlay.Hotbar.Pre(e), ZRenderGuiOverlay.Hotbar.Pre.class); - else if (e.getOverlay() == VanillaGuiOverlay.CROSSHAIR.type()) - playBus.fire(new ForgeZRenderGuiOverlay.Crosshair.Pre(e), ZRenderGuiOverlay.Crosshair.Pre.class); - else if (e.getOverlay() == VanillaGuiOverlay.PLAYER_HEALTH.type()) - playBus.fire(new ForgeZRenderGuiOverlay.PlayerHealth.Pre(e), ZRenderGuiOverlay.PlayerHealth.Pre.class); - else if (e.getOverlay() == VanillaGuiOverlay.ARMOR_LEVEL.type()) - playBus.fire(new ForgeZRenderGuiOverlay.ArmorLevel.Pre(e), ZRenderGuiOverlay.ArmorLevel.Pre.class); - else if (e.getOverlay() == VanillaGuiOverlay.DEBUG_TEXT.type()) - playBus.fire(new ForgeZRenderGuiOverlay.DebugText.Pre(e), ZRenderGuiOverlay.DebugText.Pre.class); - else if (e.getOverlay() == VanillaGuiOverlay.POTION_ICONS.type()) - playBus.fire(new ForgeZRenderGuiOverlay.PotionIcons.Pre(e), ZRenderGuiOverlay.PotionIcons.Pre.class); - else if (e.getOverlay() == VanillaGuiOverlay.CHAT_PANEL.type()) - playBus.fire(new ForgeZRenderGuiOverlay.ChatPanel.Pre(e), ZRenderGuiOverlay.ChatPanel.Pre.class); - } - - public void renderGuiOverlayPost(RenderGuiOverlayEvent.Post e) { - NamedGuiOverlay overlay = e.getOverlay(); - if (overlay == VanillaGuiOverlay.HOTBAR.type()) - playBus.fire(new ForgeZRenderGuiOverlay.Hotbar.Post(e), ZRenderGuiOverlay.Hotbar.Post.class); - else if (overlay == VanillaGuiOverlay.CROSSHAIR.type()) - playBus.fire(new ForgeZRenderGuiOverlay.Crosshair.Post(e), ZRenderGuiOverlay.Crosshair.Post.class); - else if (overlay == VanillaGuiOverlay.PLAYER_HEALTH.type()) - playBus.fire(new ForgeZRenderGuiOverlay.PlayerHealth.Post(e), ZRenderGuiOverlay.PlayerHealth.Post.class); - else if (overlay == VanillaGuiOverlay.ARMOR_LEVEL.type()) - playBus.fire(new ForgeZRenderGuiOverlay.ArmorLevel.Post(e), ZRenderGuiOverlay.ArmorLevel.Post.class); - else if (overlay == VanillaGuiOverlay.DEBUG_TEXT.type()) - playBus.fire(new ForgeZRenderGuiOverlay.DebugText.Post(e), ZRenderGuiOverlay.DebugText.Post.class); - else if (overlay == VanillaGuiOverlay.POTION_ICONS.type()) - playBus.fire(new ForgeZRenderGuiOverlay.PotionIcons.Post(e), ZRenderGuiOverlay.PotionIcons.Post.class); - else if (overlay == VanillaGuiOverlay.CHAT_PANEL.type()) - playBus.fire(new ForgeZRenderGuiOverlay.ChatPanel.Post(e), ZRenderGuiOverlay.ChatPanel.Post.class); - } } diff --git a/src/main/java/org/violetmoon/zetaimplforge/client/event/play/ForgeZRenderGuiOverlay.java b/src/main/java/org/violetmoon/zetaimplforge/client/event/play/ForgeZRenderGuiOverlay.java index 3a589a4..2679201 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/client/event/play/ForgeZRenderGuiOverlay.java +++ b/src/main/java/org/violetmoon/zetaimplforge/client/event/play/ForgeZRenderGuiOverlay.java @@ -1,5 +1,6 @@ package org.violetmoon.zetaimplforge.client.event.play; +import net.minecraftforge.eventbus.api.Event; import org.violetmoon.zeta.client.event.play.ZRenderGuiOverlay; import com.mojang.blaze3d.platform.Window; @@ -9,7 +10,7 @@ import net.minecraftforge.client.event.RenderGuiOverlayEvent; import net.minecraftforge.client.gui.overlay.ForgeGui; -public class ForgeZRenderGuiOverlay implements ZRenderGuiOverlay { +public class ForgeZRenderGuiOverlay extends Event implements ZRenderGuiOverlay { private final RenderGuiOverlayEvent e; public ForgeZRenderGuiOverlay(RenderGuiOverlayEvent e) { diff --git a/src/main/java/org/violetmoon/zetaimplforge/event/NotAForgeWrapper.java b/src/main/java/org/violetmoon/zetaimplforge/event/NotAForgeWrapper.java new file mode 100644 index 0000000..249ca03 --- /dev/null +++ b/src/main/java/org/violetmoon/zetaimplforge/event/NotAForgeWrapper.java @@ -0,0 +1,9 @@ +package org.violetmoon.zetaimplforge.event; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +// Hideous marker interface used to denote Zeta specific events that are NOT supposed to be remapped to forge events +@Retention(RetentionPolicy.RUNTIME) +public @interface NotAForgeWrapper { +} diff --git a/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModClientProxy.java b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModClientProxy.java new file mode 100644 index 0000000..77399d5 --- /dev/null +++ b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModClientProxy.java @@ -0,0 +1,80 @@ +package org.violetmoon.zetaimplforge.mod; + +import net.minecraftforge.client.event.RenderGuiOverlayEvent; +import net.minecraftforge.client.gui.overlay.NamedGuiOverlay; +import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.TickEvent; +import org.violetmoon.zeta.Zeta; +import org.violetmoon.zeta.client.TopLayerTooltipHandler; +import org.violetmoon.zeta.client.event.play.ZFirstClientTick; +import org.violetmoon.zeta.client.event.play.ZRenderGuiOverlay; +import org.violetmoon.zeta.util.handler.RequiredModTooltipHandler; +import org.violetmoon.zeta.util.zetalist.ZetaList; +import org.violetmoon.zetaimplforge.client.ForgeZetaClient; +import org.violetmoon.zetaimplforge.client.event.play.ForgeZRenderGuiOverlay; + +public class ZetaModClientProxy extends ZetaModCommonProxy { + + private final ForgeZetaClient clientZeta; + + public ZetaModClientProxy(Zeta zeta) { + super(zeta); + this.clientZeta = new ForgeZetaClient(zeta); + + zeta.playBus + .subscribe(TopLayerTooltipHandler.class) + .subscribe(new RequiredModTooltipHandler.Client(zeta)); + + MinecraftForge.EVENT_BUS.addListener(this::clientTick); + + MinecraftForge.EVENT_BUS.addListener(this::renderGuiOverlayPre); + MinecraftForge.EVENT_BUS.addListener(this::renderGuiOverlayPost); + } + + // added once per zeta. Its fine as we then fire it on zeta load bos which is one per zeta too. + boolean clientTicked = false; + public void clientTick(TickEvent.ClientTickEvent e) { + if(!clientTicked) { + ZetaList.INSTANCE.fireLoadEvent(new ZFirstClientTick()); + clientTicked = true; + } + } + + public void renderGuiOverlayPre(RenderGuiOverlayEvent.Pre e) { + NamedGuiOverlay overlay = e.getOverlay(); + if (overlay == VanillaGuiOverlay.HOTBAR.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.Hotbar.Pre(e), ZRenderGuiOverlay.Hotbar.Pre.class); + else if (overlay == VanillaGuiOverlay.CROSSHAIR.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.Crosshair.Pre(e), ZRenderGuiOverlay.Crosshair.Pre.class); + else if (overlay == VanillaGuiOverlay.PLAYER_HEALTH.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.PlayerHealth.Pre(e), ZRenderGuiOverlay.PlayerHealth.Pre.class); + else if (overlay == VanillaGuiOverlay.ARMOR_LEVEL.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.ArmorLevel.Pre(e), ZRenderGuiOverlay.ArmorLevel.Pre.class); + else if (overlay == VanillaGuiOverlay.DEBUG_TEXT.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.DebugText.Pre(e), ZRenderGuiOverlay.DebugText.Pre.class); + else if (overlay == VanillaGuiOverlay.POTION_ICONS.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.PotionIcons.Pre(e), ZRenderGuiOverlay.PotionIcons.Pre.class); + else if (overlay == VanillaGuiOverlay.CHAT_PANEL.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.ChatPanel.Pre(e), ZRenderGuiOverlay.ChatPanel.Pre.class); + } + + public void renderGuiOverlayPost(RenderGuiOverlayEvent.Post e) { + NamedGuiOverlay overlay = e.getOverlay(); + if (overlay == VanillaGuiOverlay.HOTBAR.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.Hotbar.Post(e), ZRenderGuiOverlay.Hotbar.Post.class); + else if (overlay == VanillaGuiOverlay.CROSSHAIR.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.Crosshair.Post(e), ZRenderGuiOverlay.Crosshair.Post.class); + else if (overlay == VanillaGuiOverlay.PLAYER_HEALTH.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.PlayerHealth.Post(e), ZRenderGuiOverlay.PlayerHealth.Post.class); + else if (overlay == VanillaGuiOverlay.ARMOR_LEVEL.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.ArmorLevel.Post(e), ZRenderGuiOverlay.ArmorLevel.Post.class); + else if (overlay == VanillaGuiOverlay.DEBUG_TEXT.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.DebugText.Post(e), ZRenderGuiOverlay.DebugText.Post.class); + else if (overlay == VanillaGuiOverlay.POTION_ICONS.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.PotionIcons.Post(e), ZRenderGuiOverlay.PotionIcons.Post.class); + else if (overlay == VanillaGuiOverlay.CHAT_PANEL.type()) + clientZeta.playBus.fire(new ForgeZRenderGuiOverlay.ChatPanel.Post(e), ZRenderGuiOverlay.ChatPanel.Post.class); + } + +} diff --git a/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaForgeMod.java b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModCommonProxy.java similarity index 51% rename from src/main/java/org/violetmoon/zetaimplforge/mod/ZetaForgeMod.java rename to src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModCommonProxy.java index 38bd970..297b02c 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaForgeMod.java +++ b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModCommonProxy.java @@ -1,42 +1,42 @@ package org.violetmoon.zetaimplforge.mod; -import org.apache.logging.log4j.LogManager; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.violetmoon.zeta.Zeta; -import org.violetmoon.zeta.mod.ZetaClientProxy; -import org.violetmoon.zeta.mod.ZetaMod; -import org.violetmoon.zeta.mod.ZetaModProxy; +import org.violetmoon.zeta.config.SyncedFlagHandler; +import org.violetmoon.zeta.config.ZetaGeneralConfig; +import org.violetmoon.zeta.util.handler.RecipeCrawlHandler; import org.violetmoon.zeta.util.handler.ToolInteractionHandler; -import org.violetmoon.zetaimplforge.ForgeZeta; -import org.violetmoon.zetaimplforge.client.ForgeZetaClient; +import org.violetmoon.zeta.world.EntitySpawnHandler; +import org.violetmoon.zeta.world.WorldGenHandler; import org.violetmoon.zetaimplforge.config.ConfigEventDispatcher; import org.violetmoon.zetaimplforge.world.ZetaBiomeModifier; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.eventbus.api.IEventBus; -import net.minecraftforge.fml.DistExecutor; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +public class ZetaModCommonProxy { -@Mod("zeta") -public class ZetaForgeMod { - - public ZetaForgeMod() { - ForgeZeta zeta = new ForgeZeta(Zeta.ZETA_ID, LogManager.getLogger(Zeta.ZETA_ID + "-internal")); - - ZetaModProxy proxy = DistExecutor.runForDist(() -> ZetaClientProxy::new, () -> ZetaModProxy::new); - Object zetaClient = DistExecutor.runForDist(() -> () -> new ForgeZetaClient(zeta), () -> () -> new Object()); - - ZetaMod.start(zeta, proxy); - ZetaMod.proxy.setClientZeta(zetaClient); - - MinecraftForge.EVENT_BUS.register(ToolInteractionHandler.class); - ZetaBiomeModifier.registerBiomeModifier(FMLJavaModLoadingContext.get().getModEventBus()); - + public ZetaModCommonProxy(Zeta zeta) { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); bus.addListener(this::setup); + + 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 setup(FMLCommonSetupEvent event) { event.enqueueWork(ConfigEventDispatcher::dispatchAllInitialLoads); } diff --git a/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModForge.java b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModForge.java new file mode 100644 index 0000000..bda1cd2 --- /dev/null +++ b/src/main/java/org/violetmoon/zetaimplforge/mod/ZetaModForge.java @@ -0,0 +1,24 @@ +package org.violetmoon.zetaimplforge.mod; + +import org.apache.logging.log4j.LogManager; +import org.violetmoon.zeta.Zeta; +import org.violetmoon.zeta.mod.ZetaMod; +import org.violetmoon.zetaimplforge.ForgeZeta; + +import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.common.Mod; + +@Mod("zeta") +public class ZetaModForge { + + public ZetaModForge() { + ForgeZeta zeta = new ForgeZeta(Zeta.ZETA_ID, LogManager.getLogger(Zeta.ZETA_ID + "-internal")); + + // creates 2 dist specific objects that will handle zeta specific & loader specific events needed for zeta to work + DistExecutor.runForDist(() -> () -> new ZetaModClientProxy(zeta), () -> () -> new ZetaModCommonProxy(zeta)); + + ZetaMod.start(zeta); + } + + +}