Armour disappears when dropped

Here is what I am doing:

        for(Inventory slot : user.getInventory().slots()){
	    	if (slot.peek().isPresent()) {
	    		build.offer(slot.peek().get());
	    	}
        }

	    player.openInventory(build.parent(), Text.of(TextColors.DARK_RED, targetName + "'s " + "inventory"));

You can get the items this way… but if you equip the armour, and then try to drop it on the ground, it disappears. If you just drop the items normally, all is fine. They appear on the ground as normal.

What should I be doing here to fix this?

Sorry there are a few things you have assumed that the reader will know.

First of all what API are you using? Api 8 (MC 1.16) or API 7 (1.12) - based on your usage of Text im going to assume API 7 but clarification would be useful

Next is what are the types of your variables?

Player user;
Player player;
Inventory build;

for(Inventory slot : user.getInventory().slots()){
	    	if (slot.peek().isPresent()) {
	    		build.offer(slot.peek().get());
	    	}
        }

	    player.openInventory(build.parent(), Text.of(TextColors.DARK_RED, targetName + "'s " + "inventory"));

Like that? Or is user a type of User?

Next. Is this code ran as a command or as event? If event then what event?

And finally… When you say Drop normally could you please clarify. Is it?

When the armor is equiped in the selected slot and then the player presses Q to drop the item this is “Normal”

Or

When the inventory is open and the player drags the armor outside the inventory window to drop the item this is “Normal”

Also the same goes for what is causing you bug. Is it when the inventory is open and the item is equipped to the player (say helmet on the helmet slot) and then attempts to drop the item, is this what causes the bug? And if you have it in that slot, but move it to another slot and then drop it, does it not cause the bug?

Sadly, if you want help, you need to specify as much useful data as possible

But in all seriousness. In Sponge, there is no special rules for specific items when dropping. That is unless a event gets in the way.

I would first check your testing environment. I would recommend Sponge Vanilla with only your plugin to ensure another plugin, mod or Forge is not interfering

If it still happens, i would then take a look at your own events, in particular any events that covers either dropping items or changing slots and ensure it doesnt delete the item (please note in sponge, cancelling events may not reset the inventory to its state before the trigger, therefore cancelling the drop item event will cancel the item being dropped, but the action still triggered and therefore the item is gone from the inventory)

Apologies for the missing details. Made the same mistake in another thread heh.

API 7. user is of type User, player is of type Player, and build is of type Inventory. It is ran as a command.

…and wow, I can’t bug test I guess. Thanks - the armour factor here doesn’t matter. When I drop the items by pressing Q, all is fine. When I drag them out of my inventory window with my mouse to drop them, they disappear. That is the whole story (for example if I put the armour on, put it in my hotbar and then press Q, it drops normally).

The only other plugin I have is worldedit - I will remove it tomorrow when testing. I am also using Sponge Vanilla.

I am not entirely sure what event means. I haven’t really created any events I don’t think but I’ll read documentation tomorrow.

So “events” are things that happen in game that you as a developer can listen to and manipulate (such as cancel or even change more specific things)

Common events are

MoveEntityEvent (typically filtered to just player)
InventoryInteractEvent (typically on custom inventories)
BlockInteractEvent (filtered to a player)

These can come in really useful. Take a look at the javadocs for all events :slight_smile: