добавлена возможность указывать произвольные слои блоков
This commit is contained in:
@@ -9,15 +9,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.world.World;
|
||||
import mc.core.world.WorldType;
|
||||
import mc.core.world.block.BlockType;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
import mc.core.world.chunk.ChunkSection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class FlatWorld implements World {
|
||||
@Getter
|
||||
private final WorldType worldType = WorldType.FLAT;
|
||||
private EntityLocation spawn;
|
||||
private ChunkSection chunkSection = new SimpleChunkSection();
|
||||
private ChunkSection chunkSection;
|
||||
|
||||
@Override
|
||||
public EntityLocation getSpawn() {
|
||||
@@ -46,4 +50,25 @@ public class FlatWorld implements World {
|
||||
public void setChunk(int x, int z, Chunk chunk) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void setLayersBlock(List<String> listOfLayers) {
|
||||
List<BlockType> layoutsBlock = new ArrayList<>();
|
||||
|
||||
for (String value : listOfLayers) {
|
||||
String[] splitValue = value.split(";");
|
||||
|
||||
BlockType blockType;
|
||||
try {
|
||||
blockType = BlockType.valueOf(splitValue[1]);
|
||||
} catch (IllegalArgumentException e) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Integer.parseInt(splitValue[0]); i++) {
|
||||
layoutsBlock.add(blockType);
|
||||
}
|
||||
}
|
||||
|
||||
this.chunkSection = new SimpleChunkSection(layoutsBlock, this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package mc.world.flat;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.exception.ResourceUnloadedException;
|
||||
import mc.core.world.Biome;
|
||||
import mc.core.world.World;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
@@ -47,7 +48,7 @@ public class SimpleChunk implements Chunk {
|
||||
@Override
|
||||
public World getWorld() {
|
||||
if (refWorld.get() == null) {
|
||||
throw new WorldUnloadedException();
|
||||
throw new ResourceUnloadedException("World unloaded");
|
||||
} else {
|
||||
return refWorld.get();
|
||||
}
|
||||
|
||||
@@ -4,18 +4,28 @@
|
||||
*/
|
||||
package mc.world.flat;
|
||||
|
||||
import mc.core.exception.ResourceUnloadedException;
|
||||
import mc.core.world.Biome;
|
||||
import mc.core.world.World;
|
||||
import mc.core.world.block.Block;
|
||||
import mc.core.world.block.BlockFactory;
|
||||
import mc.core.world.block.BlockType;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
import mc.core.world.chunk.ChunkSection;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleChunkSection implements ChunkSection {
|
||||
private final BlockFactory blockFactory = new BlockFactory();
|
||||
private final List<BlockType> layersBlock;
|
||||
private Reference<World> refWorld;
|
||||
|
||||
public SimpleChunkSection(List<BlockType> layersBlock, World world) {
|
||||
this.layersBlock = layersBlock;
|
||||
this.refWorld = new WeakReference<>(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkyLight(int x, int y, int z) {
|
||||
if (y <= 3) return 0;
|
||||
@@ -61,16 +71,23 @@ public class SimpleChunkSection implements ChunkSection {
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
BlockFactory blockFactory = new BlockFactory();
|
||||
if (y >= layersBlock.size()) {
|
||||
return blockFactory.create(BlockType.AIR, x, y, z, getWorld());
|
||||
}
|
||||
|
||||
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());
|
||||
BlockType blockType = layersBlock.get(y);
|
||||
if (blockType == null) return blockFactory.create(BlockType.AIR, x, y, z, getWorld());
|
||||
|
||||
return blockFactory.create(blockType, x, y, z, getWorld());
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
throw new UnsupportedOperationException();
|
||||
World world = refWorld.get();
|
||||
if (world == null) {
|
||||
throw new ResourceUnloadedException("World unloaded");
|
||||
}
|
||||
|
||||
return world;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user