Blocks

Blocks doesn’t support moving things, right? For example we can’t create cars with blocks right?

No, I’m not looking into that at the moment and probably will also not do this in the near future.

If you try to implement it on your own, I’m always glad to help out of course. And contributions are always welcome :slight_smile:

No.

You can however build a car using Blocks and use the generated geometry as the body of your car.

to rotate it I think is possible. But I failed when try to make a block spinning ( keep rotating). Maybe I missed something. Or, I mean is there a way to make it move?

A block so far as my understanding follows is part of a larger mesh. A rotating block would probably be an entity.

Hi,

Thanks so much for the response! This does clear up quite a few things. However, when you say that a ChunkManager can have a larger cache than the size of the grid, you mean the grid of the Pager, right? If the cache was larger than the size of the BlockConfigs grid, wouldn’t that mean the cache is larger than the size of the world? Or are these worlds infinite? From what I understand, the BlocksConfig specifies the chunk size of the world(there will be nothing beyond that, like MineCraft’s finite worlds) the Pager specifies the amount of chunks to render around the player (should not be too much) and the ChunkManager’s cacheSize is the amount of chunks that will be kept in memory. So if the cacheSize is the same than the Pager’s size (not the world size, which is the BlockConfig grid) then as soon as you go into unloaded chunks, they will take time to be generated, but if the cacheSize is larger than the Pager’s grid, they will already be generated. So, just to confirm, you meant that of the ChunkManager has a larger cache than the grid size of the pager(not world), then it will have faster loading.

It’s weird because reading your question it seems like you repeatedly answer it yourself.

Either the cache is bigger than the world (which makes no sense because when would you ever need a cache bigger than the world) or it’s bigger than the pager… which makes total sense because what good is a cache at all if it’s only caching what’s already displayed.

…and as you say, if worlds can be ‘infinite’ (super likely), it also doesn’t make sense to have a cache ‘bigger than infinite’.

I don’t even use Blocks and I can make 99% guesses as to the answer just from what you wrote.

Re-reading my answer it does look I am… :laughing: Imaging that the “grid” was a certain part of the world(as opposed to the entirety of the world) meaning the world was infinite, so that when you left the boundaries of one grid, one could be created, then I was thinking that maybe Rem meant that the chunkcache could be bigger than the “grid” that defines portions of an infinite world, though that doesn’t make too much sense, now because chunks exist for that purpose… An infinite world would basically be one with an extremely large grid then, large enough for most purposes.

Hi,

I mostly understand your ProceduralTerrain example however I am still a bit confused on some things:

  float height = getHeight(getWorldLocation(new Vector3f(x, 0, z), chunk));
                                int worldY = (chunk.getLocation().y * chunkSize.y) + y;
 float h = Math.max(height, waterHeight);
                        if (worldY <= h) {
                            Block block = worldY <= height ? BlocksConfig.getInstance().getBlockRegistry().get(BlockIds.GRASS) : BlocksConfig.getInstance().getBlockRegistry().get(BlockIds.WATER);
                            chunk.addBlock(x, y, z, block);
                        }

So I see that you are getting the random (perlin) height for a specific x, z coordinate, and then you get the world y coordinate we are currently scanning. I’m confused as to why you must compare it against the current y coordinate. Why can’t you simply get the y coordinate of the x, z pair (also make chunks 32 * 32 * heightLimit long), scale it so its within the y limit of the chunk, and simply add blocks at that x, z coordinate y-amount of times? Also, why do you add 30 to the getHeight() method?

yes. and what i understand as entity here is chunk. and I think it is not possible to make chunk a moving thing, like car. I can make a body car with blocks but it does not move like a car. I was just still wondering is that possible? But I think the answer is clear, no it is not possible.

As already mentioned you can build a car with Blocks editor and export the mesh into a j3o file, then you can load it like a regular model and move or rotate it like a regular spatial.

I’m having trouble understanding the issue. Could you explain the use case what you are trying to do?

