refactory world and clean classes
This commit is contained in:
@@ -4,38 +4,21 @@
|
||||
*/
|
||||
package mc.world.flat;
|
||||
|
||||
import com.flowpowered.nbt.Tag;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.world.IWorldType;
|
||||
import mc.core.world.Region;
|
||||
import mc.core.world.World;
|
||||
import mc.core.world.WorldType;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
import mc.core.world.chunk.ChunkSection;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Slf4j
|
||||
public class FlatWorld implements World {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private UUID worldId = UUID.fromString("00000000-0000-0000-C000-000000000046");
|
||||
@Getter
|
||||
@Setter
|
||||
private String name;
|
||||
|
||||
private final WorldType worldType = WorldType.FLAT;
|
||||
private EntityLocation spawn;
|
||||
private ChunkSection chunkSection = new SimpleChunkSection();
|
||||
|
||||
@Override
|
||||
public IWorldType getWorldType() {
|
||||
return WorldType.GENERAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityLocation getSpawn() {
|
||||
if (this.spawn == null) {
|
||||
@@ -53,42 +36,14 @@ public class FlatWorld implements World {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkSection getChunk(int x, int y, int z) {
|
||||
return chunkSection;
|
||||
public Chunk getChunk(int x, int z) {
|
||||
Chunk chunk = new SimpleChunk(x, z, this);
|
||||
chunk.setChunkSection(0, chunkSection);
|
||||
return chunk;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChunk(int x, int y, int z, ChunkSection chunkSection) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region getRegion(int x, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRegion(int x, int z, Region region) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSeed() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag<?> getTag(String name) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTag(Tag<?> tag) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<Tag<?>> tagStream() {
|
||||
public void setChunk(int x, int z, Chunk chunk) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
61
flat_world/src/main/java/mc/world/flat/SimpleChunk.java
Normal file
61
flat_world/src/main/java/mc/world/flat/SimpleChunk.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package mc.world.flat;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.world.Biome;
|
||||
import mc.core.world.World;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
import mc.core.world.chunk.ChunkSection;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
@Slf4j
|
||||
public class SimpleChunk implements Chunk {
|
||||
@Getter
|
||||
private int x, z;
|
||||
private Reference<World> refWorld;
|
||||
private ChunkSection chunkSection;
|
||||
private final Biome biome = Biome.PLAINS;
|
||||
|
||||
public SimpleChunk(int x, int z, World world) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
setWorld(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkSection getChunkSection(int height) {
|
||||
return chunkSection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChunkSection(int height, ChunkSection chunkSection) {
|
||||
this.chunkSection = chunkSection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int localX, int localZ) {
|
||||
return biome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int localX, int localZ, Biome biome) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
if (refWorld.get() == null) {
|
||||
log.error("World unloaded?");
|
||||
return null;
|
||||
} else {
|
||||
return refWorld.get();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorld(World world) {
|
||||
this.refWorld = new WeakReference<>(world);
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,6 @@
|
||||
*/
|
||||
package mc.world.flat;
|
||||
|
||||
import mc.core.world.Biome;
|
||||
import mc.core.world.Region;
|
||||
import mc.core.world.World;
|
||||
import mc.core.world.block.Block;
|
||||
import mc.core.world.block.BlockFactory;
|
||||
@@ -34,16 +32,6 @@ public class SimpleChunkSection implements ChunkSection {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int x, int z) {
|
||||
return Biome.PLAINS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBiome(int x, int z, Biome biome) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getX() {
|
||||
return 0;
|
||||
@@ -68,15 +56,10 @@ public class SimpleChunkSection implements ChunkSection {
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
BlockFactory blockFactory = new BlockFactory();
|
||||
|
||||
if (y == 0) return blockFactory.create(BlockType.BEDROCK, 0);
|
||||
else if (y >= 1 && y <= 2) return blockFactory.create(BlockType.DIRT, 0);
|
||||
else if (y == 3) return blockFactory.create(BlockType.GRASS, 0);
|
||||
else return blockFactory.create(BlockType.AIR, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Region getRegion() {
|
||||
return null;
|
||||
if (y == 0) return blockFactory.create(BlockType.BEDROCK, x, y, z, getWorld());
|
||||
else if (y >= 1 && y <= 2) return blockFactory.create(BlockType.DIRT, x, y, z, getWorld());
|
||||
else if (y == 3) return blockFactory.create(BlockType.GRASS, x, y, z, getWorld());
|
||||
else return blockFactory.create(BlockType.AIR, x, y, z, getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user