mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-12-29 00:52:27 -05:00
24w04a
This commit is contained in:
parent
8f1834d906
commit
7cdfa6ef36
10 changed files with 64 additions and 11 deletions
|
@ -83,7 +83,7 @@ public class MinecraftProtocolTest {
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
new PlayerSpawnInfo(
|
new PlayerSpawnInfo(
|
||||||
"minecraft:overworld",
|
0,
|
||||||
"minecraft:world",
|
"minecraft:world",
|
||||||
100,
|
100,
|
||||||
GameMode.SURVIVAL,
|
GameMode.SURVIVAL,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.github.steveice10.mc.auth.data.GameProfile;
|
||||||
import com.github.steveice10.mc.auth.exception.request.RequestException;
|
import com.github.steveice10.mc.auth.exception.request.RequestException;
|
||||||
import com.github.steveice10.mc.auth.service.SessionService;
|
import com.github.steveice10.mc.auth.service.SessionService;
|
||||||
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
import com.github.steveice10.mc.protocol.data.ProtocolState;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.RegistryEntry;
|
||||||
import com.github.steveice10.mc.protocol.data.status.PlayerInfo;
|
import com.github.steveice10.mc.protocol.data.status.PlayerInfo;
|
||||||
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
|
import com.github.steveice10.mc.protocol.data.status.ServerStatusInfo;
|
||||||
import com.github.steveice10.mc.protocol.data.status.VersionInfo;
|
import com.github.steveice10.mc.protocol.data.status.VersionInfo;
|
||||||
|
@ -28,6 +29,10 @@ import com.github.steveice10.mc.protocol.packet.status.clientbound.ClientboundSt
|
||||||
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundPingRequestPacket;
|
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundPingRequestPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundStatusRequestPacket;
|
import com.github.steveice10.mc.protocol.packet.status.serverbound.ServerboundStatusRequestPacket;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import com.github.steveice10.packetlib.Session;
|
import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
|
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
|
||||||
import com.github.steveice10.packetlib.event.session.DisconnectingEvent;
|
import com.github.steveice10.packetlib.event.session.DisconnectingEvent;
|
||||||
|
@ -40,8 +45,11 @@ import java.security.KeyPair;
|
||||||
import java.security.KeyPairGenerator;
|
import java.security.KeyPairGenerator;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
|
import java.util.AbstractList;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -131,7 +139,23 @@ public class ServerListener extends SessionAdapter {
|
||||||
new Thread(new UserAuthTask(session, key)).start();
|
new Thread(new UserAuthTask(session, key)).start();
|
||||||
} else if (packet instanceof ServerboundLoginAcknowledgedPacket) {
|
} else if (packet instanceof ServerboundLoginAcknowledgedPacket) {
|
||||||
((MinecraftProtocol) session.getPacketProtocol()).setState(ProtocolState.CONFIGURATION);
|
((MinecraftProtocol) session.getPacketProtocol()).setState(ProtocolState.CONFIGURATION);
|
||||||
session.send(new ClientboundRegistryDataPacket(networkCodec));
|
|
||||||
|
// Credit ViaVersion: https://github.com/ViaVersion/ViaVersion/blob/dev/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java
|
||||||
|
for (Map.Entry<String, Tag> entry : networkCodec.getValue().entrySet()) {
|
||||||
|
CompoundTag entryTag = (CompoundTag) entry.getValue();
|
||||||
|
StringTag typeTag = entryTag.get("type");
|
||||||
|
ListTag valueTag = entryTag.get("value");
|
||||||
|
List<RegistryEntry> entries = new ArrayList<>();
|
||||||
|
for (Tag tag : valueTag) {
|
||||||
|
CompoundTag compoundTag = (CompoundTag) tag;
|
||||||
|
StringTag nameTag = compoundTag.get("name");
|
||||||
|
int id = ((IntTag) compoundTag.get("id")).getValue();
|
||||||
|
entries.add(id, new RegistryEntry(nameTag.getValue(), compoundTag.get("element")));
|
||||||
|
}
|
||||||
|
|
||||||
|
session.send(new ClientboundRegistryDataPacket(typeTag.getValue(), entries));
|
||||||
|
}
|
||||||
|
|
||||||
session.send(new ClientboundFinishConfigurationPacket());
|
session.send(new ClientboundFinishConfigurationPacket());
|
||||||
}
|
}
|
||||||
} else if (protocol.getState() == ProtocolState.STATUS) {
|
} else if (protocol.getState() == ProtocolState.STATUS) {
|
||||||
|
|
|
@ -216,9 +216,9 @@ public class MinecraftCodec {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final PacketCodec CODEC = PacketCodec.builder()
|
public static final PacketCodec CODEC = PacketCodec.builder()
|
||||||
.protocolVersion((1 << 30) | 171)
|
.protocolVersion((1 << 30) | 173)
|
||||||
.helper(() -> new MinecraftCodecHelper(LEVEL_EVENTS, SOUND_NAMES))
|
.helper(() -> new MinecraftCodecHelper(LEVEL_EVENTS, SOUND_NAMES))
|
||||||
.minecraftVersion("24w03a")
|
.minecraftVersion("24w04a")
|
||||||
.state(ProtocolState.HANDSHAKE, PacketStateCodec.builder()
|
.state(ProtocolState.HANDSHAKE, PacketStateCodec.builder()
|
||||||
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
|
.registerServerboundPacket(ClientIntentionPacket.class, ClientIntentionPacket::new)
|
||||||
)
|
)
|
||||||
|
|
|
@ -413,7 +413,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerSpawnInfo readPlayerSpawnInfo(ByteBuf buf) {
|
public PlayerSpawnInfo readPlayerSpawnInfo(ByteBuf buf) {
|
||||||
String dimension = this.readString(buf);
|
int dimension = this.readVarInt(buf);
|
||||||
String worldName = this.readString(buf);
|
String worldName = this.readString(buf);
|
||||||
long hashedSeed = buf.readLong();
|
long hashedSeed = buf.readLong();
|
||||||
GameMode gameMode = GameMode.byId(buf.readByte());
|
GameMode gameMode = GameMode.byId(buf.readByte());
|
||||||
|
@ -426,7 +426,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writePlayerSpawnInfo(ByteBuf buf, PlayerSpawnInfo info) {
|
public void writePlayerSpawnInfo(ByteBuf buf, PlayerSpawnInfo info) {
|
||||||
this.writeString(buf, info.getDimension());
|
this.writeVarInt(buf, info.getDimension());
|
||||||
this.writeString(buf, info.getWorldName());
|
this.writeString(buf, info.getWorldName());
|
||||||
buf.writeLong(info.getHashedSeed());
|
buf.writeLong(info.getHashedSeed());
|
||||||
buf.writeByte(info.getGameMode().ordinal());
|
buf.writeByte(info.getGameMode().ordinal());
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.github.steveice10.mc.protocol.data.game;
|
||||||
|
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class RegistryEntry {
|
||||||
|
private final String id;
|
||||||
|
private final CompoundTag data;
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PlayerSpawnInfo {
|
public class PlayerSpawnInfo {
|
||||||
private final @NonNull String dimension;
|
private final int dimension;
|
||||||
private final @NonNull String worldName;
|
private final @NonNull String worldName;
|
||||||
private final long hashedSeed;
|
private final long hashedSeed;
|
||||||
private final @NonNull GameMode gameMode;
|
private final @NonNull GameMode gameMode;
|
||||||
|
|
|
@ -63,6 +63,7 @@ public enum BuiltinSound implements Sound {
|
||||||
BLOCK_ANVIL_USE("block.anvil.use"),
|
BLOCK_ANVIL_USE("block.anvil.use"),
|
||||||
ENTITY_ARMADILLO_EAT("entity.armadillo.eat"),
|
ENTITY_ARMADILLO_EAT("entity.armadillo.eat"),
|
||||||
ENTITY_ARMADILLO_HURT("entity.armadillo.hurt"),
|
ENTITY_ARMADILLO_HURT("entity.armadillo.hurt"),
|
||||||
|
ENTITY_ARMADILLO_HURT_REDUCED("entity.armadillo.hurt_reduced"),
|
||||||
ENTITY_ARMADILLO_AMBIENT("entity.armadillo.ambient"),
|
ENTITY_ARMADILLO_AMBIENT("entity.armadillo.ambient"),
|
||||||
ENTITY_ARMADILLO_STEP("entity.armadillo.step"),
|
ENTITY_ARMADILLO_STEP("entity.armadillo.step"),
|
||||||
ENTITY_ARMADILLO_DEATH("entity.armadillo.death"),
|
ENTITY_ARMADILLO_DEATH("entity.armadillo.death"),
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.github.steveice10.mc.protocol.packet.configuration.clientbound;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||||
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.RegistryEntry;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
@ -9,19 +10,34 @@ import lombok.Data;
|
||||||
import lombok.With;
|
import lombok.With;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@With
|
@With
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class ClientboundRegistryDataPacket implements MinecraftPacket {
|
public class ClientboundRegistryDataPacket implements MinecraftPacket {
|
||||||
private final CompoundTag registry;
|
private final String registry;
|
||||||
|
private final List<RegistryEntry> entries;
|
||||||
|
|
||||||
public ClientboundRegistryDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
public ClientboundRegistryDataPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||||
this.registry = helper.readAnyTag(in);
|
this.registry = helper.readResourceLocation(in);
|
||||||
|
this.entries = new ArrayList<>();
|
||||||
|
|
||||||
|
int entryCount = helper.readVarInt(in);
|
||||||
|
for (int i = 0; i < entryCount; i++) {
|
||||||
|
this.entries.add(new RegistryEntry(helper.readResourceLocation(in), helper.readAnyTag(in)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||||
helper.writeAnyTag(out, this.registry);
|
helper.writeResourceLocation(out, this.registry);
|
||||||
|
|
||||||
|
helper.writeVarInt(out, this.entries.size());
|
||||||
|
for (RegistryEntry entry : this.entries) {
|
||||||
|
helper.writeResourceLocation(out, entry.getId());
|
||||||
|
helper.writeAnyTag(out, entry.getData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -43,7 +43,7 @@ public class MinecraftProtocolTest {
|
||||||
null,
|
null,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
private static final ClientboundLoginPacket JOIN_GAME_PACKET = new ClientboundLoginPacket(0, false, new String[]{"minecraft:world"}, 0, 16, 16, false, false, false, new PlayerSpawnInfo("overworld", "minecraft:world", 100, GameMode.SURVIVAL, GameMode.SURVIVAL, false, false, null, 100), true);
|
private static final ClientboundLoginPacket JOIN_GAME_PACKET = new ClientboundLoginPacket(0, false, new String[]{"minecraft:world"}, 0, 16, 16, false, false, false, new PlayerSpawnInfo(0, "minecraft:world", 100, GameMode.SURVIVAL, GameMode.SURVIVAL, false, false, null, 100), true);
|
||||||
|
|
||||||
private static Server server;
|
private static Server server;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue