Statically adding new blocks is showing its limitations, especially as large numbers of new blocks are added (see https://github.com/satoshinm/NetCraft/issues/154). Several parallel arrays have to be updated in src/item.[ch], not to mention functions, all have to be carefully kept in sync.
To fix this, allocate the blocks dynamically. Review changes from the DanielOaks:dynamic_stuff fork https://github.com/satoshinm/NetCraft/issues/25#issuecomment-293212777, too. The interface I envision would be something like calling a function to increment the next available block/item id, while populating:
const char *item_names[] - human-readable string name
int register_block(name, textures, properties...) // return allocated id
allocate and expand the arrays as needed (not hardcoding 256, up to 16-bit? https://github.com/satoshinm/NetCraft/issues/55)
Also important: registering block "states". Furnace (https://github.com/satoshinm/WebSandboxMC/issues/61) for example should have 4 sub-blocks, one for each orthogonal direction. register_blocks("Furnace", 4, ...), allocating 4 block ids. Then somehow get the "associated data" from a block, 0-3 for the furnace. Different textures per sub-block type, they should be merely regular blocks, but grouped together logically for programmatic convenience. Info text should show type=furnace (id=...) but attached data=0-3.
Registering groups of blocks is now possible, and the data values shows in the info text. Example is furnace, it has 4 blocks for each orthogonal rotation, direction the front is facing:
Statically adding new blocks is showing its limitations, especially as large numbers of new blocks are added (see https://github.com/satoshinm/NetCraft/issues/154). Several parallel arrays have to be updated in src/item.[ch], not to mention functions, all have to be carefully kept in sync.
To fix this, allocate the blocks dynamically. Review changes from the DanielOaks:dynamic_stuff fork https://github.com/satoshinm/NetCraft/issues/25#issuecomment-293212777, too. The interface I envision would be something like calling a function to increment the next available block/item id, while populating:
const int plants[256] - plant textures, used instead of(do we need two arrays? update: removed in https://github.com/satoshinm/NetCraft/pull/161/commits/6d7c39537f7faa0ccff2e34f03a546361eeb8800)blocks
ifis_plant
int register_block(name, textures, properties...) // return allocated id allocate and expand the arrays as needed (not hardcoding 256, up to 16-bit? https://github.com/satoshinm/NetCraft/issues/55)
Also important: registering block "states". Furnace (https://github.com/satoshinm/WebSandboxMC/issues/61) for example should have 4 sub-blocks, one for each orthogonal direction. register_blocks("Furnace", 4, ...), allocating 4 block ids. Then somehow get the "associated data" from a block, 0-3 for the furnace. Different textures per sub-block type, they should be merely regular blocks, but grouped together logically for programmatic convenience. Info text should show type=furnace (id=...) but attached data=0-3.