Prevent NMS ItemStack Physics

Discussion in 'Plugin Development' started by Excel8392, May 10, 2020.

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

    Excel8392

    I'm trying to create floating items above some NMS EntityPlayers that I have set up. I have managed to make the NPCs just fine, but the NMS items seem to be a little tricky.
    This is how I am summoning the item:
    Code:
    EntityItem item = new EntityItem(
                            ((CraftWorld) location.getWorld()).getHandle(),
                            location.getX(),
                            location.getY() + 3,
                            location.getZ(),
                            CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(material)));
                    item.setNoGravity(true);
                    item.setMot(0, 0, 0);
                    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutSpawnEntity(item, 2));
                    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(item.getId(), item.getDataWatcher(), true));
    However, when setting noGravity to true, the items do this weird thing where they just start floating up into the air (lmk if you want a video to see it). If I set noGravity to false, they just drop down on the floor.
    So after a lot of googling online, I have learned that item stack physics are done client side. However, it was mentioned somewhere that if you make the item a passenger of another entity (like an armorstand), then the client will ignore the item stack physics. So I tried to add this code to the code above:
    Code:
                    final EntityArmorStand armorStand = new EntityArmorStand(((CraftWorld) location.getWorld()).getHandle(), location.getX(), location.getY() + 3, location.getZ());
                    armorStand.setSmall(true);
                    armorStand.setInvisible(true);
                    armorStand.setMarker(true);
                    armorStand.passengers.add(item);
                    NBTTagCompound tag = new NBTTagCompound();
                    tag.setInt("DisabledSlot", 2039589);
                    armorStand.c(tag);
                    ((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutSpawnEntityLiving(armorStand));
                    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutEntityMetadata(armorStand.getId(), armorStand.getDataWatcher(), true));
                    ((CraftPlayer)player).getHandle().playerConnection.sendPacket(new PacketPlayOutAttachEntity(armorStand, item));
    But as a result, I got no difference, just now there are some floating armor stands in my world.
    Can anyone tell me
    1) If there is any other way to make it so that the client ignores the item stack physics
    or
    2) How to correctly make the item stack sit on another entity

    Any help is appreciated.

    EDIT: here is what is happening to my items: https://imgur.com/a/tjPF8ar
     
    Last edited: May 11, 2020
Thread Status:
Not open for further replies.

Share This Page