-
Notifications
You must be signed in to change notification settings - Fork 56
Custom Models
Cross loader custom baked models, model loaders and per block model data.
Forge and Fabric have completely different model APIs. CustomBakedModel is one interface that
works on both: you return quads for a state, a direction and a render type, and you get extra
model data so a block entity can feed information into its own model.
CustomModelLoader registers a json loader for your own model format, and NestedModelLoader
lets your format contain other models.
Register the loader on client init:
ClientHelper.addModelLoaderRegistration(event ->
event.register(MyMod.res("custom_loader"), new MyModelLoader()));public class MyModelLoader implements CustomModelLoader {
@Override
public CustomGeometry deserialize(JsonObject json, JsonDeserializationContext context) {
JsonElement inner = json.get("inner_model");
boolean translated = json.get("is_translated").getAsBoolean();
return (modelBaker, spriteGetter, transform) -> {
var innerModel = CustomModelLoader.parseModel(inner, modelBaker, spriteGetter, transform);
return new MyBakedModel(innerModel, translated, transform);
};
}
}The model itself:
@Override
public List<BakedQuad> getBlockQuads(BlockState state, Direction dir, RandomSource random,
RenderType renderType, ExtraModelData data) {
List<BakedQuad> quads = new ArrayList<>();
// per render type, so one model can draw into several layers
if (renderType == RenderType.translucent()) {
quads.add(...);
}
// data pushed in by the block entity
Block mimic = data.get(MIMIC_BLOCK_KEY);
if (mimic != null) {
quads.addAll(Minecraft.getInstance().getBlockRenderer()
.getBlockModel(mimic.defaultBlockState())
.getQuads(mimic.defaultBlockState(), dir, random));
}
return quads;
}To feed data in, implement IExtraModelDataProvider on the block entity and declare a
ModelDataKey for each value.
Building and editing quads is BakedQuadBuilder and BakedQuadsTransformer.
Examples: CustomModelLoaderExample, QuadUtilsExample
Basics Platform Helpers Registration Networking Events Configs Config Screen
Resources Runtime Resource Packs Texture Manipulation Resource Helpers Block Set API
Client Custom Models Item Rendering Rendered Textures Post Shaders GUI Toolkit Colors
World Block and Item Interfaces Additional Item Placements Improved Entities Fake Levels World Data Dispenser Behaviors
Utilities Codec Utilities Misc Helpers Commands
Datapacks Villagers Soft Fluids Map Markers Spawn Boxes Global Datapack Folder