Search in sources :

Example 6 with BlockModeled

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;
}
Also used : BlockModeled(org.asassecreations.voxelgame.world.block.BlockModeled) Block(org.asassecreations.voxelgame.world.block.Block) File(java.io.File)

Example 7 with BlockModeled

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);
}
Also used : BlockModeled(org.asassecreations.voxelgame.world.block.BlockModeled) FloatHolder(org.asassecreations.engine.math.FloatHolder)

Example 8 with BlockModeled

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));
            }
        }
    }
}
Also used : BlockModeled(org.asassecreations.voxelgame.world.block.BlockModeled) Vec3(org.asassecreations.engine.math.vector.Vec3) Vector3f(org.lwjgl.util.vector.Vector3f) ArrayList(java.util.ArrayList)

Aggregations

BlockModeled (org.asassecreations.voxelgame.world.block.BlockModeled)8 ArrayList (java.util.ArrayList)4 Block (org.asassecreations.voxelgame.world.block.Block)3 Vector3f (org.lwjgl.util.vector.Vector3f)3 Vec3 (org.asassecreations.engine.math.vector.Vec3)2 ADatabase (org.asassecreations.engine.serializer.ADatabase)2 AObject (org.asassecreations.engine.serializer.AObject)2 File (java.io.File)1 List (java.util.List)1 FloatHolder (org.asassecreations.engine.math.FloatHolder)1 Chunk (org.asassecreations.voxelgame.world.chunk.Chunk)1