Skip to content

Commit

Permalink
23w33a + 23w35a + implement PlayerSpawnInfo object
Browse files Browse the repository at this point in the history
  • Loading branch information
basaigh committed Aug 30, 2023
1 parent 7a86e7e commit c7a653f
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ public class MinecraftCodec {
}

public static final PacketCodec CODEC = PacketCodec.builder()
.protocolVersion((1 << 30) | 145)
.protocolVersion((1 << 30) | 147)
.helper(() -> new MinecraftCodecHelper(LEVEL_EVENTS, SOUND_NAMES))
.minecraftVersion("23w32a")
.minecraftVersion("23w35a")
.state(ProtocolState.HANDSHAKE, PacketStateCodec.builder()
.registerServerboundPacket(0x00, ClientIntentionPacket.class, ClientIntentionPacket::new)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.github.steveice10.mc.protocol.data.game.entity.metadata.VillagerData;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import com.github.steveice10.mc.protocol.data.game.entity.player.BlockBreakStage;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerSpawnInfo;
import com.github.steveice10.mc.protocol.data.game.entity.type.PaintingType;
import com.github.steveice10.mc.protocol.data.game.level.LightUpdateData;
import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType;
Expand Down Expand Up @@ -442,6 +444,31 @@ public void writeGlobalPos(ByteBuf buf, GlobalPos pos) {
this.writePosition(buf, pos.getPosition());
}

public PlayerSpawnInfo readPlayerSpawnInfo(ByteBuf buf) {
String dimension = this.readString(buf);
String worldName = this.readString(buf);
long hashedSeed = buf.readLong();
GameMode gameMode = GameMode.byId(buf.readByte());
GameMode previousGamemode = GameMode.byNullableId(buf.readByte());
boolean debug = buf.readBoolean();
boolean flat = buf.readBoolean();
GlobalPos lastDeathPos = this.readNullable(buf, this::readGlobalPos);
int portalCooldown = this.readVarInt(buf);
return new PlayerSpawnInfo(dimension, worldName, hashedSeed, gameMode, previousGamemode, debug, flat, lastDeathPos, portalCooldown);
}

public void writePlayerSpawnInfo(ByteBuf buf, PlayerSpawnInfo info) {
this.writeString(buf, info.getDimension());
this.writeString(buf, info.getWorldName());
buf.writeLong(info.getHashedSeed());
buf.writeByte(info.getGameMode().ordinal());
buf.writeByte(GameMode.toNullableId(info.getPreviousGamemode()));
buf.writeBoolean(info.isDebug());
buf.writeBoolean(info.isFlat());
this.writeNullable(buf, info.getLastDeathPos(), this::writeGlobalPos);
this.writeVarInt(buf, info.getPortalCooldown());
}

public ParticleType readParticleType(ByteBuf buf) {
return ParticleType.from(this.readVarInt(buf));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@
@AllArgsConstructor
public class Advancement {
private final @NonNull String id;
private final @NonNull List<String> criteria;
private final @NonNull List<List<String>> requirements;
private final String parentId;
private final DisplayData displayData;
private final boolean sendsTelemetryEvent;

public Advancement(@NonNull String id, @NonNull List<String> criteria, @NonNull List<List<String>> requirements, boolean sendsTelemetryEvent) {
this(id, criteria, requirements, null, null, sendsTelemetryEvent);
public Advancement(@NonNull String id, @NonNull List<List<String>> requirements, boolean sendsTelemetryEvent) {
this(id, requirements, null, null, sendsTelemetryEvent);
}

public Advancement(@NonNull String id, @NonNull List<String> criteria, @NonNull List<List<String>> requirements, String parentId, boolean sendsTelemetryEvent) {
this(id, criteria, requirements, parentId, null, sendsTelemetryEvent);
public Advancement(@NonNull String id, @NonNull List<List<String>> requirements, String parentId, boolean sendsTelemetryEvent) {
this(id, requirements, parentId, null, sendsTelemetryEvent);
}

public Advancement(@NonNull String id, @NonNull List<String> criteria, @NonNull List<List<String>> requirements, DisplayData displayData, boolean sendsTelemetryEvent) {
this(id, criteria, requirements, null, displayData, sendsTelemetryEvent);
public Advancement(@NonNull String id, @NonNull List<List<String>> requirements, DisplayData displayData, boolean sendsTelemetryEvent) {
this(id, requirements, null, displayData, sendsTelemetryEvent);
}

@Data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.steveice10.mc.protocol.data.game.entity.player;

import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import org.jetbrains.annotations.Nullable;

@Data
@AllArgsConstructor
public class PlayerSpawnInfo {
private final @NonNull String dimension;
private final @NonNull String worldName;
private final long hashedSeed;
private final @NonNull GameMode gameMode;
private final @Nullable GameMode previousGamemode;
private final boolean debug;
private final boolean flat;
private final @Nullable GlobalPos lastDeathPos;
private final int portalCooldown;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,12 @@ public enum BuiltinSound implements Sound {
ENTITY_SPIDER_STEP("entity.spider.step"),
ENTITY_SPLASH_POTION_BREAK("entity.splash_potion.break"),
ENTITY_SPLASH_POTION_THROW("entity.splash_potion.throw"),
BLOCK_SPONGE_BREAK("block.sponge.break"),
BLOCK_SPONGE_FALL("block.sponge.fall"),
BLOCK_SPONGE_HIT("block.sponge.hit"),
BLOCK_SPONGE_PLACE("block.sponge.place"),
BLOCK_SPONGE_STEP("block.sponge.step"),
BLOCK_SPONGE_ABSORB("block.sponge.absorb"),
ITEM_SPYGLASS_USE("item.spyglass.use"),
ITEM_SPYGLASS_STOP_USING("item.spyglass.stop_using"),
ENTITY_SQUID_AMBIENT("entity.squid.ambient"),
Expand Down Expand Up @@ -1409,6 +1415,11 @@ public enum BuiltinSound implements Sound {
BLOCK_WET_GRASS_HIT("block.wet_grass.hit"),
BLOCK_WET_GRASS_PLACE("block.wet_grass.place"),
BLOCK_WET_GRASS_STEP("block.wet_grass.step"),
BLOCK_WET_SPONGE_BREAK("block.wet_sponge.break"),
BLOCK_WET_SPONGE_FALL("block.wet_sponge.fall"),
BLOCK_WET_SPONGE_HIT("block.wet_sponge.hit"),
BLOCK_WET_SPONGE_PLACE("block.wet_sponge.place"),
BLOCK_WET_SPONGE_STEP("block.wet_sponge.step"),
ENTITY_WITCH_AMBIENT("entity.witch.ambient"),
ENTITY_WITCH_CELEBRATE("entity.witch.celebrate"),
ENTITY_WITCH_DEATH("entity.witch.death"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerSpawnInfo;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
Expand All @@ -26,15 +27,7 @@ public class ClientboundLoginPacket implements MinecraftPacket {
private final int simulationDistance;
private final boolean reducedDebugInfo;
private final boolean enableRespawnScreen;
private final @NonNull String dimension;
private final @NonNull String worldName;
private final long hashedSeed;
private final @NonNull GameMode gameMode;
private final @Nullable GameMode previousGamemode;
private final boolean debug;
private final boolean flat;
private final @Nullable GlobalPos lastDeathPos;
private final int portalCooldown;
private final PlayerSpawnInfo commonPlayerSpawnInfo;

This comment has been minimized.

Copy link
@Konicai

Konicai Aug 30, 2023

Member

why the common?

This comment has been minimized.

Copy link
@basaigh

basaigh Aug 30, 2023

Author Member

It's by no means necessary, I just personally prefer to stay consistent with mojang's names.


public ClientboundLoginPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
this.entityId = in.readInt();
Expand All @@ -49,19 +42,7 @@ public ClientboundLoginPacket(ByteBuf in, MinecraftCodecHelper helper) throws IO
this.simulationDistance = helper.readVarInt(in);
this.reducedDebugInfo = in.readBoolean();
this.enableRespawnScreen = in.readBoolean();
this.dimension = helper.readString(in);
this.worldName = helper.readString(in);
this.hashedSeed = in.readLong();
this.gameMode = GameMode.byId(in.readByte());
this.previousGamemode = GameMode.byNullableId(in.readByte());
this.debug = in.readBoolean();
this.flat = in.readBoolean();
if (in.readBoolean()) {
this.lastDeathPos = helper.readGlobalPos(in);
} else {
this.lastDeathPos = null;
}
this.portalCooldown = helper.readVarInt(in);
this.commonPlayerSpawnInfo = helper.readPlayerSpawnInfo(in);
}

@Override
Expand All @@ -77,17 +58,6 @@ public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOExcepti
helper.writeVarInt(out, this.simulationDistance);
out.writeBoolean(this.reducedDebugInfo);
out.writeBoolean(this.enableRespawnScreen);
helper.writeString(out, this.dimension);
helper.writeString(out, this.worldName);
out.writeLong(this.hashedSeed);
out.writeByte(this.gameMode.ordinal());
out.writeByte(GameMode.toNullableId(this.previousGamemode));
out.writeBoolean(this.debug);
out.writeBoolean(this.flat);
out.writeBoolean(this.lastDeathPos != null);
if (this.lastDeathPos != null) {
helper.writeGlobalPos(out, this.lastDeathPos);
}
helper.writeVarInt(out, this.portalCooldown);
helper.writePlayerSpawnInfo(out, this.commonPlayerSpawnInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.GlobalPos;
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerSpawnInfo;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand All @@ -18,45 +19,21 @@ public class ClientboundRespawnPacket implements MinecraftPacket {
private static final byte KEEP_ATTRIBUTES = 1;
private static final byte KEEP_ENTITY_DATA = 2;

private final @NonNull String dimension;
private final @NonNull String worldName;
private final long hashedSeed;
private final @NonNull GameMode gamemode;
private final @Nullable GameMode previousGamemode;
private final boolean debug;
private final boolean flat;
private final @Nullable GlobalPos lastDeathPos;
private final int portalCooldown;
private final PlayerSpawnInfo commonPlayerSpawnInfo;
// The following two are the dataToKeep byte
private final boolean keepMetadata;
private final boolean keepAttributes;

public ClientboundRespawnPacket(ByteBuf in, MinecraftCodecHelper helper) {
this.dimension = helper.readString(in);
this.worldName = helper.readString(in);
this.hashedSeed = in.readLong();
this.gamemode = GameMode.byId(in.readUnsignedByte()); // Intentionally unsigned as of 1.19.3
this.previousGamemode = GameMode.byNullableId(in.readByte());
this.debug = in.readBoolean();
this.flat = in.readBoolean();
this.lastDeathPos = helper.readNullable(in, helper::readGlobalPos);
this.portalCooldown = helper.readVarInt(in);
this.commonPlayerSpawnInfo = helper.readPlayerSpawnInfo(in);
byte dataToKeep = in.readByte();
this.keepAttributes = (dataToKeep & KEEP_ATTRIBUTES) != 0;
this.keepMetadata = (dataToKeep & KEEP_ENTITY_DATA) != 0;
}

@Override
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
helper.writeString(out, this.dimension);
helper.writeString(out, this.worldName);
out.writeLong(this.hashedSeed);
out.writeByte(this.gamemode.ordinal());
out.writeByte(GameMode.toNullableId(this.previousGamemode));
out.writeBoolean(this.debug);
out.writeBoolean(this.flat);
helper.writeNullable(out, this.lastDeathPos, helper::writeGlobalPos);
helper.writeVarInt(out, this.portalCooldown);
helper.writePlayerSpawnInfo(out, this.commonPlayerSpawnInfo);
byte dataToKeep = 0;
if (this.keepMetadata) {
dataToKeep += KEEP_ENTITY_DATA;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ClientboundUpdateAdvancementsPacket(ByteBuf in, MinecraftCodecHelper help
this.advancements = new Advancement[helper.readVarInt(in)];
for (int i = 0; i < this.advancements.length; i++) {
String id = helper.readString(in);
String parentId = in.readBoolean() ? helper.readString(in) : null;
String parentId = helper.readNullable(in, helper::readString);
DisplayData displayData = null;
if (in.readBoolean()) {
Component title = helper.readComponent(in);
Expand All @@ -72,12 +72,6 @@ public ClientboundUpdateAdvancementsPacket(ByteBuf in, MinecraftCodecHelper help
displayData = new DisplayData(title, description, icon, frameType, showToast, hidden, posX, posY, backgroundTexture);
}

List<String> criteria = new ArrayList<>();
int criteriaCount = helper.readVarInt(in);
for (int j = 0; j < criteriaCount; j++) {
criteria.add(helper.readString(in));
}

List<List<String>> requirements = new ArrayList<>();
int requirementCount = helper.readVarInt(in);
for (int j = 0; j < requirementCount; j++) {
Expand All @@ -92,7 +86,7 @@ public ClientboundUpdateAdvancementsPacket(ByteBuf in, MinecraftCodecHelper help

boolean sendTelemetryEvent = in.readBoolean();

this.advancements[i] = new Advancement(id, criteria, requirements, parentId, displayData, sendTelemetryEvent);
this.advancements[i] = new Advancement(id, requirements, parentId, displayData, sendTelemetryEvent);
}

this.removedAdvancements = new String[helper.readVarInt(in)];
Expand Down Expand Up @@ -165,11 +159,6 @@ public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOExcepti
out.writeBoolean(false);
}

helper.writeVarInt(out, advancement.getCriteria().size());
for (String criterion : advancement.getCriteria()) {
helper.writeString(out, criterion);
}

helper.writeVarInt(out, advancement.getRequirements().size());
for (List<String> requirement : advancement.getRequirements()) {
helper.writeVarInt(out, requirement.size());
Expand Down
Binary file modified src/main/resources/networkCodec.nbt
Binary file not shown.

0 comments on commit c7a653f

Please sign in to comment.