ServerboundSetCommandBlockPacket 0x37

ServerboundSetCommandBlockPacket: Minecraft 26.3 packet (0x37 Play serverbound). Wire name 'set_command_block', fields: pos, command, mode, trackOutput

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x3755PLAYServerboundGamePacketTypes.SERVERBOUND_SET_COMMAND_BLOCK: "set_command_block"

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 (6)

FieldType
posBlockPos
commandString
modeCommandBlockEntity.Mode
trackOutputboolean
conditionalboolean
automaticboolean

Stream codec

static final StreamCodec<FriendlyByteBuf, ServerboundSetCommandBlockPacket> STREAM_CODEC = Packet.codec( ServerboundSetCommandBlockPacket::write, ServerboundSetCommandBlockPacket::new );

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleSetCommandBlock(ServerboundSetCommandBlockPacket serverboundsetcommandblockpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundSetCommandBlockPacket.java98 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.network.FriendlyByteBuf;
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.level.block.entity.CommandBlockEntity;
9
10
public class ServerboundSetCommandBlockPacket implements Packet<ServerGamePacketListener> {
11
	public static final StreamCodec<FriendlyByteBuf, ServerboundSetCommandBlockPacket> STREAM_CODEC = Packet.codec(
12
		ServerboundSetCommandBlockPacket::write, ServerboundSetCommandBlockPacket::new
13
	);
14
	private static final int FLAG_TRACK_OUTPUT = 1;
15
	private static final int FLAG_CONDITIONAL = 2;
16
	private static final int FLAG_AUTOMATIC = 4;
17
	private final BlockPos pos;
18
	private final String command;
19
	private final boolean trackOutput;
20
	private final boolean conditional;
21
	private final boolean automatic;
22
	private final CommandBlockEntity.Mode mode;
23
24
	public ServerboundSetCommandBlockPacket(
25
		final BlockPos pos, final String command, final CommandBlockEntity.Mode mode, final boolean trackOutput, final boolean conditional, final boolean automatic
26
	) {
27
		this.pos = pos;
28
		this.command = command;
29
		this.trackOutput = trackOutput;
30
		this.conditional = conditional;
31
		this.automatic = automatic;
32
		this.mode = mode;
33
	}
34
35
	private ServerboundSetCommandBlockPacket(final FriendlyByteBuf input) {
36
		this.pos = input.readBlockPos();
37
		this.command = input.readUtf();
38
		this.mode = input.readEnum(CommandBlockEntity.Mode.class);
39
		int flags = input.readByte();
40
		this.trackOutput = (flags & 1) != 0;
41
		this.conditional = (flags & 2) != 0;
42
		this.automatic = (flags & 4) != 0;
43
	}
44
45
	private void write(final FriendlyByteBuf output) {
46
		output.writeBlockPos(this.pos);
47
		output.writeUtf(this.command);
48
		output.writeEnum(this.mode);
49
		int flags = 0;
50
		if (this.trackOutput) {
51
			flags |= 1;
52
		}
53
54
		if (this.conditional) {
55
			flags |= 2;
56
		}
57
58
		if (this.automatic) {
59
			flags |= 4;
60
		}
61
62
		output.writeByte(flags);
63
	}
64
65
	@Override
66
	public PacketType<ServerboundSetCommandBlockPacket> type() {
67
		return GamePacketTypes.SERVERBOUND_SET_COMMAND_BLOCK;
68
	}
69
70
	public void handle(final ServerGamePacketListener listener) {
71
		listener.handleSetCommandBlock(this);
72
	}
73
74
	public BlockPos getPos() {
75
		return this.pos;
76
	}
77
78
	public String getCommand() {
79
		return this.command;
80
	}
81
82
	public boolean isTrackOutput() {
83
		return this.trackOutput;
84
	}
85
86
	public boolean isConditional() {
87
		return this.conditional;
88
	}
89
90
	public boolean isAutomatic() {
91
		return this.automatic;
92
	}
93
94
	public CommandBlockEntity.Mode getMode() {
95
		return this.mode;
96
	}
97
}
98