Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's the best way to store block states? #50

Closed
Igrium opened this issue May 27, 2020 · 2 comments
Closed

What's the best way to store block states? #50

Igrium opened this issue May 27, 2020 · 2 comments

Comments

@Igrium
Copy link

Igrium commented May 27, 2020

This isn't an issue per se, but I don't really know where else to put this as there isn't a community forum for this project.

I'm trying to integrate this library into a pre-existing block data structure which has a feature where it can store arbitrary block data that may change the block's model. I've already written a basic adapter and I am not trying to store this data in the render blocks themselves, but I need a way of conforming this multi-model system into your single-model system at runtime.

How would you recommend doing this in a way that makes sense?

@rvandoosselaer
Copy link
Owner

rvandoosselaer commented May 28, 2020

There is a dedicated thread for Blocks at the jMonkeyEngine forum. You can ask all your questions there.

I don't quite understand the question, but I'll try to answer it generally.

It's not a good idea to mix render data and business data together. In JME terms, it would be the same as storing game data on Spatials. If you want to add data to blocks, don't put this data in the Block class. Store the data and link it with the block id.

The Block class is pure data. It has an id, type, shape, ... It contains the bare minimum info so Blocks know how to render this specific block. A block will always render in exactly the same way. Some blocks however have only differences in shapes, or models as you call it.

A wedge block for example, actually has 4 different shapes. One shape facing north, east, south and west. Each shape is represented by a different block object (eg. oak_log-wedge_north, oak_log-wedge_east, ...). You could for example create an object (WedgeBlock), that holds a collection of blocks (Collection<Block> models) containing all the different shapes of a specific type. This way you have sort of a multi-model system.

For handling blocks, there is the Chunk class. A chunk is a way of organising and structuring block data. Internally it has optimizations for block data lookup etc.
A ChunkRepository is used to serialize and deserialize (save and load) block data using protocol buffers.

@Igrium
Copy link
Author

Igrium commented May 29, 2020

That makes sense. Thanks!

@Igrium Igrium closed this as completed May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants