Search in sources :

Example 1 with AddItemEntityPacket

use of org.dragonet.net.packet.minecraft.AddItemEntityPacket in project Dragonet-Legacy by DragonetMC.

the class EntityMetadataMessageTranslator method handleSpecific.

@Override
public PEPacket[] handleSpecific(EntityMetadataMessage packet) {
    if (!this.getTranslator().cachedEntityIDs.contains(packet.id)) {
        //Not spawned yet, let's create them
        if (this.getTranslator().cachedSpawnObjects.containsKey(packet.id)) {
            //Spawn it :) 
            SpawnObjectMessage msgObj = this.getTranslator().cachedSpawnObjects.get(packet.id);
            switch(msgObj.type) {
                case //Dropped Item
                2:
                    AddItemEntityPacket pkAddItemEntity = new AddItemEntityPacket();
                    pkAddItemEntity.eid = msgObj.id;
                    pkAddItemEntity.item = new PEInventorySlot((short) (((ItemStack) packet.entries.get(0).value).getTypeId() & 0xFFFF), (byte) (((ItemStack) packet.entries.get(0).value).getAmount() & 0xFF), (short) (((ItemStack) packet.entries.get(0).value).getDurability() & 0xFFFF));
                    pkAddItemEntity.x = (float) msgObj.velX / 32;
                    pkAddItemEntity.y = (float) msgObj.velY / 32;
                    pkAddItemEntity.z = (float) msgObj.velZ / 32;
                    return new PEPacket[] { pkAddItemEntity };
            }
            //Remove it
            this.getTranslator().cachedSpawnObjects.remove(packet.id);
        } else {
            return null;
        }
    }
    return null;
}
Also used : SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) AddItemEntityPacket(org.dragonet.net.packet.minecraft.AddItemEntityPacket) PEPacket(org.dragonet.net.packet.minecraft.PEPacket) PEInventorySlot(org.dragonet.inventory.PEInventorySlot)

Aggregations

SpawnObjectMessage (net.glowstone.net.message.play.entity.SpawnObjectMessage)1 PEInventorySlot (org.dragonet.inventory.PEInventorySlot)1 AddItemEntityPacket (org.dragonet.net.packet.minecraft.AddItemEntityPacket)1 PEPacket (org.dragonet.net.packet.minecraft.PEPacket)1