Merge branch 'master' into feature/new-protocol-lib

This commit is contained in:
RednedEpic 2020-02-14 17:58:53 -06:00
commit e6d166d4d4
8 changed files with 46 additions and 20 deletions

View file

@ -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,7 +193,8 @@ public class Entity {
metadata.put(EntityData.NAMETAG, MessageUtils.getBedrockMessage(name));
break;
case 3: // is custom name visible
metadata.put(EntityData.ALWAYS_SHOW_NAMETAG, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
if (!this.is(PlayerEntity.class))
metadata.put(EntityData.ALWAYS_SHOW_NAMETAG, (byte) ((boolean) entityMetadata.getValue() ? 1 : 0));
break;
case 4: // silent
metadata.getFlags().setFlag(EntityFlag.SILENT, (boolean) entityMetadata.getValue());
@ -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);

View file

@ -27,6 +27,7 @@ package org.geysermc.connector.entity;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.ContainerId;
import com.nukkitx.protocol.bedrock.data.EntityData;
import com.nukkitx.protocol.bedrock.data.ItemData;
import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket;
@ -42,11 +43,12 @@ import org.geysermc.connector.network.session.GeyserSession;
@Setter
public class LivingEntity extends Entity {
protected ItemData helmet;
protected ItemData chestplate;
protected ItemData leggings;
protected ItemData boots;
protected ItemData hand = ItemData.of(0, (short) 0, 0);
protected ItemData helmet = ItemData.AIR;
protected ItemData chestplate = ItemData.AIR;
protected ItemData leggings = ItemData.AIR;
protected ItemData boots = ItemData.AIR;
protected ItemData hand = ItemData.AIR;
protected ItemData offHand = ItemData.AIR;
public LivingEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position, motion, rotation);
@ -80,11 +82,22 @@ public class LivingEntity extends Entity {
armorEquipmentPacket.setLeggings(leggings);
armorEquipmentPacket.setBoots(boots);
MobEquipmentPacket mobEquipmentPacket = new MobEquipmentPacket();
mobEquipmentPacket.setRuntimeEntityId(geyserId);
mobEquipmentPacket.setItem(hand);
MobEquipmentPacket handPacket = new MobEquipmentPacket();
handPacket.setRuntimeEntityId(geyserId);
handPacket.setItem(hand);
handPacket.setHotbarSlot(-1);
handPacket.setInventorySlot(0);
handPacket.setContainerId(ContainerId.INVENTORY);
MobEquipmentPacket offHandPacket = new MobEquipmentPacket();
offHandPacket.setRuntimeEntityId(geyserId);
offHandPacket.setItem(offHand);
offHandPacket.setHotbarSlot(-1);
offHandPacket.setInventorySlot(0);
offHandPacket.setContainerId(ContainerId.OFFHAND);
session.getUpstream().sendPacket(armorEquipmentPacket);
session.getUpstream().sendPacket(mobEquipmentPacket);
session.getUpstream().sendPacket(handPacket);
session.getUpstream().sendPacket(offHandPacket);
}
}

View file

@ -80,10 +80,13 @@ public class PlayerEntity extends LivingEntity {
addPlayerPacket.getAdventureSettings().setPlayerPermission(PlayerPermission.VISITOR);
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) {

View file

@ -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) {

View file

@ -70,7 +70,7 @@ public class JavaEntityEquipmentTranslator extends PacketTranslator<ServerEntity
livingEntity.setHand(item);
break;
case OFF_HAND:
// TODO: livingEntity.setOffHand(item);
livingEntity.setOffHand(item);
break;
}

View file

@ -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);
for (EntityMetadata metadata : packet.getMetadata()) {
entity.updateBedrockMetadata(metadata, session);
}
}
}

View file

@ -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()) {

View file

@ -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()) {