ClientboundMerchantOffersPacket 0x35

ClientboundMerchantOffersPacket: Minecraft 26.3 packet (0x35 Play clientbound). Wire name 'merchant_offers', fields: containerId, offers, merchantLevel

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x3553PLAYClientboundGamePacketTypes.CLIENTBOUND_MERCHANT_OFFERS: "merchant_offers"

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
containerIdint
offersMerchantOffers
merchantLevelint
merchantXpint
showProgressboolean
canRestockboolean

Stream codec

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

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleMerchantOffers(ClientboundMerchantOffersPacket clientboundmerchantofferspacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundMerchantOffersPacket.java82 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.network.RegistryFriendlyByteBuf;
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.item.trading.MerchantOffers;
8
9
public class ClientboundMerchantOffersPacket implements Packet<ClientGamePacketListener> {
10
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundMerchantOffersPacket> STREAM_CODEC = Packet.codec(
11
		ClientboundMerchantOffersPacket::write, ClientboundMerchantOffersPacket::new
12
	);
13
	private final int containerId;
14
	private final MerchantOffers offers;
15
	private final int villagerLevel;
16
	private final int villagerXp;
17
	private final boolean showProgress;
18
	private final boolean canRestock;
19
20
	public ClientboundMerchantOffersPacket(
21
		final int containerId, final MerchantOffers offers, final int merchantLevel, final int merchantXp, final boolean showProgress, final boolean canRestock
22
	) {
23
		this.containerId = containerId;
24
		this.offers = offers.copy();
25
		this.villagerLevel = merchantLevel;
26
		this.villagerXp = merchantXp;
27
		this.showProgress = showProgress;
28
		this.canRestock = canRestock;
29
	}
30
31
	private ClientboundMerchantOffersPacket(final RegistryFriendlyByteBuf input) {
32
		this.containerId = input.readContainerId();
33
		this.offers = MerchantOffers.STREAM_CODEC.decode(input);
34
		this.villagerLevel = input.readVarInt();
35
		this.villagerXp = input.readVarInt();
36
		this.showProgress = input.readBoolean();
37
		this.canRestock = input.readBoolean();
38
	}
39
40
	private void write(final RegistryFriendlyByteBuf output) {
41
		output.writeContainerId(this.containerId);
42
		MerchantOffers.STREAM_CODEC.encode(output, this.offers);
43
		output.writeVarInt(this.villagerLevel);
44
		output.writeVarInt(this.villagerXp);
45
		output.writeBoolean(this.showProgress);
46
		output.writeBoolean(this.canRestock);
47
	}
48
49
	@Override
50
	public PacketType<ClientboundMerchantOffersPacket> type() {
51
		return GamePacketTypes.CLIENTBOUND_MERCHANT_OFFERS;
52
	}
53
54
	public void handle(final ClientGamePacketListener listener) {
55
		listener.handleMerchantOffers(this);
56
	}
57
58
	public int getContainerId() {
59
		return this.containerId;
60
	}
61
62
	public MerchantOffers getOffers() {
63
		return this.offers;
64
	}
65
66
	public int getVillagerLevel() {
67
		return this.villagerLevel;
68
	}
69
70
	public int getVillagerXp() {
71
		return this.villagerXp;
72
	}
73
74
	public boolean showProgress() {
75
		return this.showProgress;
76
	}
77
78
	public boolean canRestock() {
79
		return this.canRestock;
80
	}
81
}
82