ServerboundInteractPacket 0x1A

ServerboundInteractPacket: Minecraft 26.3 packet (0x1A Play serverbound). Wire name 'interact', fields: entityId, hand, location, usingSecondaryAction

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x1A26PLAYServerboundGamePacketTypes.SERVERBOUND_INTERACT: "interact"

Packet ids are positional: the id is the index of the addPacket call in the protocol builder (see ProtocolInfoBuilder.listPackets). Ids change between game versions.

Wire fields (4)

FieldType
entityIdint
handInteractionHand
locationVec3
usingSecondaryActionboolean

Fields are the components of the packet record.

Stream codec

static final StreamCodec<ByteBuf, ServerboundInteractPacket> STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.VAR_INT, ServerboundInteractPacket::entityId, InteractionHand.STREAM_CODEC, Serverbound

Modern packets serialize through StreamCodecs instead of read/write methods.

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleInteract(ServerboundInteractPacket serverboundinteractpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundInteractPacket.java34 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import io.netty.buffer.ByteBuf;
4
import net.minecraft.network.codec.ByteBufCodecs;
5
import net.minecraft.network.codec.StreamCodec;
6
import net.minecraft.network.protocol.Packet;
7
import net.minecraft.network.protocol.PacketType;
8
import net.minecraft.world.InteractionHand;
9
import net.minecraft.world.phys.Vec3;
10
11
public record ServerboundInteractPacket(int entityId, InteractionHand hand, Vec3 location, boolean usingSecondaryAction)
12
	implements Packet<ServerGamePacketListener> {
13
	public static final StreamCodec<ByteBuf, ServerboundInteractPacket> STREAM_CODEC = StreamCodec.composite(
14
		ByteBufCodecs.VAR_INT,
15
		ServerboundInteractPacket::entityId,
16
		InteractionHand.STREAM_CODEC,
17
		ServerboundInteractPacket::hand,
18
		Vec3.LP_STREAM_CODEC,
19
		ServerboundInteractPacket::location,
20
		ByteBufCodecs.BOOL,
21
		ServerboundInteractPacket::usingSecondaryAction,
22
		ServerboundInteractPacket::new
23
	);
24
25
	@Override
26
	public PacketType<ServerboundInteractPacket> type() {
27
		return GamePacketTypes.SERVERBOUND_INTERACT;
28
	}
29
30
	public void handle(final ServerGamePacketListener listener) {
31
		listener.handleInteract(this);
32
	}
33
}
34