1

I'm not very familiar with the new Minecraft 1.13 commands so I'm not exactly sure of how I would go about doing this. I would like to replace the item "Water Bottle" with a different item whenever a player has either filled a water bottle up or found one in the world. For example, the player walks up to a body of water with an empty glass bottle, they fill it up and immediately the water bottle is replaced with a fire resistance potion (just as an idea of what I'm trying to do). I had tried to use a repeat command block that clears the player's inventory of any water bottle that is in their inventory using the /clear command, and then if that is successful (I check with a comparator) I simply give the player my desired item using the /give command. However, the problem I'm having with this is that it seems to be very inconsistent. For example, if I was to click multiple times on a source of water relatively fast then the majority of them are not turned into my item and the player is left over with different Water Bottles.

  • If you're already using a comparator, you might as well put a long redstone line behind it and command blocks with that give command in them. That way, if two items are cleared, two command blocks are activated and give two items. The proper way would be putting the return value of /clear into a scoreboard using /execute store and then using that. – Fabian Röling Apr 13 at 1:42
0

If you are willing to use a datapack (its pretty simple and easy) you can set it up to run a function every tick which checks for a player having a water bottle, and if they do have one you can give them something else. Unfortunately, this requires recursion if you want to handle the player putting multiple items in their inventory at once (so taking them out of chests), so if someone knows how to do recursion, or has another fix, please modify my answer to explain it. If you want to do the datapack, here are some instructions for setting it up. Your tick function might look like this:

execute as @a[nbt={Inventory:[{id:"minecraft:potion",Count:1b,tag:{Potion:"minecraft:water"}}]}] run give @s minecraft:dragon_breath 1
execute as @a[nbt={Inventory:[{id:"minecraft:potion",Count:1b,tag:{Potion:"minecraft:water"}}]}] run clear @s minecraft:potion{Potion:"minecraft:water"} 1

Because a tick is the smallest unit of game time, you couldn't outclick this function. Make sure your give command comes before your clear, and you can change the dragons breath to any item id you want.

Edit: Just realized the link doesn't explain how to make a function run every tick. Basically, you put the above function in a .mcfunction file in your functions folder in your namespace. However, in your data folder (which has your namespace) you make a folder called minecraft, and inside that a folder called tags, and inside that a folder called functions. That folder will get a JSON document with the name 'tick' and the following text:

{
    "replace": false,
    "values": ["<your namespace>:tick"]
}

This runs the function (which checks for water bottles) every tick.

  • 1
    So I noticed that when I tried this out water_bottle didn't work, since that is not what it is called in the game. I tired minecraft:potion, which works but it will activate with any potion the player has in their inventory, not just the water bottle. I tired execute as @a[nbt={Inventory:[{id:"minecraft:potion{Potion:minecraft:water}"}]}] run say True but that doesn't seem to work either. – Hydra Jun 1 at 1:32
  • Sorry yeah I think that's a new 1.14 thing or maybe it was like that all along. Either way for a new execute command try execute as @a[nbt={Inventory:[{id:"minecraft:potion",Count:1b,tag:{Potion:"minecraft:water"}}]}] run give @s minecraft:dragon_breath 1. This works because each set of curly braces in the Inventory:[] tag is an item stack, and the potion type is in the tag:{} tag, so this specifies a single water bottle potion in the player's inventory. – Nik3141 Jun 1 at 1:52
  • Added the new give command and accompanying clear command to the answer. – Nik3141 Jun 1 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.