Adding Blocks
Last updated
Was this helpful?
Last updated
Was this helpful?
Now that you have created a Lua mod in , let's continue by adding blocks.
The Exdilin API is a global variable that allows to interact with Blocksworld. It has a lot of functions which are all referenced in the Lua API Reference. But in this tutorial, we'll be interested in exdilin.new_block
.
The exdilin.new_block
function takes a table (see ), today we will only need to understand two fields in the table: id
and modelName
.
The first is straightforward, id must be set to the block's identifier/name, model name is the name (inside Blocksworld's Resources!) of the 3D model of the block, this defaults to the block's name, but we don't have any model to put for our block, so we will use the cube's model. The cube's model name is very simple, it's simply Cube
, with all that setup let's create a block named Test.
However the block does not register itself (read: does not exist yet), so we will have to register it.
To do that we need to add a block item, it is not really specific to block and can be applied to script functions, textures, and others.
Manually creating a block item is exhausting and takes a lot of lines of code, hopefully the block we just saved in a variable provides a way to do just that, the default_block_item
function.
This function is simple, it takes two arguments: the first is the icon name and the second is the rarity (rarity define the border around it, like does it have any, are they golden, etc.)
Like the block, we will also have to register that new block item, now let's write the code:
Now launch Blocksworld, scroll down the Blocks tab and tada! A new block you just made has appeared!
You can also fiddle with the rarity and the icon, try the Yellow/Cylinder
icon, or the rare
rarity.
Cool, the block is registered, however we cannot place it from the Build Panel
The icon of the default cube block is Yellow/Cube
, and the rarity will be common
(note: you can choose any rarity that is present in )