Block - rvandoosselaer/Blocks GitHub Wiki

A Block is the basic building element of Blocks. The parameters specify the shape of the block, the look and feel and even the interactions with the physics engine.

See javadoc

Paramaters

The following parameters can be set on a block:

  • Name: the name or id of the Block. The name is used for registering and retrieving the Block from the BlockRegistry.
  • Shape: the name or id of the shape of the Block. The shape specifies the form or outline. See the Shape section for more information.
  • Type: the name or id of the type of the Block. The type specifies the look and feel of the block. See the Type section for more information.
  • usingMultipleImages: a flag indicating if the shape of the block should use multiple images in the texture. When enabled, the Shape should take care of proper UV mapping.
  • Transparent: a flag indicating if the block is transparent.
  • Solid: A flag indicating if the block should be part of the collision mesh of the chunk.

API

Creating a block:

Block grassBlock = Block.builder()
                .name(BlockIds.GRASS)
                .shape(ShapeIds.CUBE)
                .type(TypeIds.GRASS)
                .usingMultipleImages(true)
                .transparent(false)
                .solid(true)
                .build();

BlockRegistry

A block should be reused, and there should only be one instance of a block available at any time. Eg.if you want to place 2 grass blocks next to each other, the same grass block instance should be used.

To keep track of all the different block instances, the BlockRegistry is used. When initialising the Blocks framework (see Getting started) the BlockRegistry is created and filled with the default blocks.

The BlockRegistry can be retrieved from the BlocksConfig instance:

BlockRegistry blockRegistry = BlocksConfig.getInstance().getBlockRegistry();

Registering and retrieving blocks from the BlockRegistry is done with the name of the block:

blockRegistry.register(grassBlock);
Block dirtBlock = blockRegistry.get(BlockIds.DIRT);

All keys of the default available blocks are available as constants in the BlockIds interface. It's best practice to use these constants to retrieve the blocks from the registry instead of using the name.

Block oakLog = blockRegistry.get(BlockIds.OAK_LOG);
Block grassBlock = blockRegistry.get(BlockIds.GRASS);

See javadoc

Default blocks

For an overview of all the available blocks, see BlockIds

Shape

The shape of the block defines the form or outline of the block. Same as with the blocks, shapes should be reused.

To keep track of all the different shape instances, the ShapeRegistry is used. When initialising the Blocks framework the ShapeRegistry is created and filled with the default block shapes.

The ShapeRegistry can be retrieved from the BlocksConfig instance:

ShapeRegistry shapeRegistry = BlocksConfig.getInstance().getShapeRegistry();

Registering and retrieving shapes from the ShapeRegistry is done with the name of the shape and the associated shape implementation:

shapeRegistry.register(ShapeIds.CUBE, new Cube());
Shape cubeShape = shapeRegistry.get(ShapeIds.CUBE);

All keys of the available shapes are available as constants in the ShapeIds interface. It's best practice to use these constants to retrieve the shapes from the registry instead of using the name.

Shape cube = shapeRegistry.get(ShapeIds.CUBE);
Shape pyramid = shapeRegistry.get(ShapeIds.PYRAMID);

See javadoc

Default shapes

For an overview of all the available shapes, see ShapeIds

Type

The type of the block defines how the block should look like. Same as with the blocks and shapes, types should be reused.

To keep track of all the different type instances, the TypeRegistry is used. When initialising the Blocks framework the TypeRegistry is created and filled with the default block types.

The TypeRegistry can be retrieved from the BlocksConfig instance:

TypeRegistry typeRegistry = BlocksConfig.getInstance().getTypeRegistry();

Registering and retrieving types from the TypeRegistry is done with the name of the type and the material:

typeRegistry.register(TypeIds.GRASS, assetManager.loadMaterial("/path/to/my/material.j3m"));
Material myGrassMaterial = typeRegistry.get(TypeIds.GRASS);

All keys of the default available types are available as constants in the TypeIds interface. It's best practice to use these constants to retrieve the types from the registry instead of using the name.

💡 For creating new types, or changing textures see Theming

See javadoc

Default types

For an overview of all the available types, see TypeIds