Item packet

Discussion in 'Plugin Development' started by Someone_Like_You, Apr 11, 2014.

Thread Status:
Not open for further replies.
  1. I need to spawn item entity for specific player only (packets.) I succeed spawning an item for the player only, but I cant set the item type... (its only spawned with stone material) .
    heres my code so far :
    Code:java
    1. public static void showFakeItem(Location loc, Material material, Player p){
    2. ItemStack i = new ItemStack(material, 1);
    3. EntityItem item = new EntityItem(((CraftWorld) loc.getWorld()).getHandle());
    4. item.setLocation(loc.getX(), loc.getY(), loc.getZ(), 0 ,0);
    5. item.setItemStack(CraftItemStack.asNMSCopy(i));
    6. PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(item, 2);
    7. ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
    8. }

    anyone know why it isnt working and only displaying stone?
    by the way - will packet item despawn for player? and what does the integer in the packet means, entity type id?
     
  2. Offline

    xTrollxDudex

  3. xTrollxDudex thanks! so do I need to send that packet too in order to get the item type to change from stone?
    is it client or server?...
    also, Im kinda new to packets, whats notchian?...
     
  4. Offline

    xTrollxDudex

    Someone_Like_You
    Notchian is default mine craft client, vendor must be mojang.

    You send that packet instead of spawn entity packet
     
  5. Offline

    xTrollxDudex

  6. xTrollxDudex Its says the fields are status (type of action), X, Y , Z, and block face... :confused:
     
  7. Offline

    xTrollxDudex

    Someone_Like_You
    X, Y, Z

    As you can see. What do you mean by "where does it goes again?"
     
  8. xTrollxDudex I need to show the player specific item, so like water bottle maybe.. (might be other stuff. ) so where does the itemstack goes in the dig packet?
     
  9. Offline

    xTrollxDudex

  10. xTrollxDudex isnt working ;( I cant set the fields..
    (spam me with errors at field A)
    Code:java
    1. private static void sendDigPacket(Player p){
    2. try{
    3. PacketPlayInBlockDig packet = new PacketPlayInBlockDig();
    4. Field a = packet.getClass().getDeclaredField("a");
    5. a.setAccessible(true);
    6. a.set(a, p.getLocation().getBlockX());
    7. a.setAccessible(false);
    8. Field b = packet.getClass().getDeclaredField("b");
    9. b.setAccessible(true);
    10. b.set(b, p.getLocation().getBlockY());
    11. b.setAccessible(false);
    12. Field c = packet.getClass().getDeclaredField("c");
    13. c.setAccessible(true);
    14. c.set(c, p.getLocation().getBlockZ());
    15. c.setAccessible(false);
    16. Field face = packet.getClass().getDeclaredField("face");
    17. face.setAccessible(true);
    18. face.set(face, 0);
    19. face.setAccessible(false);
    20. Field e = packet.getClass().getDeclaredField("e");
    21. e.setAccessible(true);
    22. e.set(e, 4);
    23. e.setAccessible(false);
    24. ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
    25. }catch(Exception e){
    26. e.printStackTrace();
    27. }
     
  11. Offline

    xTrollxDudex

    Someone_Like_You
    Hmm, this seems a bit... Over complicated....

    Why don't you just spawn real ItemStack set pickup delay to max value? You can send the destroy entity packet easily after that for players that you don't want to see
     
  12. xTrollxDudex LOL! youre amazing ;), another question - if I will send destroy packet on player id for certain players and then send entity packet with the player id for the same players, will they see the player as it were that mob? (so when he moves his head, the mob itself will move too)
     
  13. Offline

    xTrollxDudex

  14. xTrollxDudex okay, and one more question (so many haha) - when Im sending destroy entity packet to the player, do I have to resend it when player dies? also, is it okay to make arraylists of packets (and send them to player upon login) without any lags problems?
     
  15. Offline

    xTrollxDudex

    Someone_Like_You
    1) I'm not sure lol. I don't play with packets often, so I'm a "theorist" of packets :p
    In my experience, it should still work but that is not guaranteed
    2) You can do that
     
  16. xTrollxDudex ty haha youre AMAZING!, but Il still have to figure out how to send item entity to one single player only, due to the fact that no matter when Il send destroy packet on an item entity for all player except one, It will still show for the players.. (for few ticks/seconds...), if you have any other ideas Id like to hear ... Im desperate :'(
     
Thread Status:
Not open for further replies.

Share This Page