исключена ссылка на World из класса Chunk
This commit is contained in:
@@ -1,30 +1,20 @@
|
||||
package mc.world.simple;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
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;
|
||||
import mc.core.world.chunk.ChunkSection;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class SimpleChunk implements Chunk {
|
||||
@Getter
|
||||
private int x, z;
|
||||
private Reference<World> refWorld;
|
||||
private final int x, z;
|
||||
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;
|
||||
@@ -44,18 +34,4 @@ public class SimpleChunk implements Chunk {
|
||||
public void setBiome(int localX, int localZ, Biome biome) {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SimpleWorld implements World {
|
||||
|
||||
@Override
|
||||
public Chunk getChunk(int x, int z) {
|
||||
Chunk chunk = new SimpleChunk(x, z, this);
|
||||
Chunk chunk = new SimpleChunk(x, z);
|
||||
chunk.setChunkSection(0, chunkSection);
|
||||
return chunk;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user