Search in sources :

Example 1 with EntityLivingHandle

use of com.bergerkiller.generated.net.minecraft.world.entity.EntityLivingHandle in project BKCommonLib by bergerhealer.

the class EntityUtil method setSpeed.

/**
 * Changes the speed of a living entity
 *
 * @param entity Entity
 * @param speed New entity speed
 */
public static void setSpeed(LivingEntity entity, double speed) {
    EntityLivingHandle nmsEntity = CommonNMS.getHandle(entity);
    nmsEntity.getAttribute(GenericAttributesHandle.MOVEMENT_SPEED).setValue(speed);
}
Also used : EntityLivingHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityLivingHandle)

Example 2 with EntityLivingHandle

use of com.bergerkiller.generated.net.minecraft.world.entity.EntityLivingHandle in project BKCommonLib by bergerhealer.

the class CommonLivingEntity method setPathfindingRange.

/**
 * Sets the path finding radius.
 *
 * @param range of path finding
 */
public void setPathfindingRange(double range) {
    EntityLivingHandle nmsEntity = this.handle.cast(EntityLivingHandle.T);
    nmsEntity.getAttribute(GenericAttributesHandle.FOLLOW_RANGE).setValue(range);
}
Also used : EntityLivingHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityLivingHandle)

Example 3 with EntityLivingHandle

use of com.bergerkiller.generated.net.minecraft.world.entity.EntityLivingHandle 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
        Collection<AttributeModifiableHandle> attributes = living.getAttributeMap().getSynchronizedAttributes();
        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.world.entity.EntityLivingHandle) DataWatcher(com.bergerkiller.bukkit.common.wrappers.DataWatcher) AttributeModifiableHandle(com.bergerkiller.generated.net.minecraft.world.entity.ai.attributes.AttributeModifiableHandle)

Example 4 with EntityLivingHandle

use of com.bergerkiller.generated.net.minecraft.world.entity.EntityLivingHandle 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
        Collection<AttributeModifiableHandle> attributes = living.getAttributeMap().getSynchronizedAttributes();
        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));
        }
    }
}
Also used : EntityLivingHandle(com.bergerkiller.generated.net.minecraft.world.entity.EntityLivingHandle) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) MobEffectHandle(com.bergerkiller.generated.net.minecraft.world.effect.MobEffectHandle) DataWatcher(com.bergerkiller.bukkit.common.wrappers.DataWatcher) AttributeModifiableHandle(com.bergerkiller.generated.net.minecraft.world.entity.ai.attributes.AttributeModifiableHandle)

Aggregations

EntityLivingHandle (com.bergerkiller.generated.net.minecraft.world.entity.EntityLivingHandle)4 DataWatcher (com.bergerkiller.bukkit.common.wrappers.DataWatcher)2 AttributeModifiableHandle (com.bergerkiller.generated.net.minecraft.world.entity.ai.attributes.AttributeModifiableHandle)2 MobEffectHandle (com.bergerkiller.generated.net.minecraft.world.effect.MobEffectHandle)1 EquipmentSlot (org.bukkit.inventory.EquipmentSlot)1