How to make a block that gives off light in a Minecraft mod
A block’s light comes from its properties: lightLevel takes a function from the block’s state to a level from 0 to 15, so a lamp can glow always (state -> 15) or only in some states. Set it when you register the block; the game spreads the light around it. On 1.12.2 a block has a setLightLevel method that takes one float for every state.
Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.
- Register a block whose properties have .lightLevel(state -> 15) (0 to 15; a torch gives 14).
- Give it a sound that fits, such as SoundType.GLASS.
- Add its blockstate, models, texture, loot table and name like any block.
What you can change
Section titled “What you can change”The example uses these values. Change them in the code.
| Setting | In the example | What it does |
|---|---|---|
| light | 15 |
How bright it glows, 0 to 15 (a torch is 14, glowstone 15). |
For each loader and version
Section titled “For each loader and version”The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.
Fabric 1.20 to 26.2
Section titled “Fabric 1.20 to 26.2”Uses:
Registry.registerBuiltInRegistries.BLOCKBuiltInRegistries.ITEMBlockBehaviour.Properties.ofBlockItemBlockBehaviour.Properties.lightLevel
It’s registered like any other block: see a new block.
BlockBehaviour.Properties.of().mapColor(MapColor.GOLD).strength(0.3F).sound(SoundType.GLASS).lightLevel(state -> 15)NeoForge 1.20.1 to 1.21, Forge 1.20 to 1.20.1
Section titled “NeoForge 1.20.1 to 1.21, Forge 1.20 to 1.20.1”Uses:
DeferredRegister.createForgeRegistries.BLOCKSForgeRegistries.ITEMSRegistryObjectBlockBehaviour.Properties.ofBlockBehaviour.Properties.lightLevel
It’s registered like any other block: see a new block.
BlockBehaviour.Properties.of().mapColor(MapColor.GOLD).strength(0.3F).sound(SoundType.GLASS).lightLevel(state -> 15)NeoForge 1.21.1 to 26.3
Section titled “NeoForge 1.21.1 to 26.3”Uses:
DeferredRegister.createBlocksDeferredRegister.Blocks.registerSimpleBlockDeferredRegister.Items.registerSimpleBlockItemDeferredBlockBlockBehaviour.Properties.ofBlockBehaviour.Properties.lightLevel
It’s registered like any other block: see a new block.
BlockBehaviour.Properties.of().mapColor(MapColor.GOLD).strength(0.3F).sound(SoundType.GLASS).lightLevel(state -> 15)Fabric 26.3
Section titled “Fabric 26.3”Uses:
Registry.registerBuiltInRegistries.BLOCKResourceKey.createBlockBehaviour.Properties.setIdBlockBehaviour.Properties.ofBlockItemBlockBehaviour.Properties.lightLevel
It’s registered like any other block: see a new block.
BlockBehaviour.Properties.of().mapColor(MapColor.GOLD).strength(0.3F).sound(SoundType.GLASS).lightLevel(state -> 15)Forge 1.17.1 to 1.19.4
Section titled “Forge 1.17.1 to 1.19.4”Uses:
DeferredRegister.createForgeRegistries.BLOCKSForgeRegistries.ITEMSRegistryObjectBlockBehaviour.Properties.ofBlockBehaviour.Properties.lightLevel
It’s registered like any other block: see a new block.
BlockBehaviour.Properties.of(Material.GLASS).strength(0.3F).sound(SoundType.GLASS).lightLevel(state -> 15)Fabric 1.16.5 to 1.19.4
Section titled “Fabric 1.16.5 to 1.19.4”Uses:
Registry.registerBuiltInRegistries.BLOCKBuiltInRegistries.ITEMBlockBehaviour.Properties.ofBlockItemBlockBehaviour.Properties.lightLevel
It’s registered like any other block: see a new block.
BlockBehaviour.Properties.of(Material.GLASS).strength(0.3F).sound(SoundType.GLASS).lightLevel(state -> 15)Forge 1.16.5
Section titled “Forge 1.16.5”Uses:
DeferredRegister.createForgeRegistries.BLOCKSForgeRegistries.ITEMSRegistryObjectAbstractBlock.Properties.ofAbstractBlock.Properties.lightLevel
It’s registered like any other block: see a new block.
AbstractBlock.Properties.of(Material.GLASS).strength(0.3F).sound(SoundType.GLASS).lightLevel(state -> 15)Forge 1.12.2
Section titled “Forge 1.12.2”Uses:
Block.setLightLevel
In 1.12.2 the light is block.setLightLevel(1.0F), a float from 0.0 (dark) to 1.0 (level 15) that is the same in every state.
src/main/java/com/example/examplemod/block/GlowLampBlock.java
package com.example.examplemod.block;
import net.minecraft.block.Block;import net.minecraft.block.material.Material;import net.minecraft.block.SoundType;
// Glow Lamp: a block that gives off light of level 15. 1.12.2 takes the light as a fraction of 15.public class GlowLampBlock extends Block { public GlowLampBlock() { super(Material.GLASS); setHardness(0.3F); setSoundType(SoundType.GLASS); setLightLevel(15 / 15.0F); }}It’s registered like any other block, as GlowLampBlock: see a new block.
Sources
Section titled “Sources”- https://docs.fabricmc.net/1.21.1/develop/blocks/blockstates
- https://docs.neoforged.net/docs/1.21.1/blocks/
Related how-tos
Section titled “Related how-tos”- A block that changes over time with random ticks
- A block with the properties you choose
- A new block
- A block that can hold water
- A block that faces the player
In Linen
Section titled “In Linen”Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.