package fr.mvinet.craftal.packet;
import net.minecraft.client.network.play.IClientPlayNetHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.network.INetHandler;
import net.minecraft.network.IPacket;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.registry.Registry;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.UUID;
public class SpawnPacket implements IPacket {
private int entityId;
private UUID uniqueId;
private double x;
private double y;
private double z;
private int speedX;
private int speedY;
private int speedZ;
private int pitch;
private int yaw;
private EntityType<?> type;
public SpawnPacket() {
}
public SpawnPacket(Entity entity) {
this();
this.entityId = entity.getEntityId();
this.uniqueId = entity.getUniqueID();
this.x = entity.posX;
this.y = entity.posY;
this.z = entity.posZ;
this.pitch = MathHelper.floor(entity.rotationPitch * 256.0F / 360.0F);
this.yaw = MathHelper.floor(entity.rotationYaw * 256.0F / 360.0F);
this.type = entity.getType();
this.speedX = (int) (MathHelper.clamp(entity.getMotion().x, -3.9D, 3.9D) * 8000.0D);
this.speedY = (int) (MathHelper.clamp(entity.getMotion().y, -3.9D, 3.9D) * 8000.0D);
this.speedZ = (int) (MathHelper.clamp(entity.getMotion().z, -3.9D, 3.9D) * 8000.0D);
}
/**
* Reads the raw packet data from the data stream.
*/
public void readPacketData(PacketBuffer buf) {
this.entityId = buf.readVarInt();
this.uniqueId = buf.readUniqueId();
this.type = Registry.ENTITY_TYPE.getByValue(buf.readVarInt());
this.x = buf.readDouble();
this.y = buf.readDouble();
this.z = buf.readDouble();
this.pitch = buf.readByte();
this.yaw = buf.readByte();
this.speedX = buf.readShort();
this.speedY = buf.readShort();
this.speedZ = buf.readShort();
}
/**
* Writes the raw packet data to the data stream.
*/
public void writePacketData(PacketBuffer buf) {
buf.writeVarInt(this.entityId);
buf.writeUniqueId(this.uniqueId);
buf.writeVarInt(Registry.ENTITY_TYPE.getId(this.type));
buf.writeDouble(this.x);
buf.writeDouble(this.y);
buf.writeDouble(this.z);
buf.writeByte(this.pitch);
buf.writeByte(this.yaw);
buf.writeShort(this.speedX);
buf.writeShort(this.speedY);
buf.writeShort(this.speedZ);
}
@Override
public void processPacket(INetHandler handler) {
//Like this ? i really don't know how to do that
handler.getNetworkManager().sendPacket(this);
}
@OnlyIn(Dist.CLIENT)
public int getEntityID() {
return this.entityId;
}
@OnlyIn(Dist.CLIENT)
public UUID getUniqueId() {
return this.uniqueId;
}
@OnlyIn(Dist.CLIENT)
public double getX() {
return this.x;
}
@OnlyIn(Dist.CLIENT)
public double getY() {
return this.y;
}
@OnlyIn(Dist.CLIENT)
public double getZ() {
return this.z;
}
@OnlyIn(Dist.CLIENT)
public double func_218693_g() {
return (double) this.speedX / 8000.0D;
}
@OnlyIn(Dist.CLIENT)
public double func_218695_h() {
return (double) this.speedY / 8000.0D;
}
@OnlyIn(Dist.CLIENT)
public double func_218692_i() {
return (double) this.speedZ / 8000.0D;
}
@OnlyIn(Dist.CLIENT)
public int getPitch() {
return this.pitch;
}
@OnlyIn(Dist.CLIENT)
public int getYaw() {
return this.yaw;
}
@OnlyIn(Dist.CLIENT)
public EntityType<?> getType() {
return this.type;
}
}
Nothing .. like i said, i don't know how to implement this .. so i have nothing ..