mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
fix region serialization
This commit is contained in:
@@ -24,11 +24,11 @@ public final class TerraCLI {
|
||||
|
||||
ConfigPack generate = platform.getConfigRegistry().get("OVERWORLD").orElseThrow(); // TODO: make this a cli argument
|
||||
|
||||
CLIWorld world = new CLIWorld(1, 2, 384, -64, generate);
|
||||
CLIWorld world = new CLIWorld(2, 2, 384, -64, generate);
|
||||
|
||||
world.generate();
|
||||
|
||||
world.serialize().forEach(mcaFile -> {
|
||||
world.serialize().parallel().forEach(mcaFile -> {
|
||||
Vector2Int pos = mcaFile.getLeft();
|
||||
String name = MCAUtil.createNameFromRegionLocation(pos.getX(), pos.getZ());
|
||||
LOGGER.info("Writing region ({}, {}) to {}", pos.getX(), pos.getZ(), name);
|
||||
@@ -39,6 +39,9 @@ public final class TerraCLI {
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
LOGGER.info("Wrote region to file.");
|
||||
});
|
||||
LOGGER.info("Done.");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,26 @@ public class CLIBlockState implements BlockState {
|
||||
public CLIBlockState(String value) {
|
||||
this.value = value;
|
||||
if(value.contains("[")) {
|
||||
this.type = new CLIBlockType(value.substring(0, value.indexOf("[")));
|
||||
|
||||
} else {
|
||||
this.type = new CLIBlockType(value);
|
||||
|
||||
}
|
||||
this.isAir = value.startsWith("minecraft:air");
|
||||
this.nbt = new CompoundTag();
|
||||
this.nbt.putString("Name", value);
|
||||
if(value.contains("[")) {
|
||||
this.type = new CLIBlockType(value.substring(0, value.indexOf("[")));
|
||||
String properties = value.substring(value.indexOf('[') + 1, value.indexOf(']'));
|
||||
String[] props = properties.split(",");
|
||||
CompoundTag pTag = new CompoundTag();
|
||||
for(String property : props) {
|
||||
String name = property.substring(0, property.indexOf('='));
|
||||
String val = property.substring(property.indexOf('=') + 1);
|
||||
|
||||
pTag.putString(name, val);
|
||||
}
|
||||
this.nbt.put("Properties", pTag);
|
||||
} else this.type = new CLIBlockType(value);
|
||||
this.nbt.putString("Name", type.getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,13 +14,13 @@ public class CLIBlockType implements BlockType {
|
||||
public CLIBlockType(String value) {
|
||||
if(value.contains("[")) throw new IllegalArgumentException("Block Type must not contain properties");
|
||||
this.value = value;
|
||||
this.solid = value.equals("minecraft:air");
|
||||
this.solid = !value.equals("minecraft:air");
|
||||
this.water = value.equals("minecraft:water");
|
||||
this.defaultState = Lazy.lazy(() -> new CLIBlockState(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getHandle() {
|
||||
public String getHandle() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
@@ -74,20 +75,28 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
public void generate() {
|
||||
int sizeChunks = size * 32;
|
||||
List<Future<?>> futures = new ArrayList<>();
|
||||
final long start = System.nanoTime();
|
||||
for(int x = -sizeChunks + 1; x < sizeChunks; x++) {
|
||||
for(int z = -sizeChunks + 1; z < sizeChunks; z++) {
|
||||
final AtomicLong start = new AtomicLong(System.nanoTime());
|
||||
for(int x = 0; x < sizeChunks; x++) {
|
||||
for(int z = 0; z < sizeChunks; z++) {
|
||||
int finalX = x;
|
||||
int finalZ = z;
|
||||
futures.add(executor.submit(() -> {
|
||||
int num = amount.getAndIncrement();
|
||||
long time = System.nanoTime();
|
||||
double cps = num / ((double) (time - start) / 1000000000);
|
||||
LOGGER.info("Generating chunk at ({}, {}), generated {} chunks at {}cps", finalX, finalZ, num, cps);
|
||||
CLIChunk chunk = getChunkAt(finalX, finalZ);
|
||||
chunkGenerator.generateChunkData(chunk, this, finalX, finalZ);
|
||||
CLIProtoWorld protoWorld = new CLIProtoWorld(this, finalX, finalZ);
|
||||
pack.getStages().forEach(stage -> stage.populate(protoWorld));
|
||||
try {
|
||||
int num = amount.getAndIncrement();
|
||||
CLIChunk chunk = getChunkAt(finalX, finalZ);
|
||||
chunkGenerator.generateChunkData(chunk, this, finalX, finalZ);
|
||||
CLIProtoWorld protoWorld = new CLIProtoWorld(this, finalX, finalZ);
|
||||
pack.getStages().forEach(stage -> stage.populate(protoWorld));
|
||||
if(num % 240 == 239) {
|
||||
long time = System.nanoTime();
|
||||
double cps = num / ((double) (time - start.get()) / 1000000000);
|
||||
LOGGER.info("Generating chunk at ({}, {}), generated {} chunks at {}cps", finalX, finalZ, num, cps);
|
||||
amount.set(0);
|
||||
start.set(System.nanoTime());
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -154,10 +163,10 @@ public class CLIWorld implements ServerWorld, NBTSerializable<Stream<Pair<Vector
|
||||
|
||||
@Override
|
||||
public CLIChunk getChunkAt(int x, int z) {
|
||||
x += (size + 1) * 16;
|
||||
z += (size + 1) * 16;
|
||||
return regions[FastMath.floorDiv(x, regionBlocks) + regionBlocks * FastMath.floorDiv(z, regionBlocks)]
|
||||
.get(FastMath.floorMod(FastMath.floorDiv(x, 16), 32), FastMath.floorMod(FastMath.floorDiv(z, 16), 32));
|
||||
int cx = x + (size + 1) * 16;
|
||||
int cz = z + (size + 1) * 16;
|
||||
return regions[FastMath.floorDiv(cx, regionBlocks) + regionBlocks * FastMath.floorDiv(cz, regionBlocks)]
|
||||
.get(FastMath.floorMod(x, 32), FastMath.floorMod(z, 32));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Region implements NBTSerializable<MCAFile> {
|
||||
MCAFile mcaFile = new MCAFile(x, z);
|
||||
for(int cx = 0; cx < 32; cx++) {
|
||||
for(int cz = 0; cz < 32; cz++) {
|
||||
mcaFile.setChunk(cx, cz, chunks[cx + cz * 32].serialize());
|
||||
mcaFile.setChunk(cx + cz * 32, chunks[cx + cz * 32].serialize());
|
||||
}
|
||||
}
|
||||
return mcaFile;
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
package com.dfsek.terra.cli.world.chunk;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.world.ServerWorld;
|
||||
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||
|
||||
import com.dfsek.terra.api.world.chunk.generation.ProtoChunk;
|
||||
import com.dfsek.terra.cli.NBTSerializable;
|
||||
import com.dfsek.terra.cli.block.CLIBlockState;
|
||||
|
||||
import com.dfsek.terra.cli.handle.CLIWorldHandle;
|
||||
import com.dfsek.terra.cli.world.CLIWorld;
|
||||
|
||||
import net.querz.mca.MCAFile;
|
||||
import net.querz.nbt.tag.CompoundTag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.dfsek.terra.cli.handle.CLIWorldHandle.getAIR;
|
||||
|
||||
|
||||
@@ -71,7 +65,7 @@ public class CLIChunk implements Chunk, ProtoChunk, NBTSerializable<net.querz.mc
|
||||
|
||||
@Override
|
||||
public net.querz.mca.Chunk serialize() {
|
||||
net.querz.mca.Chunk chunk = net.querz.mca.Chunk.newChunk();
|
||||
net.querz.mca.Chunk chunk = net.querz.mca.Chunk.newChunk(2230);
|
||||
for(int x = 0; x < blocks.length; x++) {
|
||||
for(int z = 0; z < blocks[x].length; z++) {
|
||||
for(int y = 0; y < blocks[z][z].length; y++) {
|
||||
@@ -85,6 +79,7 @@ public class CLIChunk implements Chunk, ProtoChunk, NBTSerializable<net.querz.mc
|
||||
}
|
||||
}
|
||||
}
|
||||
chunk.setStatus("features");
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user