Search in sources :

Example 1 with EntityEquipmentMessage

use of net.glowstone.net.message.play.entity.EntityEquipmentMessage in project Glowstone by GlowstoneMC.

the class GlowHumanEntity method processArmorChanges.

/**
     * Process changes to the human enitity's armor, and update the entity's armor attributes accordingly.
     */
private void processArmorChanges() {
    GlowPlayer player = null;
    if (this instanceof GlowPlayer) {
        player = ((GlowPlayer) this);
    }
    boolean armorUpdate = false;
    List<EquipmentMonitor.Entry> armorChanges = getEquipmentMonitor().getArmorChanges();
    if (armorChanges.size() > 0) {
        for (EquipmentMonitor.Entry entry : armorChanges) {
            if (player != null && needsArmorUpdate) {
                player.getSession().send(new EntityEquipmentMessage(0, entry.slot, entry.item));
            }
            armorUpdate = true;
        }
    }
    if (armorUpdate) {
        getAttributeManager().setProperty(AttributeManager.Key.KEY_ARMOR, ArmorConstants.getDefense(getEquipment().getArmorContents()));
        getAttributeManager().setProperty(AttributeManager.Key.KEY_ARMOR_TOUGHNESS, ArmorConstants.getToughness(getEquipment().getArmorContents()));
    }
    needsArmorUpdate = true;
}
Also used : EntityEquipmentMessage(net.glowstone.net.message.play.entity.EntityEquipmentMessage)

Example 2 with EntityEquipmentMessage

use of net.glowstone.net.message.play.entity.EntityEquipmentMessage in project Glowstone by GlowstoneMC.

the class GlowLivingEntity method createUpdateMessage.

@Override
public List<Message> createUpdateMessage() {
    List<Message> messages = super.createUpdateMessage();
    messages.addAll(equipmentMonitor.getChanges().stream().map(change -> new EntityEquipmentMessage(id, change.slot, change.item)).collect(Collectors.toList()));
    if (headRotated) {
        messages.add(new EntityHeadRotationMessage(id, Position.getIntHeadYaw(headYaw)));
        headRotated = false;
    }
    attributeManager.applyMessages(messages);
    return messages;
}
Also used : EntityHeadRotationMessage(net.glowstone.net.message.play.entity.EntityHeadRotationMessage) EntityEquipmentMessage(net.glowstone.net.message.play.entity.EntityEquipmentMessage) Message(com.flowpowered.network.Message) EntityRemoveEffectMessage(net.glowstone.net.message.play.entity.EntityRemoveEffectMessage) EntityHeadRotationMessage(net.glowstone.net.message.play.entity.EntityHeadRotationMessage) EntityEffectMessage(net.glowstone.net.message.play.entity.EntityEffectMessage) EntityEquipmentMessage(net.glowstone.net.message.play.entity.EntityEquipmentMessage)

Example 3 with EntityEquipmentMessage

use of net.glowstone.net.message.play.entity.EntityEquipmentMessage in project Glowstone by GlowstoneMC.

the class GlowArmorStand method createSpawnMessage.

@Override
public List<Message> createSpawnMessage() {
    double x = location.getX();
    double y = location.getY();
    double z = location.getZ();
    int yaw = Position.getIntYaw(location);
    int pitch = Position.getIntPitch(location);
    return Arrays.asList(// TODO: once UUID is documented, actually use the appropriate ID here
    new SpawnObjectMessage(id, UUID.randomUUID(), 78, x, y, z, pitch, yaw), new EntityMetadataMessage(id, metadata.getEntryList()), new EntityEquipmentMessage(id, EntityEquipmentMessage.HELD_ITEM, getItemInHand()), new EntityEquipmentMessage(id, EntityEquipmentMessage.BOOTS_SLOT, getBoots()), new EntityEquipmentMessage(id, EntityEquipmentMessage.LEGGINGS_SLOT, getLeggings()), new EntityEquipmentMessage(id, EntityEquipmentMessage.CHESTPLATE_SLOT, getChestplate()), new EntityEquipmentMessage(id, EntityEquipmentMessage.HELMET_SLOT, getHelmet()));
}
Also used : SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) EntityEquipmentMessage(net.glowstone.net.message.play.entity.EntityEquipmentMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage)

Example 4 with EntityEquipmentMessage

use of net.glowstone.net.message.play.entity.EntityEquipmentMessage in project Glowstone by GlowstoneMC.

the class GlowHumanEntity method createSpawnMessage.

////////////////////////////////////////////////////////////////////////////
// Internals
@Override
public List<Message> createSpawnMessage() {
    List<Message> result = new LinkedList<>();
    // spawn player
    double x = location.getX();
    double y = location.getY();
    double z = location.getZ();
    int yaw = Position.getIntYaw(location);
    int pitch = Position.getIntPitch(location);
    result.add(new SpawnPlayerMessage(id, profile.getUniqueId(), x, y, z, yaw, pitch, metadata.getEntryList()));
    // head facing
    result.add(new EntityHeadRotationMessage(id, yaw));
    // equipment
    EntityEquipment equipment = getEquipment();
    result.add(new EntityEquipmentMessage(id, 0, equipment.getItemInHand()));
    for (int i = 0; i < 4; i++) {
        result.add(new EntityEquipmentMessage(id, i + 1, equipment.getArmorContents()[i]));
    }
    return result;
}
Also used : EntityHeadRotationMessage(net.glowstone.net.message.play.entity.EntityHeadRotationMessage) SpawnPlayerMessage(net.glowstone.net.message.play.entity.SpawnPlayerMessage) EntityEquipmentMessage(net.glowstone.net.message.play.entity.EntityEquipmentMessage) Message(com.flowpowered.network.Message) EntityHeadRotationMessage(net.glowstone.net.message.play.entity.EntityHeadRotationMessage) SpawnPlayerMessage(net.glowstone.net.message.play.entity.SpawnPlayerMessage) EntityEquipment(org.bukkit.inventory.EntityEquipment) EntityEquipmentMessage(net.glowstone.net.message.play.entity.EntityEquipmentMessage)

Example 5 with EntityEquipmentMessage

use of net.glowstone.net.message.play.entity.EntityEquipmentMessage in project Glowstone by GlowstoneMC.

the class EntityEquipmentCodec method decode.

@Override
public EntityEquipmentMessage decode(ByteBuf buf) throws IOException {
    int id = ByteBufUtils.readVarInt(buf);
    int slot = ByteBufUtils.readVarInt(buf);
    ItemStack stack = GlowBufUtils.readSlot(buf);
    return new EntityEquipmentMessage(id, slot, stack);
}
Also used : EntityEquipmentMessage(net.glowstone.net.message.play.entity.EntityEquipmentMessage) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

EntityEquipmentMessage (net.glowstone.net.message.play.entity.EntityEquipmentMessage)5 Message (com.flowpowered.network.Message)2 EntityHeadRotationMessage (net.glowstone.net.message.play.entity.EntityHeadRotationMessage)2 EntityEffectMessage (net.glowstone.net.message.play.entity.EntityEffectMessage)1 EntityMetadataMessage (net.glowstone.net.message.play.entity.EntityMetadataMessage)1 EntityRemoveEffectMessage (net.glowstone.net.message.play.entity.EntityRemoveEffectMessage)1 SpawnObjectMessage (net.glowstone.net.message.play.entity.SpawnObjectMessage)1 SpawnPlayerMessage (net.glowstone.net.message.play.entity.SpawnPlayerMessage)1 EntityEquipment (org.bukkit.inventory.EntityEquipment)1 ItemStack (org.bukkit.inventory.ItemStack)1