mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix piglin attack animation when switching weapons
This commit is contained in:
parent
e9b309e8fa
commit
ccabd0d8e4
2 changed files with 32 additions and 6 deletions
|
|
@ -42,9 +42,7 @@ public class BasePiglinEntity extends MonsterEntity {
|
|||
public BasePiglinEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
|
||||
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
|
||||
// Both TARGET_EID and BLOCK are needed for melee attack animation
|
||||
if (definition.entityType() == EntityType.PIGLIN_BRUTE) {
|
||||
dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getDefinition(1));
|
||||
}
|
||||
dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getDefinition(1));
|
||||
setFlag(EntityFlag.SHAKING, isShaking());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,15 +29,20 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
import org.cloudburstmc.math.vector.Vector3f;
|
||||
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
|
||||
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
|
||||
import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerId;
|
||||
import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData;
|
||||
import org.cloudburstmc.protocol.bedrock.packet.MobEquipmentPacket;
|
||||
import org.geysermc.geyser.entity.EntityDefinition;
|
||||
import org.geysermc.geyser.inventory.GeyserItemStack;
|
||||
import org.geysermc.geyser.item.Items;
|
||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.session.cache.tags.ItemTag;
|
||||
import org.geysermc.geyser.util.InteractionResult;
|
||||
import org.geysermc.geyser.util.InteractiveTag;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -65,6 +70,32 @@ public class PiglinEntity extends BasePiglinEntity {
|
|||
setFlag(EntityFlag.DANCING, entityMetadata.getPrimitiveValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHand(ItemStack stack) {
|
||||
ItemMapping crossbow = session.getItemMappings().getStoredItems().crossbow();
|
||||
boolean toCrossbow = stack != null && stack.getId() == crossbow.getJavaItem().javaId();
|
||||
|
||||
if (toCrossbow ^ this.hand.getDefinition() == crossbow.getBedrockDefinition()) { // If switching to/from crossbow
|
||||
dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getDefinition(toCrossbow ? 0 : 1));
|
||||
dirtyMetadata.put(EntityDataTypes.CHARGE_AMOUNT, (byte) 0);
|
||||
setFlag(EntityFlag.CHARGED, false);
|
||||
setFlag(EntityFlag.USING_ITEM, false);
|
||||
updateBedrockMetadata();
|
||||
|
||||
if (this.hand.isValid()) {
|
||||
MobEquipmentPacket mobEquipmentPacket = new MobEquipmentPacket();
|
||||
mobEquipmentPacket.setRuntimeEntityId(geyserId);
|
||||
mobEquipmentPacket.setContainerId(ContainerId.INVENTORY);
|
||||
mobEquipmentPacket.setInventorySlot(0);
|
||||
mobEquipmentPacket.setHotbarSlot(-1);
|
||||
mobEquipmentPacket.setItem(ItemData.AIR);
|
||||
session.sendUpstreamPacket(mobEquipmentPacket);
|
||||
}
|
||||
}
|
||||
|
||||
super.setHand(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMainHand(GeyserSession session) {
|
||||
super.updateMainHand(session);
|
||||
|
|
@ -80,9 +111,6 @@ public class PiglinEntity extends BasePiglinEntity {
|
|||
setFlag(EntityFlag.CHARGED, false);
|
||||
setFlag(EntityFlag.USING_ITEM, false);
|
||||
}
|
||||
} else if (this.hand.isValid()) {
|
||||
// Needed for melee attack animation to work, but also breaks crossbow animation
|
||||
dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getDefinition(1));
|
||||
}
|
||||
|
||||
updateBedrockMetadata();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue