Search in sources :

Example 1 with AttributeMapServerHandle

use of com.bergerkiller.generated.net.minecraft.server.AttributeMapServerHandle in project BKCommonLib by bergerhealer.

the class NBTUtil method loadAttributes.

/**
 * Loads the attributes for an Entity, applying the new attributes to the
 * entity
 *
 * @param livingEntity to load
 * @param data to load from
 */
public static void loadAttributes(LivingEntity livingEntity, CommonTagList data) {
    if (data == null) {
        throw new IllegalArgumentException("Data can not be null");
    }
    AttributeMapServerHandle map = CommonNMS.getEntityAttributes(livingEntity);
    GenericAttributesHandle.loadFromNBT(map, data);
}
Also used : AttributeMapServerHandle(com.bergerkiller.generated.net.minecraft.server.AttributeMapServerHandle)

Example 2 with AttributeMapServerHandle

use of com.bergerkiller.generated.net.minecraft.server.AttributeMapServerHandle in project BKCommonLib by bergerhealer.

the class NBTUtil method resetAttributes.

/**
 * Resets all attributes set for an Entity to the defaults. This should be
 * called prior to loading in new attributes using
 * {@link #loadAttributes(LivingEntity, CommonTagList)}
 *
 * @param livingEntity to reset
 */
public static void resetAttributes(LivingEntity livingEntity) {
    Object livingHandle = Conversion.toEntityHandle.convert(livingEntity);
    AttributeMapServerHandle ams = AttributeMapServerHandle.createNew();
    // Clear old attributes and force a re-create
    EntityLivingHandle.createHandle(livingHandle).setAttributeMapField(ams);
}
Also used : AttributeMapServerHandle(com.bergerkiller.generated.net.minecraft.server.AttributeMapServerHandle)

Example 3 with AttributeMapServerHandle

use of com.bergerkiller.generated.net.minecraft.server.AttributeMapServerHandle in project BKCommonLib by bergerhealer.

the class EntityNetworkController method syncMetaData.

/**
 * Synchronizes all Entity Meta Data including Entity Attributes and other
 * specific flags. Movement and positioning information is not updated. Only
 * the changes are sent, it is a relative update.
 */
public void syncMetaData() {
    // Meta Data
    DataWatcher meta = entity.getMetaData();
    if (meta.isChanged()) {
        broadcast(PacketType.OUT_ENTITY_METADATA.newInstance(entity.getEntityId(), meta, false), true);
    }
    // Living Entity - only data
    Object entityHandle = this.entity.getHandle();
    if (EntityLivingHandle.T.isAssignableFrom(entityHandle)) {
        EntityLivingHandle living = EntityLivingHandle.createHandle(entityHandle);
        // Entity Attributes
        AttributeMapServerHandle attributeMap = living.getAttributeMap();
        Collection<?> attributes = attributeMap.attributes();
        ;
        if (!attributes.isEmpty()) {
            this.broadcast(PacketType.OUT_ENTITY_UPDATE_ATTRIBUTES.newInstance(entity.getEntityId(), attributes), true);
        }
        attributes.clear();
    }
}
Also used : EntityLivingHandle(com.bergerkiller.generated.net.minecraft.server.EntityLivingHandle) AttributeMapServerHandle(com.bergerkiller.generated.net.minecraft.server.AttributeMapServerHandle) DataWatcher(com.bergerkiller.bukkit.common.wrappers.DataWatcher)

Example 4 with AttributeMapServerHandle

use of com.bergerkiller.generated.net.minecraft.server.AttributeMapServerHandle in project BKCommonLib by bergerhealer.

the class EntityNetworkController method initMetaData.

/**
 * Synchronizes all Entity Meta Data including Entity Attributes and other
 * specific flags. Movement and positioning information is not
 * updated.<br><br>
 * <p/>
 * This should be called when making this Entity visible to a viewer.
 *
 * @param viewer to send the meta data to
 */
public void initMetaData(Player viewer) {
    // Meta Data
    DataWatcher metaData = entity.getMetaData();
    if (!metaData.isEmpty()) {
        PacketUtil.sendPacket(viewer, PacketType.OUT_ENTITY_METADATA.newInstance(entity.getEntityId(), metaData, true));
    }
    // Living Entity - only data
    Object entityHandle = this.entity.getHandle();
    if (EntityLivingHandle.T.isAssignableFrom(entityHandle)) {
        EntityLivingHandle living = EntityLivingHandle.createHandle(entityHandle);
        // Entity Attributes
        AttributeMapServerHandle attributeMap = living.getAttributeMap();
        Collection<?> attributes = attributeMap.attributes();
        if (!attributes.isEmpty()) {
            PacketUtil.sendPacket(viewer, PacketType.OUT_ENTITY_UPDATE_ATTRIBUTES.newInstance(entity.getEntityId(), attributes));
        }
        // Entity Equipment
        for (EquipmentSlot slot : EquipmentSlot.values()) {
            org.bukkit.inventory.ItemStack itemstack = living.getEquipment(slot);
            if (itemstack != null) {
                PacketUtil.sendPacket(viewer, PacketType.OUT_ENTITY_EQUIPMENT.newInstance(entity.getEntityId(), slot, itemstack));
            }
        }
        // Entity Mob Effects
        for (MobEffectHandle effect : living.getEffects()) {
            PacketUtil.sendPacket(viewer, PacketType.OUT_ENTITY_EFFECT_ADD.newInstance(entity.getEntityId(), effect.getRaw()));
        }
    }
}
Also used : EntityLivingHandle(com.bergerkiller.generated.net.minecraft.server.EntityLivingHandle) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) AttributeMapServerHandle(com.bergerkiller.generated.net.minecraft.server.AttributeMapServerHandle) MobEffectHandle(com.bergerkiller.generated.net.minecraft.server.MobEffectHandle) DataWatcher(com.bergerkiller.bukkit.common.wrappers.DataWatcher)

Aggregations

AttributeMapServerHandle (com.bergerkiller.generated.net.minecraft.server.AttributeMapServerHandle)4 DataWatcher (com.bergerkiller.bukkit.common.wrappers.DataWatcher)2 EntityLivingHandle (com.bergerkiller.generated.net.minecraft.server.EntityLivingHandle)2 MobEffectHandle (com.bergerkiller.generated.net.minecraft.server.MobEffectHandle)1 EquipmentSlot (org.bukkit.inventory.EquipmentSlot)1