Crystal Block!
Your First Custom Block
Add a glowing Crystal Block to Minecraft it lights up in the dark, can be mined with a pickaxe and drops your Crystal Gem when broken. Time to build with your own block!
Add a glowing Crystal Block to Minecraft it lights up in the dark, can be mined with a pickaxe and drops your Crystal Gem when broken. Time to build with your own block!
Understand what extra files a block needs compared to an item, so nothing surprises you later.
Create ModBlocks.java with the Crystal Block registered as a glowing, mineable block.
luminance(state -> 10) makes the block glow with brightness 10 (like a glowstone is 15, torch is 14). requiresTool() means it only drops when mined with the correct tool (pickaxe).Add one line to CrystalMod.java so your block gets registered when the game starts.
onInitialize() method, add a call to ModBlocks.registerModBlocks(); put it before the ModItems line:com.example.crystalmod package and the package declaration at the top of the file matches.registerModBlocks() adds the block via ItemGroupEvents with entries.add(CRYSTAL_BLOCK).ModBlocks.registerModBlocks() is called before ModItems.registerModItems() in CrystalMod.java.Create a PNG texture for the Crystal Block and save it in the right folder.
textures/block.textures/block/ folder.Create two JSON model files one for the block in the world, one for it as a held/placed item.
assets/crystalmod, create the folder models/block.assets/crystalmod/models/item (which you created in Episode 1), create crystal_block.json:Create the blockstates JSON this tells Minecraft which model to use for the block's default state.
assets/crystalmod, create the folder blockstates."" means "default state"."block.crystalmod.crystal_block": "Crystal Block"assets/crystalmod/textures/block/crystal_block.png folder is block, not blocks.assets/crystalmod/blockstates/crystal_block.json folder is blockstates (with an s, unlike texture).models/block/ and the item model goes in models/item/. Two separate files in two separate folders!Create a loot table so that mining the Crystal Block drops 1 Crystal Gem.
src/main/resources, navigate to the data folder. Create the path: data/crystalmod/loot_table/blocks/rolls: 1 means drop 1 item. survives_explosion means creepers won't drop the gem (realistic behaviour blow up a block and you lose the loot!). Remove that condition if you want it to always drop.Create a crafting recipe so players can turn 9 Crystal Gems into 1 Crystal Block (like iron ingots → iron block).
data/crystalmod, create a recipe folder."G G" with spaces means the middle column is empty. You could make a 2×2 recipe using just 4 gems by using only the top-left 2×2 area of the pattern.Launch Minecraft, find your Crystal Block in creative mode, place it and see it glow!
/gamemode survival) and try to mine it you'll need a pickaxe, and it should drop a Crystal Gem when broken.crystal_block.png and is in the right folder. Check the blockstates JSON matches that name too.Customise your Crystal Block's properties to make it exactly the way you want it.
luminance(state -> 10) to 15 for maximum brightness, or 4 for a subtle glow.strength(3.0f, 4.0f) to strength(50.0f, 1200.0f) to make it as hard as obsidian!BlockSoundGroup.GLASS, BlockSoundGroup.METAL or BlockSoundGroup.STONE each gives a different sound when walked on and mined.MapColor.BLUE, MapColor.PURPLE or MapColor.EMERALD_GREEN this changes the colour the block shows on a map.