All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.magistuarmory.network.PacketLanceCollision Maven / Gradle / Ivy

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.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();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy