mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 08:25:31 +00:00
implement CLI world & chunk
This commit is contained in:
parent
5ea6f44a96
commit
d49ee4f3fc
@ -7,9 +7,11 @@ dependencies {
|
|||||||
shadedApi("com.github.Querz:NBT:6.1")
|
shadedApi("com.github.Querz:NBT:6.1")
|
||||||
shadedApi(project(":common:implementation:base"))
|
shadedApi(project(":common:implementation:base"))
|
||||||
|
|
||||||
implementation("com.google.guava:guava:31.0.1-jre")
|
shadedImplementation("com.google.guava:guava:31.0.1-jre")
|
||||||
|
|
||||||
implementation("ch.qos.logback:logback-classic:1.2.7")
|
shadedImplementation("ch.qos.logback:logback-classic:1.2.7")
|
||||||
|
|
||||||
|
shadedImplementation("net.jafama", "jafama", Versions.Libraries.Internal.jafama)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named("build") {
|
tasks.named("build") {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.dfsek.terra.cli;
|
package com.dfsek.terra.cli;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
import com.dfsek.terra.api.event.events.platform.PlatformInitializationEvent;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -14,5 +15,9 @@ public final class TerraCLI {
|
|||||||
|
|
||||||
CLIPlatform platform = new CLIPlatform();
|
CLIPlatform platform = new CLIPlatform();
|
||||||
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
platform.getEventManager().callEvent(new PlatformInitializationEvent());
|
||||||
|
|
||||||
|
ConfigPack generate = platform.getConfigRegistry().get("OVERWORLD").orElseThrow(); // TODO: make this a cli argument
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.dfsek.terra.cli.generator;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||||
|
import com.dfsek.terra.api.world.chunk.generation.util.GeneratorWrapper;
|
||||||
|
|
||||||
|
|
||||||
|
public class CLIChunkGenerator implements GeneratorWrapper {
|
||||||
|
@Override
|
||||||
|
public ChunkGenerator getHandle() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,140 @@
|
|||||||
|
package com.dfsek.terra.cli.world;
|
||||||
|
|
||||||
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.block.entity.BlockEntity;
|
||||||
|
import com.dfsek.terra.api.block.state.BlockState;
|
||||||
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
|
import com.dfsek.terra.api.entity.Entity;
|
||||||
|
import com.dfsek.terra.api.entity.EntityType;
|
||||||
|
import com.dfsek.terra.api.util.vector.Vector3;
|
||||||
|
import com.dfsek.terra.api.world.ServerWorld;
|
||||||
|
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||||
|
import com.dfsek.terra.api.world.chunk.Chunk;
|
||||||
|
import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator;
|
||||||
|
|
||||||
|
|
||||||
|
public class CLIWorld implements ServerWorld {
|
||||||
|
private static final int regionBlocks = 32 * 16;
|
||||||
|
private final Region[] regions;
|
||||||
|
private final int size;
|
||||||
|
private final long seed;
|
||||||
|
private final int maxHeight;
|
||||||
|
private final int minHeight;
|
||||||
|
private final ChunkGenerator chunkGenerator;
|
||||||
|
private final BiomeProvider biomeProvider;
|
||||||
|
private final ConfigPack pack;
|
||||||
|
|
||||||
|
public CLIWorld(int size,
|
||||||
|
long seed,
|
||||||
|
int maxHeight,
|
||||||
|
int minHeight,
|
||||||
|
ConfigPack pack) {
|
||||||
|
this.size = size;
|
||||||
|
this.regions = new Region[size * size];
|
||||||
|
this.seed = seed;
|
||||||
|
this.maxHeight = maxHeight;
|
||||||
|
this.minHeight = minHeight;
|
||||||
|
this.chunkGenerator = pack.getGeneratorProvider().newInstance(pack);
|
||||||
|
this.biomeProvider = pack.getBiomeProvider();
|
||||||
|
this.pack = pack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getHandle() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockState(int x, int y, int z) {
|
||||||
|
return getChunkAt(FastMath.floorDiv(x, 16), FastMath.floorDiv(z, 16))
|
||||||
|
.getBlock(FastMath.floorMod(x, 16), y, FastMath.floorMod(z, 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockEntity getBlockEntity(int x, int y, int z) {
|
||||||
|
return new BlockEntity() {
|
||||||
|
@Override
|
||||||
|
public boolean update(boolean applyPhysics) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector3 getPosition() {
|
||||||
|
return Vector3.of(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getZ() {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getBlockState() {
|
||||||
|
return CLIWorld.this.getBlockState(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getHandle() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Chunk getChunkAt(int x, int z) {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSeed() {
|
||||||
|
return seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxHeight() {
|
||||||
|
return maxHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMinHeight() {
|
||||||
|
return minHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChunkGenerator getGenerator() {
|
||||||
|
return chunkGenerator;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BiomeProvider getBiomeProvider() {
|
||||||
|
return biomeProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigPack getPack() {
|
||||||
|
return pack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBlockState(int x, int y, int z, BlockState data, boolean physics) {
|
||||||
|
getChunkAt(FastMath.floorDiv(x, 16), FastMath.floorDiv(z, 16))
|
||||||
|
.setBlock(FastMath.floorMod(x, 16), y, FastMath.floorMod(z, 16), data, physics);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Entity spawnEntity(double x, double y, double z, EntityType entityType) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.dfsek.terra.cli.world;
|
||||||
|
|
||||||
|
import com.dfsek.terra.cli.world.chunk.CLIChunk;
|
||||||
|
|
||||||
|
|
||||||
|
public class Region {
|
||||||
|
private final CLIChunk[] chunks;
|
||||||
|
|
||||||
|
public Region(CLIWorld world) {
|
||||||
|
CLIChunk[] chunks = new CLIChunk[32 * 32];
|
||||||
|
for(int x = 0; x < 32; x++) {
|
||||||
|
for(int z = 0; z < 32; z++) {
|
||||||
|
chunks[x * z * 32] = new CLIChunk(x, z, world);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.chunks = chunks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CLIChunk get(int x, int z) {
|
||||||
|
return chunks[x + z*32];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package com.dfsek.terra.cli.world.chunk;
|
||||||
|
|
||||||
|
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.cli.block.CLIBlockState;
|
||||||
|
|
||||||
|
import com.dfsek.terra.cli.world.CLIWorld;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|
||||||
|
public class CLIChunk implements Chunk {
|
||||||
|
private final int x;
|
||||||
|
private final int z;
|
||||||
|
private final CLIBlockState[][][] blocks;
|
||||||
|
private final int minHeight;
|
||||||
|
private final CLIWorld world;
|
||||||
|
|
||||||
|
public CLIChunk(int x, int z, CLIWorld world) {
|
||||||
|
this.x = x;
|
||||||
|
this.z = z;
|
||||||
|
this.minHeight = world.getMinHeight();
|
||||||
|
this.world = world;
|
||||||
|
this.blocks= new CLIBlockState[16][16][world.getMaxHeight() - minHeight];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getHandle() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBlock(int x, int y, int z, BlockState data, boolean physics) {
|
||||||
|
blocks[x][z][y - minHeight] = (CLIBlockState) data;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull BlockState getBlock(int x, int y, int z) {
|
||||||
|
return blocks[x][z][y - minHeight];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getZ() {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServerWorld getWorld() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user