use of org.asassecreations.voxelgame.world.block.BlockModeled in project Voxel_Game by ASasseCreations.
the class Chunk method generate.
// Generate terrain
public final boolean generate() {
if (operation == null)
return false;
if (!operation.equals(ChunkOperation.GENERATING)) {
operation = null;
return false;
}
for (int z = 0; z < H_SIZE; z++) for (int x = 0; x < H_SIZE; x++) {
final float dirtHeight = ChunkGenerator.getDirtHeight(this, x, z);
for (int y = 0; y < dirtHeight; y++) {
final Block texture = Block.BLOCKS.get("dirt");
blocks[x][y][z] = new BlockModeled(texture);
}
blocks[x][(int) dirtHeight][z] = new BlockModeled(Block.BLOCKS.get("grass"));
if (ChunkGenerator.canTreeSpawn(x + this.x * Chunk.H_SIZE, z + this.z * Chunk.H_SIZE))
BlockGroup.GROUP_TREE.insert(this, Mathi.constrain(x, 1, H_SIZE - 2), (int) dirtHeight, Mathi.constrain(z, 1, H_SIZE - 2));
final int bedrockHeight = ChunkGenerator.getBedrockHeight(x + this.x * Chunk.H_SIZE, z + this.z * Chunk.H_SIZE);
final Block bedrock = Block.BLOCKS.get("bedrock");
for (int y = 0; y <= bedrockHeight; y++) blocks[x][y][z] = new BlockModeled(bedrock);
}
if (new File(Content.WORLD_FOLDER + "chunk_" + x + "_" + z + ".dat").exists())
load();
generated = true;
operation = null;
return true;
}
use of org.asassecreations.voxelgame.world.block.BlockModeled in project Voxel_Game by ASasseCreations.
the class Chunk method modelUpdate.
private void modelUpdate() {
if (!generated)
return;
final FloatHolder positions = new FloatHolder();
final FloatHolder textures = new FloatHolder();
final FloatHolder normals = new FloatHolder();
final FloatHolder lighting = new FloatHolder();
for (int y = 0; y < V_SIZE; y++) {
if (!layers[y])
continue;
for (int z = 0; z < H_SIZE; z++) for (int x = 0; x < H_SIZE; x++) {
final BlockModeled b = blocks[x][y][z];
if (b == null || !b.visible)
continue;
final float[][] data = generateCube(b, x, y, z);
positions.add(data[0]);
textures.add(data[1]);
normals.add(data[2]);
lighting.add(data[3]);
}
}
ModelLoader.appendData(positions.get(), 3);
ModelLoader.appendData(textures.get(), 2);
ModelLoader.appendData(normals.get(), 3);
ModelLoader.appendData(lighting.get(), 1);
model = ModelLoader.loadToVAO(0);
}
use of org.asassecreations.voxelgame.world.block.BlockModeled in project Voxel_Game by ASasseCreations.
the class ChunkSystem method checkRightClick.
public static final void checkRightClick() {
final Vec3 block = BlockRaycast.placeCast();
if (block != null) {
final Chunk chunk = Chunk.getChunk((int) Math.floor(block.x / Chunk.H_SIZE), (int) Math.floor(block.z / Chunk.H_SIZE));
if (chunk != null) {
final Vector3f blockToSet = Chunk.getBlockCoordinates(block.x, block.y, block.z);
chunk.blocks[(int) blockToSet.x][(int) blockToSet.y][(int) blockToSet.z] = new BlockModeled(BlockPlacement.getSelection());
chunk.modified.put(new Vector3f((int) blockToSet.x, (int) blockToSet.y, (int) blockToSet.z), new ArrayList<>(Block.BLOCKS.values()).indexOf(BlockPlacement.getSelection()));
{
final int cx = chunk.x;
final int cz = chunk.z;
addToQueues(chunk);
addToQueues(Chunk.getChunk(cx - 1, cz));
addToQueues(Chunk.getChunk(cx + 1, cz));
addToQueues(Chunk.getChunk(cx, cz - 1));
addToQueues(Chunk.getChunk(cx, cz + 1));
}
}
}
}
Aggregations