com.magistuarmory.network.PacketLanceCollision Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of 1.19.2-epic-knights-fabric Show documentation
Show all versions of 1.19.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.LanceItem;
import dev.architectury.networking.NetworkManager;
import io.netty.buffer.Unpooled;
import net.minecraft.class_1297;
import net.minecraft.class_1799;
import net.minecraft.class_2540;
import net.minecraft.class_2960;
import net.minecraft.class_3222;
public class PacketLanceCollision
{
public static final class_2960 ID = new class_2960(EpicKnights.ID, "packet_lance_collision");
public static void sendToServer(int entityid, float damage, boolean dismount)
{
NetworkManager.sendToServer(ID, PacketLanceCollision.encode(entityid, damage, dismount));
}
static class_2540 encode(int entityid, float speed, boolean dismount)
{
class_2540 buf = new class_2540(Unpooled.buffer());
buf.writeInt(entityid);
buf.writeFloat(speed);
buf.writeBoolean(dismount);
return buf;
}
public static void apply(class_2540 buf, NetworkManager.PacketContext context)
{
if (!(context.getPlayer() instanceof class_3222 player))
return;
class_1297 victim = player.field_6002.method_8469(buf.readInt());
if (victim == null)
return;
float speed = buf.readFloat();
boolean dismount = buf.readBoolean();
context.queue(() -> execute(victim, speed, dismount, player));
}
static void execute(class_1297 victim, float speed, boolean dismount, class_3222 player)
{
class_1799 stack = player.method_6047();
if (stack.method_7909() instanceof LanceItem lance)
{
lance.setRideSpeed(stack, speed);
lance.setDismount(stack, dismount);
player.method_7324(victim);
player.method_7350();
}
}
}