forked from GeyserMC/Geyser
Fix new player entity data getting lost while loading skin
This commit is contained in:
parent
fa7324e1f5
commit
35bf1b455e
6 changed files with 23 additions and 10 deletions
|
@ -154,6 +154,8 @@ public class Entity {
|
|||
}
|
||||
|
||||
public void updateBedrockAttributes(GeyserSession session) {
|
||||
if (!valid) return;
|
||||
|
||||
List<com.nukkitx.protocol.bedrock.data.Attribute> attributes = new ArrayList<>();
|
||||
for (Map.Entry<AttributeType, Attribute> entry : this.attributes.entrySet()) {
|
||||
if (!entry.getValue().getType().isBedrockAttribute())
|
||||
|
@ -191,6 +193,7 @@ public class Entity {
|
|||
metadata.put(EntityData.NAMETAG, MessageUtils.getBedrockMessage(name));
|
||||
break;
|
||||
case 3: // is custom name visible
|
||||
if (!this.is(PlayerEntity.class))
|
||||
metadata.put(EntityData.ALWAYS_SHOW_NAMETAG, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
|
||||
break;
|
||||
case 4: // silent
|
||||
|
@ -201,6 +204,12 @@ public class Entity {
|
|||
break;
|
||||
}
|
||||
|
||||
updateBedrockMetadata(session);
|
||||
}
|
||||
|
||||
public void updateBedrockMetadata(GeyserSession session) {
|
||||
if (!valid) return;
|
||||
|
||||
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
||||
entityDataPacket.setRuntimeEntityId(geyserId);
|
||||
entityDataPacket.getMetadata().putAll(metadata);
|
||||
|
|
|
@ -81,10 +81,13 @@ public class PlayerEntity extends LivingEntity {
|
|||
addPlayerPacket.setCustomFlags(0);
|
||||
addPlayerPacket.setDeviceId("");
|
||||
addPlayerPacket.setPlatformChatId("");
|
||||
addPlayerPacket.getMetadata().putAll(getMetadata());
|
||||
addPlayerPacket.getMetadata().putAll(metadata);
|
||||
|
||||
valid = true;
|
||||
session.getUpstream().sendPacket(addPlayerPacket);
|
||||
|
||||
updateEquipment(session);
|
||||
updateBedrockAttributes(session);
|
||||
}
|
||||
|
||||
public void sendPlayer(GeyserSession session) {
|
||||
|
|
|
@ -56,9 +56,13 @@ public class EntityCache {
|
|||
|
||||
public void spawnEntity(Entity entity) {
|
||||
entity.moveAbsolute(entity.getPosition(), entity.getRotation().getX(), entity.getRotation().getY());
|
||||
cacheEntity(entity);
|
||||
entity.spawnEntity(session);
|
||||
}
|
||||
|
||||
public void cacheEntity(Entity entity) {
|
||||
entityIdTranslations.put(entity.getEntityId(), entity.getGeyserId());
|
||||
entities.put(entity.getGeyserId(), entity);
|
||||
entity.spawnEntity(session);
|
||||
}
|
||||
|
||||
public boolean removeEntity(Entity entity, boolean force) {
|
||||
|
|
|
@ -41,12 +41,8 @@ public class JavaEntityMetadataTranslator extends PacketTranslator<ServerEntityM
|
|||
}
|
||||
if (entity == null) return;
|
||||
|
||||
if (entity.isValid()) {
|
||||
for (EntityMetadata metadata : packet.getMetadata()) {
|
||||
entity.updateBedrockMetadata(metadata, session);
|
||||
}
|
||||
} else {
|
||||
entity.spawnEntity(session);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class JavaEntityPropertiesTranslator extends PacketTranslator<ServerEntit
|
|||
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
|
||||
entity = session.getPlayerEntity();
|
||||
}
|
||||
if (entity == null || !entity.isValid()) return;
|
||||
if (entity == null) return;
|
||||
|
||||
for (Attribute attribute : packet.getAttributes()) {
|
||||
switch (attribute.getType()) {
|
||||
|
|
|
@ -50,6 +50,7 @@ public class JavaSpawnPlayerTranslator extends PacketTranslator<ServerSpawnPlaye
|
|||
entity.setEntityId(packet.getEntityId());
|
||||
entity.setPosition(position);
|
||||
entity.setRotation(rotation);
|
||||
session.getEntityCache().cacheEntity(entity);
|
||||
|
||||
// async skin loading
|
||||
if (session.getUpstream().isInitialized()) {
|
||||
|
|
Loading…
Reference in a new issue