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