3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00

Merge pull request #165 from AJ-Ferguson/mob-equipment-fixes

Equipment fixes
Dieser Commit ist enthalten in:
Redned 2020-02-13 23:18:11 -06:00 committet von GitHub
Commit 5913cb6164
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
8 geänderte Dateien mit 46 neuen und 20 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

@ -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);
}
}

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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);
}
}
}

Datei anzeigen

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

Datei anzeigen

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