use of org.asassecreations.voxelgame.world.block.Block in project Voxel_Game by ASasseCreations.
the class Chunk method save.
public final boolean save() {
if (operation == null || !operation.equals(ChunkOperation.SAVING)) {
if (!generated)
return true;
System.out.println("CANT SAVE");
return false;
}
if (modified.isEmpty())
return true;
final ADatabase database = new ADatabase("Chunk");
final List<Block> list = new ArrayList<>(Block.BLOCKS.values());
for (final Vector3f vector : modified.keySet()) {
final int x = (int) vector.x;
final int y = (int) vector.y;
final int z = (int) vector.z;
final BlockModeled block = blocks[x][y][z];
final Block texture;
int id;
if (block == null || block.preset == null || block.preset.texture == null)
id = -1;
else {
texture = block.preset;
id = list.indexOf(texture);
}
final AObject object = new AObject(x + ":" + y + ":" + z);
object.addField(AField.Integer("id", id));
database.addObject(object);
}
database.serializeToFile(Content.WORLD_FOLDER + "chunk_" + x + "_" + z + ".dat");
System.out.println("Saved chunk at [" + x + ", " + z + "]");
operation = null;
return true;
}
use of org.asassecreations.voxelgame.world.block.Block in project Voxel_Game by ASasseCreations.
the class Chunk method load.
public final void load() {
System.out.println("Loaded at [" + x + ", " + z + "]");
final ADatabase database = ADatabase.DeserializeFromFile(Content.WORLD_FOLDER + "chunk_" + x + "_" + z + ".dat");
final List<AObject> modifications = database.objects;
System.out.println(modifications.size());
final List<Block> list = new ArrayList<>(Block.BLOCKS.values());
for (final AObject object : modifications) {
final String[] parsed = object.getName().split(":");
final int x = Integer.parseInt(parsed[0]);
final int y = Integer.parseInt(parsed[1]);
final int z = Integer.parseInt(parsed[2]);
final int id = object.findField("id").getInt();
modified.put(new Vector3f(x, y, z), id);
if (id == -1)
blocks[x][y][z] = null;
else
blocks[x][y][z] = new BlockModeled(list.get(id));
}
System.out.println("Generated modifications chunk at [" + x + ", " + z + "]");
}
use of org.asassecreations.voxelgame.world.block.Block 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.Block in project Voxel_Game by ASasseCreations.
the class AssetLoader method loadBlocks.
public static final Map<String, Block> loadBlocks(final Map<String, BlockTexture> atlasPos) throws MalformedURLException, IOException, URISyntaxException {
final List<String> fileNames = getItems("/def/block", "def");
fileNames.addAll(getItems(Content.MOD_BLOCK_FOLDER, "def", true));
final Map<String, Block> finalBlocks = new HashMap<>();
for (int i = 0; i < fileNames.size(); i++) {
final String block = getName(fileNames.get(i), 3);
final BlockTexture texture = new BlockTexture(0, 0);
boolean breakable = true;
ItemPreset item = null;
final Properties properties = new Properties();
properties.load(Tools.getReader(fileNames.get(i)));
{
texture.left_uv = atlasPos.get(properties.getProperty("left")).left_uv;
texture.right_uv = atlasPos.get(properties.getProperty("right")).right_uv;
texture.top_uv = atlasPos.get(properties.getProperty("top")).top_uv;
texture.bottom_uv = atlasPos.get(properties.getProperty("bottom")).bottom_uv;
texture.front_uv = atlasPos.get(properties.getProperty("front")).front_uv;
texture.back_uv = atlasPos.get(properties.getProperty("back")).back_uv;
if (properties.getProperty("breakable") != null)
breakable = Boolean.parseBoolean(properties.getProperty("breakable"));
if (properties.getProperty("item") != null)
item = ItemPreset.get(properties.getProperty("item"));
}
finalBlocks.put(block, new Block(i, texture, BlockAudio.BLOCK_CLOTH, item, breakable));
}
return finalBlocks;
}
Aggregations