diff --git a/src/main/java/org/violetmoon/zeta/Zeta.java b/src/main/java/org/violetmoon/zeta/Zeta.java index 6c10ff5..525afde 100644 --- a/src/main/java/org/violetmoon/zeta/Zeta.java +++ b/src/main/java/org/violetmoon/zeta/Zeta.java @@ -213,10 +213,7 @@ public EntitySpawnHandler createEntitySpawnHandler() { public abstract ZetaNetworkHandler createNetworkHandler(int protocolVersion); - // event bus - public abstract T fireExternalEvent(T impl); - - // ummmmmm why is this here + // ummmmmm why is this here?? public abstract boolean fireRightClickBlock(Player player, InteractionHand hand, BlockPos pos, BlockHitResult bhr); // Let's Jump diff --git a/src/main/java/org/violetmoon/zeta/advancement/AdvancementModifierRegistry.java b/src/main/java/org/violetmoon/zeta/advancement/AdvancementModifierRegistry.java index 8c63bff..43bfa34 100644 --- a/src/main/java/org/violetmoon/zeta/advancement/AdvancementModifierRegistry.java +++ b/src/main/java/org/violetmoon/zeta/advancement/AdvancementModifierRegistry.java @@ -18,6 +18,7 @@ import org.violetmoon.zeta.api.IAdvancementModifier; import org.violetmoon.zeta.api.IAdvancementModifierDelegate; import org.violetmoon.zeta.event.bus.LoadEvent; +import org.violetmoon.zeta.event.bus.PlayEvent; import org.violetmoon.zeta.event.load.ZAddReloadListener; import org.violetmoon.zeta.event.load.ZGatherAdvancementModifiers; @@ -36,7 +37,10 @@ import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; +import org.violetmoon.zetaimplforge.api.ForgeZGatherAdvancementModifiers; +import org.violetmoon.zetaimplforge.client.event.play.ForgeZEarlyRender; +//TODO: make this zeta-independent public class AdvancementModifierRegistry { protected final Zeta zeta; protected final Multimap modifiers = HashMultimap.create(); @@ -59,11 +63,11 @@ public void addModifier(IAdvancementModifier mod) { modifiers.put(r, mod); } - @LoadEvent + @PlayEvent public void addListeners(ZAddReloadListener event) { if(!gatheredAddons) { IAdvancementModifierDelegate delegateImpl = new DelegateImpl(); - zeta.loadBus.fireExternal(new ZGatherAdvancementModifiers() { + zeta.playBus.fire(new ZGatherAdvancementModifiers() { @Override public void register(IAdvancementModifier modifier) { addModifier(modifier); @@ -73,7 +77,7 @@ public void register(IAdvancementModifier modifier) { public IAdvancementModifierDelegate getDelegate() { return delegateImpl; } - }, ZGatherAdvancementModifiers.class); + }); gatheredAddons = true; } diff --git a/src/main/java/org/violetmoon/zeta/client/ClientRegistryExtension.java b/src/main/java/org/violetmoon/zeta/client/ClientRegistryExtension.java index 660f0a6..09e866f 100644 --- a/src/main/java/org/violetmoon/zeta/client/ClientRegistryExtension.java +++ b/src/main/java/org/violetmoon/zeta/client/ClientRegistryExtension.java @@ -9,6 +9,7 @@ import org.violetmoon.zeta.client.event.load.ZAddItemColorHandlers; import org.violetmoon.zeta.client.event.load.ZClientSetup; import org.violetmoon.zeta.event.bus.LoadEvent; +import org.violetmoon.zeta.event.load.ZLoadComplete; import org.violetmoon.zeta.registry.DyeablesRegistry; import org.violetmoon.zeta.registry.RenderLayerRegistry; import org.violetmoon.zeta.registry.ZetaRegistry; @@ -56,32 +57,16 @@ public void registerItemColorHandlers(ZAddItemColorHandlers event) { } } - //these are in Post events to give other listeners a chance to populate .registerNamed @LoadEvent - public void registerBlockColorsPost(ZAddBlockColorHandlers.Post event) { - registry.finalizeBlockColors((block, name) -> { - Function blockColorCreator = event.getNamedBlockColors().get(name); - if(blockColorCreator == null) - z.log.error("Unknown block color creator {} used on block {}", name, block); - else - event.register(blockColorCreator.apply(block), block); - }); + public void registerRenderLayers(ZClientSetup event) { + z.renderLayerRegistry.finalize(this::doSetRenderLayer); } - @LoadEvent - public void registerItemColorsPost(ZAddItemColorHandlers.Post event) { - registry.finalizeItemColors((item, name) -> { - Function itemColorCreator = event.getNamedItemColors().get(name); - if(itemColorCreator == null) - z.log.error("Unknown item color creator {} used on item {}", name, item); - else - event.register(itemColorCreator.apply(item), item); - }); - } + //I hope this won't run on dedicated servers @LoadEvent - public void registerRenderLayers(ZClientSetup event) { - z.renderLayerRegistry.finalize(this::doSetRenderLayer); + public void onLoadComplete(ZLoadComplete event){ + z.registry.validateColorsProviders(); } protected abstract void doSetRenderLayer(Block block, RenderLayerRegistry.Layer layer); diff --git a/src/main/java/org/violetmoon/zeta/client/event/load/ZAddBlockColorHandlers.java b/src/main/java/org/violetmoon/zeta/client/event/load/ZAddBlockColorHandlers.java index 5a7febc..1748b3d 100644 --- a/src/main/java/org/violetmoon/zeta/client/event/load/ZAddBlockColorHandlers.java +++ b/src/main/java/org/violetmoon/zeta/client/event/load/ZAddBlockColorHandlers.java @@ -13,9 +13,4 @@ public interface ZAddBlockColorHandlers extends IZetaLoadEvent { void register(BlockColor c, Block... blocks); void registerNamed(Function c, String... names); BlockColors getBlockColors(); - - Post makePostEvent(); - interface Post extends ZAddBlockColorHandlers { - Map> getNamedBlockColors(); - } } diff --git a/src/main/java/org/violetmoon/zeta/client/event/load/ZAddItemColorHandlers.java b/src/main/java/org/violetmoon/zeta/client/event/load/ZAddItemColorHandlers.java index 5e11982..d8cce85 100644 --- a/src/main/java/org/violetmoon/zeta/client/event/load/ZAddItemColorHandlers.java +++ b/src/main/java/org/violetmoon/zeta/client/event/load/ZAddItemColorHandlers.java @@ -14,9 +14,4 @@ public interface ZAddItemColorHandlers extends IZetaLoadEvent { void register(ItemColor c, ItemLike... items); void registerNamed(Function c, String... names); ItemColors getItemColors(); - - Post makePostEvent(); - interface Post extends ZAddItemColorHandlers { - Map> getNamedItemColors(); - } } diff --git a/src/main/java/org/violetmoon/zeta/config/ConfigManager.java b/src/main/java/org/violetmoon/zeta/config/ConfigManager.java index f22dbfe..0783265 100644 --- a/src/main/java/org/violetmoon/zeta/config/ConfigManager.java +++ b/src/main/java/org/violetmoon/zeta/config/ConfigManager.java @@ -110,7 +110,7 @@ public ConfigManager(Zeta z, Object rootPojo) { } //grab any extra flags - z.playBus.fire(new ForgeZGatherAdditionalFlags(cfm)); + 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 @@ -124,7 +124,7 @@ public ConfigManager(Zeta z, Object rootPojo) { }); //update extra flags - z.playBus.fire(new ForgeZGatherAdditionalFlags(cfm)); + z.playBus.fire(() -> cfm,ZGatherAdditionalFlags.class); }); this.rootConfig = rootConfigBuilder.build(); diff --git a/src/main/java/org/violetmoon/zeta/event/bus/FabricZetaEventBus.java b/src/main/java/org/violetmoon/zeta/event/bus/FabricZetaEventBus.java index 8f34886..47c4f0c 100644 --- a/src/main/java/org/violetmoon/zeta/event/bus/FabricZetaEventBus.java +++ b/src/main/java/org/violetmoon/zeta/event/bus/FabricZetaEventBus.java @@ -84,19 +84,6 @@ private String logSpamSimpleName(Class clazz) { return split[split.length - 1]; } - public T fireExternal(@NotNull T event, Class firedAs) { - event = fire(event, firedAs); - - if(event instanceof Cancellable cancellable && cancellable.isCanceled()) - return event; - else{ - throw new RuntimeException(); - //TODO: re add. this shuld be put in loader specific bus code - //return z.fireExternalEvent(event); // Interfaces with the platform-specific event bus utility - } - - } - /** * Picks out the "Foo" in "void handleFoo(Foo event)", and gets/creates the Listeners corresponding to that type. */ 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 0e87d4e..7d14346 100644 --- a/src/main/java/org/violetmoon/zeta/event/bus/ForgeZetaEventBus.java +++ b/src/main/java/org/violetmoon/zeta/event/bus/ForgeZetaEventBus.java @@ -9,6 +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 java.lang.annotation.Annotation; import java.lang.invoke.MethodHandle; @@ -27,6 +30,7 @@ public class ForgeZetaEventBus extends ZetaEventBus { private final Map, Function> forgeToZetaMap = new HashMap<>(); private final Map, Function> zetaToForgeMap = new HashMap<>(); + private final Map, Class> zetaToForgeEventClass = new HashMap<>(); private final Map, Class> generics = new HashMap<>(); private final Map convertedHandlers = new HashMap<>(); @@ -53,7 +57,7 @@ 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) && !Event.class.isAssignableFrom(zetaEventClass)) + if (!eventRoot.isAssignableFrom(zetaEventClass) && !forgeEventRoot.isAssignableFrom(zetaEventClass)) throw typeERR(method); MethodHandle handle; @@ -68,7 +72,7 @@ protected void subscribeMethod(Method method, Object receiver, Class owningCl handle = handle.bindTo(receiver); Consumer consumer = remapMethod(handle, zetaEventClass); - registerListenerToForgeWithPriorityAndGenerics(owningClazz, consumer); + registerListenerToForgeWithPriorityAndGenerics(owningClazz, consumer, zetaEventClass); //store here so we can unregister later convertedHandlers.put(new Key(method, receiver, owningClazz), consumer); } @@ -82,6 +86,7 @@ protected void unsubscribeMethod(Method m, Object receiver, Class owningClazz } } + private record Key(Method method, Object receiver, Class owningClazz) { } @@ -101,25 +106,25 @@ 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 - private F remapEvent(@NotNull T event, Class firedAs) { - - //if a forge event were to be passed here directly we don't touch it. Still this should not happen - if (forgeEventRoot.isAssignableFrom(event.getClass())) { - return (F) event; - } - + private F remapEvent(@NotNull Z2 zetaEvent, Class firedAs) { Function zetaToForgeFunc = zetaToForgeMap.get(firedAs); if (zetaToForgeFunc == null) { - throw new RuntimeException("No wrapped forge Event found for Zeta event class. You must register its subclass using registerSubclass. " + firedAs); + // 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(event, zetaToForgeFunc); + 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); if (forgeToZetaFunc == null) { - throw new RuntimeException("No forge-Event-wrapping constructor found for Zeta event class. You must register its subclass using registerSubclass. " + zetaEventClass); + // no remap needed + if (forgeEventRoot.isAssignableFrom(zetaEventClass)) { + 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); } return createForgeConsumer(originalEventConsumer, forgeToZetaFunc, zetaEventClass); } @@ -132,22 +137,18 @@ private Consumer createForgeConsumer(MethodHand Class zetaEventClass) { //hack for tick events Phase phase = Phase.guessFromClassName(zetaEventClass); - Consumer consumer = new Consumer() { - @Override - public void accept(F2 event) { - try { - //luckily this phase madness will go away with new neoforge - if (phase != Phase.NONE && event instanceof TickEvent te) { - if (phase == Phase.START && te.phase != TickEvent.Phase.START) return; - if (phase == Phase.END && te.phase != TickEvent.Phase.END) return; - } - zetaEventConsumer.invoke(forgeToZetaFunc.apply((F2) event)); - } catch (Throwable e) { - throw new RuntimeException(e); + return event -> { + try { + //luckily this phase madness will go away with new neoforge + if (phase != Phase.NONE && event instanceof TickEvent te) { + if (phase == Phase.START && te.phase != TickEvent.Phase.START) return; + if (phase == Phase.END && te.phase != TickEvent.Phase.END) return; } + zetaEventConsumer.invoke(forgeToZetaFunc.apply(event)); + } catch (Throwable e) { + throw new RuntimeException(e); } }; - return consumer; } // for generic events @@ -157,11 +158,9 @@ public void registerSubClass(Class eventClass, Cla } public void registerSubClass(Class eventClass, Class zetaEventClass) { - var old1 = forgeToZetaMap.put(eventClass, findWrappingConstructor(zetaEventClass)); - var old2 = zetaToForgeMap.put(eventClass, findWrappedEvent(zetaEventClass)); - if (old1 != null || old2 != null) { - throw new RuntimeException("Already registered subclass " + eventClass); - } + + Function wrappingConstructor = findForgeWrapper(zetaEventClass, eventClass); + registerSubClass(eventClass, zetaEventClass, wrappingConstructor); } public void registerSubClass(Class eventClass, Class zetaEventClass, @@ -171,28 +170,39 @@ public void registerSubClass(Class eventClass, Cla } public void registerSubClass(Class eventClass, Class zetaEventClass, - Function constructor) { - forgeToZetaMap.put(eventClass, constructor); - zetaToForgeMap.put(eventClass, findWrappedEvent(zetaEventClass)); + @Nullable Function constructor) { + Object old1 = null; + Object old2 = null; + if (constructor != null) { + old1 = forgeToZetaMap.put(eventClass, constructor); + } + Function zetaToForge = findWrappedForgeEvent(zetaEventClass, eventClass); + if (zetaToForge == null) { + zetaToForge = findZetaWrapper(zetaEventClass); + } + + if (zetaToForge != null) { + old2 = zetaToForgeMap.put(eventClass, zetaToForge); + } + + if (old1 != null || old2 != null) { + throw new RuntimeException("Event class " + eventClass + " already registered"); + } } - private Function findWrappingConstructor(Class zetaEventClass) { + private Function findForgeWrapper(Class zetaEventClass, Class baseZetaEventClass) { + // if it's an Event already ust returns the no argument constructor if (forgeEventRoot.isAssignableFrom(zetaEventClass)) { - return event -> { - try { - return zetaEventClass.getConstructor().newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } - }; + zetaToForgeEventClass.put(baseZetaEventClass, zetaEventClass); + return event -> (Z2) event; } // Find the constructor that takes a single parameter of type A for (Constructor constructor : zetaEventClass.getConstructors()) { Class[] parameterTypes = constructor.getParameterTypes(); - if (parameterTypes.length == 1 && Event.class.isAssignableFrom(parameterTypes[0])) { + if (parameterTypes.length == 1 && forgeEventRoot.isAssignableFrom(parameterTypes[0])) { return event -> { try { return (Z2) constructor.newInstance(event); @@ -205,22 +215,54 @@ private Function findWrappingConstructor(Cl throw new RuntimeException("No forge-Event-wrapping constructor found for Zeta event class " + zetaEventClass); } - - private Function findWrappedEvent(Class zetaEventClass) { + 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(); + if (parameterTypes.length == 1 && eventRoot.isAssignableFrom(parameterTypes[0])) { + return event -> { + try { + return (F2) constructor.newInstance(event); + } catch (Exception e) { + throw new RuntimeException("Failed to create new instance of event class " + zetaEventClass, e); + } + }; + } + } + if (forgeEventRoot.isAssignableFrom(zetaEventClass)) { - return instance -> (F) instance; + return null; } - Field eventField = findFieldInClassHierarchy(zetaEventClass, f -> Event.class.isAssignableFrom(f.getType())); + + throw new RuntimeException("No Zeta-Event-wrapping constructor found for Zeta event class " + zetaEventClass); + } + + + private Function findWrappedForgeEvent(Class zetaEventClass, Class baseZetaEventClass) { + + Field eventField = findFieldInClassHierarchy(zetaEventClass, f -> + forgeEventRoot.isAssignableFrom(f.getType())); if (eventField != null) { + //hack + eventField.setAccessible(true); + zetaToForgeEventClass.put(baseZetaEventClass, eventField.getType()); return instance -> { try { - return (F) eventField.get(instance); - } catch (IllegalAccessException illegalAccessException) { - throw new RuntimeException(illegalAccessException); + return (F2) eventField.get(instance); + } catch (Exception e) { + throw new RuntimeException(e); } }; } + + //tries to unwrap first. Then if its already a forge event we just keep it + if (forgeEventRoot.isAssignableFrom(zetaEventClass)) { + zetaToForgeEventClass.put(baseZetaEventClass, zetaEventClass); + return null; + } + throw new RuntimeException("No wrapped forge Event found for Zeta event class " + zetaEventClass); } @@ -240,13 +282,17 @@ public static Field findFieldInClassHierarchy(Class clazz, Predicate p //TODO: refactor in 1.21 using interfaces and stuff. This is just here for now as i want to keep binary compatibility - private void registerListenerToForgeWithPriorityAndGenerics(Class owningClazz, Consumer consumer) { + private void registerListenerToForgeWithPriorityAndGenerics(Class owningClazz, Consumer consumer, Class zetaEventClass) { EventPriority priority = guessPriorityFromClassName(owningClazz); Class gen = generics.get(owningClazz); + Class eventType = zetaToForgeEventClass.get(zetaEventClass); + if (eventType == null) { + throw new RuntimeException("No event type found for " + zetaEventClass); + } if (gen != null) { - forgeBus.addGenericListener(gen, priority, (Consumer) consumer); + forgeBus.addGenericListener(gen, priority, false, eventType, (Consumer) consumer); } else { - forgeBus.addListener(priority, consumer); + forgeBus.addListener(priority, false, eventType, consumer); } } diff --git a/src/main/java/org/violetmoon/zeta/event/load/ZAddReloadListener.java b/src/main/java/org/violetmoon/zeta/event/load/ZAddReloadListener.java index 6351bb9..f7100c7 100644 --- a/src/main/java/org/violetmoon/zeta/event/load/ZAddReloadListener.java +++ b/src/main/java/org/violetmoon/zeta/event/load/ZAddReloadListener.java @@ -7,7 +7,7 @@ import net.minecraft.server.packs.resources.PreparableReloadListener; import org.violetmoon.zeta.event.bus.IZetaPlayEvent; -public interface ZAddReloadListener extends IZetaLoadEvent { +public interface ZAddReloadListener extends IZetaPlayEvent { ReloadableServerResources getServerResources(); RegistryAccess getRegistryAccess(); void addListener(PreparableReloadListener listener); diff --git a/src/main/java/org/violetmoon/zeta/event/load/ZGatherAdvancementModifiers.java b/src/main/java/org/violetmoon/zeta/event/load/ZGatherAdvancementModifiers.java index af535b5..aae4537 100644 --- a/src/main/java/org/violetmoon/zeta/event/load/ZGatherAdvancementModifiers.java +++ b/src/main/java/org/violetmoon/zeta/event/load/ZGatherAdvancementModifiers.java @@ -14,8 +14,9 @@ import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.block.Block; +import org.violetmoon.zeta.event.bus.IZetaPlayEvent; -public interface ZGatherAdvancementModifiers extends IZetaLoadEvent { +public interface ZGatherAdvancementModifiers extends IZetaPlayEvent { void register(IAdvancementModifier modifier); IAdvancementModifierDelegate getDelegate(); diff --git a/src/main/java/org/violetmoon/zeta/event/load/ZTagsUpdated.java b/src/main/java/org/violetmoon/zeta/event/load/ZTagsUpdated.java index 343c685..d5cbd46 100644 --- a/src/main/java/org/violetmoon/zeta/event/load/ZTagsUpdated.java +++ b/src/main/java/org/violetmoon/zeta/event/load/ZTagsUpdated.java @@ -2,9 +2,10 @@ import net.minecraft.core.RegistryAccess; import org.violetmoon.zeta.event.bus.IZetaLoadEvent; +import org.violetmoon.zeta.event.bus.IZetaPlayEvent; //TODO: just used by RecipeCrawlHandler -public interface ZTagsUpdated extends IZetaLoadEvent { +public interface ZTagsUpdated extends IZetaPlayEvent { RegistryAccess getRegistryAccess(); diff --git a/src/main/java/org/violetmoon/zeta/registry/ZetaRegistry.java b/src/main/java/org/violetmoon/zeta/registry/ZetaRegistry.java index 9787dc6..8fc463e 100644 --- a/src/main/java/org/violetmoon/zeta/registry/ZetaRegistry.java +++ b/src/main/java/org/violetmoon/zeta/registry/ZetaRegistry.java @@ -6,10 +6,11 @@ import java.util.IdentityHashMap; import java.util.List; import java.util.Map; -import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import org.violetmoon.zeta.Zeta; import org.violetmoon.zeta.item.ZetaBlockItem; @@ -141,14 +142,45 @@ public void clearDeferCache(ResourceLocation resourceLocation) { defers.removeAll(resourceLocation); } - public void finalizeBlockColors(BiConsumer consumer) { - blocksToColorProviderName.forEach(consumer); - blocksToColorProviderName.clear(); + @ApiStatus.Internal + public void assignBlockColor(String name, Consumer regFunc) { + boolean success = false; + var iterator = blocksToColorProviderName.entrySet().iterator(); + while(iterator.hasNext()) { + var entry = iterator.next(); + if(entry.getValue().equals(name)) { + success = true; + regFunc.accept(entry.getKey()); + iterator.remove(); + } + } + if (!success) + z.log.error("Unknown block color creator {} used on block", name); } - public void finalizeItemColors(BiConsumer consumer) { - itemsToColorProviderName.forEach(consumer); - itemsToColorProviderName.clear(); + @ApiStatus.Internal + public void assignItemColor(String name, Consumer regFunc) { + boolean success = false; + var iterator = itemsToColorProviderName.entrySet().iterator(); + while(iterator.hasNext()) { + var entry = iterator.next(); + if(entry.getValue().equals(name)) { + success = true; + regFunc.accept(entry.getKey()); + iterator.remove(); + } + } + if (!success) + z.log.error("Unknown item color creator {} used on item", name); + } + + @ApiStatus.Internal + public void validateColorsProviders(){ + if(!blocksToColorProviderName.isEmpty()) + z.log.error("Block color providers {} were not assigned to any blocks", blocksToColorProviderName.values()); + if(!itemsToColorProviderName.isEmpty()) + z.log.error("Item color providers {} were not assigned to any items", itemsToColorProviderName.values()); + } /// performing registration (dynamic registry jank - for registering ConfiguredFeature etc through code) /// 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 ff0784e..48fe47c 100644 --- a/src/main/java/org/violetmoon/zeta/util/handler/RecipeCrawlHandler.java +++ b/src/main/java/org/violetmoon/zeta/util/handler/RecipeCrawlHandler.java @@ -15,6 +15,7 @@ import org.violetmoon.zeta.event.load.ZTagsUpdated; import org.violetmoon.zeta.event.play.ZRecipeCrawl; import org.violetmoon.zeta.event.play.ZServerTick; +import org.violetmoon.zeta.mod.ZetaMod; import org.violetmoon.zeta.util.zetalist.ZetaList; import com.google.common.collect.HashMultimap; @@ -34,6 +35,7 @@ import net.minecraft.world.item.crafting.RecipeManager; import net.minecraft.world.item.crafting.ShapedRecipe; import net.minecraft.world.item.crafting.ShapelessRecipe; +import org.violetmoon.zetaimplforge.event.play.ForgeZRecipeCrawl; @ApiStatus.Internal public class RecipeCrawlHandler { @@ -47,7 +49,7 @@ public class RecipeCrawlHandler { private static boolean needsCrawl = false; private static boolean mayCrawl = false; - @LoadEvent + @PlayEvent public static void addListener(ZAddReloadListener event) { event.addListener(new SimplePreparableReloadListener() { @Override @@ -63,7 +65,7 @@ protected void apply(Void what, ResourceManager mgr, ProfilerFiller prof) { }); } - @LoadEvent + @PlayEvent public static void tagsHaveUpdated(ZTagsUpdated event) { mayCrawl = true; } @@ -74,7 +76,7 @@ private static void clear() { } private static void fire(IZetaPlayEvent event) { - ZetaList.INSTANCE.fireEvent(event); + ZetaMod.ZETA.playBus.fire(event); } @SuppressWarnings("ConstantValue") @@ -96,7 +98,8 @@ private static void load(RecipeManager manager, RegistryAccess access) { if (recipe.getResultItem(access) == null) throw new IllegalStateException("Recipe getResultItem is null"); - ZRecipeCrawl.Visit event; + boolean isMisc = false; + IZetaPlayEvent event; if (recipe instanceof ShapedRecipe sr) event = new ZRecipeCrawl.Visit.Shaped(sr, access); else if (recipe instanceof ShapelessRecipe sr) @@ -105,12 +108,13 @@ else if (recipe instanceof CustomRecipe cr) event = new ZRecipeCrawl.Visit.Custom(cr, access); else if (recipe instanceof AbstractCookingRecipe acr) event = new ZRecipeCrawl.Visit.Cooking(acr, access); - else + else { event = new ZRecipeCrawl.Visit.Misc(recipe, access); - + isMisc = true; + } //misc recipes could have custom logic that we cant make many assumptions on. For example FD cutting board recipes are lossy. //for instance a hanging sign can be cut into a plank. A hanging sign is magnetic but this does not mean planks are - if(!(event instanceof ZRecipeCrawl.Visit.Misc)) { + if(!isMisc) { vanillaRecipesToLazyDigest.add(recipe); } fire(event); 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 f59ac40..280b474 100644 --- a/src/main/java/org/violetmoon/zeta/util/zetalist/ZetaList.java +++ b/src/main/java/org/violetmoon/zeta/util/zetalist/ZetaList.java @@ -19,14 +19,6 @@ public void register(T z) { knownZetas.add(z); } - public void fireEvent(E event) { - knownZetas.forEach(z -> z.asZeta().playBus.fire(event)); - } - - public void fireEvent(E event, Class eventClass) { - knownZetas.forEach(z -> z.asZeta().playBus.fire(event, eventClass)); - } - public void fireEvent(E event) { knownZetas.forEach(z -> z.asZeta().loadBus.fire(event)); } diff --git a/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java b/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java index d60911a..8e007de 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java +++ b/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java @@ -9,18 +9,15 @@ import net.minecraft.world.level.block.FlowerPotBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.phys.BlockHitResult; +import net.minecraftforge.client.event.RegisterColorHandlersEvent; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.AddReloadListenerEvent; import net.minecraftforge.event.AttachCapabilitiesEvent; -import net.minecraftforge.event.entity.EntityAttributeCreationEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.EventPriority; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.fml.ModList; -import net.minecraftforge.fml.event.IModBusEvent; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.loading.FMLEnvironment; @@ -30,6 +27,9 @@ import org.violetmoon.zeta.Zeta; import org.violetmoon.zeta.block.ext.BlockExtensionFactory; import org.violetmoon.zeta.capability.ZetaCapabilityManager; +import org.violetmoon.zeta.client.ClientRegistryExtension; +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.IZetaConfigInternals; import org.violetmoon.zeta.config.SectionDefinition; @@ -45,9 +45,10 @@ import org.violetmoon.zeta.registry.*; import org.violetmoon.zeta.util.RaytracingUtil; import org.violetmoon.zeta.util.ZetaSide; -import org.violetmoon.zetaimplforge.api.GatherAdvancementModifiersEvent; +import org.violetmoon.zetaimplforge.api.ForgeZGatherAdvancementModifiers; import org.violetmoon.zetaimplforge.block.IForgeBlockBlockExtensions; import org.violetmoon.zetaimplforge.capability.ForgeCapabilityManager; +import org.violetmoon.zetaimplforge.client.event.load.*; import org.violetmoon.zetaimplforge.client.event.play.*; import org.violetmoon.zetaimplforge.config.ConfigEventDispatcher; import org.violetmoon.zetaimplforge.config.ForgeBackedConfig; @@ -77,10 +78,11 @@ public ForgeZeta(String modid, Logger log) { @Override protected ZetaEventBus createLoadBus() { - if (true) return new FabricZetaEventBus<>(LoadEvent.class, + if (false) return new FabricZetaEventBus<>(LoadEvent.class, IZetaLoadEvent.class, log); - // thanks forge and your dumb Event + IModEvent classes and hacky runtime genericst stuff. I cant get this to work + // 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); @@ -90,10 +92,27 @@ protected ZetaEventBus createLoadBus() { bus.registerSubClass(ZModulesReady.class, ForgeZModulesReady.class); bus.registerSubClass(ZRegister.class, ForgeZRegister.class); bus.registerSubClass(ZRegister.Post.class, ForgeZRegister.Post.class); - bus.registerSubClass(ZTagsUpdated.class, ForgeZTagsUpdated.class); bus.registerSubClass(ZConfigChanged.class, ForgeZConfigChange.class); bus.registerSubClass(ZLoadComplete.class, ForgeZLoadComplete.class); + // client ones again? + bus.registerSubClass(ZAddModels.class, ForgeZAddModels.class); + bus.registerSubClass(ZAddModelLayers.class, ForgeZAddModelLayers.class); + bus.registerSubClass(ZClientSetup.class, ForgeZClientSetup.class); + bus.registerSubClass(ZKeyMapping.class, ForgeZKeyMapping.class); + bus.registerSubClass(ZModel.RegisterGeometryLoaders.class, ForgeZModel.RegisterGeometryLoaders.class); + bus.registerSubClass(ZModel.RegisterAdditional.class, ForgeZModel.RegisterAdditional.class); + bus.registerSubClass(ZModel.BakingCompleted.class, ForgeZModel.BakingCompleted.class); + bus.registerSubClass(ZModel.ModifyBakingResult.class, ForgeZModel.ModifyBakingResult.class); + bus.registerSubClass(ZRegisterLayerDefinitions.class, ForgeZRegisterLayerDefinitions.class); + bus.registerSubClass(ZTooltipComponents.class, ForgeZTooltipComponents.class); + + bus.registerSubClass(ZAddBlockColorHandlers.class, ForgeZAddBlockColorHandlers.class, + (Function) inner -> + new ForgeZAddBlockColorHandlers(inner, this.registry)); + bus.registerSubClass(ZAddItemColorHandlers.class, ForgeZAddItemColorHandlers.class, + (Function) inner -> + new ForgeZAddItemColorHandlers(inner, this.registry)); return bus; } @@ -101,6 +120,7 @@ protected ZetaEventBus createLoadBus() { protected ForgeZetaEventBus createPlayBus() { var bus = new ForgeZetaEventBus<>(PlayEvent.class, IZetaPlayEvent.class, log, MinecraftForge.EVENT_BUS, Event.class); bus.registerSubClass(ZAnvilRepair.class, ForgeZAnvilRepair.class); + bus.registerSubClass(ZTagsUpdated.class, ForgeZTagsUpdated.class); bus.registerSubClass(ZBabyEntitySpawn.class, ForgeZBabyEntitySpawn.class); bus.registerSubClass(ZBlock.Break.class, ForgeZBlock.Break.class); bus.registerSubClass(ZBlock.EntityPlace.class, ForgeZBlock.EntityPlace.class); @@ -150,6 +170,9 @@ protected ZetaEventBus createLoadBus() { bus.registerSubClass(ZGatherAdditionalFlags.class, ForgeZGatherAdditionalFlags.class); bus.registerSubClass(ZServerTick.Start.class, ForgeZServerTick.Start.class); bus.registerSubClass(ZServerTick.End.class, ForgeZServerTick.End.class); + bus.registerSubClass(ZAddReloadListener.class, ForgeZAddReloadListener.class); + bus.registerSubClass(ZGatherAdvancementModifiers.class, ForgeZGatherAdvancementModifiers.class); + //Hmm client events here? maybe i should move them bus.registerSubClass(ZClientTick.class, ForgeZClientTick.class); @@ -160,7 +183,7 @@ 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(ZRenderGuiOverlay.class, ForgeZRenderGuiOverlay.class); bus.registerSubClass(ZRenderLiving.class, ForgeZRenderLiving.class); bus.registerSubClass(ZRenderPlayer.class, ForgeZRenderPlayer.class); bus.registerSubClass(ZRenderTick.class, ForgeZRenderTick.class); @@ -278,15 +301,6 @@ public boolean fireRightClickBlock(Player player, InteractionHand hand, BlockPos return MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.RightClickBlock(player, hand, pos, bhr)); } - //TODO: - @Override - public T fireExternalEvent(T impl) { - if (impl instanceof ZGatherAdvancementModifiers advancementModifiers) - MinecraftForge.EVENT_BUS.post(new GatherAdvancementModifiersEvent(this, advancementModifiers)); - - return impl; - } - @SuppressWarnings("duplicates") @Override public void start() { @@ -297,12 +311,8 @@ public void start() { modbus.addListener(ConfigEventDispatcher::configChanged); modbus.addListener(EventPriority.HIGHEST, this::registerHighest); - modbus.addListener(this::commonSetup); - modbus.addListener(this::loadComplete); - modbus.addListener(this::entityAttributeCreation); - //why is this load? - MinecraftForge.EVENT_BUS.addListener(this::addReloadListener); + //MinecraftForge.EVENT_BUS.addListener(this::addReloadListener); } private boolean registerDone = false; @@ -319,21 +329,9 @@ public void registerHighest(RegisterEvent e) { } - public void addReloadListener(AddReloadListenerEvent e) { - loadBus.fire(new ForgeZAddReloadListener(e), ZAddReloadListener.class); - } - - public void commonSetup(FMLCommonSetupEvent e) { - loadBus.fire(new ForgeZCommonSetup(e), ZCommonSetup.class); - } - - public void loadComplete(FMLLoadCompleteEvent e) { - loadBus.fire(new ForgeZLoadComplete(e), ZLoadComplete.class); - } - - public void entityAttributeCreation(EntityAttributeCreationEvent e) { - loadBus.fire(new ForgeZEntityAttributeCreation(e), ZEntityAttributeCreation.class); - } + //public void addReloadListener(AddReloadListenerEvent e) { + // loadBus.fire(new ForgeZAddReloadListener(e), ZAddReloadListener.class); + //} public static ZResult from(Event.Result r) { return switch (r) { diff --git a/src/main/java/org/violetmoon/zetaimplforge/api/GatherAdvancementModifiersEvent.java b/src/main/java/org/violetmoon/zetaimplforge/api/ForgeZGatherAdvancementModifiers.java similarity index 54% rename from src/main/java/org/violetmoon/zetaimplforge/api/GatherAdvancementModifiersEvent.java rename to src/main/java/org/violetmoon/zetaimplforge/api/ForgeZGatherAdvancementModifiers.java index e3630bb..3c27bff 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/api/GatherAdvancementModifiersEvent.java +++ b/src/main/java/org/violetmoon/zetaimplforge/api/ForgeZGatherAdvancementModifiers.java @@ -7,31 +7,21 @@ import net.minecraftforge.eventbus.api.Event; -public class GatherAdvancementModifiersEvent extends Event implements ZGatherAdvancementModifiers { - private final Zeta zeta; - private final ZGatherAdvancementModifiers inner; +public class ForgeZGatherAdvancementModifiers extends Event implements ZGatherAdvancementModifiers { + private final ZGatherAdvancementModifiers wrapped; - public GatherAdvancementModifiersEvent(Zeta zeta, ZGatherAdvancementModifiers inner) { - this.zeta = zeta; - this.inner = inner; - } - - public Zeta getZeta() { - return zeta; - } - - public String getModid() { - return zeta.modid; + public ForgeZGatherAdvancementModifiers(ZGatherAdvancementModifiers inner) { + this.wrapped = inner; } @Override public void register(IAdvancementModifier modifier) { - inner.register(modifier); + wrapped.register(modifier); } @Override public IAdvancementModifierDelegate getDelegate() { - return inner.getDelegate(); + return wrapped.getDelegate(); } //Note there are a ton of default methods available in ZGatherAdvancementModifiers for you to call. diff --git a/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java b/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java index d1b29b4..9f0deef 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java +++ b/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java @@ -1,5 +1,6 @@ package org.violetmoon.zetaimplforge.client; +import net.minecraftforge.client.gui.overlay.NamedGuiOverlay; import org.jetbrains.annotations.Nullable; import org.violetmoon.zeta.Zeta; import org.violetmoon.zeta.client.ClientRegistryExtension; @@ -139,116 +140,12 @@ public RegistryAccess hackilyGetCurrentClientLevelRegistryAccess() { public void start() { IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus(); - bus.addListener(this::registerBlockColors); - bus.addListener(this::registerItemColors); - bus.addListener(this::clientSetup); - bus.addListener(this::registerReloadListeners); - bus.addListener(this::modelModifyBakingResult); - bus.addListener(this::modelBakingCompleted); - bus.addListener(this::modelRegisterAdditional); - bus.addListener(this::modelRegisterGeometryLoaders); - bus.addListener(this::modelLayers); - bus.addListener(this::registerKeybinds); - bus.addListener(this::registerAdditionalModels); - bus.addListener(this::registerClientTooltipComponentFactories); - bus.addListener(this::registerLayerDefinitions); - - MinecraftForge.EVENT_BUS.addListener(this::renderTick); MinecraftForge.EVENT_BUS.addListener(this::clientTick); - MinecraftForge.EVENT_BUS.addListener(this::inputMouseButton); - MinecraftForge.EVENT_BUS.addListener(this::inputKey); - MinecraftForge.EVENT_BUS.addListener(this::screenshot); - MinecraftForge.EVENT_BUS.addListener(this::movementInputUpdate); - MinecraftForge.EVENT_BUS.addListener(this::renderBlockHighlight); - MinecraftForge.EVENT_BUS.addListener(this::gatherTooltipComponents); - MinecraftForge.EVENT_BUS.addListener(this::renderContainerScreenForeground); - MinecraftForge.EVENT_BUS.addListener(this::renderContainerScreenBackground); MinecraftForge.EVENT_BUS.addListener(this::renderGameOverlayNeitherPreNorPost); MinecraftForge.EVENT_BUS.addListener(this::renderGuiOverlayPre); MinecraftForge.EVENT_BUS.addListener(this::renderGuiOverlayPost); - MinecraftForge.EVENT_BUS.addListener(this::renderPlayerPre); - MinecraftForge.EVENT_BUS.addListener(this::renderPlayerPost); - MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGHEST, this::renderLivingPreHighest); - MinecraftForge.EVENT_BUS.addListener(EventPriority.LOWEST, this::renderLivingPostLowest); - MinecraftForge.EVENT_BUS.addListener(this::renderTooltipGatherComponents); - MinecraftForge.EVENT_BUS.addListener(this::renderTooltipGatherComponentsLow); - - MinecraftForge.EVENT_BUS.addListener(this::screenInitPre); - MinecraftForge.EVENT_BUS.addListener(this::screenInitPost); - MinecraftForge.EVENT_BUS.addListener(this::screenRenderPre); - MinecraftForge.EVENT_BUS.addListener(this::screenRenderPost); - MinecraftForge.EVENT_BUS.addListener(this::screenMouseButtonPressedPre); - MinecraftForge.EVENT_BUS.addListener(this::screenMouseButtonPressedPost); - MinecraftForge.EVENT_BUS.addListener(this::screenMouseScrolledPre); - MinecraftForge.EVENT_BUS.addListener(this::screenMouseScrolledPost); - MinecraftForge.EVENT_BUS.addListener(this::screenKeyPressedPre); - MinecraftForge.EVENT_BUS.addListener(this::screenKeyPressedPost); - MinecraftForge.EVENT_BUS.addListener(this::screenCharacterTypedPre); - MinecraftForge.EVENT_BUS.addListener(this::screenCharacterTypedPost); - MinecraftForge.EVENT_BUS.addListener(this::screenOpening); - } - - public void registerBlockColors(RegisterColorHandlersEvent.Block event) { - ZAddBlockColorHandlers e = loadBus.fire(new ForgeZAddBlockColorHandlers(event), ZAddBlockColorHandlers.class); - loadBus.fire(e.makePostEvent(), ZAddBlockColorHandlers.Post.class); - } - - public void registerItemColors(RegisterColorHandlersEvent.Item event) { - ZAddItemColorHandlers e = loadBus.fire(new ForgeZAddItemColorHandlers(event), ZAddItemColorHandlers.class); - loadBus.fire(e.makePostEvent(), ZAddItemColorHandlers.Post.class); - } - - public void clientSetup(FMLClientSetupEvent event) { - loadBus.fire(new ForgeZClientSetup(event), ZClientSetup.class); - } - - public void registerReloadListeners(RegisterClientReloadListenersEvent event) { - loadBus.fire(new ZRegisterReloadListeners(event::registerReloadListener), ZRegisterReloadListeners.class); - } - - public void modelModifyBakingResult(ModelEvent.ModifyBakingResult e) { - loadBus.fire(new ForgeZModel.ModifyBakingResult(e), ZModel.ModifyBakingResult.class); - } - - public void modelBakingCompleted(ModelEvent.BakingCompleted e) { - loadBus.fire(new ForgeZModel.BakingCompleted(e), ZModel.BakingCompleted.class); - } - - public void modelRegisterAdditional(ModelEvent.RegisterAdditional e) { - loadBus.fire(new ForgeZModel.RegisterAdditional(e), ZModel.RegisterAdditional.class); - } - - public void modelRegisterGeometryLoaders(ModelEvent.RegisterGeometryLoaders e) { - loadBus.fire(new ForgeZModel.RegisterGeometryLoaders(e), ZModel.RegisterGeometryLoaders.class); - } - - public void modelLayers(EntityRenderersEvent.AddLayers event) { - loadBus.fire(new ForgeZAddModelLayers(event), ZAddModelLayers.class); - } - - public void registerKeybinds(RegisterKeyMappingsEvent event) { - loadBus.fire(new ForgeZKeyMapping(event), ZKeyMapping.class); - } - - public void registerAdditionalModels(ModelEvent.RegisterAdditional event) { - loadBus.fire(new ForgeZAddModels(event), ZAddModels.class); - } - - public void registerClientTooltipComponentFactories(RegisterClientTooltipComponentFactoriesEvent event) { - loadBus.fire(new ForgeZTooltipComponents(event), ZTooltipComponents.class); - } - - public void registerLayerDefinitions(EntityRenderersEvent.RegisterLayerDefinitions e) { - loadBus.fire(new ForgeZRegisterLayerDefinitions(e), ZRegisterLayerDefinitions.class); - } - - //TODO: move ticker stuff out of forge event handlers, subscribe to them from zeta - // Also these events are a mess lol; sometimes there's 2 start/end events, sometimes there's - // one event with multiple Phases... bad - public void renderTick(TickEvent.RenderTickEvent e) { - playBus.fire(new ForgeZRenderTick(e), ZRenderTick.class); } boolean clientTicked = false; @@ -261,37 +158,6 @@ public void clientTick(TickEvent.ClientTickEvent e) { playBus.fire(new ForgeZClientTick(e), ZClientTick.class); } - public void inputMouseButton(InputEvent.MouseButton e) { - playBus.fire(new ForgeZInput.MouseButton(e), ZInput.MouseButton.class); - } - - public void inputKey(InputEvent.Key e) { - playBus.fire(new ForgeZInput.Key(e), ZInput.Key.class); - } - - public void screenshot(ScreenshotEvent e) { - playBus.fire(new ZScreenshot()); - } - - public void movementInputUpdate(MovementInputUpdateEvent e) { - playBus.fire(new ForgeZInputUpdate(e), ZInputUpdate.class); - } - - public void renderBlockHighlight(RenderHighlightEvent.Block e) { - playBus.fire(new ForgeZHighlightBlock(e), ZHighlightBlock.class); - } - - public void gatherTooltipComponents(RenderTooltipEvent.GatherComponents e) { - playBus.fire(new ForgeZGatherTooltipComponents(e), ZGatherTooltipComponents.class); - } - - public void renderContainerScreenForeground(ContainerScreenEvent.Render.Foreground e) { - playBus.fire(new ForgeZRenderContainerScreen.Foreground(e), ZRenderContainerScreen.Foreground.class); - } - - public void renderContainerScreenBackground(ContainerScreenEvent.Render.Background e) { - playBus.fire(new ForgeZRenderContainerScreen.Background(e), ZRenderContainerScreen.Background.class); - } //TODO: This probably should have been a PRE/POST event (just copying quark here) public void renderGameOverlayNeitherPreNorPost(RenderGuiOverlayEvent e) { @@ -319,95 +185,21 @@ else if (e.getOverlay() == VanillaGuiOverlay.CHAT_PANEL.type()) } public void renderGuiOverlayPost(RenderGuiOverlayEvent.Post e) { - if (e.getOverlay() == VanillaGuiOverlay.HOTBAR.type()) + NamedGuiOverlay overlay = e.getOverlay(); + if (overlay == VanillaGuiOverlay.HOTBAR.type()) playBus.fire(new ForgeZRenderGuiOverlay.Hotbar.Post(e), ZRenderGuiOverlay.Hotbar.Post.class); - else if (e.getOverlay() == VanillaGuiOverlay.CROSSHAIR.type()) + else if (overlay == VanillaGuiOverlay.CROSSHAIR.type()) playBus.fire(new ForgeZRenderGuiOverlay.Crosshair.Post(e), ZRenderGuiOverlay.Crosshair.Post.class); - else if (e.getOverlay() == VanillaGuiOverlay.PLAYER_HEALTH.type()) + else if (overlay == VanillaGuiOverlay.PLAYER_HEALTH.type()) playBus.fire(new ForgeZRenderGuiOverlay.PlayerHealth.Post(e), ZRenderGuiOverlay.PlayerHealth.Post.class); - else if (e.getOverlay() == VanillaGuiOverlay.ARMOR_LEVEL.type()) + else if (overlay == VanillaGuiOverlay.ARMOR_LEVEL.type()) playBus.fire(new ForgeZRenderGuiOverlay.ArmorLevel.Post(e), ZRenderGuiOverlay.ArmorLevel.Post.class); - else if (e.getOverlay() == VanillaGuiOverlay.DEBUG_TEXT.type()) + else if (overlay == VanillaGuiOverlay.DEBUG_TEXT.type()) playBus.fire(new ForgeZRenderGuiOverlay.DebugText.Post(e), ZRenderGuiOverlay.DebugText.Post.class); - else if (e.getOverlay() == VanillaGuiOverlay.POTION_ICONS.type()) + else if (overlay == VanillaGuiOverlay.POTION_ICONS.type()) playBus.fire(new ForgeZRenderGuiOverlay.PotionIcons.Post(e), ZRenderGuiOverlay.PotionIcons.Post.class); - else if (e.getOverlay() == VanillaGuiOverlay.CHAT_PANEL.type()) + else if (overlay == VanillaGuiOverlay.CHAT_PANEL.type()) playBus.fire(new ForgeZRenderGuiOverlay.ChatPanel.Post(e), ZRenderGuiOverlay.ChatPanel.Post.class); } - public void renderPlayerPre(RenderPlayerEvent.Pre e) { - playBus.fire(new ForgeZRenderPlayer.Pre(e), ZRenderPlayer.Pre.class); - } - - public void renderPlayerPost(RenderPlayerEvent.Post e) { - playBus.fire(new ForgeZRenderPlayer.Post(e), ZRenderPlayer.Post.class); - } - - public void renderLivingPreHighest(RenderLivingEvent.Pre e) { - playBus.fire(new ForgeZRenderLiving.PreHighest(e), ZRenderLiving.PreHighest.class); - } - - public void renderLivingPostLowest(RenderLivingEvent.Post e) { - playBus.fire(new ForgeZRenderLiving.PostLowest(e), ZRenderLiving.PostLowest.class); - } - - public void renderTooltipGatherComponents(RenderTooltipEvent.GatherComponents e) { - playBus.fire(new ForgeZRenderTooltip.GatherComponents(e), ZRenderTooltip.GatherComponents.class); - } - - public void renderTooltipGatherComponentsLow(RenderTooltipEvent.GatherComponents e) { - playBus.fire(new ForgeZRenderTooltip.GatherComponents.Low(e), ZRenderTooltip.GatherComponents.Low.class); - } - - public void screenInitPre(ScreenEvent.Init.Pre e) { - playBus.fire(new ForgeZScreen.Init.Pre(e), ZScreen.Init.Pre.class); - } - - public void screenInitPost(ScreenEvent.Init.Post e) { - playBus.fire(new ForgeZScreen.Init.Post(e), ZScreen.Init.Post.class); - } - - public void screenRenderPre(ScreenEvent.Render.Pre e) { - playBus.fire(new ForgeZScreen.Render.Pre(e), ZScreen.Render.Pre.class); - } - - public void screenRenderPost(ScreenEvent.Render.Post e) { - playBus.fire(new ForgeZScreen.Render.Post(e), ZScreen.Render.Post.class); - } - - public void screenMouseButtonPressedPre(ScreenEvent.MouseButtonPressed.Pre e) { - playBus.fire(new ForgeZScreen.MouseButtonPressed.Pre(e), ZScreen.MouseButtonPressed.Pre.class); - } - - public void screenMouseButtonPressedPost(ScreenEvent.MouseButtonPressed.Post e) { - playBus.fire(new ForgeZScreen.MouseButtonPressed.Post(e), ZScreen.MouseButtonPressed.Post.class); - } - - public void screenMouseScrolledPre(ScreenEvent.MouseScrolled.Pre e) { - playBus.fire(new ForgeZScreen.MouseScrolled.Pre(e), ZScreen.MouseScrolled.Pre.class); - } - - public void screenMouseScrolledPost(ScreenEvent.MouseScrolled.Post e) { - playBus.fire(new ForgeZScreen.MouseScrolled.Post(e), ZScreen.MouseScrolled.Post.class); - } - - public void screenKeyPressedPre(ScreenEvent.KeyPressed.Pre e) { - playBus.fire(new ForgeZScreen.KeyPressed.Pre(e), ZScreen.KeyPressed.Pre.class); - } - - public void screenKeyPressedPost(ScreenEvent.KeyPressed.Post e) { - playBus.fire(new ForgeZScreen.KeyPressed.Post(e), ZScreen.KeyPressed.Post.class); - } - - public void screenCharacterTypedPre(ScreenEvent.CharacterTyped.Pre e) { - playBus.fire(new ForgeZScreen.CharacterTyped.Pre(e), ZScreen.CharacterTyped.Pre.class); - } - - public void screenCharacterTypedPost(ScreenEvent.CharacterTyped.Post e) { - playBus.fire(new ForgeZScreen.CharacterTyped.Post(e), ZScreen.CharacterTyped.Post.class); - } - - public void screenOpening(ScreenEvent.Opening e) { - playBus.fire(new ForgeZScreen.Opening(e), ZScreen.Opening.class); - } } diff --git a/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZAddBlockColorHandlers.java b/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZAddBlockColorHandlers.java index 8c705d3..09c2323 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZAddBlockColorHandlers.java +++ b/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZAddBlockColorHandlers.java @@ -1,58 +1,40 @@ package org.violetmoon.zetaimplforge.client.event.load; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -import org.violetmoon.zeta.client.event.load.ZAddBlockColorHandlers; - import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.block.BlockColors; import net.minecraft.world.level.block.Block; import net.minecraftforge.client.event.RegisterColorHandlersEvent; +import org.violetmoon.zeta.client.event.load.ZAddBlockColorHandlers; +import org.violetmoon.zeta.registry.ZetaRegistry; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; public class ForgeZAddBlockColorHandlers implements ZAddBlockColorHandlers { - protected final RegisterColorHandlersEvent.Block e; - protected final Map> namedBlockColors; - - public ForgeZAddBlockColorHandlers(RegisterColorHandlersEvent.Block e) { - this(e, new HashMap<>()); - } - - protected ForgeZAddBlockColorHandlers(RegisterColorHandlersEvent.Block e, Map> namedBlockColors) { - this.e = e; - this.namedBlockColors = namedBlockColors; - } - - @Override - public void register(BlockColor blockColor, Block... blocks) { - e.register(blockColor, blocks); - } - - @Override - public void registerNamed(Function c, String... names) { - for(String name : names) - namedBlockColors.put(name, c); - } - - @Override - public BlockColors getBlockColors() { - return e.getBlockColors(); - } - - @Override - public ZAddBlockColorHandlers.Post makePostEvent() { - return new Post(e, namedBlockColors); - } - - public static class Post extends ForgeZAddBlockColorHandlers implements ZAddBlockColorHandlers.Post { - public Post(RegisterColorHandlersEvent.Block e, Map> namedBlockColors) { - super(e, namedBlockColors); - } - - @Override - public Map> getNamedBlockColors() { - return namedBlockColors; - } - } + protected final RegisterColorHandlersEvent.Block e; + private final ZetaRegistry zetaRegistry; + + public ForgeZAddBlockColorHandlers(RegisterColorHandlersEvent.Block e, ZetaRegistry zetaRegistry) { + this.e = e; + this.zetaRegistry = zetaRegistry; + } + + @Override + public void register(BlockColor blockColor, Block... blocks) { + e.register(blockColor, blocks); + } + + @Override + public void registerNamed(Function c, String... names) { + for (String name : names) { + zetaRegistry.assignBlockColor(name, b -> register(c.apply(b), b)); + } + } + + @Override + public BlockColors getBlockColors() { + return e.getBlockColors(); + } + } diff --git a/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZAddItemColorHandlers.java b/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZAddItemColorHandlers.java index de05e1c..4ea1843 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZAddItemColorHandlers.java +++ b/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZAddItemColorHandlers.java @@ -11,18 +11,16 @@ import net.minecraft.world.item.Item; import net.minecraft.world.level.ItemLike; import net.minecraftforge.client.event.RegisterColorHandlersEvent; +import org.violetmoon.zeta.registry.ZetaRegistry; public class ForgeZAddItemColorHandlers implements ZAddItemColorHandlers { protected final RegisterColorHandlersEvent.Item e; - protected final Map> namedItemColors; + protected final Map> namedItemColors = new HashMap<>(); + private final ZetaRegistry zetaRegistry; - public ForgeZAddItemColorHandlers(RegisterColorHandlersEvent.Item e) { - this(e, new HashMap<>()); - } - - public ForgeZAddItemColorHandlers(RegisterColorHandlersEvent.Item e, Map> namedItemColors) { + public ForgeZAddItemColorHandlers(RegisterColorHandlersEvent.Item e, ZetaRegistry zetaRegistry) { this.e = e; - this.namedItemColors = namedItemColors; + this.zetaRegistry = zetaRegistry; } @Override @@ -32,8 +30,9 @@ public void register(ItemColor c, ItemLike... items) { @Override public void registerNamed(Function c, String... names) { - for(String name : names) - namedItemColors.put(name, c); + for (String name : names) { + zetaRegistry.assignItemColor(name, b -> register(c.apply(b), b)); + } } @Override @@ -41,19 +40,4 @@ public ItemColors getItemColors() { return e.getItemColors(); } - @Override - public Post makePostEvent() { - return new Post(e, namedItemColors); - } - - public static class Post extends ForgeZAddItemColorHandlers implements ZAddItemColorHandlers.Post { - public Post(RegisterColorHandlersEvent.Item e, Map> namedItemColors) { - super(e, namedItemColors); - } - - @Override - public Map> getNamedItemColors() { - return namedItemColors; - } - } } diff --git a/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZModel.java b/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZModel.java index 3ad2b97..b897be6 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZModel.java +++ b/src/main/java/org/violetmoon/zetaimplforge/client/event/load/ForgeZModel.java @@ -12,6 +12,7 @@ import net.minecraftforge.client.model.geometry.IGeometryLoader; public class ForgeZModel implements ZModel { + public static class ModifyBakingResult extends ForgeZModel implements ZModel.ModifyBakingResult { private final ModelEvent.ModifyBakingResult 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 224fd4a..89ea34b 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 @@ -5,14 +5,15 @@ import org.violetmoon.zeta.event.play.loading.ZGatherAdditionalFlags; public class ForgeZGatherAdditionalFlags extends Event implements ZGatherAdditionalFlags { - private final ConfigFlagManager flagManager; - public ForgeZGatherAdditionalFlags(ConfigFlagManager flagManager) { - this.flagManager = flagManager; + private final ZGatherAdditionalFlags wrapped; + + public ForgeZGatherAdditionalFlags(ZGatherAdditionalFlags wrapped) { + this.wrapped = wrapped; } @Override public ConfigFlagManager flagManager() { - return flagManager; + return wrapped.flagManager(); } } diff --git a/src/main/java/org/violetmoon/zetaimplforge/mixin/mixins/client/GameRenderMixin.java b/src/main/java/org/violetmoon/zetaimplforge/mixin/mixins/client/GameRenderMixin.java index b582d40..59086e1 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/mixin/mixins/client/GameRenderMixin.java +++ b/src/main/java/org/violetmoon/zetaimplforge/mixin/mixins/client/GameRenderMixin.java @@ -5,6 +5,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.violetmoon.zeta.client.event.play.ZEarlyRender; +import org.violetmoon.zeta.mod.ZetaMod; import org.violetmoon.zeta.util.zetalist.ZetaClientList; import org.violetmoon.zetaimplforge.client.event.play.ForgeZEarlyRender; @@ -12,8 +13,9 @@ @Mixin(GameRenderer.class) public class GameRenderMixin { + @Inject(method = "render", at = @At(target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", value = "INVOKE", shift = At.Shift.AFTER)) private void quark$renderEvent(float v, long l, boolean b, CallbackInfo ci) { - ZetaClientList.INSTANCE.fireEvent(new ForgeZEarlyRender(), ZEarlyRender.class); + ZetaMod.ZETA.playBus.fire(new ForgeZEarlyRender(), ZEarlyRender.class); } }