Willard21 / MineKhan

Minecraft for Khan Academy
81 stars 52 forks source link

How to fix lighting bug #106

Closed ghost closed 1 year ago

ghost commented 2 years ago

There is a lighting bug that makes blocks dark when you build too high. Here is how to fix it: Find updateLight function. Add this code inside:

if(place){ //set vertical column to 15
  let spread = []
  for(let x2 = x-1; x2 <= x+1; x2++) for(let z2 = z-1; z2 <= z+1; z2++){
    //spread around side too so the sides won't get dark
    let i = chunk.sections.length * 16 - 1
    let cx2 = x2 & 15, cz2 = z2 & 15
    for(; i >= 0; i--){
      if(!blockData[chunk.getBlock(cx2,i,cz2)].transparent) break
      if(chunk.getLight(cx2,i,cz2,0) !== 15){
        chunk.setLight(cx2,i,cz2,15,0)
        spread.push(x2,i,z2)
      }
    }
  }
  if(spread.length) chunk.spreadLight(spread, 14, true)
}
harsha7addanki commented 1 year ago

this should be a pull request

Willard21 commented 1 year ago

Pretty sure this is fixed now. I think the issue was new subchunks being generated with no light in them, but I've deleted subchunks now, so no longer an issue.