Skip to content

Commit

Permalink
refactor: add AH identifier to event handlers and factories
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Sep 18, 2022
1 parent 6d2a441 commit 64832d2
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 51 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/auioc/mcmod/arnicalib/Initialization.java
@@ -1,11 +1,11 @@
package org.auioc.mcmod.arnicalib;

import org.auioc.mcmod.arnicalib.client.config.ClientConfig;
import org.auioc.mcmod.arnicalib.client.event.ClientEventHandler;
import org.auioc.mcmod.arnicalib.client.config.AHClientConfig;
import org.auioc.mcmod.arnicalib.client.event.AHClientEventHandler;
import org.auioc.mcmod.arnicalib.common.command.AHCommandArguments;
import org.auioc.mcmod.arnicalib.common.itemgroup.AHCreativeModeTabs;
import org.auioc.mcmod.arnicalib.common.network.AHPacketHandler;
import org.auioc.mcmod.arnicalib.server.event.ServerEventHandler;
import org.auioc.mcmod.arnicalib.server.event.AHServerEventHandler;
import org.auioc.mcmod.arnicalib.server.loot.AHGlobalLootModifiers;
import org.auioc.mcmod.arnicalib.server.loot.AHLootItemConditions;
import org.auioc.mcmod.arnicalib.server.loot.AHLootItemFunctions;
Expand Down Expand Up @@ -60,7 +60,7 @@ private void modSetup() {

private void forgeSetup() {
AHCreativeModeTabs.init();
forgeEventBus.register(ServerEventHandler.class);
forgeEventBus.register(AHServerEventHandler.class);
}

}
Expand All @@ -77,13 +77,13 @@ public ClientSideOnlySetup(final IEventBus modEventBus, final IEventBus forgeEve
}

public void registerConfig() {
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ClientConfig.CONFIG);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, AHClientConfig.CONFIG);
}

public void modSetup() {}

public void forgeSetup() {
forgeEventBus.register(ClientEventHandler.class);
forgeEventBus.register(AHClientEventHandler.class);
}

}
Expand Down
Expand Up @@ -6,7 +6,7 @@
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;

