Block rendering
These types decide how a mod’s blocks look: their render layer and tint, a block drawn as
another block’s state or from a value it keeps, the state a block shows its neighbors, a box
within a block painted in another block’s look, and a resource pack shipped in the mod’s jar.
Most are registered in client initialization; BlockAppearance is answered by the block class
on both sides. What a block does in the world is on
Block behavior, and the particles
it shows on Particles.
At a glance
Section titled “At a glance”| Type | Summary | Status | Since | Side | Thread |
|---|---|---|---|---|---|
BlockAppearance |
The state a block reports to neighbors that ask how it looks, such as connected textures. | Experimental | 2.17.0 | both | any |
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 |
ClientWorldClock |
The time of day in the world the client is in. | Experimental | 2.10.0 | client | any |
Colormap |
A texture read as a grid of colors. | Experimental | 2.3.0 | client | any |
DataModel |
A block’s model drawn from a value read at its position, such as a cask’s fill level, for DataModels#register. |
Experimental | 2.10.0 | client | any |
DataModels |
A block drawn per position from a value its block entity keeps, with extra models baked for it. | Experimental | 2.10.0 | client | setup |
FoliageColors |
Foliage colors for a leaf block’s and its item’s color providers. | Experimental | 2.10.0 | client | any |
MimicModels |
A block that draws, at each position, the block state a MimicSource gives. |
Experimental | 2.10.0 | client | setup |
MimicSource |
The block state a mimic block draws at a position, for MimicModels#register. |
Experimental | 2.10.0 | client | any |
PaintedBox |
A box within a block drawn in another block state’s look, for a DataModel’s parts. |
Experimental | 2.15.0 | client | any |
PaintSource |
The block state painted in one slot of a block at a position, for PaintedBox#tint. |
Experimental | 2.15.0 | client | any |
Quick start
Section titled “Quick start”The examples on this page use the Registered handles a mod’s Registrar returns:
MAPLE_LEAVES and MAPLE_SAPLING. In your mod’s client initializer:
BlockRendering.cutout(MAPLE_SAPLING);BlockRendering.blockColor(MAPLE_LEAVES, (state, level, pos, tintIndex) -> FoliageColors.at(level, pos));BlockRendering.itemColor(MAPLE_LEAVES, (stack, tintIndex) -> FoliageColors.defaultColor());BlockRendering
Section titled “BlockRendering”BlockRendering: Experimental · Since 2.1.0 · Side: client · Thread: setup
ClientWorldClock: Experimental · Since 2.10.0 · Side: client · Thread: any
FoliageColors: Experimental · Since 2.10.0 · Side: client · Thread: any
BlockRendering sets the render layer and tint color of a mod’s see-through or tinted blocks
and items on the client. The quick start shows the three calls.
-
FoliageColorsgives a color provider the foliage color vanilla’s oak leaves take. -
ClientWorldClock#dayTimegives a color provider the client world’s day time, for a color that changes by the day. -
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
Tint a block from a colormap texture a resource pack can replace, as vanilla tints grass and leaves. In 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.
MimicModels and MimicSource
Section titled “MimicModels and MimicSource”MimicModels: Experimental · Since 2.10.0 · Side: client · Thread: setup
MimicSource: Experimental · Since 2.10.0 · Side: client · Thread: any
MimicModels makes a block draw another block’s state, which a MimicSource gives per
position. PaintedCableBlockEntity keeps the state a player painted the cable with in a
volatile BlockState field, paint, and redraws from SyncedBlockEntity#onClientData as
SyncedBlockEntity shows. In client initialization, with
PAINTED_CABLE, its block:
MimicModels.register(PAINTED_CABLE, MimicSource.fromBlockEntity( PaintedCableBlockEntity.class, cable -> cable.paint));- On the client, set
paintonly on the render thread, inreadClientData, and read it once per call.
BlockAppearance
Section titled “BlockAppearance”Experimental · Since 2.17.0 · Side: both · Thread: any
Connected-texture mods decide a join by asking each neighbor how it looks. A mimic block
that answers with the state it draws joins its neighbors as that state. The painted cable from
the section above keeps one BlockAppearance in a public static field of its block class,
PaintedCableBlock, and answers the loaders’ appearance question with it:
public static final BlockAppearance CABLE_PAINT = BlockAppearance.fromBlockEntity( PaintedCableBlockEntity.class, cable -> cable.paint);
// No @Override: common code compiles against vanilla, which has no getAppearance.public BlockState getAppearance(BlockState state, BlockAndTintGetter level, BlockPos pos, Direction side, @Nullable BlockState queryState, @Nullable BlockPos queryPos) { return CABLE_PAINT.appearance(state, level, pos);}- The server asks too, and reads the server’s block entity, so set
paintthere as well, on the server thread, where the player paints the cable.
DataModels and DataModel
Section titled “DataModels and DataModel”DataModel: Experimental · Since 2.10.0 · Side: client · Thread: any
DataModels: Experimental · Since 2.10.0 · Side: client · Thread: setup
DataModels draws a block from a value read at its position, with the chunk and no block
entity renderer. CaskBlockEntity keeps its fill in a volatile CaskFill field, fill, an
enum of EMPTY, HALF, and FULL, and redraws from SyncedBlockEntity#onClientData as
SyncedBlockEntity shows. With CASK, its block, and
id("block/cask_glass_half") and id("block/cask_glass_full") its glass models, HALF_GLASS
and FULL_GLASS, in client initialization:
DataModels.extraModel(HALF_GLASS);DataModels.extraModel(FULL_GLASS);DataModels.register(CASK, new DataModel<CaskFill>() { @Override public CaskFill valueAt(BlockAndTintGetter level, BlockPos pos) { return level.getBlockEntity(pos) instanceof CaskBlockEntity cask ? cask.fill : null; }
@Override public void parts(CaskFill fill, BlockState state, BakedModel base, Consumer<BakedModel> out) { out.accept(base); if (fill == CaskFill.HALF) out.accept(DataModels.model(HALF_GLASS)); if (fill == CaskFill.FULL) out.accept(DataModels.model(FULL_GLASS)); }});- A block drawn by what stands beside it, such as a pipe that bends toward the pipe next to
it, reads that neighbor’s block state in
DataModel#valueAtand needs no redraw call.
PaintedBox
Section titled “PaintedBox”PaintedBox: Experimental · Since 2.15.0 · Side: client · Thread: any
PaintSource: Experimental · Since 2.15.0 · Side: client · Thread: any
PaintedBox is a data model part: a box within a block drawn in a block state the player
picks, as a panel painted to look like stone or stained glass. FittingBlockEntity keeps its
panels’ paints in a volatile Panels field, panels, never null, a record of a state for each
face with paint(int slot), null for a face with no panel. With FITTING, the block, and
PANELS, a private static final List<PaintedBox> of one plate per face, trimmed where plates
meet, in slot order, in client initialization:
DataModels.register(FITTING, new DataModel<Panels>() { @Override public Panels valueAt(BlockAndTintGetter level, BlockPos pos) { return level.getBlockEntity(pos) instanceof FittingBlockEntity fitting ? fitting.panels : null; }
@Override public void parts(Panels panels, BlockState state, BakedModel base, Consumer<BakedModel> out) { out.accept(base); if (panels == null) return; for (int slot = 0; slot < PANELS.size(); slot++) { BlockState paint = panels.paint(slot); if (paint != null) out.accept(PANELS.get(slot).model(paint, slot)); } }});PaintedBox.tint(FITTING, (level, pos, slot) -> level.getBlockEntity(pos) instanceof FittingBlockEntity fitting ? fitting.panels.paint(slot) : null);- The lambda handed to
PaintedBox#tintis the block’sPaintSource. - On Forge a data model keeps its parts for each value, so a value that holds six paints makes a kept entry for each combination drawn; this suits paints a player sets by hand.
BuiltinPacks
Section titled “BuiltinPacks”Experimental · Since 2.5.0 · Side: client · Thread: setup
BuiltinPacks lists a resource pack that ships inside the mod’s jar, off until the player
turns it on. With the jar holding the folder BuiltinPacks#folder32x names, a whole pack
with pack.mcmeta, pack.png, and assets/, and the lang file holding the key
BuiltinPacks#titleKey32x gives, in client initialization:
BuiltinPacks.register32x("mymod");register32x shows the title in gold. For a title of another color, or a pack of another
name, call BuiltinPacks#register with the folder and the title. In client initialization:
BuiltinPacks.register("mymod", BuiltinPacks.folder32x("mymod"), Component.translatable(BuiltinPacks.titleKey32x("mymod")).withStyle(ChatFormatting.AQUA));- Turned on, the pack sits above the mod’s own resources, so its textures replace the mod’s defaults.
See also
Section titled “See also”- Block behavior: a wood’s fire, stripping, and sapling growers.
- Particles: leaves that fall from a leaf block, and a mod’s particle types and their client providers.
- Block entities:
SyncedBlockEntity, which sends the data a mimic or data model draws from. - Registration and ids: registering the blocks and items these calls take.
- Client events: the F3 line
example, which reads a
Colormap.