From a932d84d2b45315dfcb690b97e411f6b869fc690 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Wed, 8 Nov 2023 16:36:00 -0500 Subject: [PATCH] subscribe event is kil --- .../module/MatrixEnchantingModule.java | 1 - .../base/handler/RecipeCrawlHandler.java | 14 ++--- .../base/handler/ToolInteractionHandler.java | 33 +++++------ .../building/module/VariantChestsModule.java | 5 +- .../experimental/module/GameNerfsModule.java | 1 - .../tools/module/AncientTomesModule.java | 1 - .../tools/module/ColorRunesModule.java | 1 - .../tools/module/ParrotEggsModule.java | 1 - .../violetmoon/zeta/event/play/ZBlock.java | 7 +++ .../zeta/event/play/ZServerTick.java | 11 ++++ .../violetmoon/zetaimplforge/ForgeZeta.java | 12 ++++ .../zetaimplforge/client/ForgeZetaClient.java | 58 ++----------------- .../zetaimplforge/event/play/ForgeZBlock.java | 21 +++++++ .../event/play/ForgeZServerTick.java | 30 ++++++++++ 14 files changed, 105 insertions(+), 91 deletions(-) create mode 100644 src/main/java/org/violetmoon/zeta/event/play/ZServerTick.java create mode 100644 src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZServerTick.java diff --git a/src/main/java/org/violetmoon/quark/addons/oddities/module/MatrixEnchantingModule.java b/src/main/java/org/violetmoon/quark/addons/oddities/module/MatrixEnchantingModule.java index 86c69482d2..2bc8f63f01 100644 --- a/src/main/java/org/violetmoon/quark/addons/oddities/module/MatrixEnchantingModule.java +++ b/src/main/java/org/violetmoon/quark/addons/oddities/module/MatrixEnchantingModule.java @@ -38,7 +38,6 @@ import org.violetmoon.quark.base.handler.advancement.QuarkAdvancementHandler; import org.violetmoon.quark.base.handler.advancement.QuarkGenericTrigger; import org.violetmoon.zeta.client.event.load.ZClientSetup; -import org.violetmoon.zeta.event.*; import org.violetmoon.zeta.event.bus.LoadEvent; import org.violetmoon.zeta.event.bus.PlayEvent; import org.violetmoon.zeta.event.load.ZConfigChanged; diff --git a/src/main/java/org/violetmoon/quark/base/handler/RecipeCrawlHandler.java b/src/main/java/org/violetmoon/quark/base/handler/RecipeCrawlHandler.java index 3b99b4c4ac..e172021511 100644 --- a/src/main/java/org/violetmoon/quark/base/handler/RecipeCrawlHandler.java +++ b/src/main/java/org/violetmoon/quark/base/handler/RecipeCrawlHandler.java @@ -7,21 +7,17 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.*; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.AddReloadListenerEvent; -import net.minecraftforge.event.TagsUpdatedEvent; -import net.minecraftforge.event.TickEvent.ServerTickEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; - -import javax.annotation.Nullable; - import org.violetmoon.quark.api.event.RecipeCrawlEvent; import org.violetmoon.quark.api.event.RecipeCrawlEvent.Visit; import org.violetmoon.quark.base.Quark; 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.ZTagsUpdated; +import org.violetmoon.zeta.event.play.ZServerTick; import org.violetmoon.zeta.util.RegistryUtil; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -102,8 +98,8 @@ else if (recipe instanceof AbstractCookingRecipe acr) } } - @SubscribeEvent - public static void onTick(ServerTickEvent tick) { + @PlayEvent + public static void onTick(ZServerTick tick) { synchronized(mutex) { if(mayCrawl && needsCrawl) { RecipeManager manager = tick.getServer().getRecipeManager(); diff --git a/src/main/java/org/violetmoon/quark/base/handler/ToolInteractionHandler.java b/src/main/java/org/violetmoon/quark/base/handler/ToolInteractionHandler.java index 0975920a5f..b3472f8986 100644 --- a/src/main/java/org/violetmoon/quark/base/handler/ToolInteractionHandler.java +++ b/src/main/java/org/violetmoon/quark/base/handler/ToolInteractionHandler.java @@ -1,24 +1,8 @@ package org.violetmoon.quark.base.handler; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang3.tuple.Pair; -import org.violetmoon.quark.base.handler.advancement.QuarkAdvancementHandler; -import org.violetmoon.quark.base.handler.advancement.mod.WaxModifier; -import org.violetmoon.zeta.event.bus.LoadEvent; -import org.violetmoon.zeta.event.bus.PlayEvent; -import org.violetmoon.zeta.event.load.ZCommonSetup; -import org.violetmoon.zeta.event.play.entity.player.ZRightClickBlock; -import org.violetmoon.zeta.module.ZetaModule; - import com.google.common.collect.HashBiMap; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; - import net.minecraft.advancements.CriteriaTriggers; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerPlayer; @@ -32,8 +16,17 @@ import net.minecraft.world.level.block.state.properties.Property; import net.minecraftforge.common.ToolAction; import net.minecraftforge.common.ToolActions; -import net.minecraftforge.event.level.BlockEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; +import org.apache.commons.lang3.tuple.Pair; +import org.violetmoon.quark.base.handler.advancement.QuarkAdvancementHandler; +import org.violetmoon.quark.base.handler.advancement.mod.WaxModifier; +import org.violetmoon.zeta.event.bus.LoadEvent; +import org.violetmoon.zeta.event.bus.PlayEvent; +import org.violetmoon.zeta.event.load.ZCommonSetup; +import org.violetmoon.zeta.event.play.ZBlock; +import org.violetmoon.zeta.event.play.entity.player.ZRightClickBlock; +import org.violetmoon.zeta.module.ZetaModule; + +import java.util.*; public final class ToolInteractionHandler { @@ -73,8 +66,8 @@ public static void addModifiers(ZCommonSetup event) { } } - @SubscribeEvent - public static void toolActionEvent(BlockEvent.BlockToolModificationEvent event) { + @PlayEvent + public static void toolActionEvent(ZBlock.BlockToolModification event) { ToolAction action = event.getToolAction(); if(interactionMaps.containsKey(action)) { diff --git a/src/main/java/org/violetmoon/quark/content/building/module/VariantChestsModule.java b/src/main/java/org/violetmoon/quark/content/building/module/VariantChestsModule.java index 4bcd3a096b..fe582bd0f8 100644 --- a/src/main/java/org/violetmoon/quark/content/building/module/VariantChestsModule.java +++ b/src/main/java/org/violetmoon/quark/content/building/module/VariantChestsModule.java @@ -25,9 +25,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraftforge.common.Tags; - -import javax.annotation.Nullable; - import org.violetmoon.quark.base.Quark; import org.violetmoon.quark.base.config.Config; import org.violetmoon.quark.base.handler.StructureBlockReplacementHandler; @@ -44,7 +41,6 @@ import org.violetmoon.quark.mixin.accessor.AccessorAbstractChestedHorse; import org.violetmoon.zeta.client.event.load.ZClientSetup; import org.violetmoon.zeta.client.event.load.ZPreTextureStitch; -import org.violetmoon.zeta.event.*; import org.violetmoon.zeta.event.bus.LoadEvent; import org.violetmoon.zeta.event.bus.PlayEvent; import org.violetmoon.zeta.event.load.ZConfigChanged; @@ -57,6 +53,7 @@ import org.violetmoon.zeta.module.ZetaLoadModule; import org.violetmoon.zeta.module.ZetaModule; +import javax.annotation.Nullable; import java.util.*; import java.util.function.BooleanSupplier; import java.util.function.Consumer; diff --git a/src/main/java/org/violetmoon/quark/content/experimental/module/GameNerfsModule.java b/src/main/java/org/violetmoon/quark/content/experimental/module/GameNerfsModule.java index da43e549e6..b739cbb2d1 100644 --- a/src/main/java/org/violetmoon/quark/content/experimental/module/GameNerfsModule.java +++ b/src/main/java/org/violetmoon/quark/content/experimental/module/GameNerfsModule.java @@ -28,7 +28,6 @@ import org.violetmoon.quark.base.Quark; import org.violetmoon.quark.base.config.Config; -import org.violetmoon.zeta.event.*; import org.violetmoon.zeta.event.bus.LoadEvent; import org.violetmoon.zeta.event.bus.PlayEvent; import org.violetmoon.zeta.event.bus.ZResult; diff --git a/src/main/java/org/violetmoon/quark/content/tools/module/AncientTomesModule.java b/src/main/java/org/violetmoon/quark/content/tools/module/AncientTomesModule.java index 28c89c41d3..93d836ce6c 100644 --- a/src/main/java/org/violetmoon/quark/content/tools/module/AncientTomesModule.java +++ b/src/main/java/org/violetmoon/quark/content/tools/module/AncientTomesModule.java @@ -50,7 +50,6 @@ import org.violetmoon.quark.content.tools.item.AncientTomeItem; import org.violetmoon.quark.content.tools.loot.EnchantTome; import org.violetmoon.quark.content.world.module.MonsterBoxModule; -import org.violetmoon.zeta.event.*; import org.violetmoon.zeta.event.bus.LoadEvent; import org.violetmoon.zeta.event.bus.PlayEvent; import org.violetmoon.zeta.event.load.ZCommonSetup; diff --git a/src/main/java/org/violetmoon/quark/content/tools/module/ColorRunesModule.java b/src/main/java/org/violetmoon/quark/content/tools/module/ColorRunesModule.java index 937bb5deff..23f0b0f529 100644 --- a/src/main/java/org/violetmoon/quark/content/tools/module/ColorRunesModule.java +++ b/src/main/java/org/violetmoon/quark/content/tools/module/ColorRunesModule.java @@ -27,7 +27,6 @@ import org.violetmoon.quark.base.network.message.UpdateTridentMessage; import org.violetmoon.quark.content.tools.client.render.GlintRenderTypes; import org.violetmoon.quark.content.tools.item.RuneItem; -import org.violetmoon.zeta.event.*; import org.violetmoon.zeta.event.bus.LoadEvent; import org.violetmoon.zeta.event.bus.PlayEvent; import org.violetmoon.zeta.event.load.ZCommonSetup; diff --git a/src/main/java/org/violetmoon/quark/content/tools/module/ParrotEggsModule.java b/src/main/java/org/violetmoon/quark/content/tools/module/ParrotEggsModule.java index 59e102603d..e4eebc6887 100644 --- a/src/main/java/org/violetmoon/quark/content/tools/module/ParrotEggsModule.java +++ b/src/main/java/org/violetmoon/quark/content/tools/module/ParrotEggsModule.java @@ -37,7 +37,6 @@ import org.violetmoon.quark.content.tools.entity.ParrotEgg; import org.violetmoon.quark.content.tools.item.ParrotEggItem; import org.violetmoon.zeta.client.event.load.ZClientSetup; -import org.violetmoon.zeta.event.*; import org.violetmoon.zeta.event.bus.LoadEvent; import org.violetmoon.zeta.event.bus.PlayEvent; import org.violetmoon.zeta.event.load.ZCommonSetup; diff --git a/src/main/java/org/violetmoon/zeta/event/play/ZBlock.java b/src/main/java/org/violetmoon/zeta/event/play/ZBlock.java index 9f5a454d9d..e15275a5cd 100644 --- a/src/main/java/org/violetmoon/zeta/event/play/ZBlock.java +++ b/src/main/java/org/violetmoon/zeta/event/play/ZBlock.java @@ -1,5 +1,7 @@ package org.violetmoon.zeta.event.play; +import net.minecraftforge.common.ToolAction; +import org.jetbrains.annotations.Nullable; import org.violetmoon.zeta.event.bus.IZetaPlayEvent; import net.minecraft.core.BlockPos; @@ -19,4 +21,9 @@ interface Break extends ZBlock { interface EntityPlace extends ZBlock { BlockState getPlacedBlock(); } + + interface BlockToolModification extends ZBlock { + ToolAction getToolAction(); + void setFinalState(@Nullable BlockState finalState); + } } diff --git a/src/main/java/org/violetmoon/zeta/event/play/ZServerTick.java b/src/main/java/org/violetmoon/zeta/event/play/ZServerTick.java new file mode 100644 index 0000000000..1a29505d52 --- /dev/null +++ b/src/main/java/org/violetmoon/zeta/event/play/ZServerTick.java @@ -0,0 +1,11 @@ +package org.violetmoon.zeta.event.play; + +import net.minecraft.server.MinecraftServer; +import org.violetmoon.zeta.event.bus.IZetaPlayEvent; + +public interface ZServerTick extends IZetaPlayEvent { + MinecraftServer getServer(); + + interface Start extends ZServerTick { } + interface End extends ZServerTick { } +} diff --git a/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java b/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java index 62745c9db7..88d4551f5a 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java +++ b/src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java @@ -185,6 +185,8 @@ public void start() { MinecraftForge.EVENT_BUS.addGenericListener(BlockEntity.class, this::blockEntityCaps); MinecraftForge.EVENT_BUS.addGenericListener(Level.class, this::levelCaps); + MinecraftForge.EVENT_BUS.addListener(this::serverTickStart); + MinecraftForge.EVENT_BUS.addListener(this::serverTickEnd); MinecraftForge.EVENT_BUS.addListener(this::levelTickStart); MinecraftForge.EVENT_BUS.addListener(this::levelTickEnd); MinecraftForge.EVENT_BUS.addListener(this::playerInteract); @@ -353,6 +355,16 @@ public void levelCaps(AttachCapabilitiesEvent e) { playBus.fire(new ForgeZAttachCapabilities.LevelCaps(capabilityManager, e), ZAttachCapabilities.LevelCaps.class); } + public void serverTickStart(TickEvent.ServerTickEvent e) { + if (e.phase == TickEvent.Phase.START) + playBus.fire(new ForgeZServerTick.Start(e), ZServerTick.Start.class); + } + + public void serverTickEnd(TickEvent.ServerTickEvent e) { + if (e.phase == TickEvent.Phase.END) + playBus.fire(new ForgeZServerTick.End(e), ZServerTick.End.class); + } + public void levelTickStart(TickEvent.LevelTickEvent e) { if (e.phase == TickEvent.Phase.START) playBus.fire(new ForgeZLevelTick.Start(e), ZLevelTick.Start.class); diff --git a/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java b/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java index b16f6da3e0..d7f59856fd 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java +++ b/src/main/java/org/violetmoon/zetaimplforge/client/ForgeZetaClient.java @@ -6,6 +6,7 @@ import net.minecraft.client.color.item.ItemColors; import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; +import net.minecraftforge.client.event.*; import net.minecraftforge.client.gui.overlay.VanillaGuiOverlay; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.TickEvent; @@ -18,62 +19,13 @@ import org.violetmoon.zeta.Zeta; import org.violetmoon.zeta.client.ClientRegistryExtension; import org.violetmoon.zeta.client.ZetaClient; -import org.violetmoon.zeta.client.event.*; -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.ZModelBakingCompleted; -import org.violetmoon.zeta.client.event.load.ZPreTextureStitch; -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.ZCustomizeDebugText; -import org.violetmoon.zeta.client.event.play.ZEndClientTick; -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.client.event.play.ZStartClientTick; -import org.violetmoon.zetaimplforge.client.event.*; -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.ForgeZModelBakingCompleted; -import org.violetmoon.zetaimplforge.client.event.load.ForgeZPreTextureStitch; -import org.violetmoon.zetaimplforge.client.event.load.ForgeZRegisterLayerDefinitions; -import org.violetmoon.zetaimplforge.client.event.load.ForgeZTooltipComponents; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZCustomizeDebugText; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZGatherTooltipComponents; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZHighlightBlock; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZInput; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZInputUpdate; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZRenderContainerScreen; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZRenderGuiOverlay; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZRenderLiving; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZRenderPlayer; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZRenderTick; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZRenderTooltip; -import org.violetmoon.zetaimplforge.client.event.player.ForgeZScreen; +import org.violetmoon.zeta.client.event.load.*; +import org.violetmoon.zeta.client.event.play.*; +import org.violetmoon.zetaimplforge.client.event.load.*; +import org.violetmoon.zetaimplforge.client.event.player.*; import org.violetmoon.zetaimplforge.mixin.client.AccessorBlockColors; import org.violetmoon.zetaimplforge.mixin.client.AccessorItemColors; -import net.minecraftforge.client.event.*; - public class ForgeZetaClient extends ZetaClient { public ForgeZetaClient(Zeta z) { super(z); diff --git a/src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZBlock.java b/src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZBlock.java index d8c4f16a30..7aff8bd00a 100644 --- a/src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZBlock.java +++ b/src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZBlock.java @@ -1,5 +1,7 @@ package org.violetmoon.zetaimplforge.event.play; +import net.minecraftforge.common.ToolAction; +import org.jetbrains.annotations.Nullable; import org.violetmoon.zeta.event.play.ZBlock; import net.minecraft.core.BlockPos; @@ -57,4 +59,23 @@ public BlockState getPlacedBlock() { return e.getPlacedBlock(); } } + + public static class BlockToolModification extends ForgeZBlock implements ZBlock.BlockToolModification { + private final BlockEvent.BlockToolModificationEvent e; + + public BlockToolModification(BlockEvent.BlockToolModificationEvent e) { + super(e); + this.e = e; + } + + @Override + public ToolAction getToolAction() { + return e.getToolAction(); + } + + @Override + public void setFinalState(@Nullable BlockState finalState) { + e.setFinalState(finalState); + } + } } diff --git a/src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZServerTick.java b/src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZServerTick.java new file mode 100644 index 0000000000..bdbafc2fdf --- /dev/null +++ b/src/main/java/org/violetmoon/zetaimplforge/event/play/ForgeZServerTick.java @@ -0,0 +1,30 @@ +package org.violetmoon.zetaimplforge.event.play; + +import net.minecraft.server.MinecraftServer; +import net.minecraftforge.event.TickEvent; +import org.violetmoon.zeta.event.play.ZServerTick; + +public class ForgeZServerTick implements ZServerTick { + private final TickEvent.ServerTickEvent e; + + public ForgeZServerTick(TickEvent.ServerTickEvent e) { + this.e = e; + } + + @Override + public MinecraftServer getServer() { + return e.getServer(); + } + + public static class Start extends ForgeZServerTick implements ZServerTick.Start { + public Start(TickEvent.ServerTickEvent e) { + super(e); + } + } + + public static class End extends ForgeZServerTick implements ZServerTick.End { + public End(TickEvent.ServerTickEvent e) { + super(e); + } + } +}