ServerboundSetCommandMinecartPacket 0x38

ServerboundSetCommandMinecartPacket: Minecraft 26.3 packet (0x38 Play serverbound). Wire name 'set_command_minecart', fields: entity, command

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x3856PLAYServerboundGamePacketTypes.SERVERBOUND_SET_COMMAND_MINECART: "set_command_minecart"

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

FieldType
entityint
commandString
trackOutputboolean

Stream codec

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

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleSetCommandMinecart(ServerboundSetCommandMinecartPacket serverboundsetcommandminecartpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundSetCommandMinecartPacket.java59 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.network.FriendlyByteBuf;
4
import net.minecraft.network.codec.StreamCodec;
5
import net.minecraft.network.protocol.Packet;
6
import net.minecraft.network.protocol.PacketType;
7
import net.minecraft.world.entity.vehicle.minecart.MinecartCommandBlock;
8
import net.minecraft.world.level.BaseCommandBlock;
9
import net.minecraft.world.level.Level;
10
import org.jspecify.annotations.Nullable;
11
12
public class ServerboundSetCommandMinecartPacket implements Packet<ServerGamePacketListener> {
13
	public static final StreamCodec<FriendlyByteBuf, ServerboundSetCommandMinecartPacket> STREAM_CODEC = Packet.codec(
14
		ServerboundSetCommandMinecartPacket::write, ServerboundSetCommandMinecartPacket::new
15
	);
16
	private final int entity;
17
	private final String command;
18
	private final boolean trackOutput;
19
20
	public ServerboundSetCommandMinecartPacket(final int entity, final String command, final boolean trackOutput) {
21
		this.entity = entity;
22
		this.command = command;
23
		this.trackOutput = trackOutput;
24
	}
25
26
	private ServerboundSetCommandMinecartPacket(final FriendlyByteBuf input) {
27
		this.entity = input.readVarInt();
28
		this.command = input.readUtf();
29
		this.trackOutput = input.readBoolean();
30
	}
31
32
	private void write(final FriendlyByteBuf output) {
33
		output.writeVarInt(this.entity);
34
		output.writeUtf(this.command);
35
		output.writeBoolean(this.trackOutput);
36
	}
37
38
	@Override
39
	public PacketType<ServerboundSetCommandMinecartPacket> type() {
40
		return GamePacketTypes.SERVERBOUND_SET_COMMAND_MINECART;
41
	}
42
43
	public void handle(final ServerGamePacketListener listener) {
44
		listener.handleSetCommandMinecart(this);
45
	}
46
47
	public @Nullable BaseCommandBlock getCommandBlock(final Level level) {
48
		return level.getEntity(this.entity) instanceof MinecartCommandBlock minecartCommandBlock ? minecartCommandBlock.getCommandBlock() : null;
49
	}
50
51
	public String getCommand() {
52
		return this.command;
53
	}
54
55
	public boolean isTrackOutput() {
56
		return this.trackOutput;
57
	}
58
}
59