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.20.2-epic-knights-common Show documentation
Show all versions of 1.20.2-epic-knights-common Show documentation
mod that adds medieval stuff to the game
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.method_53002(entityid);
buf.method_52941(speed);
buf.method_52964(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.method_37908().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();
}
}
}