Skip to content

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.

  1. Register a block whose properties have .lightLevel(state -> 15) (0 to 15; a torch gives 14).
  2. Give it a sound that fits, such as SoundType.GLASS.
  3. Add its blockstate, models, texture, loot table and name like any block.

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).

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Uses:

  • Registry.register
  • BuiltInRegistries.BLOCK
  • BuiltInRegistries.ITEM
  • BlockBehaviour.Properties.of
  • BlockItem
  • BlockBehaviour.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.create
  • ForgeRegistries.BLOCKS
  • ForgeRegistries.ITEMS
  • RegistryObject
  • BlockBehaviour.Properties.of
  • BlockBehaviour.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)

Uses:

  • DeferredRegister.createBlocks
  • DeferredRegister.Blocks.registerSimpleBlock
  • DeferredRegister.Items.registerSimpleBlockItem
  • DeferredBlock
  • BlockBehaviour.Properties.of
  • BlockBehaviour.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)

Uses:

  • Registry.register
  • BuiltInRegistries.BLOCK
  • ResourceKey.create
  • BlockBehaviour.Properties.setId
  • BlockBehaviour.Properties.of
  • BlockItem
  • BlockBehaviour.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)

Uses:

  • DeferredRegister.create
  • ForgeRegistries.BLOCKS
  • ForgeRegistries.ITEMS
  • RegistryObject
  • BlockBehaviour.Properties.of
  • BlockBehaviour.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)

Uses:

  • Registry.register
  • BuiltInRegistries.BLOCK
  • BuiltInRegistries.ITEM
  • BlockBehaviour.Properties.of
  • BlockItem
  • BlockBehaviour.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)

Uses:

  • DeferredRegister.create
  • ForgeRegistries.BLOCKS
  • ForgeRegistries.ITEMS
  • RegistryObject
  • AbstractBlock.Properties.of
  • AbstractBlock.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)

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.

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.