Skip to content

Commit

Permalink
done?
Browse files Browse the repository at this point in the history
  • Loading branch information
MehVahdJukaar committed Jul 31, 2024
1 parent 9fad6d1 commit f69f054
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 147 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ mod_name=Zeta
mc_version=1.20.1
mapping_channel=official
mod_id=zeta
build_number=20
build_number=20-event
dir_output=../Build Output/Zeta/
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

import org.violetmoon.zeta.event.bus.IZetaLoadEvent;

public class ZFirstClientTick implements IZetaLoadEvent { }
public interface ZFirstClientTick extends IZetaLoadEvent { }
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

import org.violetmoon.zeta.event.bus.IZetaPlayEvent;

public class ZScreenshot implements IZetaPlayEvent { }
public interface ZScreenshot extends IZetaPlayEvent { }
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
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;
Expand Down Expand Up @@ -180,7 +177,7 @@ public <ZF extends Z, ZB extends Z> void registerSubClassWithGeneric(Class<ZB> b

public <ZF extends Z, ZB extends Z> void registerSubClass(Class<ZB> baseZetaEventClass, Class<ZF> forgeZetaEventClass,
@Nullable Function<? extends F, ZF> constructor) {
Object old1 = null;
Object old1;
Object old2 = null;
boolean isNoWrapper = false;
if (constructor == null) {
Expand All @@ -193,7 +190,7 @@ public <ZF extends Z, ZB extends Z> void registerSubClass(Class<ZB> baseZetaEven
else constructor = findForgeWrapper(forgeZetaEventClass);
}
if (constructor == null) {
throw new RuntimeException("No forge-Event-wrapping constructor found for Zeta event class " + forgeZetaEventClass);
throw new RuntimeException("No Forge-Event-wrapping constructor found for Zeta event class " + forgeZetaEventClass);
} else {
old1 = forgeToZetaMap.put(baseZetaEventClass, constructor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.zeta.Zeta;

/**
* A polymorphic event bus. Events can be fired under one of their supertypes, allowing a sort of API/impl split of events.
Expand All @@ -22,7 +21,7 @@
* - registering an anonymous `Consumer` (like Forge's "addListener" method)
* Supported Java reflection APIs don't expose this information. Forge can only get at it with a library internally using sun.misc.Unsafe.
*/
public class FabricZetaEventBus<E> extends ZetaEventBus<E> {
public class StandaloneZetaEventBus<E> extends ZetaEventBus<E> {

private final Map<Class<? extends E>, Listeners> listenerMap = new HashMap<>();

Expand All @@ -31,7 +30,7 @@ public class FabricZetaEventBus<E> extends ZetaEventBus<E> {
* @param eventRoot The superinterface of all events fired on this bus.
* @param logSpam
*/
public FabricZetaEventBus(Class<? extends Annotation> subscriberAnnotation, Class<E> eventRoot, @Nullable Logger logSpam) {
public StandaloneZetaEventBus(Class<? extends Annotation> subscriberAnnotation, Class<E> eventRoot, @Nullable Logger logSpam) {
super(subscriberAnnotation, eventRoot, logSpam);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ 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) {
Expand Down
23 changes: 16 additions & 7 deletions src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLEnvironment;
import net.minecraftforge.registries.RegisterEvent;
Expand All @@ -27,11 +26,8 @@
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.ConfigManager;
import org.violetmoon.zeta.config.IZetaConfigInternals;
import org.violetmoon.zeta.config.SectionDefinition;
import org.violetmoon.zeta.event.bus.*;
Expand All @@ -49,7 +45,6 @@
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;
Expand Down Expand Up @@ -80,8 +75,7 @@ public ForgeZeta(String modid, Logger log) {

@Override
protected ZetaEventBus<IZetaLoadEvent> createLoadBus() {
if (false) return new FabricZetaEventBus<>(LoadEvent.class,
IZetaLoadEvent.class, log);
//return new StandaloneZetaEventBus<>(LoadEvent.class, IZetaLoadEvent.class, log);

var bus = new ForgeZetaEventBus<>(LoadEvent.class, IZetaLoadEvent.class, log,
FMLJavaModLoadingContext.get().getModEventBus(), Event.class);
Expand All @@ -106,6 +100,7 @@ protected ZetaEventBus<IZetaLoadEvent> createLoadBus() {
bus.registerSubClass(ZModel.ModifyBakingResult.class, ForgeZModel.ModifyBakingResult.class);
bus.registerSubClass(ZRegisterLayerDefinitions.class, ForgeZRegisterLayerDefinitions.class);
bus.registerSubClass(ZTooltipComponents.class, ForgeZTooltipComponents.class);
bus.registerSubClass(ZFirstClientTick.class, ForgeZFirstClientTick.class);

bus.registerSubClass(ZAddBlockColorHandlers.class, ForgeZAddBlockColorHandlers.class,
(Function<RegisterColorHandlersEvent.Block, ForgeZAddBlockColorHandlers>) inner ->
Expand Down Expand Up @@ -196,6 +191,20 @@ protected ZetaEventBus<IZetaLoadEvent> createLoadBus() {
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);
bus.registerSubClass(ZRenderGuiOverlay.Crosshair.Pre.class, ForgeZRenderGuiOverlay.Crosshair.Post.class);
bus.registerSubClass(ZRenderGuiOverlay.Crosshair.Post.class, ForgeZRenderGuiOverlay.Crosshair.Pre.class);
bus.registerSubClass(ZRenderGuiOverlay.DebugText.Pre.class, ForgeZRenderGuiOverlay.DebugText.Pre.class);
bus.registerSubClass(ZRenderGuiOverlay.DebugText.Post.class, ForgeZRenderGuiOverlay.DebugText.Post.class);
bus.registerSubClass(ZRenderGuiOverlay.Hotbar.Pre.class, ForgeZRenderGuiOverlay.Hotbar.Pre.class);
bus.registerSubClass(ZRenderGuiOverlay.Hotbar.Post.class, ForgeZRenderGuiOverlay.Hotbar.Post.class);
bus.registerSubClass(ZRenderGuiOverlay.PlayerHealth.Pre.class, ForgeZRenderGuiOverlay.PlayerHealth.Pre.class);
bus.registerSubClass(ZRenderGuiOverlay.PlayerHealth.Post.class, ForgeZRenderGuiOverlay.PlayerHealth.Post.class);
bus.registerSubClass(ZRenderGuiOverlay.PotionIcons.Pre.class, ForgeZRenderGuiOverlay.PotionIcons.Pre.class);
bus.registerSubClass(ZRenderGuiOverlay.PotionIcons.Post.class, ForgeZRenderGuiOverlay.PotionIcons.Post.class);
bus.registerSubClass(ZRenderGuiOverlay.ChatPanel.Pre.class, ForgeZRenderGuiOverlay.ChatPanel.Pre.class);
bus.registerSubClass(ZRenderGuiOverlay.ChatPanel.Post.class, ForgeZRenderGuiOverlay.ChatPanel.Post.class);
bus.registerSubClass(ZScreenshot.class, ForgeZScreenshot.class);


//this is ugly. generic events here
Zeta zeta = this;
Expand Down
154 changes: 41 additions & 113 deletions src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,5 @@
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;
import org.violetmoon.zeta.client.HumanoidArmorModelGetter;
import org.violetmoon.zeta.client.ZetaClient;
import org.violetmoon.zeta.client.event.load.ZAddBlockColorHandlers;
import org.violetmoon.zeta.client.event.load.ZAddItemColorHandlers;
import org.violetmoon.zeta.client.event.load.ZAddModelLayers;
import org.violetmoon.zeta.client.event.load.ZAddModels;
import org.violetmoon.zeta.client.event.load.ZClientSetup;
import org.violetmoon.zeta.client.event.load.ZKeyMapping;
import org.violetmoon.zeta.client.event.load.ZModel;
import org.violetmoon.zeta.client.event.load.ZRegisterLayerDefinitions;
import org.violetmoon.zeta.client.event.load.ZRegisterReloadListeners;
import org.violetmoon.zeta.client.event.load.ZTooltipComponents;
import org.violetmoon.zeta.client.event.play.ZClientTick;
import org.violetmoon.zeta.client.event.play.ZFirstClientTick;
import org.violetmoon.zeta.client.event.play.ZGatherTooltipComponents;
import org.violetmoon.zeta.client.event.play.ZHighlightBlock;
import org.violetmoon.zeta.client.event.play.ZInput;
import org.violetmoon.zeta.client.event.play.ZInputUpdate;
import org.violetmoon.zeta.client.event.play.ZRenderContainerScreen;
import org.violetmoon.zeta.client.event.play.ZRenderGuiOverlay;
import org.violetmoon.zeta.client.event.play.ZRenderLiving;
import org.violetmoon.zeta.client.event.play.ZRenderPlayer;
import org.violetmoon.zeta.client.event.play.ZRenderTick;
import org.violetmoon.zeta.client.event.play.ZRenderTooltip;
import org.violetmoon.zeta.client.event.play.ZScreen;
import org.violetmoon.zeta.client.event.play.ZScreenshot;
import org.violetmoon.zeta.util.zetalist.ZetaClientList;
import org.violetmoon.zetaimplforge.client.event.load.ForgeZAddBlockColorHandlers;
import org.violetmoon.zetaimplforge.client.event.load.ForgeZAddItemColorHandlers;
import org.violetmoon.zetaimplforge.client.event.load.ForgeZAddModelLayers;
import org.violetmoon.zetaimplforge.client.event.load.ForgeZAddModels;
import org.violetmoon.zetaimplforge.client.event.load.ForgeZClientSetup;
import org.violetmoon.zetaimplforge.client.event.load.ForgeZKeyMapping;
import org.violetmoon.zetaimplforge.client.event.load.ForgeZModel;
import org.violetmoon.zetaimplforge.client.event.load.ForgeZRegisterLayerDefinitions;
import org.violetmoon.zetaimplforge.client.event.load.ForgeZTooltipComponents;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZClientTick;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZGatherTooltipComponents;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZHighlightBlock;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZInput;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZInputUpdate;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZRenderContainerScreen;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZRenderGuiOverlay;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZRenderLiving;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZRenderPlayer;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZRenderTick;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZRenderTooltip;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZScreen;
import org.violetmoon.zetaimplforge.mixin.mixins.client.AccessorBlockColors;
import org.violetmoon.zetaimplforge.mixin.mixins.client.AccessorItemColors;

import net.minecraft.client.Minecraft;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.block.BlockColors;
Expand All @@ -66,75 +11,58 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.client.event.ContainerScreenEvent;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.client.event.ModelEvent;
import net.minecraftforge.client.event.MovementInputUpdateEvent;
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
import net.minecraftforge.client.event.RegisterClientTooltipComponentFactoriesEvent;
import net.minecraftforge.client.event.RegisterColorHandlersEvent;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.client.event.RenderGuiOverlayEvent;
import net.minecraftforge.client.event.RenderHighlightEvent;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.client.event.RenderTooltipEvent;
import net.minecraftforge.client.event.ScreenEvent;
import net.minecraftforge.client.event.ScreenshotEvent;
import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.util.thread.EffectiveSide;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.jetbrains.annotations.Nullable;
import org.violetmoon.zeta.Zeta;
import org.violetmoon.zeta.client.ClientRegistryExtension;
import org.violetmoon.zeta.client.HumanoidArmorModelGetter;
import org.violetmoon.zeta.client.ZetaClient;
import org.violetmoon.zetaimplforge.mixin.mixins.client.AccessorBlockColors;
import org.violetmoon.zetaimplforge.mixin.mixins.client.AccessorItemColors;

public class ForgeZetaClient extends ZetaClient {
public ForgeZetaClient(Zeta z) {
super(z);
}

@Override
public @Nullable BlockColor getBlockColor(BlockColors bcs, Block block) {
return ForgeRegistries.BLOCKS.getDelegate(block)
.map(ref -> ((AccessorBlockColors) bcs).zeta$getBlockColors().get(ref))
.orElse(null);
}
public ForgeZetaClient(Zeta z) {
super(z);
}

@Override
public @Nullable ItemColor getItemColor(ItemColors ics, ItemLike itemlike) {
return ForgeRegistries.ITEMS.getDelegate(itemlike.asItem())
.map(ref -> ((AccessorItemColors) ics).zeta$getItemColors().get(ref))
.orElse(null);
}
@Override
public @Nullable BlockColor getBlockColor(BlockColors bcs, Block block) {
return ForgeRegistries.BLOCKS.getDelegate(block)
.map(ref -> ((AccessorBlockColors) bcs).zeta$getBlockColors().get(ref))
.orElse(null);
}

@Override
public ClientRegistryExtension createClientRegistryExtension() {
return new ForgeClientRegistryExtension(zeta);
}
@Override
public @Nullable ItemColor getItemColor(ItemColors ics, ItemLike itemlike) {
return ForgeRegistries.ITEMS.getDelegate(itemlike.asItem())
.map(ref -> ((AccessorItemColors) ics).zeta$getItemColors().get(ref))
.orElse(null);
}

@Override
public void setBlockEntityWithoutLevelRenderer(Item item, BlockEntityWithoutLevelRenderer bewlr) {
((IZetaForgeItemStuff) item).zeta$setBlockEntityWithoutLevelRenderer(bewlr);
}
@Override
public ClientRegistryExtension createClientRegistryExtension() {
return new ForgeClientRegistryExtension(zeta);
}

@Override
public void setHumanoidArmorModel(Item item, HumanoidArmorModelGetter modelGetter) {
((IZetaForgeItemStuff) item).zeta$setHumanoidArmorModel(modelGetter);
}
@Override
public void setBlockEntityWithoutLevelRenderer(Item item, BlockEntityWithoutLevelRenderer bewlr) {
((IZetaForgeItemStuff) item).zeta$setBlockEntityWithoutLevelRenderer(bewlr);
}

@Override
public RegistryAccess hackilyGetCurrentClientLevelRegistryAccess() {
if(EffectiveSide.get().isServer())
return ServerLifecycleHooks.getCurrentServer().registryAccess();
@Override
public void setHumanoidArmorModel(Item item, HumanoidArmorModelGetter modelGetter) {
((IZetaForgeItemStuff) item).zeta$setHumanoidArmorModel(modelGetter);
}

ClientPacketListener conn = Minecraft.getInstance().getConnection();
return conn == null ? null : conn.registryAccess();
}
@Override
public RegistryAccess hackilyGetCurrentClientLevelRegistryAccess() {
if (EffectiveSide.get().isServer())
return ServerLifecycleHooks.getCurrentServer().registryAccess();

ClientPacketListener conn = Minecraft.getInstance().getConnection();
return conn == null ? null : conn.registryAccess();
}

}

This file was deleted.

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

import net.minecraftforge.eventbus.api.Event;
import org.violetmoon.zeta.client.event.play.ZFirstClientTick;

public class ForgeZFirstClientTick extends Event implements ZFirstClientTick {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.violetmoon.zetaimplforge.event.play;

import net.minecraftforge.eventbus.api.Event;
import org.violetmoon.zeta.client.event.play.ZScreenshot;

public class ForgeZScreenshot extends Event implements ZScreenshot {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
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.handler.ToolInteractionHandler;
import org.violetmoon.zeta.util.zetalist.ZetaList;
import org.violetmoon.zetaimplforge.client.ForgeZetaClient;
import org.violetmoon.zetaimplforge.client.event.play.ForgeZRenderGuiOverlay;
import org.violetmoon.zetaimplforge.event.load.ForgeZFirstClientTick;
import org.violetmoon.zetaimplforge.world.ZetaBiomeModifier;

public class ZetaModClientProxy extends ZetaModCommonProxy {

Expand All @@ -36,7 +40,7 @@ public ZetaModClientProxy(Zeta zeta) {
boolean clientTicked = false;
public void clientTick(TickEvent.ClientTickEvent e) {
if(!clientTicked) {
ZetaList.INSTANCE.fireLoadEvent(new ZFirstClientTick());
ZetaList.INSTANCE.fireLoadEvent(new ForgeZFirstClientTick());
clientTicked = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class ZetaModForge {

public ZetaModForge() {
ForgeZeta zeta = new ForgeZeta(Zeta.ZETA_ID, LogManager.getLogger(Zeta.ZETA_ID + "-internal"));
ZetaMod.start(zeta);

// 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);
}


Expand Down

0 comments on commit f69f054

Please sign in to comment.