How to make a source of redstone power in a Minecraft mod
A block gives off redstone power by answering two questions. isSignalSource(state) returns true so wires and pistons look at it, and getSignal(state, level, pos, direction) returns the strength from 0 to 15 for each side. Use getDirectSignal as well if the block should power blocks it touches. Strength can depend on a block state property when the block should switch on and off.
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.
- Override isSignalSource to return true.
- Override getSignal to return a strength from 0 to 15.
- Register the block with your class.
- Place a redstone lamp or a repeater beside it to test.
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 |
|---|---|---|
| power | 15 |
The signal strength it gives off on every side. |
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 and NeoForge 1.20.1 to 1.20.4, Fabric 1.16.5 to 1.20, Forge 1.17.1 to 1.20.1
Section titled “Fabric and NeoForge 1.20.1 to 1.20.4, Fabric 1.16.5 to 1.20, Forge 1.17.1 to 1.20.1”Uses:
BlockBehaviour.isSignalSourceBlockBehaviour.getSignal
src/main/java/com/example/examplemod/block/PowerCellBlock.java
package com.example.examplemod.block;
import net.minecraft.core.BlockPos;import net.minecraft.core.Direction;import net.minecraft.world.level.BlockGetter;import net.minecraft.world.level.block.Block;import net.minecraft.world.level.block.state.BlockBehaviour;import net.minecraft.world.level.block.state.BlockState;
// Power Cell: gives off a redstone signal of 15 on every side, like a block of redstone.public class PowerCellBlock extends Block { public PowerCellBlock(BlockBehaviour.Properties properties) { super(properties); }
@Override public boolean isSignalSource(BlockState state) { return true; }
@Override public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { return 15; }}It’s registered like any other block, as PowerCellBlock: see a new block.
Fabric and NeoForge 1.20.5 to 1.21.1, Fabric and NeoForge 1.21.2 to 26.2
Section titled “Fabric and NeoForge 1.20.5 to 1.21.1, Fabric and NeoForge 1.21.2 to 26.2”Uses:
BlockBehaviour.isSignalSourceBlockBehaviour.getSignal
src/main/java/com/example/examplemod/block/PowerCellBlock.java
package com.example.examplemod.block;
import com.mojang.serialization.MapCodec;import net.minecraft.core.BlockPos;import net.minecraft.core.Direction;import net.minecraft.world.level.BlockGetter;import net.minecraft.world.level.block.Block;import net.minecraft.world.level.block.state.BlockBehaviour;import net.minecraft.world.level.block.state.BlockState;
// Power Cell: gives off a redstone signal of 15 on every side, like a block of redstone.public class PowerCellBlock extends Block { public static final MapCodec<PowerCellBlock> CODEC = simpleCodec(PowerCellBlock::new);
public PowerCellBlock(BlockBehaviour.Properties properties) { super(properties); }
@Override protected MapCodec<? extends Block> codec() { return CODEC; }
@Override protected boolean isSignalSource(BlockState state) { return true; }
@Override protected int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { return 15; }}It’s registered like any other block, as PowerCellBlock: see a new block.
Fabric and NeoForge 26.3
Section titled “Fabric and NeoForge 26.3”Uses:
BlockBehaviour.isSignalSourceBlockBehaviour.getSignal
Since 26.3 a Block no longer has a codec: there is no CODEC field and no codec() method to write.
src/main/java/com/example/examplemod/block/PowerCellBlock.java
package com.example.examplemod.block;
import net.minecraft.core.BlockPos;import net.minecraft.core.Direction;import net.minecraft.world.level.BlockGetter;import net.minecraft.world.level.block.Block;import net.minecraft.world.level.block.state.BlockBehaviour;import net.minecraft.world.level.block.state.BlockState;
// Power Cell: gives off a redstone signal of 15 on every side, like a block of redstone.public class PowerCellBlock extends Block { public PowerCellBlock(BlockBehaviour.Properties properties) { super(properties); }
@Override protected boolean isSignalSource(BlockState state) { return true; }
@Override protected int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction direction) { return 15; }}It’s registered like any other block, as PowerCellBlock: see a new block.
Forge 1.16.5
Section titled “Forge 1.16.5”Uses:
AbstractBlock.isSignalSourceAbstractBlock.getSignal
src/main/java/com/example/examplemod/block/PowerCellBlock.java
package com.example.examplemod.block;
import net.minecraft.util.math.BlockPos;import net.minecraft.util.Direction;import net.minecraft.world.IBlockReader;import net.minecraft.block.Block;import net.minecraft.block.AbstractBlock;import net.minecraft.block.BlockState;
// Power Cell: gives off a redstone signal of 15 on every side, like a block of redstone.public class PowerCellBlock extends Block { public PowerCellBlock(AbstractBlock.Properties properties) { super(properties); }
@Override public boolean isSignalSource(BlockState state) { return true; }
@Override public int getSignal(BlockState state, IBlockReader level, BlockPos pos, Direction direction) { return 15; }}It’s registered like any other block, as PowerCellBlock: see a new block.
Forge 1.12.2
Section titled “Forge 1.12.2”Uses:
Block.canProvidePowerBlock.getWeakPower
In 1.12.2 the two methods are canProvidePower(state) and getWeakPower(state, world, pos, side); getStrongPower is the direct one.
src/main/java/com/example/examplemod/block/PowerCellBlock.java
package com.example.examplemod.block;
import net.minecraft.block.Block;import net.minecraft.block.material.Material;import net.minecraft.block.state.IBlockState;import net.minecraft.util.EnumFacing;import net.minecraft.util.math.BlockPos;import net.minecraft.world.IBlockAccess;
// Power Cell: gives off a redstone signal of 15 on every side, like a block of redstone.public class PowerCellBlock extends Block { public PowerCellBlock() { super(Material.IRON); }
@Override public boolean canProvidePower(IBlockState state) { return true; }
@Override public int getWeakPower(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) { return 15; }}It’s registered like any other block, as PowerCellBlock: see a new block.
Sources
Section titled “Sources”- https://docs.fabricmc.net/1.21.1/develop/blocks/first-block
- https://docs.neoforged.net/docs/1.21.1/blocks/
Related how-tos
Section titled “Related how-tos”- A block that can hold water
- A block that faces the player
- A block that changes over time with random ticks
- A block that does something when clicked
- A block that gives off light
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.