1
0
Fork 0

remove skylight

This commit is contained in:
Sen 2025-08-27 21:11:45 +02:00
parent 375a67d10f
commit 259bcab1fd
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
12 changed files with 38 additions and 325 deletions

View file

@ -68,13 +68,12 @@ public class SPacketChunkData implements Packet<IClientPlayer>
return this.extractedData.data;
}
public static int getSize(int segments, boolean overworld, boolean biomes)
public static int getSize(int segments, boolean biomes)
{
int i = segments * 2 * 16 * 16 * 16;
int j = segments * 16 * 16 * 16 / 2;
int k = overworld ? segments * 16 * 16 * 16 / 2 : 0;
int l = biomes ? 256 * 8 : 0;
return i + j + k + l;
return i + j + l;
}
public int getChunkX()

View file

@ -10,18 +10,16 @@ public class SPacketMapChunkBulk implements Packet<IClientPlayer>
private int[] xPositions;
private int[] zPositions;
private SPacketChunkData.Extracted[] chunksData;
private boolean sky;
public SPacketMapChunkBulk()
{
}
public SPacketMapChunkBulk(int[] x, int[] z, SPacketChunkData.Extracted[] chunks, boolean sky)
public SPacketMapChunkBulk(int[] x, int[] z, SPacketChunkData.Extracted[] chunks)
{
this.xPositions = x;
this.zPositions = z;
this.chunksData = chunks;
this.sky = sky;
}
/**
@ -29,7 +27,6 @@ public class SPacketMapChunkBulk implements Packet<IClientPlayer>
*/
public void readPacketData(PacketBuffer buf) throws IOException
{
this.sky = buf.readBoolean();
int i = buf.readVarInt();
this.xPositions = new int[i];
this.zPositions = new int[i];
@ -44,7 +41,7 @@ public class SPacketMapChunkBulk implements Packet<IClientPlayer>
for(int z = 0; z < this.chunksData[j].extend.length; z++) {
this.chunksData[j].extend[z] = buf.readVarInt();
}
this.chunksData[j].data = new byte[SPacketChunkData.getSize(this.chunksData[j].extend.length, this.sky, true)];
this.chunksData[j].data = new byte[SPacketChunkData.getSize(this.chunksData[j].extend.length, true)];
}
for (int k = 0; k < i; ++k)
@ -58,7 +55,6 @@ public class SPacketMapChunkBulk implements Packet<IClientPlayer>
*/
public void writePacketData(PacketBuffer buf) throws IOException
{
buf.writeBoolean(this.sky);
buf.writeVarInt(this.chunksData.length);
for (int i = 0; i < this.xPositions.length; ++i)

View file

@ -16,15 +16,12 @@ public class BlockArray {
private int filled;
private char[] data;
private NibbleArray blocklight;
private NibbleArray skylight;
public BlockArray(int y, boolean sky, State filler) {
public BlockArray(int y, State filler) {
this.yBase = y;
this.filler = filler;
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.getId(filler));
this.blocks = this.data.length;
@ -78,14 +75,6 @@ public class BlockArray {
return this.yBase;
}
public void setSky(int x, int y, int z, int value) {
this.skylight.set(x, y, z, value);
}
public int getSky(int x, int y, int z) {
return this.skylight.get(x, y, z);
}
public void setLight(int x, int y, int z, int value) {
this.blocklight.set(x, y, z, value);
}
@ -123,10 +112,6 @@ public class BlockArray {
return this.blocklight;
}
public NibbleArray getSkylight() {
return this.skylight;
}
public void setData(char[] data) {
this.data = data;
}
@ -134,10 +119,6 @@ public class BlockArray {
public void setBlocklight(NibbleArray data) {
this.blocklight = data;
}
public void setSkylight(NibbleArray data) {
this.skylight = data;
}
public int hashCode() {
return this.yBase >> 4;

View file

@ -32,21 +32,18 @@ public abstract class Chunk {
protected final IntHashMap<BlockArray> blocks = new IntHashMap();
protected final Set<BlockArray> blockList = Sets.newHashSet();
protected final int[] precHeight = new int[256];
protected final boolean[] updateSky = new boolean[256];
protected final int[] height = new int[256];
protected final Map<BlockPos, TileEntity> tiles = Maps.<BlockPos, TileEntity>newHashMap();
protected final InheritanceMultiMap<Entity>[] entities = new InheritanceMultiMap[32];
protected final ConcurrentLinkedQueue<BlockPos> tileQueue = new ConcurrentLinkedQueue<BlockPos>();
protected boolean loaded;
protected boolean gapUpdate;
protected boolean populated;
protected boolean lightInit;
protected boolean updated;
protected boolean modified;
protected boolean hasEntity;
protected int minHeight;
protected int lightChecks = Integer.MAX_VALUE;
protected int bottom = Integer.MAX_VALUE;
protected int top = Integer.MIN_VALUE;
@ -80,7 +77,7 @@ public abstract class Chunk {
this.top = y > this.top ? y : this.top;
}
public void genSkyLight() {
public void genSky() {
int top = this.top;
int bottom = this.bottom < -64 ? -64 : this.bottom;
this.minHeight = Integer.MAX_VALUE;
@ -100,101 +97,12 @@ public abstract class Chunk {
break;
}
}
if(this.world.dimension.hasSkyLight() && top != Integer.MIN_VALUE) {
int l = 15;
int y = top + 16 - 1;
while(true) {
int b = this.getOpacity(x, y, z);
if(b == 0 && l != 15) {
b = 1;
}
l -= b;
if(l > 0) {
BlockArray stor = this.getArray(y >> 4);
if(stor != null) {
stor.setSky(x, y & 15, z, l);
this.world.clientNotifyLight(new BlockPos((this.xPos << 4) + x, y, (this.zPos << 4) + z));
}
}
--y;
if(y <= bottom || l <= 0) {
break;
}
}
}
}
}
this.modified = true;
}
private void propagateOcclusion(int x, int z) {
this.updateSky[x + z * 16] = true;
this.gapUpdate = true;
}
private void recheckGaps(boolean single) {
if(this.world.isAreaLoaded(new BlockPos(this.xPos * 16 + 8, 0, this.zPos * 16 + 8), 16)) {
for(int x = 0; x < 16; ++x) {
for(int z = 0; z < 16; ++z) {
if(this.updateSky[x + z * 16]) {
this.updateSky[x + z * 16] = false;
int h = this.getHeight(x, z);
int cx = this.xPos * 16 + x;
int cz = this.zPos * 16 + z;
int max = Integer.MAX_VALUE;
for(Facing face : Facing.Plane.HORIZONTAL) {
max = Math.min(max, this.world.getChunksLowestHorizon(cx + face.getFrontOffsetX(),
cz + face.getFrontOffsetZ()));
}
this.checkNeighbor(cx, cz, max);
for(Facing face : Facing.Plane.HORIZONTAL) {
this.checkNeighbor(cx + face.getFrontOffsetX(), cz + face.getFrontOffsetZ(), h);
}
if(single) {
return;
}
}
}
}
this.gapUpdate = false;
}
}
private void checkNeighbor(int x, int z, int max) {
int h = this.world.getHeight(new BlockPos(x, 0, z)).getY();
if(h > max) {
this.updateNeighbor(x, z, max, h + 1);
}
else if(h < max) {
this.updateNeighbor(x, z, h, max + 1);
}
}
private void updateNeighbor(int x, int z, int bottom, int top) {
if(top > bottom && this.world.isAreaLoaded(new BlockPos(x, 0, z), 16)) {
for(int y = bottom; y < top; ++y) {
this.world.checkLightFor(LightType.SKY, new BlockPos(x, y, z));
}
this.modified = true;
}
}
private void relightBlock(int x, int y, int z) {
int h = this.height[z << 4 | x];
int min = this.bottom < -64 ? -64 : this.bottom;
@ -214,52 +122,6 @@ public abstract class Chunk {
int cx = this.xPos * 16 + x;
int cz = this.zPos * 16 + z;
if(this.world.dimension.hasSkyLight()) {
if(cy < h) {
for(int n = cy; n < h; ++n) {
BlockArray stor = this.getArray(n >> 4);
if(stor != null) {
stor.setSky(x, n & 15, z, 15);
this.world.clientNotifyLight(new BlockPos((this.xPos << 4) + x, n, (this.zPos << 4) + z));
}
}
}
else {
for(int n = h; n < cy; ++n) {
BlockArray stor = this.getArray(n >> 4);
if(stor != null) {
stor.setSky(x, n & 15, z, 0);
this.world.clientNotifyLight(new BlockPos((this.xPos << 4) + x, n, (this.zPos << 4) + z));
}
}
}
int l = 15;
while(cy > min && l > 0) {
--cy;
int b = this.getOpacity(x, cy, z);
if(b == 0) {
b = 1;
}
l -= b;
if(l < 0) {
l = 0;
}
BlockArray stor = this.getArray(cy >> 4);
if(stor != null) {
stor.setSky(x, cy & 15, z, l);
}
}
}
int sh = this.height[z << 4 | x];
int sy = h;
int ey = sh;
@ -273,14 +135,6 @@ public abstract class Chunk {
this.minHeight = sh;
}
if(this.world.dimension.hasSkyLight()) {
for(Facing face : Facing.Plane.HORIZONTAL) {
this.updateNeighbor(cx + face.getFrontOffsetX(), cz + face.getFrontOffsetZ(), sy, ey);
}
this.updateNeighbor(cx, cz, sy, ey);
}
this.modified = true;
}
}
@ -334,7 +188,7 @@ public abstract class Chunk {
return null;
}
stor = new BlockArray(y >> 4 << 4, this.world.dimension.hasSkyLight(), y < 0 ? this.filler : null);
stor = new BlockArray(y >> 4 << 4, y < 0 ? this.filler : null);
this.setArray(stor);
up = y >= h;
}
@ -356,7 +210,7 @@ public abstract class Chunk {
else {
if(updateLight) {
if(up) {
this.genSkyLight();
this.genSky();
}
else {
int b = block.getLightOpacity();
@ -370,10 +224,6 @@ public abstract class Chunk {
else if(y == h - 1) {
this.relightBlock(x, y, z);
}
if(b != ob && (b < ob || this.getLight(LightType.SKY, pos) > 0 || this.getLight(LightType.BLOCK, pos) > 0)) {
this.propagateOcclusion(x, z);
}
}
}
@ -414,9 +264,9 @@ public abstract class Chunk {
int z = pos.getZ() & 15;
BlockArray stor = this.getArray(y >> 4);
if(type == LightType.SKY) {
int l = stor == null ? (this.canSeeSky(pos) ? type.defValue : 0) : (this.world.dimension.hasSkyLight() ? stor.getSky(x, y & 15, z) : 0);
if(y < 0) {
int max = y < -64 ? 0 : (y + 64) / 4;
int l = stor == null ? (this.canSeeSky(pos) ? type.defValue : 0) : (this.world.dimension.hasSkyLight() ? 15 : 0);
if(y < 64) {
int max = y < 0 ? 0 : y / 4;
l = l > max ? max : l;
}
return l;
@ -433,19 +283,14 @@ public abstract class Chunk {
BlockArray stor = this.getArray(y >> 4);
if(stor == null) {
stor = new BlockArray(y >> 4 << 4, this.world.dimension.hasSkyLight(), y < 0 ? this.filler : null);
stor = new BlockArray(y >> 4 << 4, y < 0 ? this.filler : null);
this.setArray(stor);
this.genSkyLight();
this.genSky();
}
this.modified = true;
if(type == LightType.SKY) {
if(this.world.dimension.hasSkyLight()) {
stor.setSky(x, y & 15, z, value);
}
}
else if(type == LightType.BLOCK) {
if(type == LightType.BLOCK) {
stor.setLight(x, y & 15, z, value);
}
}
@ -455,9 +300,9 @@ public abstract class Chunk {
int y = pos.getY();
int z = pos.getZ() & 15;
BlockArray stor = this.getArray(y >> 4);
int l = stor == null ? LightType.SKY.defValue : (this.world.dimension.hasSkyLight() ? stor.getSky(x, y & 15, z) : 0);
if(y < 0) {
int max = y < -64 ? 0 : (y + 64) / 4;
int l = stor == null ? LightType.SKY.defValue : (this.world.dimension.hasSkyLight() ? 15 : 0);
if(y < 64) {
int max = y < 0 ? 0 : y / 4;
l = l > max ? max : l;
}
if(stor == null)
@ -644,10 +489,6 @@ public abstract class Chunk {
}
public void update(boolean noGaps) {
if(this.gapUpdate && this.world.dimension.hasSkyLight() && !noGaps) {
this.recheckGaps(this.world.client);
}
this.updated = true;
if(!this.lightInit && this.populated) {
@ -669,53 +510,6 @@ public abstract class Chunk {
return this.updated && this.populated && this.lightInit;
}
public void resetRelight() {
this.lightChecks = 0;
}
/**
* Called once-per-chunk-per-tick, and advances the round-robin relight check
* index by up to 8 blocks at a time. In a worst-case scenario, can potentially
* take up to 51.2 seconds, calculated via (8192/8)/20, to re-check all blocks
* in a chunk, which may explain lagging light updates on initial world
* generation.
*/
public void enqueueRelight() {
BlockPos pos = new BlockPos(this.xPos << 4, 0, this.zPos << 4);
for(int n = 0; n < 8; ++n) {
if(this.top == Integer.MIN_VALUE)
return;
int h = 1 + (this.top >> 4) - (this.bottom >> 4);
if(this.lightChecks >= 256 * h)
return;
int s = (this.lightChecks % h) + (this.bottom >> 4);
int x = this.lightChecks / h % 16;
int z = this.lightChecks / 512;
++this.lightChecks;
for(int y = 0; y < 16; ++y) {
BlockPos block = pos.add(x, (s << 4) + y, z);
boolean edge = y == 0 || y == 15 || x == 0 || x == 15 || z == 0 || z == 15;
BlockArray arr = this.getArray(s);
if(arr == null && edge || arr != null
&& arr.getBlock(x, y, z) == Blocks.air) {
for(Facing face : Facing.values()) {
BlockPos side = block.offset(face);
if(this.world.getState(side).getBlock().getLight() > 0) {
this.world.checkLight(side);
}
}
this.world.checkLight(block);
}
}
}
}
public void checkLight() {
this.populated = true;
this.lightInit = true;
@ -739,8 +533,6 @@ public abstract class Chunk {
int d = face.getAxisDirection() == Facing.AxisDirection.POSITIVE ? 16 : 1;
this.world.getChunk(pos.offset(face, d)).updateColumns(face.getOpposite());
}
this.setSkyDirty();
}
}
else {
@ -749,14 +541,6 @@ public abstract class Chunk {
}
}
private void setSkyDirty() {
for(int n = 0; n < this.updateSky.length; ++n) {
this.updateSky[n] = true;
}
this.recheckGaps(false);
}
private void updateColumns(Facing facing) {
if(this.populated) {
if(facing == Facing.EAST) {

View file

@ -1495,7 +1495,7 @@ public abstract class World implements IWorldAccess {
private int getRawLight(BlockPos pos, LightType lightType) {
if(lightType == LightType.SKY && this.canSeeSky(pos)) {
return pos.getY() < 0 ? (pos.getY() < -64 ? 0 : (pos.getY() + 64) / 4) : 15;
return pos.getY() < 64 ? (pos.getY() < 0 ? 0 : pos.getY() / 4) : 15;
}
else {
Block block = this.getState(pos).getBlock();