From 54bee1f8688d19758925b78b40bd003c323aa8f2 Mon Sep 17 00:00:00 2001 From: Arktisfox <65837019+Arktisfox@users.noreply.github.com> Date: Thu, 30 Jul 2020 22:10:55 -0400 Subject: [PATCH] Small entity metadata fix, other player bow implementation (#685) * Move blocking case to LivingEntity, and make other players bows animate. This moves metadata ID 7 to LivingEntity, it's proper place. It also sets the 'USING_ITEM' flag which animates other players bows. * Add skeleton aiming support Skeletons don't have support of pushing their bows back on Bedrock, but this allows them to hold their arms up Co-authored-by: DoctorMacc --- .../org/geysermc/connector/entity/Entity.java | 6 ------ .../geysermc/connector/entity/LivingEntity.java | 12 ++++++++++++ .../living/monster/AbstractSkeletonEntity.java | 13 +++++++++++++ .../network/translators/item/ItemRegistry.java | 16 ++++++++++++---- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/Entity.java b/connector/src/main/java/org/geysermc/connector/entity/Entity.java index e4823b51..1db5d252 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/Entity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/Entity.java @@ -364,12 +364,6 @@ public class Entity { metadata.put(EntityData.PLAYER_FLAGS, (byte) 0); } break; - case 7: // blocking - if (entityMetadata.getType() == MetadataType.BYTE) { - byte xd = (byte) entityMetadata.getValue(); - metadata.getFlags().setFlag(EntityFlag.BLOCKING, (xd & 0x01) == 0x01); - } - break; } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java index 01bd9042..ae9eaee5 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/LivingEntity.java @@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadat import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.AttributeData; import com.nukkitx.protocol.bedrock.data.entity.EntityData; +import com.nukkitx.protocol.bedrock.data.entity.EntityFlag; import com.nukkitx.protocol.bedrock.data.inventory.ContainerId; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket; @@ -39,6 +40,7 @@ import lombok.Setter; import org.geysermc.connector.entity.attribute.AttributeType; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.utils.AttributeUtils; import java.util.ArrayList; @@ -63,6 +65,16 @@ public class LivingEntity extends Entity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { switch (entityMetadata.getId()) { + case 7: // blocking + byte xd = (byte) entityMetadata.getValue(); + + //blocking gets triggered when using a bow, but if we set USING_ITEM for all items, it may look like + //you're "mining" with ex. a shield. + boolean isUsingShield = (getHand().getId() == ItemRegistry.SHIELD.getBedrockId() || + getHand().equals(ItemData.AIR) && getOffHand().getId() == ItemRegistry.SHIELD.getBedrockId()); + metadata.getFlags().setFlag(EntityFlag.USING_ITEM, (xd & 0x01) == 0x01 && !isUsingShield); + metadata.getFlags().setFlag(EntityFlag.BLOCKING, (xd & 0x01) == 0x01); + break; case 8: metadata.put(EntityData.HEALTH, entityMetadata.getValue()); break; diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/AbstractSkeletonEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/AbstractSkeletonEntity.java index ff98d313..ff48d347 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/monster/AbstractSkeletonEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/AbstractSkeletonEntity.java @@ -25,12 +25,25 @@ package org.geysermc.connector.entity.living.monster; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.entity.EntityData; import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; public class AbstractSkeletonEntity extends MonsterEntity { public AbstractSkeletonEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { super(entityId, geyserId, entityType, position, motion, rotation); } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + if (entityMetadata.getId() == 14) { + byte xd = (byte) entityMetadata.getValue(); + // A bit of a loophole so the hands get raised - set the target ID to its own ID + metadata.put(EntityData.TARGET_EID, (xd == 4) ? geyserId : 0); + } + super.updateBedrockMetadata(entityMetadata, session); + } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java index d0597ebd..6fc56472 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java @@ -55,13 +55,21 @@ public class ItemRegistry { public static final List ITEMS = new ArrayList<>(); public static final Int2ObjectMap ITEM_ENTRIES = new Int2ObjectOpenHashMap<>(); - // Boat ID, used in BedrockInventoryTransactionTranslator.java + /** + * Boat item entry, used in BedrockInventoryTransactionTranslator.java + */ public static ItemEntry BOAT; - // Gold ID, used in BedrockInventoryTransactionTranslator.java + /** + * Bucket item entry, used in BedrockInventoryTransactionTranslator.java + */ public static ItemEntry BUCKET; - // Gold ID, used in PiglinEntity.java + /** + * Gold item entry, used in PiglinEntity.java + */ public static ItemEntry GOLD; - // Shield ID, used in Entity.java + /** + * Shield item entry, used in Entity.java and LivingEntity.java + */ public static ItemEntry SHIELD; public static int BARRIER_INDEX = 0;