Block definitions (JSON) - TheShubham99/Terasology GitHub Wiki
New blocks can easily be included in the game by creating a module with a .block
block definition file. This article gives an overview of what can be specified in these files.
There are two things that are generated by block definitions - blocks themselves, with their specific settings, shapes and rotations, and block families which are sets of blocks that are considered to be variations of the same block. An example is stone stairs. Each possible rotation of the stairs is a separate block, but when you pick them up they are considered the same and stack.
If a block doesn't define a shape, or defines multiple shapes, then it is made available as a full block via the uri "moduleName:blockName", where the moduleName is the id of the containing module or "engine" for built-in blocks, and the blockName is the filename of the block (ignoring the extension). It can also be requested in any shape by using the uri "blockModule:blockName:shapeModule:shapeName".
If a block has a shape defined it can only be requested using the block uri, and its shape is fixed.
The block definition files are structures as any other JSON document. For information see the JSON specification.
Block definitions can extend from other block definitions, specifying just the features by which they differ. This simplifies creating classes of block (like plants).
Option | Value(s) | Default | Description |
---|---|---|---|
basedOn | A block definition uri (e.g. "engine:plant") | Specifies the block to base this block on. | |
template | true, false | false | If true, this block cannot be created and exists only to be based on. |
Option | Value(s) | Default | Description |
---|---|---|---|
displayName | The file name of the block, with the first letter capitalised | The name of the block that is shown to players - particularly when the block is picked up and in their inventory. |
Option | Value(s) | Default | Description |
---|---|---|---|
attachmentAllowed | true, false | true | Determines whether other blocks can be attached to this block. |
hardness | <int> | 3 | Specifies the hardness of the block - effectively its health. |
liquid | true, false | false | Determines if the block is a liquid. |
replacementAllowed | true, false | false | Specifies whether the block can be replaced freely by other blocks - that you can place another block over it. In order to make a block replaceable, it requires the block not to be targetable! |
supportRequired | true, false | false | Specify whether the block should be destroyed when no longer attached to any other block. Only works for vertically adjacent blocks - e.g. grass is removed if the ground under it is destroyed |
By default, a block will try to use a tile texture with a matching filename. e.g. A block defined in Grass.block will use the block tile Grass.png from the same module.
You can specify a different tile to be used with the "tile" property:
"tile" : "engine:grass"
You can also use different texture tiles for the different sides of the block. To do so,
you have to name the corresponding tiles in a tiles
section of the block definition, e.g. for the chest block:
"tiles" : {
"sides" : "core:ChestSides",
"front" : "core:ChestFront",
"topBottom" : "core:ChestTopBottom"
}
Possible block parts are
- all to change every tile (same as using the "tile" property)
- topBottom to change the top and bottom tile
- sides to change the four horizontal sides (excluding only top and bottom) and can itself be overridden
- front, left, right, back, top, bottom refer to the specific sides
- center to change the tile on the center part of the block (see the section on shapes_
Option | Value(s) | Default | Description |
---|---|---|---|
tile | a blockTile uri | A block tile with the same module and name as block definition | Specifies what blockTile to use to texture this block |
tiles | Allows the blockTile used by different parts/sides of the block to be overridden. | ||
doubleSided | true, false | false | Whether this block should be rendered double sided. This done for billboard plants to render both sides of polygons. |
invisible | true, false | false | If set to true the block is not rendered at all. |
translucent | true, false | false | Determines whether the block is transparent/translucent or not. Blocks with this option enabled can use textures with transparency (but not translucency, see ice). Moreover, translucent blocks do not prevent occluded blocks behind them from beeing rendered (blocks behind a translucent glass block are still displayed). |
ice | true, false | false | Determines whether the block is translucent, but not completely transparent. Blocks with this option enabled can use textures with translucency. Blocks with this enabled should also have translucent enabled, or they will occlude blocks behind them. |
shadowCasting | true, false | true | Should this block cast a slight shadow around it? |
waving | true, false | false | Whether the blocks waves in the wind. Mainly used for grass and foliage. |
luminance | <int> | 0 | The light level of the block. The default torches have a light value of 15, for reference. |
Color gradients can be used to change the color of specific blocks, e.g. grass or fooliage.
Option | Value(s) | Description |
---|---|---|
colorSource | <source> | e.g. "colorSource" : "color_lut" . |
colorSources | Enumerate the different color sources, default can be used to exclude LUTs for specific block parts. |
|
colorOffset | [R, G, B, A ] | Specify a color offset, e.g. given for red leaves: "colorOffset" : '[2.0, 0.0, 0.5, 1.0'] . |
Block shapes are specialised meshes that give a block its shape. If no shape is specialised then a block is a cube.
Generally for a non-cubic block you would define the shape with the shape property.
"shape" : "engine:cube"
You can also use the "shapes" property to list a number of valid shapes.
When using a block shape, it is often desirable to allow the block to rotate based on how it is being placed, or even to have different shapes depending on how it is being placed. This can be enabled using the "rotation" property. The following settings are available:
- none The block will not be rotated (default)
- horizontal The block will rotate on the horizontal plane. For instance, stairs will face towards the player when placed.
- alignToSurface Similar to horizontal but with support for different blocks when placed against the ground or ceiling.
When using the alignToSurface rotation mode, you can specify a "sides", "top" and/or "bottom" section to provide override properties for those placements. e.g.
"rotation" : "alignToSurface",
"sides" : {
"shape" : "engine:stair",
},
"bottom": {
"shape" : "engine:cube"
}
would be shaped like a cube when placed on the ground, and shaped like stairs when placed against a side. It cannot be placed against a ceiling (as no shape is defined for that case). Many properties can be overridden in this manner.
Option | Value(s) | Default | Description |
---|---|---|---|
shape | a shape uri | "engine:cube" | The shape of the block |
shapes | a lists of shape uris | A set of valid shapes for this block | |
rotation | none, horizontal, alignToSurface | none | Defines the rotation mode for the block |
top/bottom/sides | In alignToSurface rotation mode, allows settings to be specified for specific surface placements |
For more on shapes see Shape Architecture
Option | Value(s) | Default | Description |
---|---|---|---|
penetrable | true, false | false | A block is penetrable if it does not block solid objects. |
targetable | true, false | true | Define whether the block can be targeted for interactions. Must be set to false to allow direct replacement.
|
Option | Value(s) | Default | Description |
---|---|---|---|
debrisOnDestroy | true, false | true | If enabled destroyed blocks will drop a miniature instance of the block that can be picked up by the player. |
mass | <int> | 10 | The mass value for the physics simulation. |
The mass does not seem to have any influence on the objects in the game.
The options for enity integration are wrapped in the entity
option, e.g. for a chest:
"entity" : {
"prefab" : "core:chest",
"mode" : "persistent"
}
Option | Value(s) | Default | Description |
---|---|---|---|
prefab | <prefab> | The corresponding entity prefab for this block. | |
mode | <EntityMode> | onInteraction | Specify the mode for the entity. For information on the enity modes see Entity Modes. |
The inventory settings have to be in an inventory
section as well, e.g. again for the chest definition:
"inventory" : {
"stackable" : false,
"directPickup" : true
}
Option | Value(s) | Default | Description |
---|---|---|---|
directPickup | true, false | false | Whether this block should go directly into a character's inventory when harvested. |
isStackable | true, false | true | Determines whether the block type is stackable in the inventory. |
Option | Value(s) | Default | Description |
---|---|---|---|
shape | <shape> | "engine:cube" | Define the shape of the block. You can use either existing shapes or use self created ones. For more information, see Block Shapes in Blender or Shapes in general. |
shapes | [<shape>,...] | You can restrict the usage of a block type to some shapes. If not explicitly defined, a block type can be instantiated as any available shape. |
Option | Value(s) | Description |
---|---|---|
categories | <listOfCategories> | Give a list of categories the block belongs to, e.g. new soil types might go into "categories" : '["soil"'] . |
Option | Value(s) | Default | Description |
---|---|---|---|
craftPlace | true, false | true | Determines whether the player can open up the crafting system on this block. |
- Add soundfile specification for walking sounds on specific block types?