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.
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_nameis the display name. It is a text component, so it takes a colour, anditalic:falseturns off italics.loreis a list of lines under the name. Each line is its own text component.enchantmentslists 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.mcfunctionWrite 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:frostbaneIn 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
datapacksfolder is listed there. If it is absent, check thatpack.mcmetais 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?
Related guides
Summon custom entities with /summon
Use /summon to create named, armed or mounted mobs and custom villagers from the Console tab or in game, with working examples for Java 26.3.
Summon a mob with no AI using commands
Use the NoAI tag to summon a mob that stands still, freeze one that already exists, add display tags and switch its AI back on.
Respawn the Ender Dragon
Bring the Ender Dragon back with four End crystals: what you need, where the crystals go, why it may not start and what a repeat kill drops.
