the crashes in this chunloading are not the loading, but RENDERING??!?!?!?!

pull/12/head
valoeghese 2020-02-28 22:48:08 +13:00
parent 56d8c65e0e
commit 7e16f40504
2 changed files with 12 additions and 13 deletions

View File

@ -57,7 +57,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
return blocks[index(x, y, z)]; return blocks[index(x, y, z)];
} }
public BlockInstance getBlockEntity(int x, int y, int z) public BlockInstance getBlockInstance(int x, int y, int z)
{ {
if (x > CHUNK_SIZE || y > CHUNK_SIZE || z > CHUNK_SIZE || x < 0 || y < 0 || z < 0) if (x > CHUNK_SIZE || y > CHUNK_SIZE || z > CHUNK_SIZE || x < 0 || y < 0 || z < 0)
{ throw new RuntimeException("Block [" + x + ", " + y + ", " + z + ", " + "] out of chunk bounds!"); } { throw new RuntimeException("Block [" + x + ", " + y + ", " + z + ", " + "] out of chunk bounds!"); }
@ -78,16 +78,16 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
{ {
for (int z = 0; z < CHUNK_SIZE; z++) for (int z = 0; z < CHUNK_SIZE; z++)
{ {
BlockInstance block = getBlockEntity(x, y, z); BlockInstance block = getBlockInstance(x, y, z);
if (x == 0 || x == CHUNK_SIZE - 1 || z == 0 || z == CHUNK_SIZE - 1 || y == 0 || y == CHUNK_SIZE - 1) if (x == 0 || x == CHUNK_SIZE - 1 || z == 0 || z == CHUNK_SIZE - 1 || y == 0 || y == CHUNK_SIZE - 1)
{ {
renderedBlocks[index(x, y, z)] = block; renderedBlocks[index(x, y, z)] = block;
continue; continue;
} }
// check for air. Yes this is stupid, TODO fix this // check for air. Yes this is stupid, TODO fix this
if (getBlockEntity(x - 1, y, z).getModel() == null || getBlockEntity(x + 1, y, z).getModel() == null || if (getBlockInstance(x - 1, y, z).getModel() == null || getBlockInstance(x + 1, y, z).getModel() == null ||
getBlockEntity(x, y - 1, z).getModel() == null || getBlockEntity(x, y + 1, z).getModel() == null || getBlockInstance(x, y - 1, z).getModel() == null || getBlockInstance(x, y + 1, z).getModel() == null ||
getBlockEntity(x, y, z - 1).getModel() == null || getBlockEntity(x, y, z + 1).getModel() == null) getBlockInstance(x, y, z - 1).getModel() == null || getBlockInstance(x, y, z + 1).getModel() == null)
{ renderedBlocks[index(x, y, z)] = block; } { renderedBlocks[index(x, y, z)] = block; }
} }
} }

View File

@ -27,9 +27,12 @@ public class World implements BlockAccess, WorldGenConstants
private final int dimension; private final int dimension;
public Player player; public Player player;
private final int renderSize; private final int renderSize;
private final BlockInstance dummy;
public World(long seed, int renderSize, Dimension<?> dim, LitecraftSave save) public World(long seed, int renderSize, Dimension<?> dim, LitecraftSave save)
{ {
this.dummy = new BlockInstance(Blocks.ANDESITE, new Vector3f(0, 0, 0));
this.dummy.isVisible = false;
this.chunks = new Long2ObjectArrayMap<>(); this.chunks = new Long2ObjectArrayMap<>();
this.seed = seed; this.seed = seed;
this.chunkGenerator = dim.createChunkGenerator(seed); this.chunkGenerator = dim.createChunkGenerator(seed);
@ -152,13 +155,9 @@ public class World implements BlockAccess, WorldGenConstants
public void render(BlockRenderer blockRenderer) public void render(BlockRenderer blockRenderer)
{ {
Chunk chunk = getChunk(0, -1, 0); blockRenderer.prepareModel(this.dummy.getModel());
if (chunk != null) this.chunks.forEach((pos, c) -> c.render(blockRenderer));
{ blockRenderer.unbindModel();
blockRenderer.prepareModel(chunk.getBlockEntity(0, 0, 0).getModel());
this.chunks.forEach((pos, c) -> c.render(blockRenderer));
blockRenderer.unbindModel();
}
} }
public void unloadAllChunks() public void unloadAllChunks()
@ -184,7 +183,7 @@ public class World implements BlockAccess, WorldGenConstants
// loop over rendered area, adding chunks that are needed // loop over rendered area, adding chunks that are needed
for (int x = -renderSize / 2; x < renderSize / 2; x++) for (int x = -renderSize / 2; x < renderSize / 2; x++)
for (int z = -renderSize / 2; z < renderSize / 2; z++) for (int z = -renderSize / 2; z < renderSize / 2; z++)
for (int y = -2; y < 2; ++y) for (int y = -2; y < 1; ++y)
toKeep.add(this.getChunkToLoad(x, y, z)); toKeep.add(this.getChunkToLoad(x, y, z));
// list of keys to remove // list of keys to remove
LongList toRemove = new LongArrayList(); LongList toRemove = new LongArrayList();