GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
LightUpdate Class Reference

Public Member Functions

 __construct (Level $level)
 
 addSpreadNode (int $x, int $y, int $z)
 
 addRemoveNode (int $x, int $y, int $z, int $oldLight)
 
 setAndUpdateLight (int $x, int $y, int $z, int $newLevel)
 
 execute ()
 

Protected Member Functions

 getLight (int $x, int $y, int $z)
 
 setLight (int $x, int $y, int $z, int $level)
 
 computeRemoveLight (int $x, int $y, int $z, int $oldAdjacentLevel)
 
 computeSpreadLight (int $x, int $y, int $z, int $newAdjacentLevel)
 

Protected Attributes

 $level
 
 $spreadQueue
 
 $spreadVisited = []
 
 $removalQueue
 
 $removalVisited = []
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Level  $level)
40  {
41  $this->level = $level;
42  $this->removalQueue = new \SplQueue();
43  $this->spreadQueue = new \SplQueue();
44  }

Member Function Documentation

◆ addRemoveNode()

addRemoveNode ( int  $x,
int  $y,
int  $z,
int  $oldLight 
)
52  {
53  $this->spreadQueue->enqueue([$x, $y, $z, $oldLight]);
54  }

◆ addSpreadNode()

addSpreadNode ( int  $x,
int  $y,
int  $z 
)
47  {
48  $this->spreadQueue->enqueue([$x, $y, $z]);
49  }

◆ computeRemoveLight()

computeRemoveLight ( int  $x,
int  $y,
int  $z,
int  $oldAdjacentLevel 
)
protected
121  {
122  $current = $this->getLight($x, $y, $z);
123  if ($current !== 0 and $current < $oldAdjacentLevel) {
124  $this->setLight($x, $y, $z, 0);
125  if (!isset($visited[$index = Level::blockHash($x, $y, $z)])) {
126  $this->removalVisited[$index] = true;
127  if ($current > 1) {
128  $this->removalQueue->enqueue([$x, $y, $z, $current]);
129  }
130  }
131  } elseif ($current >= $oldAdjacentLevel) {
132  if (!isset($this->spreadVisited[$index = Level::blockHash($x, $y, $z)])) {
133  $this->spreadVisited[$index] = true;
134  $this->spreadQueue->enqueue([$x, $y, $z]);
135  }
136  }
137  }

◆ computeSpreadLight()

computeSpreadLight ( int  $x,
int  $y,
int  $z,
int  $newAdjacentLevel 
)
protected
140  {
141  $current = $this->getLight($x, $y, $z);
142  $potentialLight = $newAdjacentLevel - Block::$lightFilter[$this->level->getBlockIdAt($x, $y, $z)];
143  if ($current < $potentialLight) {
144  $this->setLight($x, $y, $z, $potentialLight);
145  if (!isset($this->spreadVisited[$index = Level::blockHash($x, $y, $z)])) {
146  $this->spreadVisited[$index] = true;
147  if ($potentialLight > 1) {
148  $this->spreadQueue->enqueue([$x, $y, $z]);
149  }
150  }
151  }
152  }

◆ execute()

execute ( )
79  {
80  while (!$this->removalQueue->isEmpty()) {
81  list($x, $y, $z, $oldAdjacentLight) = $this->removalQueue->dequeue();
82  $points = [
83  [$x + 1, $y, $z],
84  [$x - 1, $y, $z],
85  [$x, $y + 1, $z],
86  [$x, $y - 1, $z],
87  [$x, $y, $z + 1],
88  [$x, $y, $z - 1]
89  ];
90  foreach ($points as list($cx, $cy, $cz)) {
91  if ($cy < 0) {
92  continue;
93  }
94  $this->computeRemoveLight($cx, $cy, $cz, $oldAdjacentLight);
95  }
96  }
97  while (!$this->spreadQueue->isEmpty()) {
98  list($x, $y, $z) = $this->spreadQueue->dequeue();
99  $newAdjacentLight = $this->getLight($x, $y, $z);
100  if ($newAdjacentLight <= 0) {
101  continue;
102  }
103  $points = [
104  [$x + 1, $y, $z],
105  [$x - 1, $y, $z],
106  [$x, $y + 1, $z],
107  [$x, $y - 1, $z],
108  [$x, $y, $z + 1],
109  [$x, $y, $z - 1]
110  ];
111  foreach ($points as list($cx, $cy, $cz)) {
112  if ($cy < 0) {
113  continue;
114  }
115  $this->computeSpreadLight($cx, $cy, $cz, $newAdjacentLight);
116  }
117  }
118  }

◆ getLight()

getLight ( int  $x,
int  $y,
int  $z 
)
abstractprotected

◆ setAndUpdateLight()

setAndUpdateLight ( int  $x,
int  $y,
int  $z,
int  $newLevel 
)
61  {
62  if (isset($this->spreadVisited[$index = Level::blockHash($x, $y, $z)]) or isset($this->removalVisited[$index])) {
63  throw new \InvalidArgumentException("Already have a visit ready for this block");
64  }
65  $oldLevel = $this->getLight($x, $y, $z);
66  if ($oldLevel !== $newLevel) {
67  $this->setLight($x, $y, $z, $newLevel);
68  if ($oldLevel < $newLevel) { //light increased
69  $this->spreadVisited[$index] = true;
70  $this->spreadQueue->enqueue([$x, $y, $z]);
71  } else { //light removed
72  $this->removalVisited[$index] = true;
73  $this->removalQueue->enqueue([$x, $y, $z, $oldLevel]);
74  }
75  }
76  }

◆ setLight()

setLight ( int  $x,
int  $y,
int  $z,
int  $level 
)
abstractprotected

Field Documentation

◆ $level

$level
protected

◆ $removalQueue

$removalQueue
protected

◆ $removalVisited

$removalVisited = []
protected

◆ $spreadQueue

$spreadQueue
protected

◆ $spreadVisited

$spreadVisited = []
protected

The documentation for this class was generated from the following file: