Handling minecraft-like worlds in a rusty way?

53 points ihaveadepressionhelp

It's more a data-oriented question per se, but I want to ask it here anyway. Worlds have chunks, chunks have blocks, blocks have states with their own internal storage. I'm trying to NOT waste memory, because chunks are big as hell (16x16x256). My first idea was to store all possible states in enum, but we all know that enum is not particularly about saving memory. So the question is. If I create a some sort of state handler, where block could ask to create/save/mutate/delete its state based on event its given in this state handler. With creation and so on being allocated on demand(no state created and memory used until that block is invoked is some way). Is this a good approach with how memory sensitive this could be, ofc considering the size of chunks. My plan is to allocate one byte per block and use it as an id to command a state handler on what to do. For me this sounds right, but I would appreciate any feedback.

  • To differentiate between blocks (for example two chests) I will use their coordinates. If its position changes, I would tell the state handler to change the coords