Skip to content

Commit

Permalink
subscribe event is kil
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Nov 8, 2023
1 parent 6421699 commit a932d84
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/violetmoon/zeta/event/play/ZBlock.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/violetmoon/zeta/event/play/ZServerTick.java
Original file line number Diff line number Diff line change
@@ -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 { }
}
12 changes: 12 additions & 0 deletions src/main/java/org/violetmoon/zetaimplforge/ForgeZeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -353,6 +355,16 @@ public void levelCaps(AttachCapabilitiesEvent<Level> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit a932d84

Please sign in to comment.