satoshinm / NetCraft

Web-based fork of fogleman/Craft ⛺
https://satoshinm.github.io/NetCraft/
MIT License
56 stars 13 forks source link

Dynamic block allocation, properties and block groups #160

Closed satoshinm closed 7 years ago

satoshinm commented 7 years ago

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:

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.

satoshinm commented 7 years ago

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:

screenshot-netcraft-2017-05-25t04_35_47 809z