Checking on unloading
This commit is contained in:
@@ -3,11 +3,13 @@ package mc.world.generated_world.chunk;
|
||||
import lombok.Getter;
|
||||
import mc.core.block.Block;
|
||||
import mc.core.block.BlockType;
|
||||
import mc.core.exception.ResourceUnloadException;
|
||||
import mc.core.world.Biome;
|
||||
import mc.core.world.Chunk;
|
||||
import mc.core.world.Region;
|
||||
import mc.core.world.World;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import static mc.world.generated_world.WorldConstants.WORLD_CHUNK_SIZE;
|
||||
@@ -20,7 +22,7 @@ public class ChunkImpl implements Chunk{
|
||||
@Getter
|
||||
private final int z;
|
||||
private final Block[][][] blocks = new Block[WORLD_CHUNK_SIZE][WORLD_CHUNK_SIZE][WORLD_CHUNK_SIZE];
|
||||
private final transient WeakReference<Region> region;
|
||||
private final transient Reference<Region> region;
|
||||
|
||||
public ChunkImpl(int x, int y, int z, Region region) {
|
||||
this.x = x;
|
||||
@@ -109,6 +111,9 @@ public class ChunkImpl implements Chunk{
|
||||
|
||||
@Override
|
||||
public Region getRegion() {
|
||||
if (region.get() == null) {
|
||||
throw new ResourceUnloadException("Region is unloaded");
|
||||
}
|
||||
return region.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package mc.world.generated_world.region;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.exception.ResourceUnloadException;
|
||||
import mc.core.serialization.IRegionReaderWriter;
|
||||
import mc.core.serialization.Serializer;
|
||||
import mc.core.world.*;
|
||||
@@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
@@ -27,7 +29,7 @@ public class RegionImpl implements Region{
|
||||
private final int z;
|
||||
private final ChunkProxy[][][] chunks = new ChunkProxy[WORLD_REGION_SIZE/WORLD_CHUNK_SIZE][WORLD_REGION_SIZE/WORLD_CHUNK_SIZE][WORLD_REGION_SIZE/WORLD_CHUNK_SIZE];
|
||||
private final Biome[][] biomes = new Biome[WORLD_REGION_SIZE][WORLD_REGION_SIZE];
|
||||
private final transient WeakReference<World> world;
|
||||
private final transient Reference<World> world;
|
||||
@Autowired
|
||||
private ChunkLoader chunkLoader;
|
||||
|
||||
@@ -79,6 +81,9 @@ public class RegionImpl implements Region{
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
if (world.get() == null) {
|
||||
throw new ResourceUnloadException("World is unloaded");
|
||||
}
|
||||
return world.get();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user