PrefabRenderer:Rendering

From MutigerAffe Wiki
Jump to navigation Jump to search

This page explains how Prefab Renderer turns a prefab into 3D blocks. Where it finds the block definitions, models and textures is described on Asset Sources.

What is read from the prefab

Field Use
blocks Required. Each entry with numeric x, y, z and a name becomes one block. Entries without these fields are skipped.
blocks[].rotation Rotation of the block, see Rotation.
blocks[].filler Cells with a value other than 0 belong to a multi-block model whose origin is elsewhere. They are skipped.
blocks[].components Components.ItemContainerBlock marks a chest. Its Droplist and Capacity are shown in the sidebar.
fluids Optional. Fluid cells, see Fluids.
anchorX, anchorY, anchorZ Shown in the sidebar. They do not move the model.

Blocks named Empty or Air and blocks with an empty name are not drawn. Entities (entities) are not shown.

Block names

A block name in a prefab is split into the item ID, an optional state and an optional extra rotation:

  • A leading * is removed.
  • _State_Definitions_ separates item ID and state. *Rock_Stone_Brick_Smooth_Half_State_Definitions_Block is the item Rock_Stone_Brick_Smooth_Half in the state Block.
  • Options after a vertical bar add a rotation in degrees, as used in blueprints: Name|Yaw=90|Pitch=90|Roll=0. Upper and lower case of the option names do not matter.

Item definitions

For every item ID the extension looks for Server/Item/Items/**/<ItemID>.json in the asset sources. If no file has exactly that name, a match that differs only in upper and lower case is used.

  • Parent chains: if the item has a Parent, the parent's fields are loaded first and the item's own fields override them. Fields inside BlockType are merged the same way, one level deep.
  • States: the state is looked up in BlockType.State.Definitions. Its fields override the fields of BlockType. If the state does not exist, the base block is drawn and a warning is shown.

Draw types

DrawType How it is drawn
Empty Not drawn
Model Model from CustomModel
CubeWithModel Cube from Textures plus the model from CustomModel
not set Cube if Textures is set, otherwise the model from CustomModel
any other value Cube if Textures is set, otherwise an unknown block

Cube blocks

Cube textures come from the first entry of Textures. For each face the first key that is set is used:

Face Keys, in order
Top Up, UpDown, All
Bottom Down, UpDown, All
North, South, East, West North / South / East / West, then Sides, then All

Texture paths are relative to Common/. Only PNG files are read. A face whose texture is missing is drawn magenta and a warning is shown.

Faces between two cubes are hidden when the neighbour is a solid cube (no RequiresAlphaBlending and Opacity unset or Solid) or the same block type. This keeps large prefabs fast.

Model blocks

Models are read from Common/<CustomModel> (.blockymodel files).

  • Boxes and quads are supported, including the node hierarchy, offsets, stretch and orientation.
  • Texture coordinates follow the Hytale Blockbench plugin, including UV offset, mirror and angle.
  • 32 model units are one block. Models stand on the bottom of their cell and are centred on X and Z.
  • CustomModelScale scales the model.
  • The texture is the first entry of CustomModelTexture. If it is missing, the model is drawn magenta and a warning is shown.

Rotation

The prefab field rotation packs three quarter turns into one number:

rotation = roll × 16 + pitch × 4 + yaw

Each part is 0 to 3 for 0°, 90°, 180° or 270°. Yaw +90° turns north (−Z) to west (−X). Pitch turns around +X, roll around +Z. The rotations are applied as yaw · pitch · roll around the centre of the cell. Rotation options in the block name are added on top.

Transparency and tint

  • Cut-out textures such as leaves and plants: transparent pixels are cut away (alpha test).
  • Blended blocks: blocks with RequiresAlphaBlending are drawn semi-transparent and do not hide faces behind them.
  • Tint: if the block definition has TintUp, TintDown, TintNorth, TintSouth, TintEast, TintWest or Tint, the first color of that list is multiplied onto the texture. The face-specific key wins over Tint. Only colors in the form #rrggbb are used.
  • Grayscale textures (_GS in the file name) without a tint get a fixed green: a leaf green for leaves (Group is Leaves or the texture name contains "leaf" or "leaves"), a grass green for everything else. Biome colors are not used.

Fluids

Fluids from the fluids array are drawn as translucent full cubes. The level of the fluid is ignored. Faces between two cells of the same fluid and faces against solid cubes are hidden.

The color is chosen from the fluid name:

Name contains Color
lava Orange, almost opaque
poison Green
slime Light green
tar Almost black, almost opaque
anything else Blue

Unknown blocks

A block that cannot be resolved is drawn as a magenta cube and listed under Unknown blocks in the sidebar with the reason. See FAQ and Troubleshooting.

Limits

The view is an approximation of the game:

  • Lighting is simple: a sky light and one sun. There is no ambient occlusion, no block light and no biome color.
  • Only the first texture variant (Textures[0], CustomModelTexture[0]) is used. RandomRotation is ignored.
  • Connected-block rules (ConnectedBlockRuleSet, for example double chests, fences and roofs) are ignored. Each block is drawn exactly as it is named in the prefab.
  • Transition textures, side masks (TextureSideMask) and animations are not drawn.
  • The direction of pitch and roll has been checked against the asset data, but not in the game for every block.
  • Fluids are always full cubes. Entities are not shown.
Prefab Renderer
Start Installation · Using the 3D View
Features Rendering · Asset Sources
Reference Commands and Settings · FAQ and Troubleshooting · Version History
Links Project page on mutigeraffe.com · Download on the VS Code Marketplace