minecraft-src/net/minecraft/network/protocol/game/ClientboundSetEntityLinkPacket.java
2025-07-04 01:41:11 +03:00

60 lines
1.7 KiB
Java

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.world.entity.Entity;
import org.jetbrains.annotations.Nullable;
public class ClientboundSetEntityLinkPacket implements Packet<ClientGamePacketListener> {
public static final StreamCodec<FriendlyByteBuf, ClientboundSetEntityLinkPacket> STREAM_CODEC = Packet.codec(
ClientboundSetEntityLinkPacket::write, ClientboundSetEntityLinkPacket::new
);
private final int sourceId;
/**
* The entity that is holding the leash, or -1 to clear the holder.
*/
private final int destId;
/**
* @param destination The entity to link to or {@code null} to break any existing link.
*/
public ClientboundSetEntityLinkPacket(Entity source, @Nullable Entity destination) {
this.sourceId = source.getId();
this.destId = destination != null ? destination.getId() : 0;
}
private ClientboundSetEntityLinkPacket(FriendlyByteBuf buffer) {
this.sourceId = buffer.readInt();
this.destId = buffer.readInt();
}
/**
* Writes the raw packet data to the data stream.
*/
private void write(FriendlyByteBuf buffer) {
buffer.writeInt(this.sourceId);
buffer.writeInt(this.destId);
}
@Override
public PacketType<ClientboundSetEntityLinkPacket> type() {
return GamePacketTypes.CLIENTBOUND_SET_ENTITY_LINK;
}
/**
* Passes this Packet on to the NetHandler for processing.
*/
public void handle(ClientGamePacketListener handler) {
handler.handleEntityLinkPacket(this);
}
public int getSourceId() {
return this.sourceId;
}
public int getDestId() {
return this.destId;
}
}