com.magistuarmory.network.PacketLongReachAttack Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of 1.20.2-epic-knights-fabric Show documentation
Show all versions of 1.20.2-epic-knights-fabric Show documentation
mod that adds medieval stuff to the game
The newest version!
package com.magistuarmory.network;
import com.magistuarmory.EpicKnights;
import com.magistuarmory.item.MedievalWeaponItem;
import dev.architectury.networking.NetworkManager;
import io.netty.buffer.Unpooled;
import net.minecraft.class_1268;
import net.minecraft.class_1297;
import net.minecraft.class_1304;
import net.minecraft.class_1799;
import net.minecraft.class_2540;
import net.minecraft.class_2960;
import net.minecraft.class_3222;
public class PacketLongReachAttack
{
public static final class_2960 ID = new class_2960(EpicKnights.ID, "packet_long_reach_attack");
public static void sendToServer(int entityid)
{
NetworkManager.sendToServer(ID, PacketLongReachAttack.encode(entityid));
}
static class_2540 encode(int entityId)
{
class_2540 buf = new class_2540(Unpooled.buffer());
buf.method_53002(entityId);
return buf;
}
public static void apply(class_2540 buf, NetworkManager.PacketContext context)
{
if (!(context.getPlayer() instanceof class_3222 player))
return;
class_1297 victim = player.method_37908().method_8469(buf.readInt());
if (victim == null)
return;
context.queue(() -> execute(victim, player));
}
static void execute(class_1297 victim, class_3222 player)
{
class_1799 stack = player.method_6118(class_1304.field_6173);
if (!(stack.method_7909() instanceof MedievalWeaponItem weapon) || !weapon.isLong())
return;
player.method_7324(victim);
player.method_23667(class_1268.field_5808, true);
player.method_7350();
}
}