Help spawning item drop entity using packets!

Discussion in 'Plugin Development' started by bartboy8, Mar 26, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    bartboy8

    I've been trying to spawn an item drop entity using packets. I only want certain players to be able to view the item.. I have succeeded but, whenever I spawn it... It's always stone, anyone have any idea how to change that? Here's what I have so far:
    Code:
    EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
            EntityWitherSkull itemSkull = new EntityWitherSkull(world);
            itemSkull.setLocation(location.getX(), this.location.getY(), location.getZ(), 0, 0);
            ((CraftWorld) location.getWorld()).getHandle().addEntity(itemSkull);
         
            EntityItem item = new EntityItem(world);
            item.setItemStack(CraftItemStack.asNMSCopy(this.item));
            item.setLocation(location.getX(), Sploof.lobbyLocation.getY(), location.getZ(), 0, 0);
            item.pickupDelay = Integer.MAX_VALUE;
         
            PacketPlayOutSpawnEntity itemPacket = new PacketPlayOutSpawnEntity(item, 2, 100);
            nmsPlayer.playerConnection.sendPacket(itemPacket);
         
            PacketPlayOutAttachEntity packet = new PacketPlayOutAttachEntity(0, item, itemSkull);
            nmsPlayer.playerConnection.sendPacket(packet);
    PacketPlayOutSpawnEntity has the arguments (Entity, EntityType(id), EntityThrowerID (only for ghast fireballs))
     
  2. Offline

    2MBKindiegames

    I'm not an expert but shouldn't this line
    be
     
  3. Offline

    bartboy8

    No, that would try to set the wither skull to the itemstack causing a lot of errors :p
     
  4. Offline

    ever_x

    Ok, not sure about some of this, but...
    First, PacketPlayOutAttachEntity as I understand it will leash one entity to another. In your code, you would leash item to itemSkull. The only other reason I see that would cause the item to be stone is if this.item equales ID 1, or stone. Check you are setting this variable in the constructor or at some point along the line. I'm on my iPad ATM so I can probably look more into this in a couple of days time. This thread is quite old so I'm not sure if you have solved it already, but the only other errors I can see are that you are using both location and Spoof.lobbyLocation. Not sure if this is intended but hey, good to be sure!
     
Thread Status:
Not open for further replies.

Share This Page