package net.minecraft.network.protocol.game; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.PacketType; import net.minecraft.server.level.ServerEntity; import net.minecraft.world.entity.ExperienceOrb; import net.minecraft.world.phys.Vec3; public class ClientboundAddExperienceOrbPacket implements Packet { public static final StreamCodec STREAM_CODEC = Packet.codec( ClientboundAddExperienceOrbPacket::write, ClientboundAddExperienceOrbPacket::new ); private final int id; private final double x; private final double y; private final double z; private final int value; public ClientboundAddExperienceOrbPacket(ExperienceOrb orb, ServerEntity entity) { this.id = orb.getId(); Vec3 vec3 = entity.getPositionBase(); this.x = vec3.x(); this.y = vec3.y(); this.z = vec3.z(); this.value = orb.getValue(); } private ClientboundAddExperienceOrbPacket(FriendlyByteBuf buffer) { this.id = buffer.readVarInt(); this.x = buffer.readDouble(); this.y = buffer.readDouble(); this.z = buffer.readDouble(); this.value = buffer.readShort(); } /** * Writes the raw packet data to the data stream. */ private void write(FriendlyByteBuf buffer) { buffer.writeVarInt(this.id); buffer.writeDouble(this.x); buffer.writeDouble(this.y); buffer.writeDouble(this.z); buffer.writeShort(this.value); } @Override public PacketType type() { return GamePacketTypes.CLIENTBOUND_ADD_EXPERIENCE_ORB; } /** * Passes this Packet on to the NetHandler for processing. */ public void handle(ClientGamePacketListener handler) { handler.handleAddExperienceOrb(this); } public int getId() { return this.id; } public double getX() { return this.x; } public double getY() { return this.y; } public double getZ() { return this.z; } public int getValue() { return this.value; } }