Archived
0

исключена ссылка на World из класса Chunk

This commit is contained in:
2018-08-26 00:51:55 +03:00
parent 06835aa5a2
commit 2147c18f81
3 changed files with 4 additions and 32 deletions

View File

@@ -1,7 +1,6 @@
package mc.core.world.chunk; package mc.core.world.chunk;
import mc.core.world.Biome; import mc.core.world.Biome;
import mc.core.world.World;
public interface Chunk { public interface Chunk {
int getX(); int getX();
@@ -12,7 +11,4 @@ public interface Chunk {
Biome getBiome(int localX, int localZ); Biome getBiome(int localX, int localZ);
void setBiome(int localX, int localZ, Biome biome); void setBiome(int localX, int localZ, Biome biome);
World getWorld();
void setWorld(World world);
} }

View File

@@ -1,30 +1,20 @@
package mc.world.simple; package mc.world.simple;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor;
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.chunk.Chunk; 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.WeakReference;
@Slf4j @Slf4j
@RequiredArgsConstructor
public class SimpleChunk implements Chunk { public class SimpleChunk implements Chunk {
@Getter @Getter
private int x, z; private final int x, z;
private Reference<World> refWorld;
private ChunkSection chunkSection; private ChunkSection chunkSection;
private final Biome biome = Biome.PLAINS; private final Biome biome = Biome.PLAINS;
public SimpleChunk(int x, int z, World world) {
this.x = x;
this.z = z;
setWorld(world);
}
@Override @Override
public ChunkSection getChunkSection(int height) { public ChunkSection getChunkSection(int height) {
return chunkSection; return chunkSection;
@@ -44,18 +34,4 @@ public class SimpleChunk implements Chunk {
public void setBiome(int localX, int localZ, Biome biome) { public void setBiome(int localX, int localZ, Biome biome) {
// ignore // ignore
} }
@Override
public World getWorld() {
if (refWorld.get() == null) {
throw new ResourceUnloadedException("World unloaded");
} else {
return refWorld.get();
}
}
@Override
public void setWorld(World world) {
this.refWorld = new WeakReference<>(world);
}
} }

View File

@@ -40,7 +40,7 @@ public class SimpleWorld implements World {
@Override @Override
public Chunk getChunk(int x, int z) { public Chunk getChunk(int x, int z) {
Chunk chunk = new SimpleChunk(x, z, this); Chunk chunk = new SimpleChunk(x, z);
chunk.setChunkSection(0, chunkSection); chunk.setChunkSection(0, chunkSection);
return chunk; return chunk;
} }