добавлена возможность указывать произвольные слои блоков
This commit is contained in:
@@ -9,15 +9,19 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import mc.core.EntityLocation;
|
import mc.core.EntityLocation;
|
||||||
import mc.core.world.World;
|
import mc.core.world.World;
|
||||||
import mc.core.world.WorldType;
|
import mc.core.world.WorldType;
|
||||||
|
import mc.core.world.block.BlockType;
|
||||||
import mc.core.world.chunk.Chunk;
|
import mc.core.world.chunk.Chunk;
|
||||||
import mc.core.world.chunk.ChunkSection;
|
import mc.core.world.chunk.ChunkSection;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class FlatWorld implements World {
|
public class FlatWorld implements World {
|
||||||
@Getter
|
@Getter
|
||||||
private final WorldType worldType = WorldType.FLAT;
|
private final WorldType worldType = WorldType.FLAT;
|
||||||
private EntityLocation spawn;
|
private EntityLocation spawn;
|
||||||
private ChunkSection chunkSection = new SimpleChunkSection();
|
private ChunkSection chunkSection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntityLocation getSpawn() {
|
public EntityLocation getSpawn() {
|
||||||
@@ -46,4 +50,25 @@ public class FlatWorld implements World {
|
|||||||
public void setChunk(int x, int z, Chunk chunk) {
|
public void setChunk(int x, int z, Chunk chunk) {
|
||||||
throw new UnsupportedOperationException();
|
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.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import mc.core.exception.ResourceUnloadedException;
|
||||||
import mc.core.world.Biome;
|
import mc.core.world.Biome;
|
||||||
import mc.core.world.World;
|
import mc.core.world.World;
|
||||||
import mc.core.world.chunk.Chunk;
|
import mc.core.world.chunk.Chunk;
|
||||||
@@ -47,7 +48,7 @@ public class SimpleChunk implements Chunk {
|
|||||||
@Override
|
@Override
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
if (refWorld.get() == null) {
|
if (refWorld.get() == null) {
|
||||||
throw new WorldUnloadedException();
|
throw new ResourceUnloadedException("World unloaded");
|
||||||
} else {
|
} else {
|
||||||
return refWorld.get();
|
return refWorld.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,28 @@
|
|||||||
*/
|
*/
|
||||||
package mc.world.flat;
|
package mc.world.flat;
|
||||||
|
|
||||||
|
import mc.core.exception.ResourceUnloadedException;
|
||||||
import mc.core.world.Biome;
|
import mc.core.world.Biome;
|
||||||
import mc.core.world.World;
|
import mc.core.world.World;
|
||||||
import mc.core.world.block.Block;
|
import mc.core.world.block.Block;
|
||||||
import mc.core.world.block.BlockFactory;
|
import mc.core.world.block.BlockFactory;
|
||||||
import mc.core.world.block.BlockType;
|
import mc.core.world.block.BlockType;
|
||||||
import mc.core.world.chunk.Chunk;
|
|
||||||
import mc.core.world.chunk.ChunkSection;
|
import mc.core.world.chunk.ChunkSection;
|
||||||
|
|
||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class SimpleChunkSection implements ChunkSection {
|
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
|
@Override
|
||||||
public int getSkyLight(int x, int y, int z) {
|
public int getSkyLight(int x, int y, int z) {
|
||||||
if (y <= 3) return 0;
|
if (y <= 3) return 0;
|
||||||
@@ -61,16 +71,23 @@ public class SimpleChunkSection implements ChunkSection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Block getBlock(int x, int y, int z) {
|
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());
|
BlockType blockType = layersBlock.get(y);
|
||||||
else if (y >= 1 && y <= 2) return blockFactory.create(BlockType.DIRT, x, y, z, getWorld());
|
if (blockType == null) return blockFactory.create(BlockType.AIR, 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());
|
return blockFactory.create(blockType, x, y, z, getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
throw new UnsupportedOperationException();
|
World world = refWorld.get();
|
||||||
|
if (world == null) {
|
||||||
|
throw new ResourceUnloadedException("World unloaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
return world;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ public class ChunkDataPacket implements SCPacket {
|
|||||||
netStream.writeInt(z); // Chunk Y
|
netStream.writeInt(z); // Chunk Y
|
||||||
netStream.writeBoolean(initChunk); // Init Chunk
|
netStream.writeBoolean(initChunk); // Init Chunk
|
||||||
|
|
||||||
|
int maxH = 0;
|
||||||
if (sectionList == null && chunk != null) {
|
if (sectionList == null && chunk != null) {
|
||||||
int bitMask = 0;
|
int bitMask = 0;
|
||||||
for (int h = 15; h >= 0; h--) {
|
for (int h = 15; h >= 0; h--) {
|
||||||
@@ -109,6 +110,7 @@ public class ChunkDataPacket implements SCPacket {
|
|||||||
ChunkSection chunkSection = chunk.getChunkSection(h);
|
ChunkSection chunkSection = chunk.getChunkSection(h);
|
||||||
if (chunkSection != null && chunkSection.getY() == h) {
|
if (chunkSection != null && chunkSection.getY() == h) {
|
||||||
bitMask |= 0x01;
|
bitMask |= 0x01;
|
||||||
|
maxH++;
|
||||||
} else {
|
} else {
|
||||||
bitMask |= 0x00;
|
bitMask |= 0x00;
|
||||||
}
|
}
|
||||||
@@ -123,6 +125,7 @@ public class ChunkDataPacket implements SCPacket {
|
|||||||
ChunkSection chunkSection = sectionList.get(i);
|
ChunkSection chunkSection = sectionList.get(i);
|
||||||
if (chunkSection != null && chunkSection.getY() == h) {
|
if (chunkSection != null && chunkSection.getY() == h) {
|
||||||
bitMask |= 0x01;
|
bitMask |= 0x01;
|
||||||
|
maxH++;
|
||||||
} else {
|
} else {
|
||||||
bitMask |= 0x00;
|
bitMask |= 0x00;
|
||||||
}
|
}
|
||||||
@@ -138,7 +141,7 @@ public class ChunkDataPacket implements SCPacket {
|
|||||||
int dataItems = 0;
|
int dataItems = 0;
|
||||||
final int airBlockPalette = serializeBlockState(BlockType.AIR);
|
final int airBlockPalette = serializeBlockState(BlockType.AIR);
|
||||||
|
|
||||||
for (int h = 0; h < 16; h++) {
|
for (int h = 0; h < maxH; h++) {
|
||||||
ChunkSection chunkSection = null;
|
ChunkSection chunkSection = null;
|
||||||
|
|
||||||
if (chunk != null) {
|
if (chunk != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user