Solved Fake items not being removed.

Discussion in 'Spigot Plugin Development' started by Jonnyo101, Feb 22, 2019.

  1. Hello since 1.9 i have been using this method to spawn fake item and then remve them after X time on the ground.

    Since updating to 1.13 the item WILL spawn on the ground but will not get removed.

    Here is the mothod.

    Code (Java):

    public void sendFakeItem(final Player player, final Location location, final ItemStack item, final int removeAfter, final Float velocityX, final Float velocityY, final Float velocityZ,
                         final boolean noGravity) {
       
        final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();

        final EntityItem entityItem = new EntityItem(((CraftWorld) player.getWorld()).getHandle());
        final net.minecraft.server.v1_13_R2.ItemStack craftItem = CraftItemStack.asNMSCopy(item);

        craftItem.d(2);
        entityItem.setItemStack(craftItem);
        entityItem.setPosition(location.getX(), location.getY(), location.getZ());

        if (noGravity) {
        entityItem.setNoGravity(true);
        }

        entityItem.f(velocityX, velocityY, velocityZ);

        Bukkit.getScheduler().scheduleSyncDelayedTask(Core.plugin, () -> {
            entityItem.setItemStack(CraftItemStack.asNMSCopy(new ItemStack(Material.AIR)));

            //Ttried to TP the item away. This does not work;
            entityItem.setLocation(0,0,0,0,0);

            final PacketPlayOutSpawnEntity itemPacket = new PacketPlayOutSpawnEntity(entityItem, 2, 1);
            entityPlayer.playerConnection.sendPacket(itemPacket);

            final PacketPlayOutEntityMetadata metaPacket = new PacketPlayOutEntityMetadata(entityItem.getId(), entityItem.getDataWatcher(), true);
            entityPlayer.playerConnection.sendPacket(metaPacket);

        }, removeAfter);

        final PacketPlayOutSpawnEntity itemPacket = new PacketPlayOutSpawnEntity(entityItem, 2, 1);
        entityPlayer.playerConnection.sendPacket(itemPacket);

        final PacketPlayOutEntityMetadata metaPacket = new PacketPlayOutEntityMetadata(entityItem.getId(), entityItem.getDataWatcher(), true);
        entityPlayer.playerConnection.sendPacket(metaPacket);


        final PacketPlayOutEntityVelocity velocityPacket = new PacketPlayOutEntityVelocity(entityItem);
        entityPlayer.playerConnection.sendPacket(velocityPacket);
    }
        }
    I have no errors in console and i know for certain the code in the task is being ran as i have had a broadcast that was sending.

    Any help would be great.
     
  2. drives_a_ford

    Moderator

    Have you tried using the PacketPlayOutEntityDestroy instead?
     
  3. Yer that worked. Thankyou.