diff --git a/client/src/client/renderer/RenderGlobal.java b/client/src/client/renderer/RenderGlobal.java index 0af5835..39b65cc 100755 --- a/client/src/client/renderer/RenderGlobal.java +++ b/client/src/client/renderer/RenderGlobal.java @@ -464,7 +464,7 @@ public class RenderGlobal 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) { Chunk chunk = this.theWorld.getChunk(renderglobal$containerlocalrenderinformation.renderChunk.getPosition()); - ClassInheritanceMultiMap classinheritancemultimap = chunk.getEntities()[renderglobal$containerlocalrenderinformation.renderChunk.getPosition().getY() / 16]; + ClassInheritanceMultiMap classinheritancemultimap = chunk.getEntities()[ExtMath.clampi(renderglobal$containerlocalrenderinformation.renderChunk.getPosition().getY() / 16, 0, 31)]; if (!classinheritancemultimap.isEmpty()) { @@ -761,7 +761,7 @@ public class RenderGlobal this.frustumUpdatePosChunkX = viewEntity.chunkCoordX; this.frustumUpdatePosChunkY = viewEntity.chunkCoordY; 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 d4 = viewEntity.lastTickPosY + (viewEntity.posY - viewEntity.lastTickPosY) * partialTicks; @@ -821,18 +821,21 @@ public class RenderGlobal else { // 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 k = -this.renderDistanceChunks; k <= this.renderDistanceChunks; ++k) { - RenderChunk renderchunk1 = this.viewFrustum.getRenderChunk(new BlockPos((j << 4) + 8, i, (k << 4) + 8)); - - if (renderchunk1 != null && Frustum.isInFrustum(renderchunk1.boundingBox)) + for (int i = -this.renderDistanceChunks; i <= this.renderDistanceChunks; ++i) { - renderchunk1.setFrameIndex(frameCount); - queue.add(new RenderGlobal.ContainerLocalRenderInformation(renderchunk1, (Facing)null, 0)); + RenderChunk renderchunk1 = this.viewFrustum.getRenderChunk(new BlockPos((j << 4) + 8, (i << 4) + 8, (k << 4) + 8)); + + if (renderchunk1 != null && Frustum.isInFrustum(renderchunk1.boundingBox)) + { + renderchunk1.setFrameIndex(frameCount); + queue.add(new RenderGlobal.ContainerLocalRenderInformation(renderchunk1, (Facing)null, 0)); + } } } } @@ -932,7 +935,7 @@ public class RenderGlobal private RenderChunk getRenderChunkOffset(BlockPos playerPos, RenderChunk renderChunkBase, Facing 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) diff --git a/client/src/client/renderer/ViewFrustum.java b/client/src/client/renderer/ViewFrustum.java index df65bd6..a9a95af 100755 --- a/client/src/client/renderer/ViewFrustum.java +++ b/client/src/client/renderer/ViewFrustum.java @@ -58,13 +58,14 @@ public class ViewFrustum { int i = renderDistanceChunks * 2 + 1; this.countChunksX = i; - this.countChunksY = 32; + this.countChunksY = 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 n = ExtMath.floord(viewEntityY) - 8; int j = ExtMath.floord(viewEntityZ) - 8; int k = this.countChunksX * 16; @@ -78,7 +79,7 @@ public class ViewFrustum 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]; BlockPos blockpos = new BlockPos(i1, i2, k1); @@ -154,28 +155,28 @@ public class ViewFrustum int y = bucketInt(pos.getY()); int z = bucketInt(pos.getZ()); - if (y >= 0 && y < this.countChunksY) + x = x % this.countChunksX; + + if (x < 0) { - x = x % this.countChunksX; - - if (x < 0) - { - x += this.countChunksX; - } - - z = z % this.countChunksZ; - - if (z < 0) - { - z += this.countChunksZ; - } - - int p = (z * this.countChunksY + y) * this.countChunksX + x; - return this.renderChunks[p]; + x += this.countChunksX; } - else + + y = y % this.countChunksY; + + if (y < 0) { - return null; + y += this.countChunksY; } + + z = z % this.countChunksZ; + + if (z < 0) + { + z += this.countChunksZ; + } + + int p = (z * this.countChunksY + y) * this.countChunksX + x; + return this.renderChunks[p]; } } diff --git a/common/src/common/packet/SPacketChunkData.java b/common/src/common/packet/SPacketChunkData.java index 182f6b5..e7d94bc 100755 --- a/common/src/common/packet/SPacketChunkData.java +++ b/common/src/common/packet/SPacketChunkData.java @@ -128,7 +128,7 @@ public class SPacketChunkData implements Packet } extend = new int[list.size() - epos]; 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; diff --git a/common/src/common/world/BlockArray.java b/common/src/common/world/BlockArray.java index 44fba70..effebfe 100755 --- a/common/src/common/world/BlockArray.java +++ b/common/src/common/world/BlockArray.java @@ -1,5 +1,7 @@ package common.world; +import java.util.Arrays; + import common.block.Block; import common.init.BlockRegistry; import common.init.Blocks; @@ -13,12 +15,17 @@ public class BlockArray { private NibbleArray blocklight; private NibbleArray skylight; - public BlockArray(int y, boolean sky) { + public BlockArray(int y, boolean sky, State filler) { this.yBase = y; this.data = new char[4096]; this.blocklight = new NibbleArray(); if(sky) 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) { diff --git a/common/src/common/world/Chunk.java b/common/src/common/world/Chunk.java index 259a183..0228b27 100755 --- a/common/src/common/world/Chunk.java +++ b/common/src/common/world/Chunk.java @@ -81,7 +81,7 @@ public class Chunk { if(state != null && state.getBlock().getMaterial() != Material.air) { int y = by >> 4; 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); } } @@ -89,7 +89,7 @@ public class Chunk { } if(base != 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 bz = 0; bz < 16; ++bz) { for(int by = 0; by < 5; ++by) { @@ -102,10 +102,10 @@ public class Chunk { if(ceil != null) { int y = (height - 1) >> 4; 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; 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 bz = 0; bz < 16; ++bz) { for(int by = height - 1; by >= height - 5; --by) { @@ -119,7 +119,7 @@ public class Chunk { this.biomes[n] = (byte)biomes[n].id; } 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) this.genSkyLight(); else @@ -195,7 +195,7 @@ public class Chunk { } 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) { @@ -211,7 +211,7 @@ public class Chunk { this.extendDown = new BlockArray[-y]; 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 { if(this.extendUp == null) { @@ -480,7 +480,7 @@ public class Chunk { return stor != null ? stor.getBlock(x, y & 15, z) : Blocks.air; } 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; } 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(); } 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; } 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; if(stor == null) { - if(block == Blocks.air) { + if(block == Blocks.air && (y >= 0 || this.fillerBlock == Blocks.air)) { 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); up = y >= h; } @@ -631,7 +631,7 @@ public class Chunk { BlockArray stor = this.getArray(y >> 4); 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.genSkyLight(); } @@ -939,7 +939,7 @@ public class Chunk { for(int y = bottom; y <= top; y += 16) { BlockArray stor = this.getArray(y >> 4); - if(stor != null && !stor.isEmpty()) { + if(stor != null ? !stor.isEmpty() : (y < 0 && this.fillerBlock != Blocks.air)) { return false; } } @@ -970,7 +970,7 @@ public class Chunk { for(int n = 0; n < this.blocks.length; ++n) { if((update & 1 << n) != 0) { 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(); @@ -991,7 +991,8 @@ public class Chunk { for(int cy : extend) { BlockArray arr = this.getArray(cy); if(arr == null) { - arr = new BlockArray(cy << 4, sky); + arr = new BlockArray(cy << 4, sky, null); + this.setArray(cy, arr); } char[] blocks = arr.getData(); @@ -1111,11 +1112,11 @@ public class Chunk { for(int n = 0; n < 8; ++n) { if(this.top == Integer.MIN_VALUE) return; - int h = 1 + this.top - this.bottom; + int h = 1 + (this.top >> 4) - (this.bottom >> 4); if(this.lightChecks >= 256 * h) return; - int s = (this.lightChecks % h) + this.bottom; + int s = (this.lightChecks % h) + (this.bottom >> 4); int x = this.lightChecks / h % 16; int z = this.lightChecks / 512; ++this.lightChecks; diff --git a/server/src/server/world/Region.java b/server/src/server/world/Region.java index 21618b4..41e874d 100755 --- a/server/src/server/world/Region.java +++ b/server/src/server/world/Region.java @@ -392,7 +392,7 @@ public class Region { for(int n = 0; n < sects.tagCount(); ++n) { NBTTagCompound sect = sects.getCompoundTagAt(n); 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"); NibbleArray data = new NibbleArray(sect.getByteArray("Data")); NibbleArray adddata = sect.hasKey("Add", 7) ? new NibbleArray(sect.getByteArray("Add")) : null; @@ -417,7 +417,7 @@ public class Region { if(y >= 0 && y < stor) sections[y] = storage; else if(y < 0) - down[-down.length - y] = storage; + down[down.length + y] = storage; else up[y - stor] = storage; } @@ -510,8 +510,8 @@ public class Region { tag.setBoolean("LightPopulated", chunk.isLightPopulated()); tag.setLong("InhabitedTime", chunk.getInhabited()); BlockArray[] sections = chunk.getStorage(); - BlockArray[] down = chunk.getStorage(); - BlockArray[] up = chunk.getStorage(); + BlockArray[] down = chunk.getStorageDown(); + BlockArray[] up = chunk.getStorageUp(); NBTTagList sects = new NBTTagList(); boolean light = !world.dimension.hasNoLight();