Fix respawn "keep data" translation (#4015)

This commit is contained in:
RK_01 2024-07-13 11:00:12 +02:00 committed by GitHub
parent 465a2354c0
commit 6bbcf7d784
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -24,6 +24,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_14; import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.api.type.types.version.Types1_16; import com.viaversion.viaversion.api.type.types.version.Types1_16;
@ -119,10 +120,13 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
handler(wrapper -> { handler(wrapper -> {
wrapper.write(Types.BYTE, (byte) -1); // Previous gamemode, set to none wrapper.write(Types.BYTE, (byte) -1); // Previous gamemode, set to none
// <= 1.14.4 didn't keep attributes on respawn and 1.15.x always kept them
final boolean keepAttributes = wrapper.user().getProtocolInfo().serverProtocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_15);
String levelType = wrapper.read(Types.STRING); String levelType = wrapper.read(Types.STRING);
wrapper.write(Types.BOOLEAN, false); // debug wrapper.write(Types.BOOLEAN, false); // debug
wrapper.write(Types.BOOLEAN, levelType.equals("flat")); wrapper.write(Types.BOOLEAN, levelType.equals("flat"));
wrapper.write(Types.BOOLEAN, true); // keep all playerdata wrapper.write(Types.BOOLEAN, keepAttributes); // keep player attributes
}); });
} }
}); });
@ -227,4 +231,4 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
public EntityType typeFromId(int type) { public EntityType typeFromId(int type) {
return EntityTypes1_16.getTypeFromId(type); return EntityTypes1_16.getTypeFromId(type);
} }
} }

View File

@ -26,8 +26,8 @@ import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.data.entity.DimensionData; import com.viaversion.viaversion.api.data.entity.DimensionData;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.BlockPosition; import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19; import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData; import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
@ -227,7 +227,7 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPa
map(Types.BYTE); // Previous gamemode map(Types.BYTE); // Previous gamemode
map(Types.BOOLEAN); // Debug map(Types.BOOLEAN); // Debug
map(Types.BOOLEAN); // Flat map(Types.BOOLEAN); // Flat
map(Types.BOOLEAN); // Keep player data map(Types.BOOLEAN); // Keep player attributes
create(Types.OPTIONAL_GLOBAL_POSITION, null); // Last death location create(Types.OPTIONAL_GLOBAL_POSITION, null); // Last death location
handler(worldDataTrackerHandlerByKey()); handler(worldDataTrackerHandlerByKey());
} }
@ -349,4 +349,4 @@ public final class EntityPacketRewriter1_19 extends EntityRewriter<ClientboundPa
public EntityType typeFromId(final int type) { public EntityType typeFromId(final int type) {
return EntityTypes1_19.getTypeFromId(type); return EntityTypes1_19.getTypeFromId(type);
} }
} }