07-25-2018, 08:15 PM
I think it'd be better to have each chunk's section contain an array of VirtualBlockType (a number) plus a Palette object that provides the mapping of VirtualBlockType -> BlockTypeWithParams class instance.
BlockTypeWithParams stores the block's type (piston / grass / torch / ...) and parameters ("facing=west, powered=true, ..."). So if a piston gets extended, it receives a different VirtualBlockType from the section's Palette and the section remembers the new number. This is much better than allocating a separate object for each and every block in the world.
The Palette class manages the mapping - if a new BlockTypeWithParams is to be set in the section, it is assigned a new number; rather than removing a mapping when all of its instances are removed (-> holes in the numbers sequence, would need defragmenting), it should cooperate with the section to provide a "garbage collect" operation that would clean up the unused numbers and re-sequence the rest.
This is a huge undertaking and will break things across all of Cuberite, no idea how to tackle that sequentially, so that it's reviewable as PRs.
BlockTypeWithParams stores the block's type (piston / grass / torch / ...) and parameters ("facing=west, powered=true, ..."). So if a piston gets extended, it receives a different VirtualBlockType from the section's Palette and the section remembers the new number. This is much better than allocating a separate object for each and every block in the world.
The Palette class manages the mapping - if a new BlockTypeWithParams is to be set in the section, it is assigned a new number; rather than removing a mapping when all of its instances are removed (-> holes in the numbers sequence, would need defragmenting), it should cooperate with the section to provide a "garbage collect" operation that would clean up the unused numbers and re-sequence the rest.
This is a huge undertaking and will break things across all of Cuberite, no idea how to tackle that sequentially, so that it's reviewable as PRs.