diff --git a/src/main/java/org/auioc/mcmod/arnicalib/game/event/server/ProjectileWeaponReleaseEvent.java b/src/main/java/org/auioc/mcmod/arnicalib/game/event/server/ProjectileWeaponReleaseEvent.java new file mode 100644 index 00000000..86bcf01b --- /dev/null +++ b/src/main/java/org/auioc/mcmod/arnicalib/game/event/server/ProjectileWeaponReleaseEvent.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2024 AUIOC.ORG + * + * This file is part of ArnicaLib, a mod made for Minecraft. + * + * ArnicaLib is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +package org.auioc.mcmod.arnicalib.game.event.server; + +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.item.ItemStack; +import net.neoforged.neoforge.event.entity.living.LivingEvent; + +public class ProjectileWeaponReleaseEvent extends LivingEvent { + + private final ItemStack weapon; + private final Projectile projectile; + + public ProjectileWeaponReleaseEvent(LivingEntity living, ItemStack weapon, Projectile projectile) { + super(living); + this.weapon = weapon; + this.projectile = projectile; + } + + public ItemStack getWeapon() { + return weapon; + } + + public Projectile getProjectile() { + return projectile; + } + +} diff --git a/src/main/java/org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory.java b/src/main/java/org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory.java index ce6ef4f4..84359102 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/mod/server/event/AHServerEventFactory.java @@ -23,9 +23,14 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.handshake.ClientIntentionPacket; import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.item.ItemStack; +import net.neoforged.bus.api.IEventBus; import net.neoforged.neoforge.common.NeoForge; import org.apache.logging.log4j.Marker; import org.auioc.mcmod.arnicalib.base.log.LogUtil; +import org.auioc.mcmod.arnicalib.game.event.server.ProjectileWeaponReleaseEvent; import org.auioc.mcmod.arnicalib.game.event.server.ServerLoginEvent; import org.auioc.mcmod.arnicalib.mod.mixin.server.MixinServerHandshakePacketListenerImpl; @@ -35,6 +40,8 @@ public final class AHServerEventFactory { private static final Marker MARKER = LogUtil.getMarker("ServerHooks"); + private static final IEventBus BUS = NeoForge.EVENT_BUS; + // Return true if the event was Cancelable cancelled /** @@ -42,7 +49,7 @@ public final class AHServerEventFactory { */ public static boolean onServerLogin(final ClientIntentionPacket packet, final Connection connection) { var event = new ServerLoginEvent(packet, connection); - boolean cancelled = NeoForge.EVENT_BUS.post(event).isCanceled(); + boolean cancelled = BUS.post(event).isCanceled(); if (cancelled) { var message = Component.literal(event.getMessage()); connection.send(new ClientboundLoginDisconnectPacket(message)); @@ -58,4 +65,8 @@ public static boolean onServerLogin(final ClientIntentionPacket packet, final Co return false; } + public static void preProjectileWeaponRelease(LivingEntity player, ItemStack weapon, Projectile projectile) { + BUS.post(new ProjectileWeaponReleaseEvent(player, weapon, projectile)); + } + }