2

I am making a trade system in my Minecraft map where I give players a diamond sword if they give me 2 golden swords.

For that I put 2 command blocks. On first one:

/give @p[hasitem={item=golden_sword, quantity=2.. }] diamond_sword

and on second one:

/clear @p[hasitem={item=golden_sword, quantity=2.. }] golden_sword 0 2

Here's the problem: the system will only clear the golden swords with data value 0, which means full health, but I want that the system clears the sword even if it is about to break. I can't skip data value as after data value I have to specify the amount that is 2.

2 Answers 2

1

You can fix your problem by using more command blocks + a scoreboard. You can create 1 command block with the following command:

/clear @p golden_sword 0 1

then follow that command block up with a chain command block

/scoreboard players add @p swordCount 1

create another command block with the following command:

/clear @p golden_sword 1 1

then follow that command block up with a chain command block

/scoreboard players add @p swordCount 1

Repeat this process till you have 32 command blocks each trying to clear a golden sword of their respective data count.

Once the player has 2 points in the swordCount Scoreboard, any two golden swords would have been taken from them.

You need to make sure that the command blocks turn off when the player gets two points, otherwise they will take ALL of their gold swords instead of two

Reset their swordCount after/as the other command blocks turn off/get depowered/are no longer active

0

Per Minecraft Wiki

If not specified, or if -1, all items that match itemName: Item are cleared, regardless of their data.

Hence, you should be able to use -1 in place of the data value to clear all data values.

You must log in to answer this question.

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