Block behavior and rendering
These types give a mod’s blocks what vanilla blocks have: fire, stripping, composting, fuel, signs, render layers, tints, saplings that grow trees, and falling leaves. Call them during initialization, after the blocks are registered.
At a glance
Section titled “At a glance”| Type | Summary | Status | Since | Side | Thread |
|---|---|---|---|---|---|
BlockBehaviors |
Vanilla behaviors for blocks and items. | Experimental | 2.1.0 | both | setup |
BlockRendering |
Client rendering setup for blocks and items. | Experimental | 2.1.0 | client | setup |
BuiltinPacks |
Lists a resource pack from a mod’s jar in the client’s resource pack screen. | Experimental | 2.5.0 | client | setup |
Colormap |
A texture read as a grid of colors. | Experimental | 2.3.0 | client | any |
FallingLeaves |
Leaves that drift down from a block, as vanilla cherry leaves do. | Experimental | 2.4.0 | both | render |
ParticleProviders |
Gives a particle type its client provider from a sprite set, including Stope’s falling leaves. | Experimental | 2.4.0 | client | setup |
SaplingGrowers |
Growers for a mod’s saplings. | Experimental | 2.4.0 | both | setup |
Quick start
Section titled “Quick start”The examples on this page use the Registered handles a mod’s Registrar returns:
MAPLE_LOG and STRIPPED_MAPLE_LOG (RotatedPillarBlock), MAPLE_PLANKS, MAPLE_LEAVES,
and MAPLE_SAPLING. In your mod’s common initializer, after registering them:
BlockBehaviors.flammable(MAPLE_LOG, 5, 5);BlockBehaviors.flammable(MAPLE_PLANKS, 5, 20);BlockBehaviors.flammable(MAPLE_LEAVES, 30, 60);BlockBehaviors.strippable(MAPLE_LOG, STRIPPED_MAPLE_LOG);BlockBehaviors.compostable(MAPLE_LEAVES, 0.3f);BlockBehaviors.compostable(MAPLE_SAPLING, 0.3f);BlockBehaviors
Section titled “BlockBehaviors”Experimental · Since 2.1.0 · Side: both · Thread: setup
BlockBehaviors gives a mod’s blocks and items the fire, stripping, composting, fuel, and sign
behavior vanilla blocks have. With MAPLE_SIGN, MAPLE_WALL_SIGN, MAPLE_HANGING_SIGN, and
MAPLE_WALL_HANGING_SIGN, the maple wood’s four sign blocks:
BlockBehaviors.sign(MAPLE_SIGN);BlockBehaviors.sign(MAPLE_WALL_SIGN);BlockBehaviors.sign(MAPLE_HANGING_SIGN);BlockBehaviors.sign(MAPLE_WALL_HANGING_SIGN);- Flammability, stripping, and composting write vanilla’s own tables (
FireBlock,AxeItem.STRIPPABLES,ComposterBlock.COMPOSTABLES), which Fabric API’s content registries and Forge read too, so other mods see the values.
BlockRendering
Section titled “BlockRendering”Experimental · Since 2.1.0 · Side: client · Thread: setup
BlockRendering sets the render layer and tint color of a mod’s see-through or tinted blocks
and items on the client.
// Client initialization:BlockRendering.cutout(MAPLE_SAPLING);BlockRendering.itemColor(MAPLE_LEAVES, (stack, tintIndex) -> 0x48B518);- A mod that sets a render layer here needs no
render_typein its model JSON. - On Forge, a
render_typein the model JSON wins over the layer set here.
Colormap
Section titled “Colormap”Experimental · Since 2.3.0 · Side: client · Thread: any
// Client initialization:Colormap leaves = Colormap.of(id("textures/colormap/leaves.png"), 0x48B518);BlockRendering.blockColor(MAPLE_LEAVES, (state, level, pos, tint) -> pos == null ? leaves.color(0, 0) : leaves.color(pos.getX(), pos.getZ()));- A resource pack can replace the texture, and chunks rebuild after each resource reload, so block colors follow the new texture at once.
- A color that changes over time (by the day, say) shows only when a chunk section is next rebuilt; Stope does not rebuild sections for it.
- The texture is decoded on the render thread during the reload, which costs little for a few small colormaps.
SaplingGrowers
Section titled “SaplingGrowers”Experimental · Since 2.4.0 · Side: both · Thread: setup
The trees are configured features in the mod’s data, named by their keys. Vanilla’s
SaplingBlock constructor is protected, and a mod’s common code compiles against vanilla, so
the mod’s sapling is a subclass of its own that passes the grower to super. With
REGISTRAR, the mod’s Registrar:
public final class MapleSaplingBlock extends SaplingBlock { private static final ResourceKey<ConfiguredFeature<?, ?>> MAPLE = ResourceKey.create(Registries.CONFIGURED_FEATURE, id("maple")); private static final ResourceKey<ConfiguredFeature<?, ?>> GIANT_MAPLE = ResourceKey.create(Registries.CONFIGURED_FEATURE, id("giant_maple"));
public MapleSaplingBlock(Properties properties) { super(SaplingGrowers.withGiant(MAPLE, GIANT_MAPLE), properties); }}
// In the mod's block holder:static final Registered<SaplingBlock> MAPLE_SAPLING = REGISTRAR.block("maple_sapling", () -> new MapleSaplingBlock(BlockBehaviour.Properties.copy(Blocks.OAK_SAPLING)));FallingLeaves
Section titled “FallingLeaves”Experimental · Since 2.4.0 · Side: both · Thread: render
Register the particle type in common initialization with the mod’s REGISTRAR, then emit it
from the leaf block. The field is public because the client code below reads it from the
mod’s client package:
public static final Registered<SimpleParticleType> MAPLE_LEAF = REGISTRAR.register(Registries.PARTICLE_TYPE, "maple_leaf", FallingLeaves::newType);@Overridepublic void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) { super.animateTick(state, level, pos, random); FallingLeaves.animateTick(level, pos, random, MAPLE_LEAF.get(), FallingLeaves.CHERRY_CHANCE);}ParticleProviders
Section titled “ParticleProviders”Experimental · Since 2.4.0 · Side: client · Thread: setup
ParticleProviders tells the client how to draw a mod’s particle types;
ParticleProviders#fallingLeaves draws a type made by FallingLeaves. With MAPLE_LEAF from
the FallingLeaves example:
// Client initialization:ParticleProviders.fallingLeaves(MAPLE_LEAF);- A falling leaf lasts 300 ticks (15 seconds).
BuiltinPacks
Section titled “BuiltinPacks”Experimental · Since 2.5.0 · Side: client · Thread: setup
// Client initialization; the jar holds resourcepacks/mymod_32x/ with pack.mcmeta, pack.png,// and assets/:BuiltinPacks.register("mymod", "mymod_32x", Component.translatable("pack.mymod.mymod_32x"));- Turned on, the pack sits above the mod’s own resources, so its textures replace the mod’s defaults.
- The pack’s ID is
<modId>:<folder>on every loader, so a choice saved on one loader names the same pack on the other.
See also
Section titled “See also”- Registration and ids: registering the blocks, items, and particle types these calls take.
- Worldgen and loot: placing a mod’s trees in biomes.
- Add a wood type with boats: a guide that builds a wood step by step.