Skip to content

Enshrouded 1.0 is out! 🎉 Get 25% OFF your next Enshrouded Server today!

Game guidesMinecraft

Make custom weapons with commands

Give named, enchanted weapons with the give command, change their damage with attribute modifiers and package them in a datapack function.

Updated 4 min read

A custom weapon is a normal item with extra data on it: a name, lore text, enchantments, a damage change or the unbreakable flag. You give it with one give command, and if the command gets long or you want to hand it out repeatedly, you can move it into a small datapack. This guide does both on a Java server.

Checked against Minecraft Java Edition 26.3, October 2026. Item data changed format in 1.20.5, and again for enchantments in 1.21.5, so an older command copied from a video or forum may fail.

Give a named, enchanted sword

Open the Console tab and run this with a player's own name in place of Alex. The player has to be online. The console takes commands without a leading slash.

give Alex diamond_sword[custom_name={text:"Frostbane",color:"aqua",italic:false},lore=[{text:"Forged in the north",italic:false,color:"gold"}],enchantments={sharpness:5,knockback:2},unbreakable={}]

The square brackets hold the item's data components, written as name=value pairs separated by commas:

  • custom_name is the display name. It is a text component, so it takes a colour, and italic:false turns off italics.
  • lore is a list of lines under the name. Each line is its own text component.
  • enchantments lists each enchantment with its level. Sharpness goes up to V and Knockback to II in the normal game.
  • unbreakable={} stops the item losing durability.

Change the damage

The attribute_modifiers component changes what the item does when held. Each entry names the attribute, the slot, how to apply the number and a unique ID of your own:

give Alex diamond_sword[attribute_modifiers=[{type:"minecraft:attack_damage",id:"weapons:frostbane_damage",amount:10,operation:"add_value",slot:"mainhand"},{type:"minecraft:attack_speed",id:"weapons:frostbane_speed",amount:-2,operation:"add_value",slot:"mainhand"}]]

The attributes you will use most for a weapon are minecraft:attack_damage, minecraft:attack_speed and minecraft:attack_knockback. The operation can be add_value, add_multiplied_base or add_multiplied_total. The amounts above are examples, so pick your own and hold the item to read its tooltip, which lists the values that took effect.

The command above sets both the attack damage and the attack speed, so you choose both numbers.

Move it into a datapack

The panel console accepts commands up to 1,024 characters, and a long item command can pass that. A datapack function holds as many commands as you like, one per line.

Make the folders. On your computer, create this layout, using your own names:

frostbane/
  pack.mcmeta
  data/
    weapons/
      function/
        frostbane.mcfunction

Write pack.mcmeta. The number 121 is the data pack version for Minecraft 26.3. Other versions use other numbers, which the wiki's Pack format page lists.

{
  "pack": {
    "description": "Custom weapons",
    "min_format": 121,
    "max_format": 121
  }
}

Write the function. In frostbane.mcfunction, put your command with no slash. A line starting with # is a comment.

# Gives the player who runs this the Frostbane sword
give @s diamond_sword[custom_name={text:"Frostbane",color:"aqua",italic:false},enchantments={sharpness:5,knockback:2},unbreakable={}]

Upload it. Zip the contents of the frostbane folder, so pack.mcmeta sits at the top of the zip. Open the File Manager, go into your world folder, then datapacks, press Upload and pick the zip. Install a data pack has the full steps, including what to do when a file is over the 100 MB browser limit. Then restart the server from the Console tab.

Give the sword. Run this in the Console tab:

execute as Alex run function weapons:frostbane

In game, an operator can type /function weapons:frostbane instead. The name has two parts: the folder under data, and the file name without .mcfunction.

If it does not work

  • The pack is missing. Open the Datapacks tab and the Installed view. A zipped pack in the world's datapacks folder is listed there. If it is absent, check that pack.mcmeta is not inside an extra folder in the zip.
  • The function is not found. The folder has to be called function, singular, and the file has to end in .mcfunction.
  • A component is rejected. Check the brackets and quotes. Each component is written as name=value, with commas between them.

Was this guide helpful?

Still stuck?

Talk to a real person, we answer fast.

  • Open a ticket

    Paste the exact error and name your server, so we can look at it from our side.

  • Ask on Discord

    Chat with the team and other server owners.

  • Browse the Help Centre

    Versions, mods, plugins, backups and RAM sizing, all in plain English.

Ready to launch your Minecraft server?

Aussie hardware, NVMe disks and DDoS protection, with the version and mod loader yours to change whenever you like.