Skip to content

Commit 88d3477

Browse files
committed
26.2-snapshot-7 and implement network tags
1 parent 0e49d4d commit 88d3477

12 files changed

Lines changed: 102 additions & 39 deletions

File tree

example/src/main/java/org/geysermc/mcprotocollib/protocol/example/MinecraftProtocolTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public static void main(String[] args) {
102102
100,
103103
5
104104
),
105+
true,
105106
true
106107
))
107108
);
@@ -149,8 +150,8 @@ public void sessionRemoved(SessionRemovedEvent event) {
149150
server.bind();
150151
}
151152

152-
status();
153-
login();
153+
// status();
154+
// login();
154155
}
155156

156157
private static void status() {

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/MinecraftProtocol.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ public class MinecraftProtocol extends PacketProtocol {
4141
*/
4242
@Nullable
4343
private static NbtMap DEFAULT_NETWORK_CODEC;
44+
/**
45+
* The tags sent from the server to the client during {@link ProtocolState#CONFIGURATION}.
46+
* Lazily loaded once when {@link #newServerSession(Server, Session)} is invoked,
47+
* if {@link #isUseDefaultListeners()} is true.
48+
*/
49+
@Nullable
50+
private static NbtMap DEFAULT_NETWORK_TAGS;
4451

4552
/**
4653
* The codec used for the Minecraft protocol.
@@ -173,7 +180,11 @@ public void newServerSession(Server server, Session session) {
173180
DEFAULT_NETWORK_CODEC = loadNetworkCodec();
174181
}
175182

176-
session.addListener(new ServerListener(DEFAULT_NETWORK_CODEC));
183+
if (DEFAULT_NETWORK_TAGS == null) {
184+
DEFAULT_NETWORK_TAGS = loadNetworkTags();
185+
}
186+
187+
session.addListener(new ServerListener(DEFAULT_NETWORK_CODEC, DEFAULT_NETWORK_TAGS));
177188
}
178189
}
179190

@@ -242,4 +253,12 @@ public static NbtMap loadNetworkCodec() {
242253
throw new AssertionError("Unable to load network codec.", e);
243254
}
244255
}
256+
257+
public static NbtMap loadNetworkTags() {
258+
try (InputStream inputStream = Objects.requireNonNull(MinecraftProtocol.class.getClassLoader().getResourceAsStream("networkTags.nbt"))) {
259+
return (NbtMap) NbtUtils.createGZIPReader(inputStream).readTag(512);
260+
} catch (Exception e) {
261+
throw new AssertionError("Unable to load network tags.", e);
262+
}
263+
}
245264
}

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/ServerListener.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.geysermc.mcprotocollib.protocol.data.status.handler.ServerInfoBuilder;
2323
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundDisconnectPacket;
2424
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundKeepAlivePacket;
25+
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundUpdateTagsPacket;
2526
import org.geysermc.mcprotocollib.protocol.packet.common.serverbound.ServerboundKeepAlivePacket;
2627
import org.geysermc.mcprotocollib.protocol.packet.configuration.clientbound.ClientboundFinishConfigurationPacket;
2728
import org.geysermc.mcprotocollib.protocol.packet.configuration.clientbound.ClientboundRegistryDataPacket;
@@ -48,6 +49,7 @@
4849
import java.security.PrivateKey;
4950
import java.util.ArrayList;
5051
import java.util.Arrays;
52+
import java.util.HashMap;
5153
import java.util.List;
5254
import java.util.Map;
5355
import java.util.Random;
@@ -76,6 +78,7 @@ public class ServerListener extends SessionAdapter {
7678
}
7779

7880
private final NbtMap networkCodec;
81+
private final NbtMap networkTags;
7982

8083
private final byte[] challenge = new byte[4];
8184
private String username = "";
@@ -84,8 +87,9 @@ public class ServerListener extends SessionAdapter {
8487
@Getter
8588
private boolean isTransfer = false;
8689

87-
public ServerListener(NbtMap networkCodec) {
90+
public ServerListener(NbtMap networkCodec, NbtMap networkTags) {
8891
this.networkCodec = networkCodec;
92+
this.networkTags = networkTags;
8993
new Random().nextBytes(this.challenge);
9094
}
9195

@@ -167,6 +171,25 @@ private void handleLoginPacket(Session session, MinecraftProtocol protocol, Pack
167171
session.send(new ClientboundRegistryDataPacket(typeTag, entries));
168172
}
169173

174+
Map<Key, Map<Key, int[]>> tags = new HashMap<>();
175+
for (Map.Entry<String, Object> entry : networkTags.entrySet()) {
176+
@SuppressWarnings("PatternValidation")
177+
Key registryKey = Key.key(entry.getKey());
178+
NbtMap registry = (NbtMap) entry.getValue();
179+
180+
Map<Key, int[]> registryTags = new HashMap<>();
181+
for (String tag : registry.keySet()) {
182+
@SuppressWarnings("PatternValidation")
183+
Key tagKey = Key.key(tag);
184+
int[] tagData = registry.getIntArray(tag);
185+
186+
registryTags.put(tagKey, tagData);
187+
}
188+
189+
tags.put(registryKey, registryTags);
190+
}
191+
session.send(new ClientboundUpdateTagsPacket(tags));
192+
170193
session.send(new ClientboundFinishConfigurationPacket());
171194
}
172195
}

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/codec/MinecraftCodec.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
217217
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundPlayerCommandPacket;
218218
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSetCarriedItemPacket;
219-
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSpectateEntityPacket;
219+
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSpectatorActionPacket;
220220
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundSwingPacket;
221221
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundUseItemOnPacket;
222222
import org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player.ServerboundUseItemPacket;
@@ -236,8 +236,8 @@
236236

237237
public class MinecraftCodec {
238238
public static final PacketCodec CODEC = PacketCodec.builder()
239-
.protocolVersion((1 << 30) | 312)
240-
.minecraftVersion("26.2 Snapshot 6")
239+
.protocolVersion((1 << 30) | 313)
240+
.minecraftVersion("26.2 Snapshot 7")
241241
.state(ProtocolState.HANDSHAKE, MinecraftPacketRegistry.builder()
242242
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
243243
)
@@ -493,7 +493,7 @@ public class MinecraftCodec {
493493
.registerServerboundPacket(ServerboundSetStructureBlockPacket.class, ServerboundSetStructureBlockPacket::new)
494494
.registerServerboundPacket(ServerboundSetTestBlockPacket.class, ServerboundSetTestBlockPacket::new)
495495
.registerServerboundPacket(ServerboundSignUpdatePacket.class, ServerboundSignUpdatePacket::new)
496-
.registerServerboundPacket(ServerboundSpectateEntityPacket.class, ServerboundSpectateEntityPacket::new)
496+
.registerServerboundPacket(ServerboundSpectatorActionPacket.class, ServerboundSpectatorActionPacket::new)
497497
.registerServerboundPacket(ServerboundSwingPacket.class, ServerboundSwingPacket::new)
498498
.registerServerboundPacket(ServerboundTeleportToEntityPacket.class, ServerboundTeleportToEntityPacket::new)
499499
.registerServerboundPacket(ServerboundTestInstanceBlockActionPacket.class, ServerboundTestInstanceBlockActionPacket::new)

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/data/game/level/sound/BuiltinSound.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ public enum BuiltinSound implements Sound {
10401040
MUSIC_DISC_11("music_disc.11"),
10411041
MUSIC_DISC_13("music_disc.13"),
10421042
MUSIC_DISC_BLOCKS("music_disc.blocks"),
1043+
MUSIC_DISC_BOUNCE("music_disc.bounce"),
10431044
MUSIC_DISC_CAT("music_disc.cat"),
10441045
MUSIC_DISC_CHIRP("music_disc.chirp"),
10451046
MUSIC_DISC_FAR("music_disc.far"),
@@ -1085,6 +1086,7 @@ public enum BuiltinSound implements Sound {
10851086
MUSIC_OVERWORLD_JUNGLE("music.overworld.jungle"),
10861087
MUSIC_OVERWORLD_SPARSE_JUNGLE("music.overworld.sparse_jungle"),
10871088
MUSIC_OVERWORLD_BAMBOO_JUNGLE("music.overworld.bamboo_jungle"),
1089+
MUSIC_OVERWORLD_SULFUR_CAVES("music.overworld.sulfur_caves"),
10881090
MUSIC_UNDER_WATER("music.under_water"),
10891091
ENTITY_NAUTILUS_AMBIENT("entity.nautilus.ambient"),
10901092
ENTITY_NAUTILUS_AMBIENT_LAND("entity.nautilus.ambient_land"),
@@ -1929,6 +1931,8 @@ public enum BuiltinSound implements Sound {
19291931
BLOCK_POTENT_SULFUR_FALL("block.potent_sulfur.fall"),
19301932
BLOCK_POTENT_SULFUR_GEYSER_ERUPTION("block.potent_sulfur.geyser_eruption"),
19311933
BLOCK_POTENT_SULFUR_GEYSER_ERUPTION_ACTIVE("block.potent_sulfur.geyser_eruption_active"),
1934+
BLOCK_POTENT_SULFUR_GEYSER_CONTINUOUS_ERUPTION("block.potent_sulfur.geyser_continuous_eruption"),
1935+
BLOCK_POTENT_SULFUR_GEYSER_CONTINUOUS_ERUPTION_ACTIVE("block.potent_sulfur.geyser_continuous_eruption_active"),
19321936
BLOCK_CINNABAR_BREAK("block.cinnabar.break"),
19331937
BLOCK_CINNABAR_STEP("block.cinnabar.step"),
19341938
BLOCK_CINNABAR_PLACE("block.cinnabar.place"),

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/common/clientbound/ClientboundUpdateTagsPacket.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616
@With
1717
@AllArgsConstructor
1818
public class ClientboundUpdateTagsPacket implements MinecraftPacket {
19-
private final @NonNull Map<Key, Map<Key, int[]>> tags = new HashMap<>();
19+
private final Map<Key, Map<Key, int[]>> tags;
2020

2121
public ClientboundUpdateTagsPacket(ByteBuf in) {
22+
this.tags = new HashMap<>();
23+
2224
int totalTagCount = MinecraftTypes.readVarInt(in);
2325
for (int i = 0; i < totalTagCount; i++) {
2426
Map<Key, int[]> tag = new HashMap<>();

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/clientbound/ClientboundLoginPacket.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class ClientboundLoginPacket implements MinecraftPacket {
2424
private final boolean enableRespawnScreen;
2525
private final boolean doLimitedCrafting;
2626
private final PlayerSpawnInfo commonPlayerSpawnInfo;
27+
private final boolean onlineMode;
2728
private final boolean enforcesSecureChat;
2829

2930
public ClientboundLoginPacket(ByteBuf in) {
@@ -41,6 +42,7 @@ public ClientboundLoginPacket(ByteBuf in) {
4142
this.enableRespawnScreen = in.readBoolean();
4243
this.doLimitedCrafting = in.readBoolean();
4344
this.commonPlayerSpawnInfo = MinecraftTypes.readPlayerSpawnInfo(in);
45+
this.onlineMode = in.readBoolean();
4446
this.enforcesSecureChat = in.readBoolean();
4547
}
4648

@@ -59,6 +61,7 @@ public void serialize(ByteBuf out) {
5961
out.writeBoolean(this.enableRespawnScreen);
6062
out.writeBoolean(this.doLimitedCrafting);
6163
MinecraftTypes.writePlayerSpawnInfo(out, this.commonPlayerSpawnInfo);
64+
out.writeBoolean(this.onlineMode);
6265
out.writeBoolean(this.enforcesSecureChat);
6366
}
6467

protocol/src/main/java/org/geysermc/mcprotocollib/protocol/packet/ingame/serverbound/player/ServerboundSpectateEntityPacket.java

Lines changed: 0 additions & 29 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.geysermc.mcprotocollib.protocol.packet.ingame.serverbound.player;
2+
3+
import io.netty.buffer.ByteBuf;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.With;
7+
import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket;
8+
import org.geysermc.mcprotocollib.protocol.codec.MinecraftTypes;
9+
10+
import java.util.OptionalInt;
11+
12+
@Data
13+
@With
14+
@AllArgsConstructor
15+
public class ServerboundSpectatorActionPacket implements MinecraftPacket {
16+
private final OptionalInt entityId;
17+
18+
public ServerboundSpectatorActionPacket(ByteBuf in) {
19+
if (in.readBoolean()) {
20+
this.entityId = OptionalInt.of(MinecraftTypes.readVarInt(in));
21+
} else {
22+
this.entityId = OptionalInt.empty();
23+
}
24+
}
25+
26+
@Override
27+
public void serialize(ByteBuf out) {
28+
if (this.entityId.isPresent()) {
29+
out.writeBoolean(true);
30+
MinecraftTypes.writeVarInt(out, this.entityId.getAsInt());
31+
} else {
32+
out.writeBoolean(false);
33+
}
34+
}
35+
36+
@Override
37+
public boolean shouldRunOnGameThread() {
38+
return true;
39+
}
40+
}
34 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)