I am writing a datapack to allow endgame items that work sort of like guns, because creepers are annoying. The following code is in a function, but I can't find it with /function in game. I have other functions in the same file which are registering, so is there anything about the contents of the function which would disqualify it? The function only disappears when I edit it and then /reload the world, and when moving the datapack to another world which it has never been in and not editing it, just straightaway doing /reload and /function, it is still not present in the function list, and the function is not found when I manually type it in.

execute as @e[type=item,nbt={Item:{id:"minecraft:gunpowder",Count:64b}}] at @e[type=item,nbt={Item:{id:"minecraft:gunpowder",Count:64b}}] run summon minecraft:lightning_bolt ~ ~ ~
kill @e[type=item,nbt={Item:{id:"minecraft:iron_sword"}}]
kill @e[type=item,nbt={Item:{id:"minecraft:nether_star", Count:4b}}]
kill @e[type=item,nbt={Item:{id:"minecraft:gunpowder", Count:64b}}]
give @p minecraft:carrot_on_a_stick{Enchantments:[{id:"minecraft:infinity",lvl:1}],Unbreakable:1,display:{Name:"{\"text\":\"Shotgun\"}",Lore:["Pchow"]}} 1

The function is being run as @p (the closest player to the stack of gunpowder on the ground), and when I run the commands individually they all work.

  • Have you tried replacing it all with "say test"? Does it work then? Apr 12, 2019 at 15:29
  • I put say hi at the end, and it still didn't work. The weird thing is if I copy one of the functions that is there and don't change the content, that one works. If I paste this function into the copy, it disappears. But if I manually retype everything in the copy, it works until some arbitrary edit makes it dissapear. I can even rename it sometimes and it stays, but sometimes it doesn't.
    – Nik3141
    Apr 12, 2019 at 16:42
  • No, I mean replacing it all with that, to make sure that there are no syntax errors. That way you can see if the issue is in the function or somewhere else. If that works, give more details to what exact changes you do that makes it break. Apr 12, 2019 at 21:50
  • Ok so it was the first command: execute as @e[type=item,nbt={Item:{id:"minecraft:gunpowder",Count:64b}}] at @e[type=item,nbt={Item:{id:"minecraft:gunpowder",Count:64b}}] run summon minecraft:lightning_bolt ~ ~ ~ that broke it. The others worked fine by themselves. I realized I didn't catch some spelling errors and forgot the run keyword. Thanks for your help.
    – Nik3141
    Apr 13, 2019 at 4:53
  • You can write a self-answer and mark it as accepted, not many people read the comments. Apr 13, 2019 at 11:32

2 Answers 2


A lit of bit late, but for everyone who is on the same trouble in the future, make sure your function name doesn't have CAPITAL letters, make every function name lowercase. It worked for me! :D


Basically, make sure that you copy commands from Minecraft exactly into functions (without the slash obviously), and if Minecraft doesn't recognize your function, run each command in Minecraft to make sure they're all valid and spelled correctly.

You must log in to answer this question.

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