ServerboundSetStructureBlockPacket 0x3C

ServerboundSetStructureBlockPacket: Minecraft 26.3 packet (0x3C Play serverbound). Wire name 'set_structure_block', fields: pos, updateType, mode, name

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x3C60PLAYServerboundGamePacketTypes.SERVERBOUND_SET_STRUCTURE_BLOCK: "set_structure_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 (15)

FieldType
posBlockPos
updateTypeStructureBlockEntity.UpdateType
modeStructureMode
nameString
offsetBlockPos
sizeVec3i
mirrorMirror
rotationRotation
dataString
ignoreEntitiesboolean
strictboolean
showAirboolean
showBoundingBoxboolean
integrityfloat
seedlong

Stream codec

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

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleSetStructureBlock(ServerboundSetStructureBlockPacket serverboundsetstructureblockpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundSetStructureBlockPacket.java199 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.Vec3i;
5
import net.minecraft.network.FriendlyByteBuf;
6
import net.minecraft.network.codec.StreamCodec;
7
import net.minecraft.network.protocol.Packet;
8
import net.minecraft.network.protocol.PacketType;
9
import net.minecraft.util.Mth;
10
import net.minecraft.world.level.block.Mirror;
11
import net.minecraft.world.level.block.Rotation;
12
import net.minecraft.world.level.block.entity.StructureBlockEntity;
13
import net.minecraft.world.level.block.state.properties.StructureMode;
14
15
public class ServerboundSetStructureBlockPacket implements Packet<ServerGamePacketListener> {
16
	public static final StreamCodec<FriendlyByteBuf, ServerboundSetStructureBlockPacket> STREAM_CODEC = Packet.codec(
17
		ServerboundSetStructureBlockPacket::write, ServerboundSetStructureBlockPacket::new
18
	);
19
	private static final int FLAG_IGNORE_ENTITIES = 1;
20
	private static final int FLAG_SHOW_AIR = 2;
21
	private static final int FLAG_SHOW_BOUNDING_BOX = 4;
22
	private static final int FLAG_STRICT = 8;
23
	private final BlockPos pos;
24
	private final StructureBlockEntity.UpdateType updateType;
25
	private final StructureMode mode;
26
	private final String name;
27
	private final BlockPos offset;
28
	private final Vec3i size;
29
	private final Mirror mirror;
30
	private final Rotation rotation;
31
	private final String data;
32
	private final boolean ignoreEntities;
33
	private final boolean strict;
34
	private final boolean showAir;
35
	private final boolean showBoundingBox;
36
	private final float integrity;
37
	private final long seed;
38
39
	public ServerboundSetStructureBlockPacket(
40
		final BlockPos pos,
41
		final StructureBlockEntity.UpdateType updateType,
42
		final StructureMode mode,
43
		final String name,
44
		final BlockPos offset,
45
		final Vec3i size,
46
		final Mirror mirror,
47
		final Rotation rotation,
48
		final String data,
49
		final boolean ignoreEntities,
50
		final boolean strict,
51
		final boolean showAir,
52
		final boolean showBoundingBox,
53
		final float integrity,
54
		final long seed
55
	) {
56
		this.pos = pos;
57
		this.updateType = updateType;
58
		this.mode = mode;
59
		this.name = name;
60
		this.offset = offset;
61
		this.size = size;
62
		this.mirror = mirror;
63
		this.rotation = rotation;
64
		this.data = data;
65
		this.ignoreEntities = ignoreEntities;
66
		this.strict = strict;
67
		this.showAir = showAir;
68
		this.showBoundingBox = showBoundingBox;
69
		this.integrity = integrity;
70
		this.seed = seed;
71
	}
72
73
	private ServerboundSetStructureBlockPacket(final FriendlyByteBuf input) {
74
		this.pos = input.readBlockPos();
75
		this.updateType = input.readEnum(StructureBlockEntity.UpdateType.class);
76
		this.mode = input.readEnum(StructureMode.class);
77
		this.name = input.readUtf();
78
		int maxOffset = 48;
79
		this.offset = new BlockPos(Mth.clamp(input.readByte(), -48, 48), Mth.clamp(input.readByte(), -48, 48), Mth.clamp(input.readByte(), -48, 48));
80
		int maxSize = 48;
81
		this.size = new Vec3i(Mth.clamp(input.readByte(), 0, 48), Mth.clamp(input.readByte(), 0, 48), Mth.clamp(input.readByte(), 0, 48));
82
		this.mirror = input.readEnum(Mirror.class);
83
		this.rotation = Rotation.STREAM_CODEC.decode(input);
84
		this.data = input.readUtf(128);
85
		this.integrity = Mth.clamp(input.readFloat(), 0.0F, 1.0F);
86
		this.seed = input.readVarLong();
87
		int flags = input.readByte();
88
		this.ignoreEntities = (flags & 1) != 0;
89
		this.strict = (flags & 8) != 0;
90
		this.showAir = (flags & 2) != 0;
91
		this.showBoundingBox = (flags & 4) != 0;
92
	}
93
94
	private void write(final FriendlyByteBuf output) {
95
		output.writeBlockPos(this.pos);
96
		output.writeEnum(this.updateType);
97
		output.writeEnum(this.mode);
98
		output.writeUtf(this.name);
99
		output.writeByte(this.offset.getX());
100
		output.writeByte(this.offset.getY());
101
		output.writeByte(this.offset.getZ());
102
		output.writeByte(this.size.getX());
103
		output.writeByte(this.size.getY());
104
		output.writeByte(this.size.getZ());
105
		output.writeEnum(this.mirror);
106
		Rotation.STREAM_CODEC.encode(output, this.rotation);
107
		output.writeUtf(this.data);
108
		output.writeFloat(this.integrity);
109
		output.writeVarLong(this.seed);
110
		int flags = 0;
111
		if (this.ignoreEntities) {
112
			flags |= 1;
113
		}
114
115
		if (this.showAir) {
116
			flags |= 2;
117
		}
118
119
		if (this.showBoundingBox) {
120
			flags |= 4;
121
		}
122
123
		if (this.strict) {
124
			flags |= 8;
125
		}
126
127
		output.writeByte(flags);
128
	}
129
130
	@Override
131
	public PacketType<ServerboundSetStructureBlockPacket> type() {
132
		return GamePacketTypes.SERVERBOUND_SET_STRUCTURE_BLOCK;
133
	}
134
135
	public void handle(final ServerGamePacketListener listener) {
136
		listener.handleSetStructureBlock(this);
137
	}
138
139
	public BlockPos getPos() {
140
		return this.pos;
141
	}
142
143
	public StructureBlockEntity.UpdateType getUpdateType() {
144
		return this.updateType;
145
	}
146
147
	public StructureMode getMode() {
148
		return this.mode;
149
	}
150
151
	public String getName() {
152
		return this.name;
153
	}
154
155
	public BlockPos getOffset() {
156
		return this.offset;
157
	}
158
159
	public Vec3i getSize() {
160
		return this.size;
161
	}
162
163
	public Mirror getMirror() {
164
		return this.mirror;
165
	}
166
167
	public Rotation getRotation() {
168
		return this.rotation;
169
	}
170
171
	public String getData() {
172
		return this.data;
173
	}
174
175
	public boolean isIgnoreEntities() {
176
		return this.ignoreEntities;
177
	}
178
179
	public boolean isStrict() {
180
		return this.strict;
181
	}
182
183
	public boolean isShowAir() {
184
		return this.showAir;
185
	}
186
187
	public boolean isShowBoundingBox() {
188
		return this.showBoundingBox;
189
	}
190
191
	public float getIntegrity() {
192
		return this.integrity;
193
	}
194
195
	public long getSeed() {
196
		return this.seed;
197
	}
198
}
199