Solved PacketPlayOutSpawnEntity

Discussion in 'Plugin Development' started by CeramicTitan, Apr 3, 2014.

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

    CeramicTitan

  2. Offline

    RawCode

    protip:

    open gravel and sand blocks source code and check how they spawn fallingblock.

    you will instantly get answer.
     
  3. Offline

    CeramicTitan

    I will instantly get an answer? What am I looking for?
     
  4. Offline

    skyrimfan1

    I reread the wiki.vg/protocol article on your packet again, and it seems that it is not the one you would want. I would instead recommend this one:

    http://wiki.vg/Protocol#Spawn_Object

    Comphenix is usually a god with packets. He could probably give you more help with this than I could ever.
     
  5. Offline

    CeramicTitan

    It's the same packet. I know what I'm doing when it comes to packets, it's just debugging I'm not too sure about
     
  6. Offline

    Comphenix

    Ah, I see - you're not actually spawning a falling block (like a sand entity) - you're spawning an item stack entity.

    In that case, try setting the item material using an ENTITY_METADATA packet (here using ProtocolLib + PacketWrapper):
    Code:java
    1. public class ExampleMod extends JavaPlugin {
    2. private int entityId = Short.MAX_VALUE;
    3.  
    4. @Override
    5. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    6. if (sender instanceof Player) {
    7. Player p = (Player) sender;
    8. spawnFloatingItemStack(p, new ItemStack(Material.DIAMOND, 1));
    9. }
    10. return true;
    11. }
    12.  
    13. private void spawnFloatingItemStack(Player p, ItemStack stack) {
    14. WrapperPlayServerSpawnEntity block = new WrapperPlayServerSpawnEntity();
    15. block.setEntityID(entityId++);
    16. block.setX(p.getLocation().getX());
    17. block.setY(p.getLocation().getY());
    18. block.setZ(p.getLocation().getZ());
    19. block.setType(2);
    20. block.sendPacket(p);
    21.  
    22. WrapperPlayServerEntityMetadata metadata = new WrapperPlayServerEntityMetadata();
    23. metadata.setEntityId(block.getEntityID());
    24. metadata.setEntityMetadata(
    25. Arrays.asList(new WrappedWatchableObject(10, stack))
    26. );
    27. metadata.sendPacket(p);
    28. }
    29. }
     
    CeramicTitan likes this.
  7. Offline

    CeramicTitan

    Thank you! I will try this when I get back from school
     
Thread Status:
Not open for further replies.

Share This Page