#Unbreakable Tools

1 messages · Page 1 of 1 (latest)

wet knot
#

Hi i want to make a datapack where if it detects an iron axe (or any other tool) it will remove the tool and give the tool Unbreakable 1 and damage 1 (the command looks for damage 0)

execute as @a[nbt={Inventory:[{id:"minecraft:iron_axe",Count:1b,tag:{Damage:0}}]}] run clear @a minecraft:iron_axe 1

only code i have for now ^

soft meteorBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 If nobody has answered you by <t:1723903120:t>, feel free to use the Summon Helpers button to ping our helper team.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

tall lark
#

what minecraft version are you in?

wet knot
#

1.20.1

tall lark
#

okay, then that command should already do something
to give yourself an unbreakable age with damage of 1 you just run a simple give command, you can even add a unique tag if you ever plan to do anything else with that item
give <player> iron_axe{Damage:1,is_my_custom_axe:1b,Unbreakable:1b}

#

and when clearing you can specify data of the item you want to clear, so if you only want to clear iron axes with damage of 0, you can simply
clear <player> iron_axe{Damage:0}

wet knot
#

okay

#

but like how should it be in a function that runs every tick?

tall lark
#

when do you want it to happen?

wet knot
#

every tick

#

i want it to be so when you craft an item it removes the original and gives you the modified version

tall lark
#

you can either do it every tick - that may lag if there are a lot of players or you do this with more items/data packs/mods
or only when a player crafts something, but that won't work if they drop the item from the crafting table

#

i suggest doing it every tick for now, it's a lot easier to set up aswell

wet knot
#

okay

tall lark
#

then the idea would be to

  1. check if someone has the unmodified axe -> then give the custom axe
  2. check if someone has the unmodified axe -> then clear all unmodified axes
#

you can do it a little bit more fancy, by only checking the condition once but these 2 commands should do it

#

the checking is what you already did in your original post and the other stuff is what i send in the message earlier

wet knot
#

with command blocks i did that a repeater does the execute command and then conditional chain command will give the modified axe

tall lark
#

yea, in data packs it works a little differently, you either check the condition twice, where stuff may change - like checking for a cleared axe isn't possible

or, the data pack way

execute if <condition> run function other:function
# other:function
clear ...
give ...
wet knot
#

okay, i made an simple function with this code
execute as @a[nbt={Inventory:[{id:"minecraft:iron_axe",Count:1b,tag:{Damage:0}}]}]
give @a iron_axe{Unbreakable:1b,Damage:1}

but the give command runs even if i dont have and axe, how can i make it only give the axe when the execute is succesful?

wraith kayak
#

You need to put the execute command in your tick function, and run that function in the execute command

tall lark
#

like you did in your original command, execute works like this:
execute <condition> run <command>

#

then the command is only ran if the condition succeeds

#

if you run a whole other function using execute and the condition you only need to check that once

wet knot
wet knot
#

i made it work but now the axe appers in the second slot like i will make the axe and it will be for a split second in the first slot of hotbar but then the unbreakable version will be in the second

tall lark
#

what way did you decide to do it? if you did it in just 2 commands thats not fixable - if you did it in the function way just swap the order of the commands

wet knot
#

well i did it in the two commands

#

execute as @a[nbt={Inventory:[{id:"minecraft:iron_axe",Count:1b,tag:{Damage:0}}]}] run give @a iron_axe{Unbreakable:1b,Damage:1}
execute as @a[nbt={Inventory:[{id:"minecraft:iron_axe",Count:1b,tag:{Damage:0}}]}] run clear @a iron_axe{Damage:0}

#

could you show me how to fix it?

tall lark
#

sure
in tick:

execute as ... run function some:other/function

in some:other/function:

clear ...
give ...
#

to add a function just add another mcfunction file in the functions folder

tall lark
#

your ticking function

wet knot
#

that does the command?

tall lark
tall lark
wet knot
#

tomitom/functions

tall lark
#

in what file? how is it ran?

wet knot
tall lark
#

not quite sure what "the data file" means but if it's ran by the tick.json function tag, it's a ticking function - it runs every tick

wet knot
#

yeah

#

yo man i just did it

#

it works

#

thanks for help <3