The thing is, Blocks just generates meshes for box-based things. In the end you choose what you do with that mesh. Do you want to create a rigidbody from that mesh and apply forces on it, you can do it.

Blocks is however a framework and not a game implementation. The thing you describe is game-specific and will never be in blocks. Unless there is really a broad use case for it.

I never looked at vehicles, so I don’t have a background in it. You can always take a look at the advanced vehicles example of @jayfella on the monkeystore.

But I presume you do all the setup in bullet (chassis, wheels, …) and then add the blocks vehicle mesh to the physics space. I guess it is not that hard to do. But if you expect that Blocks will do this out of the box, then the answer is indeed no.

1 Like

To be clear:

BlocksConfig#grid = the size of the visible grid. This parameter is used by the pager. The default is (9, 5, 9). This means that when using the pager there will be 9x5x9 (405) chunks visible.
When you don’t set a cache size when initializing the ChunkManager, the ChunkManager will use this parameter as a fallback to get a ‘feeling’ of what cache size should be used.

If you create an ‘infinite’ world, you should indeed crank up the cache size when initialising the chunkmanager. The grid parameter will only define the visible grid. The size of the world can be defined in the pager: Pager#gridLowerBounds and Pager#gridUpperBounds.

The ChunkManager doesn’t have any knowledge of a grid, why should it? The ChunkManager is just a helper class to ‘help you manage chunks’.

Thanks! That clears about everything up…

I tried simply having blocks placed height amount of times, but it results in some very strange thing(hardfloor diabled). Everything is the same height but they are just games in some locations. I have no idea why that doesn’t work but your implentation does. Here’s a pic of what I’m getting (with placing blocks at every x, y, z coordinate height amoutn of times)

As you can see, they are wide gaps everwhere, almost as if the noise is the wrong way. Code:

It’s clearer now. That’s the answer I want. I just misunderstood what I have tried. Thank’s.

1 Like

I remember seeing someone add a JME Mesh to a ChunkMesh once so they could make use of code that wasn’t purpose-built for Blocks, but I can’t find that post anymore. How do you do this? (version 1.5.1)

I don’t fully understand the question. The ChunkMesh class is just a helper class to create a Mesh, with easy access to the positions, normals, uv’s, … so you don’t have to mess with the buffers.

Why do you need to create ChunkMesh from a Mesh? What is the problem you are trying to solve?

If you don’t have a previous version of Blocks and require backwards compatibility, you should really move to version 1.6.0 instead of 1.5.1. A lot of the code for the shapes was rewritten and some quality of life updates where added.

I’m trying to write the ability to write a shape class that will render a shape into the chunk based on a Minecraft block-model. Instead of directly calling functions on the chunkMesh, I wrote code that creates a vanilla JME mesh based on the visibility arguments of certain sides so I could re-use the code to render entities. How do you actually add these meshes to the master chunk mesh?

Similar to what you said here:

If you already have the code to generate a Mesh, maybe Blocks isn’t the framework for you?

As you have the code to create a mesh it should be trivial to adapt this code to create a ChunkMesh object. Instead of adding the positions/uv’s/… objects to the correct buffer in the mesh, you add them to the corresponding list in the ChunkMesh class…

change the part where you do something like:

FloatBuffer buffer = BufferUtils.createFloatBuffer(size);
buffer.put(x).put(y).put(z);
mesh.setBuffer(VertexBuffer.Type.Position, 3, buffer);

to:

chunkMesh.getPositions().add(new Vector3f(x, y, z));

Sorry if I’m a little spammy. I think I’m pushing this API way beyond what it was designed to do.

I wrote my own shape registry that handles the storing of shapes in a different way as required by my program, but I can’t figure out how to get the block builder to use my shape registry, nor how to create a block object without the default builder (I only see the create methods in the Block class source). What’s the best way to do that? Can I create a Block with just a shape object instead of a shape key?