Advertisement
Guest User

Sunlight algorithm

a guest
May 11th, 2019
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1.  
  2. def setSunlight(at, val):
  3.     sunlightDict[at]=val
  4.  
  5. def getSunlight(at):
  6.     if(getBlock(at) != None):
  7.         return 0
  8.     return sunlightDict[at]
  9.  
  10. def afterPlaceBlock(position):
  11.     placeOneMoreLayerOfSunlight()
  12.  
  13.     def recalc(v,ignore=None):
  14.         if(v.xmi refers to v and v.xmi != ignore) recalc(v.xmi, ignore=v)
  15.         if(v.xpl refers to v and v.xpl != ignore) recalc(v.xpl, ignore=v)
  16.         if(v.zmi refers to v and v.zmi != ignore) recalc(v.zmi, ignore=v)
  17.         if(v.zpl refers to v and v.zpl != ignore) recalc(v.zpl, ignore=v)
  18.         if(v.ymi refers to v and v.ymi != ignore) recalc(v.ymi, ignore=v)
  19.  
  20.         if(getBlock(v) != None):
  21.             setSunlight(at=v, val=0)
  22.         else:
  23.             setSunlight(at=v, val=math.max(getSunlight(v.xmi)-1,getSunlight(v.xpl)-1,getSunlight(v.zmi)-1,getSunlight(v.zpl)-1,getSunlight(v.ypl)))
  24.  
  25.     recalc(position, ignore=None)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement