fix lighting
This commit is contained in:
parent
15459fc627
commit
5357dde0e3
3 changed files with 103 additions and 110 deletions
|
@ -24,7 +24,7 @@ public class ChunkClient extends Chunk {
|
|||
|
||||
private void genHeights() {
|
||||
int top = this.top;
|
||||
int bottom = this.bottom;
|
||||
int bottom = this.bottom < -64 ? -64 : this.bottom;
|
||||
this.minHeight = Integer.MAX_VALUE;
|
||||
|
||||
for(int x = 0; x < 16; ++x) {
|
||||
|
|
|
@ -83,7 +83,7 @@ public abstract class Chunk {
|
|||
|
||||
public void genSkyLight() {
|
||||
int top = this.top;
|
||||
int bottom = this.bottom;
|
||||
int bottom = this.bottom < -64 ? -64 : this.bottom;
|
||||
this.minHeight = Integer.MAX_VALUE;
|
||||
|
||||
for(int x = 0; x < 16; ++x) {
|
||||
|
@ -198,7 +198,7 @@ public abstract class Chunk {
|
|||
|
||||
private void relightBlock(int x, int y, int z) {
|
||||
int h = this.height[z << 4 | x];
|
||||
int min = this.bottom;
|
||||
int min = this.bottom < -64 ? -64 : this.bottom;
|
||||
int cy = h;
|
||||
|
||||
if(y > h) {
|
||||
|
@ -412,9 +412,17 @@ public abstract class Chunk {
|
|||
int y = pos.getY();
|
||||
int z = pos.getZ() & 15;
|
||||
BlockArray stor = this.getArray(y >> 4);
|
||||
return stor == null ? (this.canSeeSky(pos) ? type.defValue : 0)
|
||||
: (type == LightType.SKY ? (this.world.dimension.hasNoLight() ? 0 : stor.getSky(x, y & 15, z))
|
||||
: (type == LightType.BLOCK ? stor.getLight(x, y & 15, z) : type.defValue));
|
||||
if(type == LightType.SKY) {
|
||||
int l = stor == null ? (this.canSeeSky(pos) ? type.defValue : 0) : (this.world.dimension.hasNoLight() ? 0 : stor.getSky(x, y & 15, z));
|
||||
if(y < 0) {
|
||||
int max = y < -64 ? 0 : (y + 64) / 4;
|
||||
l = l > max ? max : l;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
if(stor == null)
|
||||
return this.canSeeSky(pos) ? type.defValue : 0;
|
||||
return type == LightType.BLOCK ? stor.getLight(x, y & 15, z) : type.defValue;
|
||||
}
|
||||
|
||||
public void setLight(LightType type, BlockPos pos, int value) {
|
||||
|
@ -446,22 +454,16 @@ public abstract class Chunk {
|
|||
int y = pos.getY();
|
||||
int z = pos.getZ() & 15;
|
||||
BlockArray stor = this.getArray(y >> 4);
|
||||
|
||||
if(stor == null) {
|
||||
return !this.world.dimension.hasNoLight() && amount < LightType.SKY.defValue
|
||||
? LightType.SKY.defValue - amount : 0;
|
||||
}
|
||||
else {
|
||||
int l = this.world.dimension.hasNoLight() ? 0 : stor.getSky(x, y & 15, z);
|
||||
l = l - amount;
|
||||
int b = stor.getLight(x, y & 15, z);
|
||||
|
||||
if(b > l) {
|
||||
l = b;
|
||||
}
|
||||
|
||||
return l;
|
||||
int l = stor == null ? LightType.SKY.defValue : (this.world.dimension.hasNoLight() ? 0 : stor.getSky(x, y & 15, z));
|
||||
if(y < 0) {
|
||||
int max = y < -64 ? 0 : (y + 64) / 4;
|
||||
l = l > max ? max : l;
|
||||
}
|
||||
if(stor == null)
|
||||
return !this.world.dimension.hasNoLight() && amount < l ? l - amount : 0;
|
||||
l = l - amount;
|
||||
int b = stor.getLight(x, y & 15, z);
|
||||
return b > l ? b : l;
|
||||
}
|
||||
|
||||
public void addEntity(Entity entity) {
|
||||
|
@ -631,11 +633,11 @@ public abstract class Chunk {
|
|||
|
||||
if(loc.getY() == -99999999) {
|
||||
int y = this.top + 15;
|
||||
int min = this.bottom;
|
||||
int min = this.bottom < -64 ? -64 : this.bottom;
|
||||
loc = new BlockPos(pos.getX(), y, pos.getZ());
|
||||
int h = -1;
|
||||
int h = -99999999;
|
||||
|
||||
while(loc.getY() > min && h == -1) {
|
||||
while(loc.getY() > min && h == -99999999) {
|
||||
Block block = this.getBlock(loc);
|
||||
Material mat = block.getMaterial();
|
||||
|
||||
|
@ -796,7 +798,7 @@ public abstract class Chunk {
|
|||
|
||||
private boolean updateColumn(int x, int z) {
|
||||
int top = this.top;
|
||||
int bottom = this.bottom;
|
||||
int bottom = this.bottom < -64 ? -64 : this.bottom;
|
||||
boolean opaque = false;
|
||||
boolean below = false;
|
||||
BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos((this.xPos << 4) + x, 0, (this.zPos << 4) + z);
|
||||
|
|
|
@ -1601,7 +1601,7 @@ public abstract class World implements IWorldAccess {
|
|||
|
||||
private int getRawLight(BlockPos pos, LightType lightType) {
|
||||
if(lightType == LightType.SKY && this.canSeeSky(pos)) {
|
||||
return 15;
|
||||
return pos.getY() < 0 ? (pos.getY() < -64 ? 0 : (pos.getY() + 64) / 4) : 15;
|
||||
}
|
||||
else {
|
||||
Block block = this.getState(pos).getBlock();
|
||||
|
@ -1641,119 +1641,110 @@ public abstract class World implements IWorldAccess {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean checkLightFor(LightType lightType, BlockPos pos) {
|
||||
if(!this.isAreaLoaded(pos, 17, false)) {
|
||||
public boolean checkLightFor(LightType type, BlockPos pos) {
|
||||
if(!this.isAreaLoaded(pos, 17, false))
|
||||
return false;
|
||||
int done = 0;
|
||||
int cnt = 0;
|
||||
int light = this.getLightFor(type, pos);
|
||||
int raw = this.getRawLight(pos, type);
|
||||
int bx = pos.getX();
|
||||
int by = pos.getY();
|
||||
int bz = pos.getZ();
|
||||
|
||||
if(raw > light) {
|
||||
this.lightUpdate[cnt++] = 133152;
|
||||
}
|
||||
else {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
// this.profiler.start("getBrightness");
|
||||
int k = this.getLightFor(lightType, pos);
|
||||
int l = this.getRawLight(pos, lightType);
|
||||
int i1 = pos.getX();
|
||||
int j1 = pos.getY();
|
||||
int k1 = pos.getZ();
|
||||
else if(raw < light) {
|
||||
this.lightUpdate[cnt++] = 133152 | light << 18;
|
||||
|
||||
if(l > k) {
|
||||
this.lightUpdate[j++] = 133152;
|
||||
}
|
||||
else if(l < k) {
|
||||
this.lightUpdate[j++] = 133152 | k << 18;
|
||||
while(done < cnt) {
|
||||
int p = this.lightUpdate[done++];
|
||||
int x = (p & 63) - 32 + bx;
|
||||
int y = (p >> 6 & 63) - 32 + by;
|
||||
int z = (p >> 12 & 63) - 32 + bz;
|
||||
int s = p >> 18 & 15;
|
||||
BlockPos blk = new BlockPos(x, y, z);
|
||||
int l = this.getLightFor(type, blk);
|
||||
|
||||
while(i < j) {
|
||||
int l1 = this.lightUpdate[i++];
|
||||
int i2 = (l1 & 63) - 32 + i1;
|
||||
int j2 = (l1 >> 6 & 63) - 32 + j1;
|
||||
int k2 = (l1 >> 12 & 63) - 32 + k1;
|
||||
int l2 = l1 >> 18 & 15;
|
||||
BlockPos blockpos = new BlockPos(i2, j2, k2);
|
||||
int i3 = this.getLightFor(lightType, blockpos);
|
||||
if(l == s) {
|
||||
this.setLightFor(type, blk, 0);
|
||||
|
||||
if(i3 == l2) {
|
||||
this.setLightFor(lightType, blockpos, 0);
|
||||
if(s > 0) {
|
||||
int dx = ExtMath.absi(x - bx);
|
||||
int dy = ExtMath.absi(y - by);
|
||||
int dz = ExtMath.absi(z - bz);
|
||||
|
||||
if(l2 > 0) {
|
||||
int j3 = ExtMath.absi(i2 - i1);
|
||||
int k3 = ExtMath.absi(j2 - j1);
|
||||
int l3 = ExtMath.absi(k2 - k1);
|
||||
if(dx + dy + dz < 17) {
|
||||
BlockPos.MutableBlockPos bpos = new BlockPos.MutableBlockPos();
|
||||
|
||||
if(j3 + k3 + l3 < 17) {
|
||||
BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();
|
||||
for(Facing dir : Facing.values()) {
|
||||
int ox = x + dir.getFrontOffsetX();
|
||||
int oy = y + dir.getFrontOffsetY();
|
||||
int oz = z + dir.getFrontOffsetZ();
|
||||
bpos.set(ox, oy, oz);
|
||||
int op = Math.max(1, this.getState(bpos).getBlock().getLightOpacity());
|
||||
l = this.getLightFor(type, bpos);
|
||||
|
||||
for(Facing enumfacing : Facing.values()) {
|
||||
int i4 = i2 + enumfacing.getFrontOffsetX();
|
||||
int j4 = j2 + enumfacing.getFrontOffsetY();
|
||||
int k4 = k2 + enumfacing.getFrontOffsetZ();
|
||||
blockpos$mutableblockpos.set(i4, j4, k4);
|
||||
int l4 = Math.max(1, this.getState(blockpos$mutableblockpos).getBlock().getLightOpacity());
|
||||
i3 = this.getLightFor(lightType, blockpos$mutableblockpos);
|
||||
|
||||
if(i3 == l2 - l4 && j < this.lightUpdate.length) {
|
||||
this.lightUpdate[j++] = i4 - i1 + 32 | j4 - j1 + 32 << 6 | k4 - k1 + 32 << 12 | l2 - l4 << 18;
|
||||
}
|
||||
if(l == s - op && cnt < this.lightUpdate.length) {
|
||||
this.lightUpdate[cnt++] = ox - bx + 32 | oy - by + 32 << 6 | oz - bz + 32 << 12 | s - op << 18;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i = 0;
|
||||
}
|
||||
|
||||
// this.profiler.end();
|
||||
// this.profiler.start("checkedPosition < toCheckCount");
|
||||
done = 0;
|
||||
}
|
||||
|
||||
while(i < j) {
|
||||
int i5 = this.lightUpdate[i++];
|
||||
int j5 = (i5 & 63) - 32 + i1;
|
||||
int k5 = (i5 >> 6 & 63) - 32 + j1;
|
||||
int l5 = (i5 >> 12 & 63) - 32 + k1;
|
||||
BlockPos blockpos1 = new BlockPos(j5, k5, l5);
|
||||
int i6 = this.getLightFor(lightType, blockpos1);
|
||||
int j6 = this.getRawLight(blockpos1, lightType);
|
||||
while(done < cnt) {
|
||||
int p = this.lightUpdate[done++];
|
||||
int x = (p & 63) - 32 + bx;
|
||||
int y = (p >> 6 & 63) - 32 + by;
|
||||
int z = (p >> 12 & 63) - 32 + bz;
|
||||
BlockPos blk = new BlockPos(x, y, z);
|
||||
int l = this.getLightFor(type, blk);
|
||||
int r = this.getRawLight(blk, type);
|
||||
|
||||
if(j6 != i6) {
|
||||
this.setLightFor(lightType, blockpos1, j6);
|
||||
if(r != l) {
|
||||
this.setLightFor(type, blk, r);
|
||||
|
||||
if(j6 > i6) {
|
||||
int k6 = Math.abs(j5 - i1);
|
||||
int l6 = Math.abs(k5 - j1);
|
||||
int i7 = Math.abs(l5 - k1);
|
||||
boolean flag = j < this.lightUpdate.length - 6;
|
||||
if(r > l) {
|
||||
int k6 = Math.abs(x - bx);
|
||||
int l6 = Math.abs(y - by);
|
||||
int i7 = Math.abs(z - bz);
|
||||
boolean flag = cnt < this.lightUpdate.length - 6;
|
||||
|
||||
if(k6 + l6 + i7 < 17 && flag) {
|
||||
if(this.getLightFor(lightType, blockpos1.west()) < j6) {
|
||||
this.lightUpdate[j++] = j5 - 1 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
|
||||
}
|
||||
if(k6 + l6 + i7 < 17 && flag) {
|
||||
if(this.getLightFor(type, blk.west()) < r) {
|
||||
this.lightUpdate[cnt++] = x - 1 - bx + 32 + (y - by + 32 << 6) + (z - bz + 32 << 12);
|
||||
}
|
||||
|
||||
if(this.getLightFor(lightType, blockpos1.east()) < j6) {
|
||||
this.lightUpdate[j++] = j5 + 1 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
|
||||
}
|
||||
if(this.getLightFor(type, blk.east()) < r) {
|
||||
this.lightUpdate[cnt++] = x + 1 - bx + 32 + (y - by + 32 << 6) + (z - bz + 32 << 12);
|
||||
}
|
||||
|
||||
if(this.getLightFor(lightType, blockpos1.down()) < j6) {
|
||||
this.lightUpdate[j++] = j5 - i1 + 32 + (k5 - 1 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
|
||||
}
|
||||
if(this.getLightFor(type, blk.down()) < r) {
|
||||
this.lightUpdate[cnt++] = x - bx + 32 + (y - 1 - by + 32 << 6) + (z - bz + 32 << 12);
|
||||
}
|
||||
|
||||
if(this.getLightFor(lightType, blockpos1.up()) < j6) {
|
||||
this.lightUpdate[j++] = j5 - i1 + 32 + (k5 + 1 - j1 + 32 << 6) + (l5 - k1 + 32 << 12);
|
||||
}
|
||||
if(this.getLightFor(type, blk.up()) < r) {
|
||||
this.lightUpdate[cnt++] = x - bx + 32 + (y + 1 - by + 32 << 6) + (z - bz + 32 << 12);
|
||||
}
|
||||
|
||||
if(this.getLightFor(lightType, blockpos1.north()) < j6) {
|
||||
this.lightUpdate[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 - 1 - k1 + 32 << 12);
|
||||
}
|
||||
if(this.getLightFor(type, blk.north()) < r) {
|
||||
this.lightUpdate[cnt++] = x - bx + 32 + (y - by + 32 << 6) + (z - 1 - bz + 32 << 12);
|
||||
}
|
||||
|
||||
if(this.getLightFor(lightType, blockpos1.south()) < j6) {
|
||||
this.lightUpdate[j++] = j5 - i1 + 32 + (k5 - j1 + 32 << 6) + (l5 + 1 - k1 + 32 << 12);
|
||||
}
|
||||
if(this.getLightFor(type, blk.south()) < r) {
|
||||
this.lightUpdate[cnt++] = x - bx + 32 + (y - by + 32 << 6) + (z + 1 - bz + 32 << 12);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// this.profiler.end();
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<Entity> getEntitiesWithinAABBExcludingEntity(Entity entityIn, BoundingBox bb) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue