Refactor Block & Tile: getPos() to getPosition() (#4395)

this also changes the name of the class property 'pos' to 'position' as well as Block->getPosOffset() to Block->getPositionOffset()
This commit is contained in:
SalmonDE
2021-08-23 15:01:32 +02:00
committed by GitHub
parent 22316976fa
commit 7fd712c1ff
93 changed files with 402 additions and 402 deletions

View File

@ -52,27 +52,27 @@ class Grass extends Opaque{
}
public function onRandomTick() : void{
$lightAbove = $this->pos->getWorld()->getFullLightAt($this->pos->x, $this->pos->y + 1, $this->pos->z);
if($lightAbove < 4 and $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z)->getLightFilter() >= 2){
$lightAbove = $this->position->getWorld()->getFullLightAt($this->position->x, $this->position->y + 1, $this->position->z);
if($lightAbove < 4 and $this->position->getWorld()->getBlockAt($this->position->x, $this->position->y + 1, $this->position->z)->getLightFilter() >= 2){
//grass dies
$ev = new BlockSpreadEvent($this, $this, VanillaBlocks::DIRT());
$ev->call();
if(!$ev->isCancelled()){
$this->pos->getWorld()->setBlock($this->pos, $ev->getNewState(), false);
$this->position->getWorld()->setBlock($this->position, $ev->getNewState(), false);
}
}elseif($lightAbove >= 9){
//try grass spread
for($i = 0; $i < 4; ++$i){
$x = mt_rand($this->pos->x - 1, $this->pos->x + 1);
$y = mt_rand($this->pos->y - 3, $this->pos->y + 1);
$z = mt_rand($this->pos->z - 1, $this->pos->z + 1);
$x = mt_rand($this->position->x - 1, $this->position->x + 1);
$y = mt_rand($this->position->y - 3, $this->position->y + 1);
$z = mt_rand($this->position->z - 1, $this->position->z + 1);
$b = $this->pos->getWorld()->getBlockAt($x, $y, $z);
$b = $this->position->getWorld()->getBlockAt($x, $y, $z);
if(
!($b instanceof Dirt) or
$b->isCoarse() or
$this->pos->getWorld()->getFullLightAt($x, $y + 1, $z) < 4 or
$this->pos->getWorld()->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2
$this->position->getWorld()->getFullLightAt($x, $y + 1, $z) < 4 or
$this->position->getWorld()->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2
){
continue;
}
@ -80,7 +80,7 @@ class Grass extends Opaque{
$ev = new BlockSpreadEvent($b, $this, VanillaBlocks::GRASS());
$ev->call();
if(!$ev->isCancelled()){
$this->pos->getWorld()->setBlock($b->pos, $ev->getNewState(), false);
$this->position->getWorld()->setBlock($b->position, $ev->getNewState(), false);
}
}
}
@ -92,17 +92,17 @@ class Grass extends Opaque{
}
if($item instanceof Fertilizer){
$item->pop();
TallGrassObject::growGrass($this->pos->getWorld(), $this->pos, new Random(mt_rand()), 8, 2);
TallGrassObject::growGrass($this->position->getWorld(), $this->position, new Random(mt_rand()), 8, 2);
return true;
}elseif($item instanceof Hoe){
$item->applyDamage(1);
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::FARMLAND());
$this->position->getWorld()->setBlock($this->position, VanillaBlocks::FARMLAND());
return true;
}elseif($item instanceof Shovel and $this->getSide(Facing::UP)->getId() === BlockLegacyIds::AIR){
$item->applyDamage(1);
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::GRASS_PATH());
$this->position->getWorld()->setBlock($this->position, VanillaBlocks::GRASS_PATH());
return true;
}