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 <toy.fighter1@gmail.com>
This commit is contained in:
Arktisfox 2020-07-30 22:10:55 -04:00 committed by GitHub
parent f7ac078ead
commit 54bee1f868
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 10 deletions

View file

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

View file

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

View file

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

View file

@ -55,13 +55,21 @@ public class ItemRegistry {
public static final List<StartGamePacket.ItemEntry> ITEMS = new ArrayList<>();
public static final Int2ObjectMap<ItemEntry> 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;