Skip to content

Commit

Permalink
Small entity metadata fix, other player bow implementation (GeyserMC#685
Browse files Browse the repository at this point in the history
)

* 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 <[email protected]>
  • Loading branch information
Arktisfox and Camotoy authored Jul 31, 2020
1 parent f7ac078 commit 54bee1f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,6 @@ public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession s
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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand All @@ -39,6 +40,7 @@
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;
Expand All @@ -63,6 +65,16 @@ public LivingEntity(long entityId, long geyserId, EntityType entityType, Vector3
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 54bee1f

Please sign in to comment.