Search in sources :

Example 11 with DataWatcher

use of com.bergerkiller.bukkit.common.wrappers.DataWatcher 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

DataWatcher (com.bergerkiller.bukkit.common.wrappers.DataWatcher)11 Test (org.junit.Test)6 ItemStack (org.bukkit.inventory.ItemStack)3 MapSession (com.bergerkiller.bukkit.common.map.MapSession)2 MapUUID (com.bergerkiller.bukkit.common.map.util.MapUUID)2 EntityLivingHandle (com.bergerkiller.generated.net.minecraft.world.entity.EntityLivingHandle)2 AttributeModifiableHandle (com.bergerkiller.generated.net.minecraft.world.entity.ai.attributes.AttributeModifiableHandle)2 UUID (java.util.UUID)2 Player (org.bukkit.entity.Player)2 PlayerInventory (org.bukkit.inventory.PlayerInventory)2 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)1 ItemFrameInfo (com.bergerkiller.bukkit.common.map.binding.ItemFrameInfo)1 MapDisplayInfo (com.bergerkiller.bukkit.common.map.binding.MapDisplayInfo)1 PacketPlayOutEntityTeleportHandle (com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutEntityTeleportHandle)1 PacketPlayOutPositionHandle (com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutPositionHandle)1 PacketPlayOutSpawnEntityLivingHandle (com.bergerkiller.generated.net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLivingHandle)1 MobEffectHandle (com.bergerkiller.generated.net.minecraft.world.effect.MobEffectHandle)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 EquipmentSlot (org.bukkit.inventory.EquipmentSlot)1