How to create an unbreakable block in Minecraft using a data pack

Makin' Blocks

How to create an unbreakable block in Minecraft using a data pack

In Minecraft, you can create a custom block with unbreakable properties using a data pack. Data packs are a way to customize the game experience by adding or modifying game elements such as recipes, advancements, structures, and more.

Here's how to create an unbreakable block in Minecraft using a data pack:

  1. Create a new folder for the data pack:

Navigate to the datapacks folder inside the Minecraft world folder you want to add the unbreakable block to. Create a new folder named unbreakable_block.

  1. Create the pack.mcmeta file:

Inside the unbreakable_block folder, create a file named pack.mcmeta. This file contains metadata about the data pack. Add the following contents to the file:

{
  "pack": {
    "pack_format": 7,
    "description": "Adds an unbreakable custom block to the game."
  }
}

Adjust the pack_format value based on the Minecraft version you are using.

  1. Create the folder structure for the custom block:

Inside the unbreakable_block folder, create the following folder structure: data/unbreakable_block/blockstates, data/unbreakable_block/models/block, and data/unbreakable_block/tags/blocks.

  1. Create the blockstate file:

Inside the blockstates folder, create a file named unbreakable_block.json. Add the following contents to the file:

{
  "variants": {
    "": { "model": "unbreakable_block:block/unbreakable_block" }
  }
}
  1. Create the block model file:

Inside the models/block folder, create a file named unbreakable_block.json. Add the following contents to the file:

{
  "parent": "block/cube_all",
  "textures": {
    "all": "block/obsidian"
  }
}

This file defines the block model, and in this example, it uses the obsidian texture. You can replace the texture with any other block texture you prefer.

  1. Create the block tag file:

Inside the tags/blocks folder, create a file named unbreakable.json. Add the following contents to the file:

{
  "values": [
    "unbreakable_block:unbreakable_block"
  ]
}

This file tags the custom block as unbreakable, which prevents it from being broken by players or explosions.

  1. Create a function to give the player the unbreakable block:

Inside the unbreakable_block folder, create another folder named functions. Inside the functions folder, create a file named give_block.mcfunction and add the following command:

give @s unbreakable_block:unbreakable_block

This function gives the player an unbreakable block when executed.

  1. Load the data pack in the game:

Start Minecraft and load the world with the data pack. Once in the game, type the following command to reload data packs:

/reload
  1. Give the player the unbreakable block:

To give the player the unbreakable block, type the following command:

/function unbreakable_block:give_block

You should now have an unbreakable block in your inventory. Place it in the world, and it will be unbreakable by normal means.

Note: This unbreakable block will not prevent players in Creative mode from breaking it. To create a truly unbreakable block, you would need to use a mod or plugin that adds more functionality beyond what data packs can provide.