Archived
0

исключена ссылка на World в Location и ChunkSection

This commit is contained in:
2018-08-26 01:13:21 +03:00
parent 2147c18f81
commit 464a2e7be6
12 changed files with 133 additions and 154 deletions

View File

@@ -4,26 +4,20 @@
*/
package mc.world.simple;
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.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) {
public SimpleChunkSection(List<BlockType> layersBlock) {
this.layersBlock = layersBlock;
this.refWorld = new WeakReference<>(world);
}
@Override
@@ -72,22 +66,12 @@ public class SimpleChunkSection implements ChunkSection {
@Override
public Block getBlock(int x, int y, int z) {
if (y >= layersBlock.size()) {
return blockFactory.create(BlockType.AIR, x, y, z, getWorld());
return blockFactory.create(BlockType.AIR, x, y, z);
}
BlockType blockType = layersBlock.get(y);
if (blockType == null) return blockFactory.create(BlockType.AIR, x, y, z, getWorld());
if (blockType == null) return blockFactory.create(BlockType.AIR, x, y, z);
return blockFactory.create(blockType, x, y, z, getWorld());
}
@Override
public World getWorld() {
World world = refWorld.get();
if (world == null) {
throw new ResourceUnloadedException("World unloaded");
}
return world;
return blockFactory.create(blockType, x, y, z);
}
}

View File

@@ -68,6 +68,6 @@ public class SimpleWorld implements World {
}
}
this.chunkSection = new SimpleChunkSection(layoutsBlock, this);
this.chunkSection = new SimpleChunkSection(layoutsBlock);
}
}