fix: update RespawnPacket to use dataToKeep bitset

This commit is contained in:
mworzala 2023-11-18 17:11:28 +02:00
parent 5bcc72b911
commit e146a9393e
No known key found for this signature in database
GPG Key ID: B148F922E64797C7
2 changed files with 14 additions and 6 deletions

View File

@ -487,7 +487,8 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
refreshHealth(); refreshHealth();
sendPacket(new RespawnPacket(getDimensionType().toString(), instance.getDimensionName(), sendPacket(new RespawnPacket(getDimensionType().toString(), instance.getDimensionName(),
0, gameMode, gameMode, false, levelFlat, true, deathLocation, portalCooldown)); 0, gameMode, gameMode, false, levelFlat, RespawnPacket.COPY_ALL,
deathLocation, portalCooldown));
PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(this); PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(this);
EventDispatcher.call(respawnEvent); EventDispatcher.call(respawnEvent);
@ -1039,7 +1040,8 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
final PlayerInfoUpdatePacket addPlayerPacket = getAddPlayerToList(); final PlayerInfoUpdatePacket addPlayerPacket = getAddPlayerToList();
RespawnPacket respawnPacket = new RespawnPacket(getDimensionType().toString(), instance.getDimensionName(), RespawnPacket respawnPacket = new RespawnPacket(getDimensionType().toString(), instance.getDimensionName(),
0, gameMode, gameMode, false, levelFlat, true, deathLocation, portalCooldown); 0, gameMode, gameMode, false, levelFlat, RespawnPacket.COPY_ALL,
deathLocation, portalCooldown);
sendPacket(removePlayerPacket); sendPacket(removePlayerPacket);
sendPacket(destroyEntitiesPacket); sendPacket(destroyEntitiesPacket);
@ -1439,7 +1441,8 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
"The dimension needs to be different than the current one!"); "The dimension needs to be different than the current one!");
this.dimensionType = dimensionType; this.dimensionType = dimensionType;
sendPacket(new RespawnPacket(dimensionType.toString(), dimensionName, sendPacket(new RespawnPacket(dimensionType.toString(), dimensionName,
0, gameMode, gameMode, false, levelFlat, true, deathLocation, portalCooldown)); 0, gameMode, gameMode, false, levelFlat,
RespawnPacket.COPY_ALL, deathLocation, portalCooldown));
refreshClientStateAfterRespawn(); refreshClientStateAfterRespawn();
} }

View File

@ -11,14 +11,19 @@ import static net.minestom.server.network.NetworkBuffer.*;
public record RespawnPacket(String dimensionType, String worldName, public record RespawnPacket(String dimensionType, String worldName,
long hashedSeed, GameMode gameMode, GameMode previousGameMode, long hashedSeed, GameMode gameMode, GameMode previousGameMode,
boolean isDebug, boolean isFlat, boolean copyMeta, boolean isDebug, boolean isFlat, byte dataToCopy,
DeathLocation deathLocation, int portalCooldown) implements ServerPacket { DeathLocation deathLocation, int portalCooldown) implements ServerPacket {
public static final byte COPY_ATTRIBUTES = 0x1;
public static final byte COPY_METADATA = 0x2;
public static final byte COPY_ALL = COPY_ATTRIBUTES | COPY_METADATA;
public RespawnPacket(@NotNull NetworkBuffer reader) { public RespawnPacket(@NotNull NetworkBuffer reader) {
this(reader.read(STRING), reader.read(STRING), this(reader.read(STRING), reader.read(STRING),
reader.read(LONG), GameMode.fromId(reader.read(BYTE)), reader.read(LONG), GameMode.fromId(reader.read(BYTE)),
GameMode.fromId(reader.read(BYTE)), GameMode.fromId(reader.read(BYTE)),
reader.read(BOOLEAN), reader.read(BOOLEAN), reader.read(BOOLEAN), reader.read(BOOLEAN),
reader.read(BOOLEAN), reader.read(DEATH_LOCATION), reader.read(BYTE), reader.read(DEATH_LOCATION),
reader.read(VAR_INT)); reader.read(VAR_INT));
} }
@ -31,7 +36,7 @@ public record RespawnPacket(String dimensionType, String worldName,
writer.write(BYTE, previousGameMode.id()); writer.write(BYTE, previousGameMode.id());
writer.write(BOOLEAN, isDebug); writer.write(BOOLEAN, isDebug);
writer.write(BOOLEAN, isFlat); writer.write(BOOLEAN, isFlat);
writer.write(BOOLEAN, copyMeta); writer.write(BYTE, dataToCopy);
writer.write(DEATH_LOCATION, deathLocation); writer.write(DEATH_LOCATION, deathLocation);
writer.write(VAR_INT, portalCooldown); writer.write(VAR_INT, portalCooldown);
} }