ServerboundLockDifficultyPacket 0x1D

ServerboundLockDifficultyPacket: Minecraft 26.3 packet (0x1D Play serverbound). Wire name 'lock_difficulty', fields: locked, handled

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x1D29PLAYServerboundGamePacketTypes.SERVERBOUND_LOCK_DIFFICULTY: "lock_difficulty"

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

FieldType
lockedboolean

Stream codec

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

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleLockDifficulty(ServerboundLockDifficultyPacket serverboundlockdifficultypacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundLockDifficultyPacket.java39 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
8
public class ServerboundLockDifficultyPacket implements Packet<ServerGamePacketListener> {
9
	public static final StreamCodec<FriendlyByteBuf, ServerboundLockDifficultyPacket> STREAM_CODEC = Packet.codec(
10
		ServerboundLockDifficultyPacket::write, ServerboundLockDifficultyPacket::new
11
	);
12
	private final boolean locked;
13
14
	public ServerboundLockDifficultyPacket(final boolean locked) {
15
		this.locked = locked;
16
	}
17
18
	private ServerboundLockDifficultyPacket(final FriendlyByteBuf input) {
19
		this.locked = input.readBoolean();
20
	}
21
22
	private void write(final FriendlyByteBuf output) {
23
		output.writeBoolean(this.locked);
24
	}
25
26
	@Override
27
	public PacketType<ServerboundLockDifficultyPacket> type() {
28
		return GamePacketTypes.SERVERBOUND_LOCK_DIFFICULTY;
29
	}
30
31
	public void handle(final ServerGamePacketListener listener) {
32
		listener.handleLockDifficulty(this);
33
	}
34
35
	public boolean isLocked() {
36
		return this.locked;
37
	}
38
}
39