mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Reset metadata and attributes if needed when respawning
This commit is contained in:
parent
a24f684123
commit
9cc6b07108
3 changed files with 29 additions and 1 deletions
|
@ -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
|
||||
* 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 ((isLeft && leftParrot != null) || (!isLeft && rightParrot != null)) {
|
||||
// No need to update a parrot's data when it already exists
|
||||
|
|
|
@ -258,10 +258,28 @@ public class SessionPlayerEntity extends PlayerEntity {
|
|||
public void resetMetadata() {
|
||||
// Reset all metadata to their default values
|
||||
// This is used when a player respawns
|
||||
this.flags.clear();
|
||||
this.initializeMetadata();
|
||||
|
||||
// Reset air
|
||||
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() {
|
||||
|
|
|
@ -49,6 +49,16 @@ public class JavaRespawnTranslator extends PacketTranslator<ClientboundRespawnPa
|
|||
SessionPlayerEntity entity = session.getPlayerEntity();
|
||||
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);
|
||||
|
||||
entity.setHealth(entity.getMaxHealth());
|
||||
|
|
Loading…
Reference in a new issue