ServerboundTestInstanceBlockActionPacket 0x41

ServerboundTestInstanceBlockActionPacket: Minecraft 26.3 packet (0x41 Play serverbound).

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x4165PLAYServerboundGamePacketTypes.SERVERBOUND_TEST_INSTANCE_BLOCK_ACTION: "test_instance_block_action"

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
posBlockPos
actionServerboundTestInstanceBlockActionPacket.Action
dataTestInstanceBlockEntity.Data

Fields are the components of the packet record.

Stream codec

static final StreamCodec<RegistryFriendlyByteBuf, ServerboundTestInstanceBlockActionPacket> STREAM_CODEC = StreamCodec.composite( BlockPos.STREAM_CODEC, ServerboundTestInstanceBlockActionPacket::pos,

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleTestInstanceBlockAction(ServerboundTestInstanceBlockActionPacket serverboundtestinstanceblockactionpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundTestInstanceBlockActionPacket.java71 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import io.netty.buffer.ByteBuf;
4
import java.util.Optional;
5
import java.util.function.IntFunction;
6
import net.minecraft.core.BlockPos;
7
import net.minecraft.core.Vec3i;
8
import net.minecraft.gametest.framework.GameTestInstance;
9
import net.minecraft.network.RegistryFriendlyByteBuf;
10
import net.minecraft.network.codec.ByteBufCodecs;
11
import net.minecraft.network.codec.StreamCodec;
12
import net.minecraft.network.protocol.Packet;
13
import net.minecraft.network.protocol.PacketType;
14
import net.minecraft.resources.ResourceKey;
15
import net.minecraft.util.ByIdMap;
16
import net.minecraft.world.level.block.Rotation;
17
import net.minecraft.world.level.block.entity.TestInstanceBlockEntity;
18
19
public record ServerboundTestInstanceBlockActionPacket(BlockPos pos, ServerboundTestInstanceBlockActionPacket.Action action, TestInstanceBlockEntity.Data data)
20
	implements Packet<ServerGamePacketListener> {
21
	public static final StreamCodec<RegistryFriendlyByteBuf, ServerboundTestInstanceBlockActionPacket> STREAM_CODEC = StreamCodec.composite(
22
		BlockPos.STREAM_CODEC,
23
		ServerboundTestInstanceBlockActionPacket::pos,
24
		ServerboundTestInstanceBlockActionPacket.Action.STREAM_CODEC,
25
		ServerboundTestInstanceBlockActionPacket::action,
26
		TestInstanceBlockEntity.Data.STREAM_CODEC,
27
		ServerboundTestInstanceBlockActionPacket::data,
28
		ServerboundTestInstanceBlockActionPacket::new
29
	);
30
31
	public ServerboundTestInstanceBlockActionPacket(
32
		final BlockPos pos,
33
		final ServerboundTestInstanceBlockActionPacket.Action action,
34
		final Optional<ResourceKey<GameTestInstance>> test,
35
		final Vec3i size,
36
		final Rotation rotation,
37
		final boolean ignoreEntities
38
	) {
39
		this(pos, action, new TestInstanceBlockEntity.Data(test, size, rotation, ignoreEntities, TestInstanceBlockEntity.Status.CLEARED, Optional.empty()));
40
	}
41
42
	@Override
43
	public PacketType<ServerboundTestInstanceBlockActionPacket> type() {
44
		return GamePacketTypes.SERVERBOUND_TEST_INSTANCE_BLOCK_ACTION;
45
	}
46
47
	public void handle(final ServerGamePacketListener listener) {
48
		listener.handleTestInstanceBlockAction(this);
49
	}
50
51
	public enum Action {
52
		INIT(0),
53
		QUERY(1),
54
		SET(2),
55
		RESET(3),
56
		SAVE(4),
57
		EXPORT(5),
58
		RUN(6);
59
60
		private static final IntFunction<ServerboundTestInstanceBlockActionPacket.Action> BY_ID = ByIdMap.continuous(
61
			e -> e.id, values(), ByIdMap.OutOfBoundsStrategy.ZERO
62
		);
63
		public static final StreamCodec<ByteBuf, ServerboundTestInstanceBlockActionPacket.Action> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, e -> e.id);
64
		private final int id;
65
66
		Action(final int id) {
67
			this.id = id;
68
		}
69
	}
70
}
71