@OnlyIn(Dist.CLIENT)
public class ClientConfig {
public class AHClientConfig {

public static final ForgeConfigSpec CONFIG;

Expand Down
Expand Up @@ -9,7 +9,7 @@
import net.minecraftforge.eventbus.api.SubscribeEvent;

@OnlyIn(Dist.CLIENT)
public final class ClientEventHandler {
public final class AHClientEventHandler {

@SubscribeEvent
public static void registerCommands(final RegisterClientCommandsEvent event) {
Expand Down
@@ -1,7 +1,7 @@
package org.auioc.mcmod.arnicalib.client.event.handler;

import org.auioc.mcmod.arnicalib.ArnicaLib;
import org.auioc.mcmod.arnicalib.client.config.ClientConfig;
import org.auioc.mcmod.arnicalib.client.config.AHClientConfig;
import org.auioc.mcmod.arnicalib.utils.game.TextUtils;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.InputConstants;
Expand All @@ -23,9 +23,9 @@ public class TooltipEventHandler {
private static Minecraft mc = Minecraft.getInstance();

public static void handle(ItemTooltipEvent event) {
if (!ClientConfig.EnableAdvancedTooltip.get()) return;
if (ClientConfig.AdvancedTooltipOnlyOnDebug.get() && !isDebugMode()) return;
if (ClientConfig.AdvancedTooltipOnlyOnShift.get() && !isShiftKeyDown()) return;
if (!AHClientConfig.EnableAdvancedTooltip.get()) return;
if (AHClientConfig.AdvancedTooltipOnlyOnDebug.get() && !isDebugMode()) return;
if (AHClientConfig.AdvancedTooltipOnlyOnShift.get() && !isShiftKeyDown()) return;

ItemStack itemStack = event.getItemStack();
if (itemStack.isEmpty()) return;
Expand Down
Expand Up @@ -14,7 +14,7 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;

public final class CommonEventFactory {
public final class AHCommonEventFactory {

private static final IEventBus BUS = MinecraftForge.EVENT_BUS;

Expand All @@ -23,7 +23,7 @@ public static boolean postPistonAddBlockLineEvent(BlockState blockState, Level l
return BUS.post(new org.auioc.mcmod.arnicalib.common.event.impl.PistonAddBlockLineEvent(blockState, level, blockPos, direction));
}

public static boolean firePistonCheckPushableEvent(BlockState blockState, Level level, BlockPos blockPos, Direction pushDirection, boolean p_60209_, Direction p_60210_) {
public static boolean onPistonCheckPushable(BlockState blockState, Level level, BlockPos blockPos, Direction pushDirection, boolean p_60209_, Direction p_60210_) {
return BUS.post(new PistonCheckPushableEvent(blockState, level, blockPos, pushDirection, p_60209_, p_60210_));
}

Expand Down
@@ -1,7 +1,7 @@
package org.auioc.mcmod.arnicalib.mixin.common;

import javax.annotation.Nullable;
import org.auioc.mcmod.arnicalib.common.event.CommonEventFactory;
import org.auioc.mcmod.arnicalib.common.event.AHCommonEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -20,7 +20,7 @@ public abstract class MixinFoodData {
*/
@Overwrite(remap = false)
public void eat(Item p_38713_, ItemStack p_38714_, @Nullable LivingEntity entity) {
var event = CommonEventFactory.onLivingEat(entity, ((FoodData) (Object) this), p_38714_);
var event = AHCommonEventFactory.onLivingEat(entity, ((FoodData) (Object) this), p_38714_);
if (!event.isCanceled()) {
int nutrition = event.getNutrition();
float saturationModifier = event.getSaturationModifier();
Expand Down
@@ -1,6 +1,6 @@
package org.auioc.mcmod.arnicalib.mixin.common;

import org.auioc.mcmod.arnicalib.common.event.CommonEventFactory;
import org.auioc.mcmod.arnicalib.common.event.AHCommonEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -23,7 +23,7 @@ public class MixinItemStack {
)
private void onInventoryTick(Level p_41667_, Entity p_41668_, int p_41669_, boolean p_41670_, CallbackInfo ci) {
if (p_41670_ && p_41668_ instanceof Player player) {
if (CommonEventFactory.onSelectedItemItemInventoryTick(player, p_41667_, ((ItemStack) (Object) this), p_41669_)) {
if (AHCommonEventFactory.onSelectedItemItemInventoryTick(player, p_41667_, ((ItemStack) (Object) this), p_41669_)) {
ci.cancel();
}
}
Expand Down
@@ -1,6 +1,6 @@
package org.auioc.mcmod.arnicalib.mixin.common;

import org.auioc.mcmod.arnicalib.common.event.CommonEventFactory;
import org.auioc.mcmod.arnicalib.common.event.AHCommonEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -23,7 +23,7 @@ public abstract class MixinPistonBaseBlock {
cancellable = true
)
private static void onCheckPushable(BlockState p_60205_, Level p_60206_, BlockPos p_60207_, Direction p_60208_, boolean p_60209_, Direction p_60210_, CallbackInfoReturnable<Boolean> cir) {
if (CommonEventFactory.firePistonCheckPushableEvent(p_60205_, p_60206_, p_60207_, p_60208_, p_60209_, p_60210_)) {
if (AHCommonEventFactory.onPistonCheckPushable(p_60205_, p_60206_, p_60207_, p_60208_, p_60209_, p_60210_)) {
cir.setReturnValue(false);
}
}
Expand Down
@@ -1,7 +1,7 @@
package org.auioc.mcmod.arnicalib.mixin.server;

import javax.annotation.Nullable;
import org.auioc.mcmod.arnicalib.server.event.ServerEventFactory;
import org.auioc.mcmod.arnicalib.server.event.AHServerEventFactory;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -28,7 +28,7 @@ public class MixinCatRelaxOnOwnerGoal {
allow = 1
)
private double modifyConstant_stop(double title) {
return ServerEventFactory.fireCatMorningGiftChanceEvent(this.cat, this.ownerPlayer);
return AHServerEventFactory.onCatSetMorningGiftChance(this.cat, this.ownerPlayer);
}

}
@@ -1,7 +1,7 @@
package org.auioc.mcmod.arnicalib.mixin.server;

import org.auioc.mcmod.arnicalib.api.mixin.server.IMixinEyeOfEnder;
import org.auioc.mcmod.arnicalib.server.event.ServerEventFactory;
import org.auioc.mcmod.arnicalib.server.event.AHServerEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand Down Expand Up @@ -40,7 +40,7 @@ private void use(
CallbackInfoReturnable<InteractionResultHolder> cir,
ItemStack itemstack, HitResult hitresult, ServerLevel serverlevel, BlockPos blockpos, EyeOfEnder eyeofender
) {
((IMixinEyeOfEnder) eyeofender).setSurvivable(ServerEventFactory.fireSetEyeOfEnderSurvivableEvent((ServerPlayer) p_41185_, eyeofender));
((IMixinEyeOfEnder) eyeofender).setSurvivable(AHServerEventFactory.fireSetEyeOfEnderSurvivableEvent((ServerPlayer) p_41185_, eyeofender));
}

}
Expand Up @@ -2,7 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import org.auioc.mcmod.arnicalib.server.event.ServerEventFactory;
import org.auioc.mcmod.arnicalib.server.event.AHServerEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import com.mojang.datafixers.util.Pair;
Expand Down Expand Up @@ -30,7 +30,7 @@ private void addEatEffect(ItemStack stack, Level level, LivingEntity entity) {
}
}

effects = ServerEventFactory.fireLivingEatAddEffectEvent(entity, stack, effects);
effects = AHServerEventFactory.onLivingEatAddEffect(entity, stack, effects);

for (MobEffectInstance instance : effects) {
entity.addEffect(instance);
Expand Down
@@ -1,6 +1,6 @@
package org.auioc.mcmod.arnicalib.mixin.server;

import org.auioc.mcmod.arnicalib.server.event.ServerEventFactory;
import org.auioc.mcmod.arnicalib.server.event.AHServerEventFactory;
import org.auioc.mcmod.arnicalib.server.event.impl.PiglinStanceEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -20,7 +20,7 @@ public class MixinPiglinAi {
allow = 1
)
private static void isWearingGold(LivingEntity p_34809_, CallbackInfoReturnable<Boolean> cri) {
var stance = ServerEventFactory.firePiglinStanceEvent(p_34809_);
var stance = AHServerEventFactory.onPiglinChooseEvent(p_34809_);
if (stance == PiglinStanceEvent.Stance.NEUTRAL) {
cri.setReturnValue(true);
} else if (stance == PiglinStanceEvent.Stance.HOSTILE) {
Expand Down
@@ -1,6 +1,6 @@
package org.auioc.mcmod.arnicalib.mixin.server;

import org.auioc.mcmod.arnicalib.server.event.ServerEventFactory;
import org.auioc.mcmod.arnicalib.server.event.AHServerEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -21,7 +21,7 @@ public abstract class MixinServerLifecycleHooks {
cancellable = true
)
private static void onServerLogin(final ClientIntentionPacket packet, final Connection manager, CallbackInfoReturnable<Boolean> cir) {
if (ServerEventFactory.fireServerLoginEvent(packet, manager)) {
if (AHServerEventFactory.onServerLogin(packet, manager)) {
cir.setReturnValue(false);
}
}
Expand Down
@@ -1,7 +1,7 @@
package org.auioc.mcmod.arnicalib.mixin.server;

import java.util.UUID;
import org.auioc.mcmod.arnicalib.server.event.ServerEventFactory;
import org.auioc.mcmod.arnicalib.server.event.AHServerEventFactory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -22,7 +22,7 @@ public abstract class MixinServerPlayer {
cancellable = true
)
private void onSendMessage(Component p_9147_, ChatType p_9148_, UUID p_9149_, CallbackInfo ci) {
if (ServerEventFactory.fireServerPlayerSendMessageEvent(((ServerPlayer) (Object) this), p_9147_, p_9148_, p_9149_)) {
if (AHServerEventFactory.onServerPlayerSendMessage(((ServerPlayer) (Object) this), p_9147_, p_9148_, p_9149_)) {
ci.cancel();
}
}
Expand Down
Expand Up @@ -16,10 +16,10 @@
import org.auioc.mcmod.arnicalib.server.event.impl.ServerPlayerSendMessageEvent;
import org.auioc.mcmod.arnicalib.server.event.impl.SetEyeOfEnderSurvivableEvent;
import org.auioc.mcmod.arnicalib.utils.LogUtil;
import org.auioc.mcmod.arnicalib.utils.game.TextUtils;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -34,18 +34,18 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;

public final class ServerEventFactory {
public final class AHServerEventFactory {

private static final Marker MARKER = LogUtil.getMarker("ServerHooks");
private static final IEventBus BUS = MinecraftForge.EVENT_BUS;

// Return true if the event was Cancelable cancelled

public static boolean fireServerLoginEvent(final ClientIntentionPacket packet, final Connection manager) {
public static boolean onServerLogin(final ClientIntentionPacket packet, final Connection manager) {
ServerLoginEvent event = new ServerLoginEvent(packet, manager);
boolean cancelled = BUS.post(event);
if (cancelled) {
TextComponent message = new TextComponent(event.getMessage());
var message = TextUtils.literal(event.getMessage());
manager.send(new ClientboundLoginDisconnectPacket(message));
manager.disconnect(message);
LOGGER.info(
Expand All @@ -57,11 +57,11 @@ public static boolean fireServerLoginEvent(final ClientIntentionPacket packet, f
return false;
}

public static boolean fireServerPlayerSendMessageEvent(ServerPlayer player, Component message, ChatType type, UUID uuid) {
public static boolean onServerPlayerSendMessage(ServerPlayer player, Component message, ChatType type, UUID uuid) {
return BUS.post(new ServerPlayerSendMessageEvent(player, message, type, uuid));
}

public static List<MobEffectInstance> fireLivingEatAddEffectEvent(LivingEntity entity, ItemStack food, List<MobEffectInstance> effects) {
public static List<MobEffectInstance> onLivingEatAddEffect(LivingEntity entity, ItemStack food, List<MobEffectInstance> effects) {
LivingEatAddEffectEvent event = new LivingEatAddEffectEvent(entity, food, effects);
if (BUS.post(event)) {
event.getEffects().clear();
Expand All @@ -75,25 +75,27 @@ public static Function<Random, Boolean> fireSetEyeOfEnderSurvivableEvent(ServerP
return event.getSurvivable();
}

public static PiglinStanceEvent.Stance firePiglinStanceEvent(LivingEntity target) {
public static PiglinStanceEvent.Stance onPiglinChooseEvent(LivingEntity target) {
var event = new PiglinStanceEvent(target);
BUS.post(event);
return event.getStance();
}

public static double fireCatMorningGiftChanceEvent(Cat cat, Player ownerPlayer) {
public static double onCatSetMorningGiftChance(Cat cat, Player ownerPlayer) {
var event = new CatMorningGiftChanceEvent(cat, ownerPlayer);
BUS.post(event);
return event.getChance();
}

public static FishingRodCastEvent.Pre firePreFishingRodCastEvent(Player player, Level level, ItemStack fishingRod, int speedBonus, int luckBonus) {
// Coremod arnicalib.fishing_rod_item
public static FishingRodCastEvent.Pre preFishingRodCast(Player player, Level level, ItemStack fishingRod, int speedBonus, int luckBonus) {
var event = new FishingRodCastEvent.Pre((ServerPlayer) player, (ServerLevel) level, fishingRod, speedBonus, luckBonus);
BUS.post(event);
return event;
}

public static int fireItemHurtEvent(ItemStack itemStack, int damage, Random random, @Nullable ServerPlayer player) {
// Coremod arnicalib.item_stack
public static int onItemHurt(ItemStack itemStack, int damage, Random random, @Nullable ServerPlayer player) {
var event = new ItemHurtEvent(itemStack, damage, random, player);
BUS.post(event);
return event.getDamage();
Expand Down
Expand Up @@ -9,7 +9,7 @@
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public final class ServerEventHandler {
public final class AHServerEventHandler {

private static final Marker MARKER = LogUtil.getMarker("ServerHooks");

Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/coremods/fishing_rod_item.js
Expand Up @@ -43,8 +43,8 @@ function initializeCoreMod() {
toInject.add(
new MethodInsnNode(
Opcodes.INVOKESTATIC,
'org/auioc/mcmod/arnicalib/server/event/ServerEventFactory',
'firePreFishingRodCastEvent',
'org/auioc/mcmod/arnicalib/server/event/AHServerEventFactory',
'preFishingRodCast',
'(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;II)Lorg/auioc/mcmod/arnicalib/server/event/impl/FishingRodCastEvent$Pre;',
false
)
Expand Down Expand Up @@ -126,7 +126,7 @@ function initializeCoreMod() {
if (!p_41290_.isClientSide) {
int k = EnchantmentHelper.getFishingSpeedBonus(itemstack);
int j = EnchantmentHelper.getFishingLuckBonus(itemstack);
+ var preEvent = org.auioc.mcmod.arnicalib.server.event.ServerEventFactory.firePreFishingRodCastEvent(p_41291_, p_41290_, itemstack, k, j);
+ var preEvent = org.auioc.mcmod.arnicalib.server.event.AHServerEventFactory.preFishingRodCast(p_41291_, p_41290_, itemstack, k, j);
+ k = preEvent.getSpeedBonus();
+ j = preEvent.getLuckBonus();
p_41290_.addFreshEntity(new FishingHook(p_41291_, p_41290_, j, k));
Expand Down Expand Up @@ -160,7 +160,7 @@ function initializeCoreMod() {
+ ALOAD 4
+ ILOAD 5
+ ILOAD 6
+ INVOKESTATIC org/auioc/mcmod/arnicalib/server/event/ServerEventFactory.firePreFishingRodCastEvent (Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;II)Lorg/auioc/mcmod/arnicalib/server/event/impl/FishingRodCastEvent$Pre;
+ INVOKESTATIC org/auioc/mcmod/arnicalib/server/event/AHServerEventFactory.preFishingRodCast (Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;II)Lorg/auioc/mcmod/arnicalib/server/event/impl/FishingRodCastEvent$Pre;
+ ASTORE 7
+ ALOAD 7
+ INVOKEVIRTUAL org/auioc/mcmod/arnicalib/server/event/impl/FishingRodCastEvent$Pre.getSpeedBonus ()I
Expand Down

0 comments on commit 64832d2

Please sign in to comment.