Skip to content

Commit

Permalink
feat(game.event): projectile weapon release event
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Feb 13, 2024
1 parent c3cd41c commit c131e55
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -35,14 +40,16 @@ 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

/**
* @see MixinServerHandshakePacketListenerImpl#handleServerLogin
*/
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));
Expand All @@ -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));
}

}

0 comments on commit c131e55

Please sign in to comment.