FAQ - rvandoosselaer/Blocks GitHub Wiki

This section is a summary of the most asked questions about Blocks. When the answer to your question isn't in this list, you can create an issue for it, or ask it on the forum.

How to use Bullet instead of Minie as physics library

Blocks uses and prefers the Minie physics library, but it can be swapped out in favour of bullet or jbullet.

Remove the Minie import in the build.gradle file and replace it with the bullet or jbullet one.

Example for bullet:

// remove this line
implementation "jme3utilities:Minie:1.2.0for33"
// with these 2 lines
implementation "org.jmonkeyengine:jme3-bullet:3.3.0-beta1"
implementation "org.jmonkeyengine:jme3-bullet-native:3.3.0-beta1"

How to get the location of a block

The ChunkManager class has some useful static methods to retrieve the location of a block from a CollisionResult or from a Vector3f.

Vec3i blockLocation = ChunkManager.getBlockLocation(new Vector3f(0, 0, 0));
Vec3i blockLocation = ChunkManager.getBlockLocation(collisionResult);

How to get the location of a chunk

The ChunkManager class has a method to retrieve the location of a chunk from a Vector3f. This way you can calculate the chunk at any given vector.

Vec3i chunkLocation = ChunkManager.getChunkLocation(new Vector3f(0, 0, 0));

How can I add a block to a chunk

You can add a block directly to a specific position inside a chunk:

chunk.addBlock(0, 0, 0, block);

You can also add a block from any Vector3f location using the ChunkManager. Based on the Vector3f location, the ChunkManager will calculate the chunk and position inside the chunk to add the block to:

chunkManager.addBlock(new Vector3f(0.1f, 1.3f, 2f), block);

How can I remove a block from a chunk

Same as adding a block, you can directly remove a block from a specific position inside a chunk:

Block removedBlock = chunk.removeBlock(0, 0, 0);

You can also remove a block from any Vector3f location using the ChunkManager. Based on the Vector3f location, the ChunkManager will calculate the chunk and position inside the chunk of the block to remove:

chunkManager.removeBlock(new Vector3f(0.1f, 1.3f, 2f));

How can I change a block in a chunk

You can just add the block inside the chunk, the previous block at that location is overwritten:

Block oldBlock = chunk.addBlock(0, 0, 0, newBlock);

You can also change a block at any Vector3f location using the ChunkManager. Based on the Vector3f location, the ChunkManager will calculate the chunk and position inside the chunk to add the block to:

chunkManager.addBlock(new Vector3f(0.1f, 1.3f, 2f), block);

How can I create a custom shape for a block

There is not yet a wiki page for this, but I wrote a rather detailed forum post about it on the jMonkeyEngine forum.