Reset metadata and attributes if needed when respawning

This commit is contained in:
AJ Ferguson 2024-04-13 20:44:15 -04:00
parent a24f684123
commit 9cc6b07108
3 changed files with 29 additions and 1 deletions

View File

@ -307,7 +307,7 @@ public class PlayerEntity extends LivingEntity implements GeyserPlayerEntity {
* Sets the parrot occupying the shoulder. Bedrock Edition requires a full entity whereas Java Edition just * Sets the parrot occupying the shoulder. Bedrock Edition requires a full entity whereas Java Edition just
* spawns it from the NBT data provided * spawns it from the NBT data provided
*/ */
private void setParrot(CompoundTag tag, boolean isLeft) { protected void setParrot(CompoundTag tag, boolean isLeft) {
if (tag != null && !tag.isEmpty()) { if (tag != null && !tag.isEmpty()) {
if ((isLeft && leftParrot != null) || (!isLeft && rightParrot != null)) { if ((isLeft && leftParrot != null) || (!isLeft && rightParrot != null)) {
// No need to update a parrot's data when it already exists // No need to update a parrot's data when it already exists

View File

@ -258,10 +258,28 @@ public class SessionPlayerEntity extends PlayerEntity {
public void resetMetadata() { public void resetMetadata() {
// Reset all metadata to their default values // Reset all metadata to their default values
// This is used when a player respawns // This is used when a player respawns
this.flags.clear();
this.initializeMetadata(); this.initializeMetadata();
// Reset air // Reset air
this.resetAir(); this.resetAir();
// Explicitly reset all metadata not handled by initializeMetadata
setParrot(null, true);
setParrot(null, false);
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
attributesPacket.setRuntimeEntityId(geyserId);
attributesPacket.setAttributes(Collections.singletonList(
new AttributeData("minecraft:absorption", 0.0f, 1024f, 0.0f, 0.0f)));
session.sendUpstreamPacket(attributesPacket);
dirtyMetadata.put(EntityDataTypes.EFFECT_COLOR, 0);
dirtyMetadata.put(EntityDataTypes.EFFECT_AMBIENCE, (byte) 0);
silent = false;
dirtyMetadata.put(EntityDataTypes.FREEZING_EFFECT_STRENGTH, 0f);
} }
public void resetAir() { public void resetAir() {

View File

@ -49,6 +49,16 @@ public class JavaRespawnTranslator extends PacketTranslator<ClientboundRespawnPa
SessionPlayerEntity entity = session.getPlayerEntity(); SessionPlayerEntity entity = session.getPlayerEntity();
PlayerSpawnInfo spawnInfo = packet.getCommonPlayerSpawnInfo(); PlayerSpawnInfo spawnInfo = packet.getCommonPlayerSpawnInfo();
if (!packet.isKeepMetadata()) {
entity.resetMetadata();
}
if (!packet.isKeepAttributes()) {
entity.getAttributes().clear();
entity.setMaxHealth(GeyserAttributeType.MAX_HEALTH.getDefaultValue());
// Relying on the server to resend speed attribute
}
session.setSpawned(false); session.setSpawned(false);
entity.setHealth(entity.getMaxHealth()); entity.setHealth(entity.getMaxHealth());