I'm trying to create quests using command blocks for a skyblock realm but I can't figure out how to do it. I want it so that when a button is clicked, it takes certain items out of the player's inventory and give the player useful items in exchange.

Any ideas?

  • 1
    What have you tried? I cant answer questions like this because I know nothing of how to write commands but generally people on here won't be willing to answer without you showing effort and what code you have tried already.
    – Kyle Rone
    Commented Sep 26, 2017 at 19:19

2 Answers 2


If I understand it correctly, you want to remove the items from the inventory from the player and give him/her other items back. There are multiple ways in which you can achieve this behaviour

First: remove items from the players inventory

The easiest way is to just use the clear command:

/clear @p

This command removes all items from all slots from the player, including the armor slots and the offhand slot.
or better(Thanks to @Fabian):

/clear @p minecraft:stick 0 10

this command clears up to 10 sticks from a players inventory

If you only want certain slots to be emptied, you can use the replaceitem command:

/replaceitem entity @p slot.hotbar.0 minecraft:air 1 0

The above command empties the first slot in the hotbar

Now to give players an item, there are two methods as well:
The give command gives a player an item, as if the player picked the item up from the ground. This makes sure that the item is placed in a slot which is not filled with something else, but if the inventory is full, the item lands on the ground

/give @p minecraft:stick 1 0

The above command gives a player a stick
You can also use the replaceitem command again like this:

/replaceitem entity @p slot.hotbar.0 minecraft:stick 1 0

This command places 1 stick in the first slot of the hotbar, overwriting any item that was present in this slot before. The benefit here is that a player is guaranteed to have this item in his/her inventory, however, if there is an item already in that specific slot, that item gets lost.

So you see there are multiple methods to achieve what you want, each with pros and cons. Now it's up to you to decide which method fits your needs.

If you want to test for specific items in the players inventory and remove only those, I'll have to disappoint you. There is no way to check if a player has an item unless you want to get crazy with the command blocks and do a check on all inventory slots. If this is some sort of crafting system that you want to make, you should have a look at floor crafting which allows players to throw items on the ground in exchange for new items.

In the upcoming 1.13 update, you can add custom recipes, which could very well suit your needs. Again: I don't quite understand what your question is about, but I think I have covered most possible interpretations.

  • He states that he wants to remove certain items in exchange for other items. I think you covered it with the second to last paragraph.
    – IronAnvil
    Commented Sep 27, 2017 at 1:45
  • You can actually use for example /clear @p stone 0 10 to remove up to 10 stone blocks from the player's inventory. But it will succeed if there's just 5 stones, so you would have to run it with the number 1 ten times to make it reliable. Commented Sep 27, 2017 at 7:18
  • This answer includes a section that deals with the problem of verifying a minimum amount before using the clear command. It uses scoreboard and command stats.
    – IronAnvil
    Commented Oct 1, 2017 at 4:16

Well, if you're trying to make a "store" like machine what I do is stack three command blocks on top of eachother with this in this exact order with a button on a block so it only activates the first command.

  1. testfor @p {Inventory:[{id:"minecraft:*item*"}]}
  2. clear @p minecraft:*item* 0 *amount*
  3. give @p minecraft:*item* *amount* 0

The testfor command checks to see if the player has the item you want to replace. This command block is set to default impulse unconditionaland needs redstone

The Clearcommand takes the specific item. this block has to be set to Chain, conditional, andalways activeso no extra redstone signals are needed and it only works if the first command is excuted.

And finally, the give command actually gives the player the item and this command block must also be set to the same conditions as the second and this allows it to only work it the player has the items to replace

hope this helps

  • As Fabian pointed out in a comment on one of the other answers, a problem with using the clear command in this way is if the player has even one of the specified item in their inventory it will succeed.
    – IronAnvil
    Commented Sep 30, 2017 at 5:42
  • true but what if you added the Count:<#> into the testfor then it would only work if the player had a set amount. without this your right. idk the scoreboards definitly better anyways
    – Chris CALS
    Commented Sep 30, 2017 at 6:32
  • well never mind there is still a downfall to the testfor with the count added in because it test for an exact amount and not a minimum
    – Chris CALS
    Commented Sep 30, 2017 at 6:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .