initial bugfix for taller chunks

This commit is contained in:
Sen 2025-05-21 12:04:28 +02:00
parent caef42dc16
commit 7fd8a49d5c
6 changed files with 67 additions and 55 deletions

View file

@ -464,7 +464,7 @@ public class RenderGlobal
if (entity != null) if (entity != null)
{ {
this.viewFrustum.updateChunkPositions(entity.posX, entity.posZ); this.viewFrustum.updateChunkPositions(entity.posX, entity.posY, entity.posZ);
} }
} }
@ -605,7 +605,7 @@ public class RenderGlobal
for (RenderGlobal.ContainerLocalRenderInformation renderglobal$containerlocalrenderinformation : this.renderInfos) for (RenderGlobal.ContainerLocalRenderInformation renderglobal$containerlocalrenderinformation : this.renderInfos)
{ {
Chunk chunk = this.theWorld.getChunk(renderglobal$containerlocalrenderinformation.renderChunk.getPosition()); Chunk chunk = this.theWorld.getChunk(renderglobal$containerlocalrenderinformation.renderChunk.getPosition());
ClassInheritanceMultiMap<Entity> classinheritancemultimap = chunk.getEntities()[renderglobal$containerlocalrenderinformation.renderChunk.getPosition().getY() / 16]; ClassInheritanceMultiMap<Entity> classinheritancemultimap = chunk.getEntities()[ExtMath.clampi(renderglobal$containerlocalrenderinformation.renderChunk.getPosition().getY() / 16, 0, 31)];
if (!classinheritancemultimap.isEmpty()) if (!classinheritancemultimap.isEmpty())
{ {
@ -761,7 +761,7 @@ public class RenderGlobal
this.frustumUpdatePosChunkX = viewEntity.chunkCoordX; this.frustumUpdatePosChunkX = viewEntity.chunkCoordX;
this.frustumUpdatePosChunkY = viewEntity.chunkCoordY; this.frustumUpdatePosChunkY = viewEntity.chunkCoordY;
this.frustumUpdatePosChunkZ = viewEntity.chunkCoordZ; this.frustumUpdatePosChunkZ = viewEntity.chunkCoordZ;
this.viewFrustum.updateChunkPositions(viewEntity.posX, viewEntity.posZ); this.viewFrustum.updateChunkPositions(viewEntity.posX, viewEntity.posY, viewEntity.posZ);
} }
double d3 = viewEntity.lastTickPosX + (viewEntity.posX - viewEntity.lastTickPosX) * partialTicks; double d3 = viewEntity.lastTickPosX + (viewEntity.posX - viewEntity.lastTickPosX) * partialTicks;
double d4 = viewEntity.lastTickPosY + (viewEntity.posY - viewEntity.lastTickPosY) * partialTicks; double d4 = viewEntity.lastTickPosY + (viewEntity.posY - viewEntity.lastTickPosY) * partialTicks;
@ -821,13 +821,15 @@ public class RenderGlobal
else else
{ {
// int i = blockpos1.getY() > 0 ? 248 : 8; // int i = blockpos1.getY() > 0 ? 248 : 8;
int i = blockpos1.getY() > 0 ? 504 : 8; // int i = blockpos1.getY() > 0 ? 504 : 8;
for (int j = -this.renderDistanceChunks; j <= this.renderDistanceChunks; ++j) for (int j = -this.renderDistanceChunks; j <= this.renderDistanceChunks; ++j)
{ {
for (int k = -this.renderDistanceChunks; k <= this.renderDistanceChunks; ++k) for (int k = -this.renderDistanceChunks; k <= this.renderDistanceChunks; ++k)
{ {
RenderChunk renderchunk1 = this.viewFrustum.getRenderChunk(new BlockPos((j << 4) + 8, i, (k << 4) + 8)); for (int i = -this.renderDistanceChunks; i <= this.renderDistanceChunks; ++i)
{
RenderChunk renderchunk1 = this.viewFrustum.getRenderChunk(new BlockPos((j << 4) + 8, (i << 4) + 8, (k << 4) + 8));
if (renderchunk1 != null && Frustum.isInFrustum(renderchunk1.boundingBox)) if (renderchunk1 != null && Frustum.isInFrustum(renderchunk1.boundingBox))
{ {
@ -837,6 +839,7 @@ public class RenderGlobal
} }
} }
} }
}
// int n = queue.size(); // int n = queue.size();
// Log.RENDER.info("** " + n + " render"); // Log.RENDER.info("** " + n + " render");
@ -932,7 +935,7 @@ public class RenderGlobal
private RenderChunk getRenderChunkOffset(BlockPos playerPos, RenderChunk renderChunkBase, Facing facing) private RenderChunk getRenderChunkOffset(BlockPos playerPos, RenderChunk renderChunkBase, Facing facing)
{ {
BlockPos blockpos = renderChunkBase.getBlockPosOffset16(facing); BlockPos blockpos = renderChunkBase.getBlockPosOffset16(facing);
return ExtMath.absi(playerPos.getX() - blockpos.getX()) > this.renderDistanceChunks * 16 ? null : (blockpos.getY() >= -World.MAX_SIZE_Y && blockpos.getY() < World.MAX_SIZE_Y ? (ExtMath.absi(playerPos.getZ() - blockpos.getZ()) > this.renderDistanceChunks * 16 ? null : this.viewFrustum.getRenderChunk(blockpos)) : null); return ExtMath.absi(playerPos.getX() - blockpos.getX()) > this.renderDistanceChunks * 16 ? null : (ExtMath.absi(playerPos.getY() - blockpos.getY()) <= this.renderDistanceChunks * 16 ? (ExtMath.absi(playerPos.getZ() - blockpos.getZ()) > this.renderDistanceChunks * 16 ? null : this.viewFrustum.getRenderChunk(blockpos)) : null);
} }
protected Vector3f getViewVector(Entity entityIn, double partialTicks) protected Vector3f getViewVector(Entity entityIn, double partialTicks)

View file

@ -58,13 +58,14 @@ public class ViewFrustum
{ {
int i = renderDistanceChunks * 2 + 1; int i = renderDistanceChunks * 2 + 1;
this.countChunksX = i; this.countChunksX = i;
this.countChunksY = 32; this.countChunksY = i;
this.countChunksZ = i; this.countChunksZ = i;
} }
public void updateChunkPositions(double viewEntityX, double viewEntityZ) public void updateChunkPositions(double viewEntityX, double viewEntityY, double viewEntityZ)
{ {
int i = ExtMath.floord(viewEntityX) - 8; int i = ExtMath.floord(viewEntityX) - 8;
int n = ExtMath.floord(viewEntityY) - 8;
int j = ExtMath.floord(viewEntityZ) - 8; int j = ExtMath.floord(viewEntityZ) - 8;
int k = this.countChunksX * 16; int k = this.countChunksX * 16;
@ -78,7 +79,7 @@ public class ViewFrustum
for (int l1 = 0; l1 < this.countChunksY; ++l1) for (int l1 = 0; l1 < this.countChunksY; ++l1)
{ {
int i2 = l1 * 16; int i2 = this.func_178157_a(n, k, l1);
RenderChunk renderchunk = this.renderChunks[(j1 * this.countChunksY + l1) * this.countChunksX + l]; RenderChunk renderchunk = this.renderChunks[(j1 * this.countChunksY + l1) * this.countChunksX + l];
BlockPos blockpos = new BlockPos(i1, i2, k1); BlockPos blockpos = new BlockPos(i1, i2, k1);
@ -154,8 +155,6 @@ public class ViewFrustum
int y = bucketInt(pos.getY()); int y = bucketInt(pos.getY());
int z = bucketInt(pos.getZ()); int z = bucketInt(pos.getZ());
if (y >= 0 && y < this.countChunksY)
{
x = x % this.countChunksX; x = x % this.countChunksX;
if (x < 0) if (x < 0)
@ -163,6 +162,13 @@ public class ViewFrustum
x += this.countChunksX; x += this.countChunksX;
} }
y = y % this.countChunksY;
if (y < 0)
{
y += this.countChunksY;
}
z = z % this.countChunksZ; z = z % this.countChunksZ;
if (z < 0) if (z < 0)
@ -173,9 +179,4 @@ public class ViewFrustum
int p = (z * this.countChunksY + y) * this.countChunksX + x; int p = (z * this.countChunksY + y) * this.countChunksX + x;
return this.renderChunks[p]; return this.renderChunks[p];
} }
else
{
return null;
}
}
} }

View file

@ -128,7 +128,7 @@ public class SPacketChunkData implements Packet<IClientPlayer>
} }
extend = new int[list.size() - epos]; extend = new int[list.size() - epos];
for(int z = 0; z < extend.length; z++) { for(int z = 0; z < extend.length; z++) {
extend[z] = list.get(z + epos).getY(); extend[z] = list.get(z + epos).getY() >> 4;
} }
s21packetchunkdata$extracted.extend = extend; s21packetchunkdata$extracted.extend = extend;

View file

@ -1,5 +1,7 @@
package common.world; package common.world;
import java.util.Arrays;
import common.block.Block; import common.block.Block;
import common.init.BlockRegistry; import common.init.BlockRegistry;
import common.init.Blocks; import common.init.Blocks;
@ -13,12 +15,17 @@ public class BlockArray {
private NibbleArray blocklight; private NibbleArray blocklight;
private NibbleArray skylight; private NibbleArray skylight;
public BlockArray(int y, boolean sky) { public BlockArray(int y, boolean sky, State filler) {
this.yBase = y; this.yBase = y;
this.data = new char[4096]; this.data = new char[4096];
this.blocklight = new NibbleArray(); this.blocklight = new NibbleArray();
if(sky) if(sky)
this.skylight = new NibbleArray(); this.skylight = new NibbleArray();
if(filler != null && filler.getBlock() != Blocks.air) {
Arrays.fill(this.data, (char)BlockRegistry.STATEMAP.get(filler));
this.blocks = this.data.length;
this.ticked = filler.getBlock().getTickRandomly() ? this.data.length : 0;
}
} }
public State get(int x, int y, int z) { public State get(int x, int y, int z) {

View file

@ -81,7 +81,7 @@ public class Chunk {
if(state != null && state.getBlock().getMaterial() != Material.air) { if(state != null && state.getBlock().getMaterial() != Material.air) {
int y = by >> 4; int y = by >> 4;
if(this.blocks[y] == null) if(this.blocks[y] == null)
this.blocks[y] = new BlockArray(y << 4, sky); this.blocks[y] = new BlockArray(y << 4, sky, null);
this.blocks[y].set(bx, by & 15, bz, state); this.blocks[y].set(bx, by & 15, bz, state);
} }
} }
@ -89,7 +89,7 @@ public class Chunk {
} }
if(base != null) { if(base != null) {
if(this.blocks[0] == null) if(this.blocks[0] == null)
this.blocks[0] = new BlockArray(0, sky); this.blocks[0] = new BlockArray(0, sky, null);
for(int bx = 0; bx < 16; ++bx) { for(int bx = 0; bx < 16; ++bx) {
for(int bz = 0; bz < 16; ++bz) { for(int bz = 0; bz < 16; ++bz) {
for(int by = 0; by < 5; ++by) { for(int by = 0; by < 5; ++by) {
@ -102,10 +102,10 @@ public class Chunk {
if(ceil != null) { if(ceil != null) {
int y = (height - 1) >> 4; int y = (height - 1) >> 4;
if(this.blocks[y] == null) if(this.blocks[y] == null)
this.blocks[y] = new BlockArray(y << 4, sky); this.blocks[y] = new BlockArray(y << 4, sky, null);
y = (height - 5) >> 4; y = (height - 5) >> 4;
if(this.blocks[y] == null) if(this.blocks[y] == null)
this.blocks[y] = new BlockArray(y << 4, sky); this.blocks[y] = new BlockArray(y << 4, sky, null);
for(int bx = 0; bx < 16; ++bx) { for(int bx = 0; bx < 16; ++bx) {
for(int bz = 0; bz < 16; ++bz) { for(int bz = 0; bz < 16; ++bz) {
for(int by = height - 1; by >= height - 5; --by) { for(int by = height - 1; by >= height - 5; --by) {
@ -119,7 +119,7 @@ public class Chunk {
this.biomes[n] = (byte)biomes[n].id; this.biomes[n] = (byte)biomes[n].id;
} }
this.bottom = height == 0 ? Integer.MAX_VALUE : 0; this.bottom = height == 0 ? Integer.MAX_VALUE : 0;
this.top = height == 0 ? Integer.MIN_VALUE : (height + 15) >> 4; this.top = height == 0 ? Integer.MIN_VALUE : ((height + 15) >> 4) << 4;
if(ceil == null) if(ceil == null)
this.genSkyLight(); this.genSkyLight();
else else
@ -195,7 +195,7 @@ public class Chunk {
} }
public BlockArray getArray(int y) { public BlockArray getArray(int y) {
return y >= 0 && y < this.blocks.length ? this.blocks[y] : (y < 0 ? (this.extendDown == null || -y > this.extendDown.length ? null : this.extendDown[-this.extendDown.length - y]) : (this.extendUp == null || y - this.blocks.length >= this.extendUp.length ? null : this.extendUp[y - this.blocks.length])); return y >= 0 && y < this.blocks.length ? this.blocks[y] : (y < 0 ? (this.extendDown == null || -y > this.extendDown.length ? null : this.extendDown[this.extendDown.length + y]) : (this.extendUp == null || y - this.blocks.length >= this.extendUp.length ? null : this.extendUp[y - this.blocks.length]));
} }
private void setArray(int y, BlockArray array) { private void setArray(int y, BlockArray array) {
@ -211,7 +211,7 @@ public class Chunk {
this.extendDown = new BlockArray[-y]; this.extendDown = new BlockArray[-y];
System.arraycopy(extendDown, 0, this.extendDown, -y - extendDown.length, extendDown.length); System.arraycopy(extendDown, 0, this.extendDown, -y - extendDown.length, extendDown.length);
} }
this.extendDown[-this.extendDown.length - y] = array; this.extendDown[this.extendDown.length + y] = array;
} }
else { else {
if(this.extendUp == null) { if(this.extendUp == null) {
@ -480,7 +480,7 @@ public class Chunk {
return stor != null ? stor.getBlock(x, y & 15, z) : Blocks.air; return stor != null ? stor.getBlock(x, y & 15, z) : Blocks.air;
} }
else if(y < 0 && this.extendDown != null && -(y >> 4) <= this.extendDown.length) { else if(y < 0 && this.extendDown != null && -(y >> 4) <= this.extendDown.length) {
BlockArray stor = this.extendDown[-this.extendDown.length - (y >> 4)]; BlockArray stor = this.extendDown[this.extendDown.length + (y >> 4)];
return stor != null ? stor.getBlock(x, y & 15, z) : this.fillerBlock; return stor != null ? stor.getBlock(x, y & 15, z) : this.fillerBlock;
} }
else if(y >> 4 >= this.blocks.length && this.extendUp != null && (y >> 4) - this.blocks.length < this.extendUp.length) { else if(y >> 4 >= this.blocks.length && this.extendUp != null && (y >> 4) - this.blocks.length < this.extendUp.length) {
@ -501,7 +501,7 @@ public class Chunk {
return stor != null ? stor.get(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15) : Blocks.air.getState(); return stor != null ? stor.get(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15) : Blocks.air.getState();
} }
else if(pos.getY() < 0 && this.extendDown != null && -(pos.getY() >> 4) <= this.extendDown.length) { else if(pos.getY() < 0 && this.extendDown != null && -(pos.getY() >> 4) <= this.extendDown.length) {
BlockArray stor = this.extendDown[-this.extendDown.length - (pos.getY() >> 4)]; BlockArray stor = this.extendDown[this.extendDown.length + (pos.getY() >> 4)];
return stor != null ? stor.get(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15) : this.filler; return stor != null ? stor.get(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15) : this.filler;
} }
else if(pos.getY() >> 4 >= this.blocks.length && this.extendUp != null && (pos.getY() >> 4) - this.blocks.length < this.extendUp.length) { else if(pos.getY() >> 4 >= this.blocks.length && this.extendUp != null && (pos.getY() >> 4) - this.blocks.length < this.extendUp.length) {
@ -538,11 +538,11 @@ public class Chunk {
boolean up = false; boolean up = false;
if(stor == null) { if(stor == null) {
if(block == Blocks.air) { if(block == Blocks.air && (y >= 0 || this.fillerBlock == Blocks.air)) {
return null; return null;
} }
stor = new BlockArray(y >> 4 << 4, !this.world.dimension.hasNoLight()); stor = new BlockArray(y >> 4 << 4, !this.world.dimension.hasNoLight(), y < 0 ? this.filler : null);
this.setArray(y >> 4, stor); this.setArray(y >> 4, stor);
up = y >= h; up = y >= h;
} }
@ -631,7 +631,7 @@ public class Chunk {
BlockArray stor = this.getArray(y >> 4); BlockArray stor = this.getArray(y >> 4);
if(stor == null) { if(stor == null) {
stor = new BlockArray(y >> 4 << 4, !this.world.dimension.hasNoLight()); stor = new BlockArray(y >> 4 << 4, !this.world.dimension.hasNoLight(), y < 0 ? this.filler : null);
this.setArray(y >> 4, stor); this.setArray(y >> 4, stor);
this.genSkyLight(); this.genSkyLight();
} }
@ -939,7 +939,7 @@ public class Chunk {
for(int y = bottom; y <= top; y += 16) { for(int y = bottom; y <= top; y += 16) {
BlockArray stor = this.getArray(y >> 4); BlockArray stor = this.getArray(y >> 4);
if(stor != null && !stor.isEmpty()) { if(stor != null ? !stor.isEmpty() : (y < 0 && this.fillerBlock != Blocks.air)) {
return false; return false;
} }
} }
@ -970,7 +970,7 @@ public class Chunk {
for(int n = 0; n < this.blocks.length; ++n) { for(int n = 0; n < this.blocks.length; ++n) {
if((update & 1 << n) != 0) { if((update & 1 << n) != 0) {
if(this.blocks[n] == null) { if(this.blocks[n] == null) {
this.blocks[n] = new BlockArray(n << 4, sky); this.blocks[n] = new BlockArray(n << 4, sky, null);
} }
char[] blocks = this.blocks[n].getData(); char[] blocks = this.blocks[n].getData();
@ -991,7 +991,8 @@ public class Chunk {
for(int cy : extend) { for(int cy : extend) {
BlockArray arr = this.getArray(cy); BlockArray arr = this.getArray(cy);
if(arr == null) { if(arr == null) {
arr = new BlockArray(cy << 4, sky); arr = new BlockArray(cy << 4, sky, null);
this.setArray(cy, arr);
} }
char[] blocks = arr.getData(); char[] blocks = arr.getData();
@ -1111,11 +1112,11 @@ public class Chunk {
for(int n = 0; n < 8; ++n) { for(int n = 0; n < 8; ++n) {
if(this.top == Integer.MIN_VALUE) if(this.top == Integer.MIN_VALUE)
return; return;
int h = 1 + this.top - this.bottom; int h = 1 + (this.top >> 4) - (this.bottom >> 4);
if(this.lightChecks >= 256 * h) if(this.lightChecks >= 256 * h)
return; return;
int s = (this.lightChecks % h) + this.bottom; int s = (this.lightChecks % h) + (this.bottom >> 4);
int x = this.lightChecks / h % 16; int x = this.lightChecks / h % 16;
int z = this.lightChecks / 512; int z = this.lightChecks / 512;
++this.lightChecks; ++this.lightChecks;

View file

@ -392,7 +392,7 @@ public class Region {
for(int n = 0; n < sects.tagCount(); ++n) { for(int n = 0; n < sects.tagCount(); ++n) {
NBTTagCompound sect = sects.getCompoundTagAt(n); NBTTagCompound sect = sects.getCompoundTagAt(n);
int y = sect.getInteger("Y"); int y = sect.getInteger("Y");
BlockArray storage = new BlockArray(y << 4, light); BlockArray storage = new BlockArray(y << 4, light, null);
byte[] blocks = sect.getByteArray("Blocks"); byte[] blocks = sect.getByteArray("Blocks");
NibbleArray data = new NibbleArray(sect.getByteArray("Data")); NibbleArray data = new NibbleArray(sect.getByteArray("Data"));
NibbleArray adddata = sect.hasKey("Add", 7) ? new NibbleArray(sect.getByteArray("Add")) : null; NibbleArray adddata = sect.hasKey("Add", 7) ? new NibbleArray(sect.getByteArray("Add")) : null;
@ -417,7 +417,7 @@ public class Region {
if(y >= 0 && y < stor) if(y >= 0 && y < stor)
sections[y] = storage; sections[y] = storage;
else if(y < 0) else if(y < 0)
down[-down.length - y] = storage; down[down.length + y] = storage;
else else
up[y - stor] = storage; up[y - stor] = storage;
} }
@ -510,8 +510,8 @@ public class Region {
tag.setBoolean("LightPopulated", chunk.isLightPopulated()); tag.setBoolean("LightPopulated", chunk.isLightPopulated());
tag.setLong("InhabitedTime", chunk.getInhabited()); tag.setLong("InhabitedTime", chunk.getInhabited());
BlockArray[] sections = chunk.getStorage(); BlockArray[] sections = chunk.getStorage();
BlockArray[] down = chunk.getStorage(); BlockArray[] down = chunk.getStorageDown();
BlockArray[] up = chunk.getStorage(); BlockArray[] up = chunk.getStorageUp();
NBTTagList sects = new NBTTagList(); NBTTagList sects = new NBTTagList();
boolean light = !world.dimension.hasNoLight(); boolean light = !world.dimension.hasNoLight();