Search in sources :

Example 11 with SpawnObjectMessage

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

the class SpawnObjectCodec method decode.

@Override
public SpawnObjectMessage decode(ByteBuf buf) throws IOException {
    int id = ByteBufUtils.readVarInt(buf);
    UUID uuid = GlowBufUtils.readUuid(buf);
    int type = buf.readByte();
    double x = buf.readDouble();
    double y = buf.readDouble();
    double z = buf.readDouble();
    int pitch = buf.readByte();
    int yaw = buf.readByte();
    int data = buf.readInt();
    int velX = buf.readShort();
    int velY = buf.readShort();
    int velZ = buf.readShort();
    return new SpawnObjectMessage(id, uuid, type, x, y, z, pitch, yaw, data, velX, velY, velZ);
}
Also used : SpawnObjectMessage(net.glowstone.net.message.play.entity.SpawnObjectMessage) UUID(java.util.UUID)

Example 12 with SpawnObjectMessage

use of net.glowstone.net.message.play.entity.SpawnObjectMessage 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)12 EntityMetadataMessage (net.glowstone.net.message.play.entity.EntityMetadataMessage)5 Message (com.flowpowered.network.Message)3 LinkedList (java.util.LinkedList)2 ParticleBuilder (com.destroystokyo.paper.ParticleBuilder)1 UUID (java.util.UUID)1 MetadataMap (net.glowstone.entity.meta.MetadataMap)1 DestroyEntitiesMessage (net.glowstone.net.message.play.entity.DestroyEntitiesMessage)1 EntityEquipmentMessage (net.glowstone.net.message.play.entity.EntityEquipmentMessage)1 EntityVelocityMessage (net.glowstone.net.message.play.entity.EntityVelocityMessage)1 PEInventorySlot (org.dragonet.inventory.PEInventorySlot)1 AddItemEntityPacket (org.dragonet.net.packet.minecraft.AddItemEntityPacket)1 PEPacket (org.dragonet.net.packet.minecraft.PEPacket)1