Position: rename getWorldNonNull() to getWorld(), remove original getWorld()

This commit is contained in:
Dylan K. Taylor 2020-06-29 21:19:46 +01:00
parent fc22fd80d8
commit 670ad9eb9d
81 changed files with 259 additions and 275 deletions

View File

@ -99,7 +99,7 @@ class Banner extends Transparent{
public function readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileBanner){
$this->baseColor = $tile->getBaseColor();
$this->setPatterns($tile->getPatterns());
@ -108,7 +108,7 @@ class Banner extends Transparent{
public function writeStateToWorld() : void{
parent::writeStateToWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
assert($tile instanceof TileBanner);
$tile->setBaseColor($this->baseColor);
$tile->setPatterns($this->patterns);
@ -171,7 +171,7 @@ class Banner extends Transparent{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -255,7 +255,7 @@ abstract class BaseRail extends Flowable{
if(isset($otherPossible[$otherSide])){
$otherConnections[] = $otherSide;
$other->setConnections($otherConnections);
$this->pos->getWorldNonNull()->setBlock($other->pos, $other);
$this->pos->getWorld()->setBlock($other->pos, $other);
$changed = true;
$thisConnections[] = $thisSide;
@ -268,7 +268,7 @@ abstract class BaseRail extends Flowable{
if($changed){
$this->setConnections($thisConnections);
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}
}
@ -287,11 +287,11 @@ abstract class BaseRail extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}else{
foreach($this->connections as $connection){
if(($connection & self::FLAG_ASCEND) !== 0 and $this->getSide($connection & ~self::FLAG_ASCEND)->isTransparent()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
break;
}
}

View File

@ -73,7 +73,7 @@ class Bed extends Transparent{
public function readStateFromWorld() : void{
parent::readStateFromWorld();
//read extra state information from the tile - this is an ugly hack
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileBed){
$this->color = $tile->getColor();
}
@ -82,7 +82,7 @@ class Bed extends Transparent{
public function writeStateToWorld() : void{
parent::writeStateToWorld();
//extra block properties storage hack
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileBed){
$tile->setColor($this->color);
}
@ -105,11 +105,11 @@ class Bed extends Transparent{
public function setOccupied(bool $occupied = true) : void{
$this->occupied = $occupied;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this, false);
$this->pos->getWorld()->setBlock($this->pos, $this, false);
if(($other = $this->getOtherHalf()) !== null){
$other->occupied = $occupied;
$this->pos->getWorldNonNull()->setBlock($other->pos, $other, false);
$this->pos->getWorld()->setBlock($other->pos, $other, false);
}
}
@ -139,7 +139,7 @@ class Bed extends Transparent{
return true;
}
$time = $this->pos->getWorldNonNull()->getTimeOfDay();
$time = $this->pos->getWorld()->getTimeOfDay();
$isNight = ($time >= World::TIME_NIGHT and $time < World::TIME_SUNRISE);

View File

@ -79,7 +79,7 @@ class Block{
}
public function __clone(){
$this->pos = Position::fromObject($this->pos, $this->pos->getWorldNonNull());
$this->pos = Position::fromObject($this->pos, $this->pos->getWorld());
}
public function getIdInfo() : BlockIdentifier{
@ -148,10 +148,10 @@ class Block{
}
public function writeStateToWorld() : void{
$this->pos->getWorldNonNull()->getChunkAtPosition($this->pos)->setFullBlock($this->pos->x & 0xf, $this->pos->y, $this->pos->z & 0xf, $this->getFullId());
$this->pos->getWorld()->getChunkAtPosition($this->pos)->setFullBlock($this->pos->x & 0xf, $this->pos->y, $this->pos->z & 0xf, $this->getFullId());
$tileType = $this->idInfo->getTileClass();
$oldTile = $this->pos->getWorldNonNull()->getTile($this->pos);
$oldTile = $this->pos->getWorld()->getTile($this->pos);
if($oldTile !== null){
if($tileType === null or !($oldTile instanceof $tileType)){
$oldTile->close();
@ -165,8 +165,8 @@ class Block{
* @var Tile $tile
* @see Tile::__construct()
*/
$tile = new $tileType($this->pos->getWorldNonNull(), $this->pos->asVector3());
$this->pos->getWorldNonNull()->addTile($tile);
$tile = new $tileType($this->pos->getWorld(), $this->pos->asVector3());
$this->pos->getWorld()->addTile($tile);
}
}
@ -225,10 +225,10 @@ class Block{
* Do the actions needed so the block is broken with the Item
*/
public function onBreak(Item $item, ?Player $player = null) : bool{
if(($t = $this->pos->getWorldNonNull()->getTile($this->pos)) !== null){
if(($t = $this->pos->getWorld()->getTile($this->pos)) !== null){
$t->onBlockDestroyed();
}
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR());
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR());
return true;
}
@ -417,7 +417,7 @@ class Block{
public function getPickedItem(bool $addUserData = false) : Item{
$item = $this->asItem();
if($addUserData){
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof Tile){
$nbt = $tile->getCleanedNBT();
if($nbt instanceof CompoundTag){
@ -479,7 +479,7 @@ class Block{
*/
public function getSide(int $side, int $step = 1){
if($this->pos->isValid()){
return $this->pos->getWorldNonNull()->getBlock($this->pos->getSide($side, $step));
return $this->pos->getWorld()->getBlock($this->pos->getSide($side, $step));
}
throw new \InvalidStateException("Block does not have a valid world");

View File

@ -60,7 +60,7 @@ class BrewingStand extends Transparent{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player instanceof Player){
$stand = $this->pos->getWorldNonNull()->getTile($this->pos);
$stand = $this->pos->getWorld()->getTile($this->pos);
if($stand instanceof TileBrewingStand and $stand->canOpenWith($item->getCustomName())){
$player->setCurrentWindow($stand->getInventory());
}

View File

@ -64,9 +64,9 @@ abstract class Button extends Flowable{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if(!$this->powered){
$this->powered = true;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, $this->getActivationTime());
$this->pos->getWorldNonNull()->addSound($this->pos->add(0.5, 0.5, 0.5), new RedstonePowerOnSound());
$this->pos->getWorld()->setBlock($this->pos, $this);
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, $this->getActivationTime());
$this->pos->getWorld()->addSound($this->pos->add(0.5, 0.5, 0.5), new RedstonePowerOnSound());
}
return true;
@ -75,8 +75,8 @@ abstract class Button extends Flowable{
public function onScheduledUpdate() : void{
if($this->powered){
$this->powered = false;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorldNonNull()->addSound($this->pos->add(0.5, 0.5, 0.5), new RedstonePowerOffSound());
$this->pos->getWorld()->setBlock($this->pos, $this);
$this->pos->getWorld()->addSound($this->pos->add(0.5, 0.5, 0.5), new RedstonePowerOffSound());
}
}
}

View File

@ -76,12 +76,12 @@ class Cactus extends Transparent{
public function onNearbyBlockChange() : void{
$down = $this->getSide(Facing::DOWN);
if($down->getId() !== BlockLegacyIds::SAND and !$down->isSameType($this)){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}else{
foreach(Facing::HORIZONTAL as $side){
$b = $this->getSide($side);
if($b->isSolid()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
break;
}
}
@ -96,23 +96,23 @@ class Cactus extends Transparent{
if(!$this->getSide(Facing::DOWN)->isSameType($this)){
if($this->age === 15){
for($y = 1; $y < 3; ++$y){
$b = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z);
$b = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z);
if($b->getId() === BlockLegacyIds::AIR){
$ev = new BlockGrowEvent($b, VanillaBlocks::CACTUS());
$ev->call();
if($ev->isCancelled()){
break;
}
$this->pos->getWorldNonNull()->setBlock($b->pos, $ev->getNewState());
$this->pos->getWorld()->setBlock($b->pos, $ev->getNewState());
}else{
break;
}
}
$this->age = 0;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}else{
++$this->age;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}
}
}

View File

@ -78,7 +78,7 @@ class Cake extends Transparent implements FoodSource{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR());
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR());
}
}
@ -127,6 +127,6 @@ class Cake extends Transparent implements FoodSource{
}
public function onConsume(Living $consumer) : void{
$this->pos->getWorldNonNull()->setBlock($this->pos, $this->getResidue());
$this->pos->getWorld()->setBlock($this->pos, $this->getResidue());
}
}

View File

@ -58,7 +58,7 @@ class Carpet extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -70,7 +70,7 @@ class Chest extends Transparent{
}
public function onPostPlace() : void{
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileChest){
foreach([
Facing::rotateY($this->facing, true),
@ -78,7 +78,7 @@ class Chest extends Transparent{
] as $side){
$c = $this->getSide($side);
if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){
$pair = $this->pos->getWorldNonNull()->getTile($c->pos);
$pair = $this->pos->getWorld()->getTile($c->pos);
if($pair instanceof TileChest and !$pair->isPaired()){
$pair->pairWith($tile);
$tile->pairWith($pair);
@ -92,7 +92,7 @@ class Chest extends Transparent{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player instanceof Player){
$chest = $this->pos->getWorldNonNull()->getTile($this->pos);
$chest = $this->pos->getWorld()->getTile($this->pos);
if($chest instanceof TileChest){
if(
!$this->getSide(Facing::UP)->isTransparent() or

View File

@ -34,7 +34,7 @@ class CoarseDirt extends Dirt{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face === Facing::UP and $item instanceof Hoe){
$item->applyDamage(1);
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT());
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT());
return true;
}

View File

@ -85,7 +85,7 @@ class CocoaBlock extends Transparent{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($this->age < 2 and $item instanceof Fertilizer){
$this->age++;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
$item->pop();
@ -98,7 +98,7 @@ class CocoaBlock extends Transparent{
public function onNearbyBlockChange() : void{
$side = $this->getSide(Facing::opposite($this->facing));
if(!($side instanceof Wood) or !$side->getTreeType()->equals(TreeType::JUNGLE())){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
@ -109,7 +109,7 @@ class CocoaBlock extends Transparent{
public function onRandomTick() : void{
if($this->age < 2 and mt_rand(1, 5) === 1){
$this->age++;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}
}

View File

@ -38,7 +38,7 @@ class ConcretePowder extends Opaque implements Fallable{
public function onNearbyBlockChange() : void{
if(($block = $this->checkAdjacentWater()) !== null){
$this->pos->getWorldNonNull()->setBlock($this->pos, $block);
$this->pos->getWorld()->setBlock($this->pos, $block);
}else{
$this->startFalling();
}

View File

@ -72,7 +72,7 @@ abstract class Crops extends Flowable{
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState());
$this->pos->getWorld()->setBlock($this->pos, $ev->getNewState());
}
$item->pop();
@ -85,7 +85,7 @@ abstract class Crops extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::FARMLAND){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
@ -100,7 +100,7 @@ abstract class Crops extends Flowable{
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState());
$this->pos->getWorld()->setBlock($this->pos, $ev->getNewState());
}
}
}

View File

@ -91,7 +91,7 @@ class DaylightSensor extends Transparent{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$this->inverted = !$this->inverted;
$this->power = $this->recalculatePower();
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
return true;
}
@ -99,18 +99,18 @@ class DaylightSensor extends Transparent{
$newPower = $this->recalculatePower();
if($this->power !== $newPower){
$this->power = $newPower;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 20);
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 20);
}
private function recalculatePower() : int{
$lightLevel = $this->pos->getWorldNonNull()->getRealBlockSkyLightAt($this->pos->x, $this->pos->y, $this->pos->z);
$lightLevel = $this->pos->getWorld()->getRealBlockSkyLightAt($this->pos->x, $this->pos->y, $this->pos->z);
if($this->inverted){
return 15 - $lightLevel;
}
$sunAngle = $this->pos->getWorldNonNull()->getSunAnglePercentage();
$sunAngle = $this->pos->getWorld()->getSunAnglePercentage();
return max(0, (int) round($lightLevel * cos(($sunAngle + ((($sunAngle < 0.5 ? 0 : 1) - $sunAngle) / 5)) * 2 * M_PI)));
}

View File

@ -47,7 +47,7 @@ class DeadBush extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -38,7 +38,7 @@ class Dirt extends Opaque{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face === Facing::UP and $item instanceof Hoe){
$item->applyDamage(1);
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::FARMLAND());
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::FARMLAND());
return true;
}

View File

@ -99,7 +99,7 @@ class Door extends Transparent{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method
$this->pos->getWorldNonNull()->useBreakOn($this->pos); //this will delete both halves if they exist
$this->pos->getWorld()->useBreakOn($this->pos); //this will delete both halves if they exist
}
}
@ -138,11 +138,11 @@ class Door extends Transparent{
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
if($other instanceof Door and $other->isSameType($this)){
$other->open = $this->open;
$this->pos->getWorldNonNull()->setBlock($other->pos, $other);
$this->pos->getWorld()->setBlock($other->pos, $other);
}
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorldNonNull()->addSound($this->pos, new DoorSound());
$this->pos->getWorld()->setBlock($this->pos, $this);
$this->pos->getWorld()->addSound($this->pos, new DoorSound());
return true;
}

View File

@ -77,7 +77,7 @@ class DoublePlant extends Flowable{
public function onNearbyBlockChange() : void{
if(!$this->isValidHalfPlant() or (!$this->top and $this->getSide(Facing::DOWN)->isTransparent())){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -63,7 +63,7 @@ class DragonEgg extends Transparent implements Fallable{
public function teleport() : void{
for($tries = 0; $tries < 16; ++$tries){
$block = $this->pos->getWorldNonNull()->getBlockAt(
$block = $this->pos->getWorld()->getBlockAt(
$this->pos->x + mt_rand(-16, 16),
max(0, min(World::Y_MAX - 1, $this->pos->y + mt_rand(-8, 8))),
$this->pos->z + mt_rand(-16, 16)
@ -76,9 +76,9 @@ class DragonEgg extends Transparent implements Fallable{
}
$blockPos = $ev->getTo();
$this->pos->getWorldNonNull()->addParticle($this->pos, new DragonEggTeleportParticle($this->pos->x - $blockPos->x, $this->pos->y - $blockPos->y, $this->pos->z - $blockPos->z));
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR());
$this->pos->getWorldNonNull()->setBlock($blockPos, $this);
$this->pos->getWorld()->addParticle($this->pos, new DragonEggTeleportParticle($this->pos->x - $blockPos->x, $this->pos->y - $blockPos->y, $this->pos->z - $blockPos->z));
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR());
$this->pos->getWorld()->setBlock($blockPos, $this);
break;
}
}

View File

@ -75,7 +75,7 @@ class EnderChest extends Transparent{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player instanceof Player){
$enderChest = $this->pos->getWorldNonNull()->getTile($this->pos);
$enderChest = $this->pos->getWorld()->getTile($this->pos);
if($enderChest instanceof TileEnderChest and $this->getSide(Facing::UP)->isTransparent()){
$player->getEnderChestInventory()->setHolderPosition($this->pos);
$player->setCurrentWindow($player->getEnderChestInventory());

View File

@ -58,7 +58,7 @@ class Farmland extends Transparent{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::UP)->isSolid()){
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT());
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT());
}
}
@ -70,13 +70,13 @@ class Farmland extends Transparent{
if(!$this->canHydrate()){
if($this->wetness > 0){
$this->wetness--;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this, false);
$this->pos->getWorld()->setBlock($this->pos, $this, false);
}else{
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT());
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT());
}
}elseif($this->wetness < 7){
$this->wetness = 7;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this, false);
$this->pos->getWorld()->setBlock($this->pos, $this, false);
}
}
@ -87,7 +87,7 @@ class Farmland extends Transparent{
for($y = $start->y; $y <= $end->y; ++$y){
for($z = $start->z; $z <= $end->z; ++$z){
for($x = $start->x; $x <= $end->x; ++$x){
if($this->pos->getWorldNonNull()->getBlockAt($x, $y, $z) instanceof Water){
if($this->pos->getWorld()->getBlockAt($x, $y, $z) instanceof Water){
return true;
}
}

View File

@ -88,7 +88,7 @@ class FenceGate extends Transparent{
$inWall = $this->checkInWall();
if($inWall !== $this->inWall){
$this->inWall = $inWall;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}
}
@ -101,8 +101,8 @@ class FenceGate extends Transparent{
}
}
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorldNonNull()->addSound($this->pos, new DoorSound());
$this->pos->getWorld()->setBlock($this->pos, $this);
$this->pos->getWorld()->addSound($this->pos, new DoorSound());
return true;
}

View File

@ -88,9 +88,9 @@ class Fire extends Flowable{
public function onNearbyBlockChange() : void{
if(!$this->getSide(Facing::DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR());
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR());
}else{
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(30, 40));
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(30, 40));
}
}
@ -124,10 +124,10 @@ class Fire extends Flowable{
}
if($result !== null){
$this->pos->getWorldNonNull()->setBlock($this->pos, $result);
$this->pos->getWorld()->setBlock($this->pos, $result);
}
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(30, 40));
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(30, 40));
if($canSpread){
//TODO: raise upper bound for chance in humid biomes
@ -168,9 +168,9 @@ class Fire extends Flowable{
if(mt_rand(0, $this->age + 9) < 5){ //TODO: check rain
$fire = clone $this;
$fire->age = min(15, $fire->age + (mt_rand(0, 4) >> 2));
$this->pos->getWorldNonNull()->setBlock($block->pos, $fire);
$this->pos->getWorld()->setBlock($block->pos, $fire);
}else{
$this->pos->getWorldNonNull()->setBlock($block->pos, VanillaBlocks::AIR());
$this->pos->getWorld()->setBlock($block->pos, VanillaBlocks::AIR());
}
}
}

View File

@ -46,7 +46,7 @@ class Flower extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -61,7 +61,7 @@ class FlowerPot extends Flowable{
public function readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileFlowerPot){
$this->setPlant($tile->getPlant());
}else{
@ -72,7 +72,7 @@ class FlowerPot extends Flowable{
public function writeStateToWorld() : void{
parent::writeStateToWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
assert($tile instanceof TileFlowerPot);
$tile->setPlant($this->plant);
}
@ -122,7 +122,7 @@ class FlowerPot extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
@ -134,7 +134,7 @@ class FlowerPot extends Flowable{
$this->setPlant($plant);
$item->pop();
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
return true;
}

View File

@ -50,17 +50,17 @@ class FrostedIce extends Ice{
public function onNearbyBlockChange() : void{
if(!$this->checkAdjacentBlocks(2)){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}else{
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40));
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40));
}
}
public function onRandomTick() : void{
if((!$this->checkAdjacentBlocks(4) or mt_rand(0, 2) === 0) and
max( //TODO: move this to World
$this->pos->getWorldNonNull()->getHighestAdjacentBlockLight($this->pos->x, $this->pos->y, $this->pos->z),
$this->pos->getWorldNonNull()->getHighestAdjacentBlockSkyLight($this->pos->x, $this->pos->y, $this->pos->z) - $this->pos->getWorldNonNull()->getSkyLightReduction()
$this->pos->getWorld()->getHighestAdjacentBlockLight($this->pos->x, $this->pos->y, $this->pos->z),
$this->pos->getWorld()->getHighestAdjacentBlockSkyLight($this->pos->x, $this->pos->y, $this->pos->z) - $this->pos->getWorld()->getSkyLightReduction()
) >= 12 - $this->age){
if($this->tryMelt()){
foreach($this->getAllSides() as $block){
@ -70,7 +70,7 @@ class FrostedIce extends Ice{
}
}
}else{
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40));
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40));
}
}
@ -86,7 +86,7 @@ class FrostedIce extends Ice{
continue;
}
if(
$this->pos->getWorldNonNull()->getBlockAt($this->pos->x + $x, $this->pos->y, $this->pos->z + $z) instanceof FrostedIce and
$this->pos->getWorld()->getBlockAt($this->pos->x + $x, $this->pos->y, $this->pos->z + $z) instanceof FrostedIce and
++$found >= $requirement
){
return true;
@ -103,13 +103,13 @@ class FrostedIce extends Ice{
*/
private function tryMelt() : bool{
if($this->age >= 3){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
return true;
}
$this->age++;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40));
$this->pos->getWorld()->setBlock($this->pos, $this);
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, mt_rand(20, 40));
return false;
}
}

View File

@ -88,7 +88,7 @@ class Furnace extends Opaque{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player instanceof Player){
$furnace = $this->pos->getWorldNonNull()->getTile($this->pos);
$furnace = $this->pos->getWorld()->getTile($this->pos);
if($furnace instanceof TileFurnace and $furnace->canOpenWith($item->getCustomName())){
$player->setCurrentWindow($furnace->getInventory());
}
@ -98,9 +98,9 @@ class Furnace extends Opaque{
}
public function onScheduledUpdate() : void{
$furnace = $this->pos->getWorldNonNull()->getTile($this->pos);
$furnace = $this->pos->getWorld()->getTile($this->pos);
if($furnace instanceof TileFurnace and $furnace->onUpdate()){
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 1); //TODO: check this
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 1); //TODO: check this
}
}
}

View File

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

View File

@ -42,7 +42,7 @@ class GrassPath extends Transparent{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::UP)->isSolid()){
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::DIRT());
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::DIRT());
}
}

View File

@ -76,7 +76,7 @@ class Hopper extends Transparent{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($player !== null){
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileHopper){ //TODO: find a way to have inventories open on click without this boilerplate in every block
$player->setCurrentWindow($tile->getInventory());
}

View File

@ -43,7 +43,7 @@ class Ice extends Transparent{
public function onBreak(Item $item, ?Player $player = null) : bool{
if(($player === null or $player->isSurvival()) and !$item->hasEnchantment(Enchantment::SILK_TOUCH())){
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::WATER());
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::WATER());
return true;
}
return parent::onBreak($item, $player);
@ -54,8 +54,8 @@ class Ice extends Transparent{
}
public function onRandomTick() : void{
if($this->pos->getWorldNonNull()->getHighestAdjacentBlockLight($this->pos->x, $this->pos->y, $this->pos->z) >= 12){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
if($this->pos->getWorld()->getHighestAdjacentBlockLight($this->pos->x, $this->pos->y, $this->pos->z) >= 12){
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -61,7 +61,7 @@ class ItemFrame extends Flowable{
public function readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileItemFrame){
$this->framedItem = $tile->getItem();
if($this->framedItem->isNull()){
@ -74,7 +74,7 @@ class ItemFrame extends Flowable{
public function writeStateToWorld() : void{
parent::writeStateToWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileItemFrame){
$tile->setItem($this->framedItem);
$tile->setItemRotation($this->itemRotation);
@ -132,7 +132,7 @@ class ItemFrame extends Flowable{
return true;
}
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
return true;
}
@ -142,16 +142,16 @@ class ItemFrame extends Flowable{
return false;
}
if(lcg_value() <= $this->itemDropChance){
$this->pos->getWorldNonNull()->dropItem($this->pos->add(0.5, 0.5, 0.5), clone $this->framedItem);
$this->pos->getWorld()->dropItem($this->pos->add(0.5, 0.5, 0.5), clone $this->framedItem);
}
$this->setFramedItem(null);
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
return true;
}
public function onNearbyBlockChange() : void{
if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -90,7 +90,7 @@ class Ladder extends Transparent{
public function onNearbyBlockChange() : void{
if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){ //Replace with common break method
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
}

View File

@ -69,17 +69,17 @@ class Lantern extends Transparent{
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if(!$this->canAttachTo($this->pos->getWorldNonNull()->getBlock($blockReplace->getPos()->up())) and !$this->canAttachTo($this->pos->getWorldNonNull()->getBlock($blockReplace->getPos()->down()))){
if(!$this->canAttachTo($this->pos->getWorld()->getBlock($blockReplace->getPos()->up())) and !$this->canAttachTo($this->pos->getWorld()->getBlock($blockReplace->getPos()->down()))){
return false;
}
$this->hanging = ($face === Facing::DOWN or !$this->canAttachTo($this->pos->getWorldNonNull()->getBlock($blockReplace->getPos()->down())));
$this->hanging = ($face === Facing::DOWN or !$this->canAttachTo($this->pos->getWorld()->getBlock($blockReplace->getPos()->down())));
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
public function onNearbyBlockChange() : void{
if(!$this->canAttachTo($this->pos->getWorldNonNull()->getBlock($this->hanging ? $this->pos->up() : $this->pos->down()))){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
if(!$this->canAttachTo($this->pos->getWorld()->getBlock($this->hanging ? $this->pos->up() : $this->pos->down()))){
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
}

View File

@ -78,7 +78,7 @@ class Leaves extends Transparent{
}
$visited[$index] = true;
$block = $this->pos->getWorldNonNull()->getBlock($pos);
$block = $this->pos->getWorld()->getBlock($pos);
if($block instanceof Wood){ //type doesn't matter
return true;
}
@ -97,7 +97,7 @@ class Leaves extends Transparent{
public function onNearbyBlockChange() : void{
if(!$this->noDecay and !$this->checkDecay){
$this->checkDecay = true;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this, false);
$this->pos->getWorld()->setBlock($this->pos, $this, false);
}
}
@ -111,9 +111,9 @@ class Leaves extends Transparent{
$ev->call();
if($ev->isCancelled() or $this->findLog($this->pos)){
$this->checkDecay = false;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this, false);
$this->pos->getWorld()->setBlock($this->pos, $this, false);
}else{
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
}

View File

@ -107,14 +107,14 @@ class Lever extends Flowable{
}
if(!$this->getSide($face)->isSolid()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$this->powered = !$this->powered;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorldNonNull()->addSound(
$this->pos->getWorld()->setBlock($this->pos, $this);
$this->pos->getWorld()->addSound(
$this->pos->add(0.5, 0.5, 0.5),
$this->powered ? new RedstonePowerOnSound() : new RedstonePowerOffSound()
);

View File

@ -188,7 +188,7 @@ abstract class Liquid extends Transparent{
++$z;
}
$sideBlock = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z);
$sideBlock = $this->pos->getWorld()->getBlockAt($x, $y, $z);
$blockDecay = $this->getEffectiveFlowDecay($sideBlock);
if($blockDecay < 0){
@ -196,7 +196,7 @@ abstract class Liquid extends Transparent{
continue;
}
$blockDecay = $this->getEffectiveFlowDecay($this->pos->getWorldNonNull()->getBlockAt($x, $y - 1, $z));
$blockDecay = $this->getEffectiveFlowDecay($this->pos->getWorld()->getBlockAt($x, $y - 1, $z));
if($blockDecay >= 0){
$realDecay = $blockDecay - ($decay - 8);
@ -218,14 +218,14 @@ abstract class Liquid extends Transparent{
if($this->falling){
if(
!$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1)) or
!$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1)) or
!$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z)) or
!$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z)) or
!$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z - 1)) or
!$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z + 1)) or
!$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x - 1, $this->pos->y + 1, $this->pos->z)) or
!$this->canFlowInto($this->pos->getWorldNonNull()->getBlockAt($this->pos->x + 1, $this->pos->y + 1, $this->pos->z))
!$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1)) or
!$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1)) or
!$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z)) or
!$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z)) or
!$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z - 1)) or
!$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z + 1)) or
!$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x - 1, $this->pos->y + 1, $this->pos->z)) or
!$this->canFlowInto($this->pos->getWorld()->getBlockAt($this->pos->x + 1, $this->pos->y + 1, $this->pos->z))
){
$vector = $vector->normalize()->add(0, -6, 0);
}
@ -252,7 +252,7 @@ abstract class Liquid extends Transparent{
public function onNearbyBlockChange() : void{
if(!$this->checkForHarden()){
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, $this->tickRate());
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, $this->tickRate());
}
}
@ -262,10 +262,10 @@ abstract class Liquid extends Transparent{
if(!$this->isSource()){
$smallestFlowDecay = -100;
$this->adjacentSources = 0;
$smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorldNonNull()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorldNonNull()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorld()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z), $smallestFlowDecay);
$smallestFlowDecay = $this->getSmallestFlowDecay($this->pos->getWorld()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z), $smallestFlowDecay);
$newDecay = $smallestFlowDecay + $multiplier;
$falling = false;
@ -274,12 +274,12 @@ abstract class Liquid extends Transparent{
$newDecay = -1;
}
if($this->getEffectiveFlowDecay($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z)) >= 0){
if($this->getEffectiveFlowDecay($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + 1, $this->pos->z)) >= 0){
$falling = true;
}
if($this->adjacentSources >= 2 and $this instanceof Water){
$bottomBlock = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y - 1, $this->pos->z);
$bottomBlock = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y - 1, $this->pos->z);
if($bottomBlock->isSolid() or ($bottomBlock instanceof Water and $bottomBlock->isSource())){
$newDecay = 0;
$falling = false;
@ -288,17 +288,17 @@ abstract class Liquid extends Transparent{
if($falling !== $this->falling or (!$falling and $newDecay !== $this->decay)){
if(!$falling and $newDecay < 0){
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR());
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR());
return;
}
$this->falling = $falling;
$this->decay = $falling ? 0 : $newDecay;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this); //local block update will cause an update to be scheduled
$this->pos->getWorld()->setBlock($this->pos, $this); //local block update will cause an update to be scheduled
}
}
$bottomBlock = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y - 1, $this->pos->z);
$bottomBlock = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y - 1, $this->pos->z);
$this->flowIntoBlock($bottomBlock, 0, true);
@ -313,19 +313,19 @@ abstract class Liquid extends Transparent{
$flags = $this->getOptimalFlowDirections();
if($flags[0]){
$this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z), $adjacentDecay, false);
$this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x - 1, $this->pos->y, $this->pos->z), $adjacentDecay, false);
}
if($flags[1]){
$this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z), $adjacentDecay, false);
$this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x + 1, $this->pos->y, $this->pos->z), $adjacentDecay, false);
}
if($flags[2]){
$this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1), $adjacentDecay, false);
$this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z - 1), $adjacentDecay, false);
}
if($flags[3]){
$this->flowIntoBlock($this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1), $adjacentDecay, false);
$this->flowIntoBlock($this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y, $this->pos->z + 1), $adjacentDecay, false);
}
}
}
@ -343,10 +343,10 @@ abstract class Liquid extends Transparent{
$ev->call();
if(!$ev->isCancelled()){
if($block->getId() > 0){
$this->pos->getWorldNonNull()->useBreakOn($block->pos);
$this->pos->getWorld()->useBreakOn($block->pos);
}
$this->pos->getWorldNonNull()->setBlock($block->pos, $ev->getNewState());
$this->pos->getWorld()->setBlock($block->pos, $ev->getNewState());
}
}
}
@ -374,10 +374,10 @@ abstract class Liquid extends Transparent{
}
if(!isset($this->flowCostVisited[$hash = World::blockHash($x, $y, $z)])){
$blockSide = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z);
$blockSide = $this->pos->getWorld()->getBlockAt($x, $y, $z);
if(!$this->canFlowInto($blockSide)){
$this->flowCostVisited[$hash] = self::BLOCKED;
}elseif($this->pos->getWorldNonNull()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){
}elseif($this->pos->getWorld()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){
$this->flowCostVisited[$hash] = self::CAN_FLOW_DOWN;
}else{
$this->flowCostVisited[$hash] = self::CAN_FLOW;
@ -426,12 +426,12 @@ abstract class Liquid extends Transparent{
}elseif($j === 3){
++$z;
}
$block = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z);
$block = $this->pos->getWorld()->getBlockAt($x, $y, $z);
if(!$this->canFlowInto($block)){
$this->flowCostVisited[World::blockHash($x, $y, $z)] = self::BLOCKED;
continue;
}elseif($this->pos->getWorldNonNull()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){
}elseif($this->pos->getWorld()->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){
$this->flowCostVisited[World::blockHash($x, $y, $z)] = self::CAN_FLOW_DOWN;
$flowCost[$j] = $maxCost = 0;
}elseif($maxCost > 0){
@ -478,13 +478,13 @@ abstract class Liquid extends Transparent{
$ev = new BlockFormEvent($this, $result);
$ev->call();
if(!$ev->isCancelled()){
$this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState());
$this->pos->getWorldNonNull()->addSound($this->pos->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (lcg_value() - lcg_value()) * 0.8));
$this->pos->getWorld()->setBlock($this->pos, $ev->getNewState());
$this->pos->getWorld()->addSound($this->pos->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (lcg_value() - lcg_value()) * 0.8));
}
return true;
}
protected function canFlowInto(Block $block) : bool{
return $this->pos->getWorldNonNull()->isInWorld($block->pos->x, $block->pos->y, $block->pos->z) and $block->canBeFlowedInto() and !($block instanceof Liquid and $block->isSource()); //TODO: I think this should only be liquids of the same type
return $this->pos->getWorld()->isInWorld($block->pos->x, $block->pos->y, $block->pos->z) and $block->canBeFlowedInto() and !($block instanceof Liquid and $block->isSource()); //TODO: I think this should only be liquids of the same type
}
}

View File

@ -53,13 +53,13 @@ class Mycelium extends Opaque{
$x = mt_rand($this->pos->x - 1, $this->pos->x + 1);
$y = mt_rand($this->pos->y - 2, $this->pos->y + 2);
$z = mt_rand($this->pos->z - 1, $this->pos->z + 1);
$block = $this->pos->getWorldNonNull()->getBlockAt($x, $y, $z);
$block = $this->pos->getWorld()->getBlockAt($x, $y, $z);
if($block->getId() === BlockLegacyIds::DIRT){
if($block->getSide(Facing::UP) instanceof Transparent){
$ev = new BlockSpreadEvent($block, $this, VanillaBlocks::MYCELIUM());
$ev->call();
if(!$ev->isCancelled()){
$this->pos->getWorldNonNull()->setBlock($block->pos, $ev->getNewState());
$this->pos->getWorld()->setBlock($block->pos, $ev->getNewState());
}
}
}

View File

@ -64,7 +64,7 @@ class NetherWartPlant extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SOUL_SAND){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
@ -79,7 +79,7 @@ class NetherWartPlant extends Flowable{
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState());
$this->pos->getWorld()->setBlock($this->pos, $ev->getNewState());
}
}
}

View File

@ -39,7 +39,7 @@ class Note extends Opaque{
public function readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileNote){
$this->pitch = $tile->getPitch();
}else{
@ -49,7 +49,7 @@ class Note extends Opaque{
public function writeStateToWorld() : void{
parent::writeStateToWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
assert($tile instanceof TileNote);
$tile->setPitch($this->pitch);
}

View File

@ -41,7 +41,7 @@ class RedMushroom extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -72,7 +72,7 @@ class RedstoneComparator extends Flowable{
public function readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof Comparator){
$this->signalStrength = $tile->getSignalStrength();
}
@ -80,7 +80,7 @@ class RedstoneComparator extends Flowable{
public function writeStateToWorld() : void{
parent::writeStateToWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
assert($tile instanceof Comparator);
$tile->setSignalStrength($this->signalStrength);
}
@ -143,13 +143,13 @@ class RedstoneComparator extends Flowable{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$this->isSubtractMode = !$this->isSubtractMode;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
return true;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -68,7 +68,7 @@ class RedstoneOre extends Opaque{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if(!$this->lit){
$this->lit = true;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this); //no return here - this shouldn't prevent block placement
$this->pos->getWorld()->setBlock($this->pos, $this); //no return here - this shouldn't prevent block placement
}
return false;
}
@ -76,7 +76,7 @@ class RedstoneOre extends Opaque{
public function onNearbyBlockChange() : void{
if(!$this->lit){
$this->lit = true;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}
}
@ -87,7 +87,7 @@ class RedstoneOre extends Opaque{
public function onRandomTick() : void{
if($this->lit){
$this->lit = false;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}
}

View File

@ -99,13 +99,13 @@ class RedstoneRepeater extends Flowable{
if(++$this->delay > 4){
$this->delay = 1;
}
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
return true;
}
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -69,7 +69,7 @@ class Sapling extends Flowable{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($item instanceof Fertilizer){
Tree::growTree($this->pos->getWorldNonNull(), $this->pos->x, $this->pos->y, $this->pos->z, new Random(mt_rand()), $this->treeType);
Tree::growTree($this->pos->getWorld(), $this->pos->x, $this->pos->y, $this->pos->z, new Random(mt_rand()), $this->treeType);
$item->pop();
@ -81,7 +81,7 @@ class Sapling extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->isTransparent()){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
@ -90,12 +90,12 @@ class Sapling extends Flowable{
}
public function onRandomTick() : void{
if($this->pos->getWorldNonNull()->getFullLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 8 and mt_rand(1, 7) === 1){
if($this->pos->getWorld()->getFullLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 8 and mt_rand(1, 7) === 1){
if($this->ready){
Tree::growTree($this->pos->getWorldNonNull(), $this->pos->x, $this->pos->y, $this->pos->z, new Random(mt_rand()), $this->treeType);
Tree::growTree($this->pos->getWorld(), $this->pos->x, $this->pos->y, $this->pos->z, new Random(mt_rand()), $this->treeType);
}else{
$this->ready = true;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}
}
}

View File

@ -86,7 +86,7 @@ class Sign extends Transparent{
public function readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileSign){
$this->text = $tile->getText();
}
@ -94,7 +94,7 @@ class Sign extends Transparent{
public function writeStateToWorld() : void{
parent::writeStateToWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
assert($tile instanceof TileSign);
$tile->setText($this->text);
}
@ -129,7 +129,7 @@ class Sign extends Transparent{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
@ -161,7 +161,7 @@ class Sign extends Transparent{
$ev->call();
if(!$ev->isCancelled()){
$this->text = clone $ev->getNewText();
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
return true;
}

View File

@ -67,7 +67,7 @@ class Skull extends Flowable{
public function readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
if($tile instanceof TileSkull){
$this->skullType = $tile->getSkullType();
$this->rotation = $tile->getRotation();
@ -77,7 +77,7 @@ class Skull extends Flowable{
public function writeStateToWorld() : void{
parent::writeStateToWorld();
//extra block properties storage hack
$tile = $this->pos->getWorldNonNull()->getTile($this->pos);
$tile = $this->pos->getWorld()->getTile($this->pos);
assert($tile instanceof TileSkull);
$tile->setRotation($this->rotation);
$tile->setSkullType($this->skullType);

View File

@ -94,8 +94,8 @@ class SnowLayer extends Flowable implements Fallable{
}
public function onRandomTick() : void{
if($this->pos->getWorldNonNull()->getBlockLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 12){
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR(), false);
if($this->pos->getWorld()->getBlockLightAt($this->pos->x, $this->pos->y, $this->pos->z) >= 12){
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR(), false);
}
}

View File

@ -45,7 +45,7 @@ abstract class Stem extends Crops{
$ev = new BlockGrowEvent($this, $block);
$ev->call();
if(!$ev->isCancelled()){
$this->pos->getWorldNonNull()->setBlock($this->pos, $ev->getNewState());
$this->pos->getWorld()->setBlock($this->pos, $ev->getNewState());
}
}else{
$grow = $this->getPlant();
@ -61,7 +61,7 @@ abstract class Stem extends Crops{
$ev = new BlockGrowEvent($side, $grow);
$ev->call();
if(!$ev->isCancelled()){
$this->pos->getWorldNonNull()->setBlock($side->pos, $ev->getNewState());
$this->pos->getWorld()->setBlock($side->pos, $ev->getNewState());
}
}
}

View File

@ -57,20 +57,20 @@ class Sugarcane extends Flowable{
if($item instanceof Fertilizer){
if(!$this->getSide(Facing::DOWN)->isSameType($this)){
for($y = 1; $y < 3; ++$y){
$b = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z);
$b = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z);
if($b->getId() === BlockLegacyIds::AIR){
$ev = new BlockGrowEvent($b, VanillaBlocks::SUGARCANE());
$ev->call();
if($ev->isCancelled()){
break;
}
$this->pos->getWorldNonNull()->setBlock($b->pos, $ev->getNewState());
$this->pos->getWorld()->setBlock($b->pos, $ev->getNewState());
}else{
break;
}
}
$this->age = 0;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}
$item->pop();
@ -84,7 +84,7 @@ class Sugarcane extends Flowable{
public function onNearbyBlockChange() : void{
$down = $this->getSide(Facing::DOWN);
if($down->isTransparent() and !$down->isSameType($this)){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
@ -96,17 +96,17 @@ class Sugarcane extends Flowable{
if(!$this->getSide(Facing::DOWN)->isSameType($this)){
if($this->age === 15){
for($y = 1; $y < 3; ++$y){
$b = $this->pos->getWorldNonNull()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z);
$b = $this->pos->getWorld()->getBlockAt($this->pos->x, $this->pos->y + $y, $this->pos->z);
if($b->getId() === BlockLegacyIds::AIR){
$this->pos->getWorldNonNull()->setBlock($b->pos, VanillaBlocks::SUGARCANE());
$this->pos->getWorld()->setBlock($b->pos, VanillaBlocks::SUGARCANE());
break;
}
}
$this->age = 0;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}else{
++$this->age;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}
}
}

View File

@ -90,11 +90,11 @@ class TNT extends Opaque{
}
public function ignite(int $fuse = 80) : void{
$this->pos->getWorldNonNull()->setBlock($this->pos, VanillaBlocks::AIR());
$this->pos->getWorld()->setBlock($this->pos, VanillaBlocks::AIR());
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
$tnt = new PrimedTNT(Location::fromObject($this->pos->add(0.5, 0, 0.5), $this->pos->getWorldNonNull()));
$tnt = new PrimedTNT(Location::fromObject($this->pos->add(0.5, 0, 0.5), $this->pos->getWorld()));
$tnt->setFuse($fuse);
$tnt->setMotion(new Vector3(-sin($mot) * 0.02, 0.2, -cos($mot) * 0.02));

View File

@ -52,7 +52,7 @@ class TallGrass extends Flowable{
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::DOWN)->isTransparent()){ //Replace with common break method
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -60,7 +60,7 @@ class Torch extends Flowable{
$face = Facing::opposite($this->facing);
if($this->getSide($face)->isTransparent() and !($face === Facing::DOWN and ($below->getId() === BlockLegacyIds::FENCE or $below->getId() === BlockLegacyIds::COBBLESTONE_WALL))){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -77,8 +77,8 @@ class Trapdoor extends Transparent{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$this->open = !$this->open;
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorldNonNull()->addSound($this->pos, new DoorSound());
$this->pos->getWorld()->setBlock($this->pos, $this);
$this->pos->getWorld()->addSound($this->pos, new DoorSound());
return true;
}
}

View File

@ -115,9 +115,9 @@ class Vine extends Flowable{
if($changed){
if(count($this->faces) === 0){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}else{
$this->pos->getWorldNonNull()->setBlock($this->pos, $this);
$this->pos->getWorld()->setBlock($this->pos, $this);
}
}
}

View File

@ -56,7 +56,7 @@ class WaterLily extends Flowable{
public function onNearbyBlockChange() : void{
if(!($this->getSide(Facing::DOWN) instanceof Water)){
$this->pos->getWorldNonNull()->useBreakOn($this->pos);
$this->pos->getWorld()->useBreakOn($this->pos);
}
}
}

View File

@ -51,7 +51,7 @@ class ChestInventory extends BlockInventory{
if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){
//TODO: this crap really shouldn't be managed by the inventory
$this->broadcastBlockEventPacket(true);
$this->getHolder()->getWorldNonNull()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound());
$this->getHolder()->getWorld()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound());
}
}
@ -59,7 +59,7 @@ class ChestInventory extends BlockInventory{
if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){
//TODO: this crap really shouldn't be managed by the inventory
$this->broadcastBlockEventPacket(false);
$this->getHolder()->getWorldNonNull()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound());
$this->getHolder()->getWorld()->addSound($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound());
}
parent::onClose($who);
}
@ -68,6 +68,6 @@ class ChestInventory extends BlockInventory{
$holder = $this->getHolder();
//event ID is always 1 for a chest
$holder->getWorldNonNull()->broadcastPacketToViewers($holder, BlockEventPacket::create(1, $isOpen ? 1 : 0, $holder->asVector3()));
$holder->getWorld()->broadcastPacketToViewers($holder, BlockEventPacket::create(1, $isOpen ? 1 : 0, $holder->asVector3()));
}
}

View File

@ -55,7 +55,7 @@ class BrewingStand extends Spawnable implements Container, Nameable{
parent::__construct($world, $pos);
$this->inventory = new BrewingStandInventory($this->pos);
$this->inventory->getListeners()->add(CallbackInventoryListener::onAnyChange(function(Inventory $unused) : void{
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 1);
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 1);
}));
}

View File

@ -99,7 +99,7 @@ class Chest extends Spawnable implements Container, Nameable{
$this->inventory->removeAllViewers();
if($this->doubleInventory !== null){
if($this->isPaired() and $this->pos->getWorldNonNull()->isChunkLoaded($this->pairX >> 4, $this->pairZ >> 4)){
if($this->isPaired() and $this->pos->getWorld()->isChunkLoaded($this->pairX >> 4, $this->pairZ >> 4)){
$this->doubleInventory->removeAllViewers();
if(($pair = $this->getPair()) !== null){
$pair->doubleInventory = null;
@ -137,7 +137,7 @@ class Chest extends Spawnable implements Container, Nameable{
}
protected function checkPairing() : void{
if($this->isPaired() and !$this->pos->getWorldNonNull()->isInLoadedTerrain(new Vector3($this->pairX, $this->pos->y, $this->pairZ))){
if($this->isPaired() and !$this->pos->getWorld()->isInLoadedTerrain(new Vector3($this->pairX, $this->pos->y, $this->pairZ))){
//paired to a tile in an unloaded chunk
$this->doubleInventory = null;
@ -173,7 +173,7 @@ class Chest extends Spawnable implements Container, Nameable{
public function getPair() : ?Chest{
if($this->isPaired()){
$tile = $this->pos->getWorldNonNull()->getTileAt($this->pairX, $this->pos->y, $this->pairZ);
$tile = $this->pos->getWorld()->getTileAt($this->pairX, $this->pos->y, $this->pairZ);
if($tile instanceof Chest){
return $tile;
}

View File

@ -94,7 +94,7 @@ trait ContainerTrait{
$pos = $this->getPos();
foreach($inv->getContents() as $k => $item){
$pos->getWorldNonNull()->dropItem($pos->add(0.5, 0.5, 0.5), $item);
$pos->getWorld()->dropItem($pos->add(0.5, 0.5, 0.5), $item);
}
$inv->clearAll();
}

View File

@ -60,7 +60,7 @@ class Furnace extends Spawnable implements Container, Nameable{
$this->inventory = new FurnaceInventory($this->pos);
$this->inventory->getListeners()->add(CallbackInventoryListener::onAnyChange(
function(Inventory $unused) : void{
$this->pos->getWorldNonNull()->scheduleDelayedBlockUpdate($this->pos, 1);
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 1);
})
);
}
@ -129,7 +129,7 @@ class Furnace extends Spawnable implements Container, Nameable{
$block = $this->getBlock();
if($block instanceof BlockFurnace and !$block->isLit()){
$block->setLit(true);
$this->pos->getWorldNonNull()->setBlock($block->getPos(), $block);
$this->pos->getWorld()->setBlock($block->getPos(), $block);
}
if($this->remainingFuelTime > 0 and $ev->isBurning()){
@ -155,7 +155,7 @@ class Furnace extends Spawnable implements Container, Nameable{
$fuel = $this->inventory->getFuel();
$raw = $this->inventory->getSmelting();
$product = $this->inventory->getResult();
$smelt = $this->pos->getWorldNonNull()->getServer()->getCraftingManager()->getFurnaceRecipeManager()->match($raw);
$smelt = $this->pos->getWorld()->getServer()->getCraftingManager()->getFurnaceRecipeManager()->match($raw);
$canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > 0 and (($smelt->getResult()->equals($product) and $product->getCount() < $product->getMaxStackSize()) or $product->isNull()));
if($this->remainingFuelTime <= 0 and $canSmelt and $fuel->getFuelTime() > 0 and $fuel->getCount() > 0){
@ -192,7 +192,7 @@ class Furnace extends Spawnable implements Container, Nameable{
$block = $this->getBlock();
if($block instanceof BlockFurnace and $block->isLit()){
$block->setLit(false);
$this->pos->getWorldNonNull()->setBlock($block->getPos(), $block);
$this->pos->getWorld()->setBlock($block->getPos(), $block);
}
$this->remainingFuelTime = $this->cookTime = $this->maxFuelTime = 0;
}

View File

@ -95,7 +95,7 @@ abstract class Tile{
}
public function getBlock() : Block{
return $this->pos->getWorldNonNull()->getBlock($this->pos);
return $this->pos->getWorld()->getBlock($this->pos);
}
public function getPos() : Position{
@ -130,7 +130,7 @@ abstract class Tile{
$this->closed = true;
if($this->pos->isValid()){
$this->pos->getWorldNonNull()->removeTile($this);
$this->pos->getWorld()->removeTile($this);
}
$this->pos = null;
}

View File

@ -49,14 +49,14 @@ trait FallableTrait{
public function onNearbyBlockChange() : void{
$pos = $this->getPos();
$down = $pos->getWorldNonNull()->getBlock($pos->getSide(Facing::DOWN));
$down = $pos->getWorld()->getBlock($pos->getSide(Facing::DOWN));
if($down->getId() === BlockLegacyIds::AIR or $down instanceof Liquid or $down instanceof Fire){
$pos->getWorldNonNull()->setBlock($pos, VanillaBlocks::AIR());
$pos->getWorld()->setBlock($pos, VanillaBlocks::AIR());
$block = $this;
if(!($block instanceof Block)) throw new AssumptionFailedError(__TRAIT__ . " should only be used by Blocks");
$fall = new FallingBlock(Location::fromObject($pos->add(0.5, 0, 0.5), $pos->getWorldNonNull()), $block);
$fall = new FallingBlock(Location::fromObject($pos->add(0.5, 0, 0.5), $pos->getWorld()), $block);
$fall->spawnToAll();
}
}

View File

@ -94,7 +94,7 @@ class ParticleCommand extends VanillaCommand{
if($sender instanceof Player){
$senderPos = $sender->getPosition();
$world = $senderPos->getWorldNonNull();
$world = $senderPos->getWorld();
$pos = new Vector3(
$this->getRelativeDouble($senderPos->getX(), $sender, $args[1]),
$this->getRelativeDouble($senderPos->getY(), $sender, $args[2], 0, World::Y_MAX),

View File

@ -44,7 +44,7 @@ class SeedCommand extends VanillaCommand{
}
if($sender instanceof Player){
$seed = $sender->getPosition()->getWorldNonNull()->getSeed();
$seed = $sender->getPosition()->getWorld()->getSeed();
}else{
$seed = $sender->getServer()->getWorldManager()->getDefaultWorld()->getSeed();
}

View File

@ -52,7 +52,7 @@ class SetWorldSpawnCommand extends VanillaCommand{
if(count($args) === 0){
if($sender instanceof Player){
$location = $sender->getPosition();
$world = $location->getWorldNonNull();
$world = $location->getWorld();
$pos = $location->asVector3()->round();
}else{
$sender->sendMessage(TextFormat::RED . "You can only perform this command as a player");

View File

@ -83,7 +83,7 @@ class SpawnpointCommand extends VanillaCommand{
}elseif(count($args) <= 1){
if($sender instanceof Player){
$cpos = $sender->getPosition();
$pos = Position::fromObject($cpos->floor(), $cpos->getWorldNonNull());
$pos = Position::fromObject($cpos->floor(), $cpos->getWorld());
$target->setSpawn($pos);
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.spawnpoint.success", [$target->getName(), round($pos->x, 2), round($pos->y, 2), round($pos->z, 2)]));

View File

@ -112,7 +112,7 @@ class TeleportCommand extends VanillaCommand{
$x = $this->getRelativeDouble($base->x, $sender, $targetArgs[0]);
$y = $this->getRelativeDouble($base->y, $sender, $targetArgs[1], 0, 256);
$z = $this->getRelativeDouble($base->z, $sender, $targetArgs[2]);
$targetLocation = new Location($x, $y, $z, $yaw, $pitch, $base->getWorldNonNull());
$targetLocation = new Location($x, $y, $z, $yaw, $pitch, $base->getWorld());
$subject->teleport($targetLocation);
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.tp.success.coordinates", [

View File

@ -223,7 +223,7 @@ abstract class Entity{
}
$this->id = self::nextRuntimeId();
$this->server = $location->getWorldNonNull()->getServer();
$this->server = $location->getWorld()->getServer();
$this->location = $location->asLocation();
assert(
@ -1289,7 +1289,7 @@ abstract class Entity{
}
public function getWorld() : World{
return $this->location->getWorldNonNull();
return $this->location->getWorld();
}
protected function setPosition(Vector3 $pos) : bool{
@ -1297,8 +1297,8 @@ abstract class Entity{
return false;
}
if($pos instanceof Position and $pos->isValid() and $pos->getWorldNonNull() !== $this->getWorld()){
if(!$this->switchWorld($pos->getWorldNonNull())){
if($pos instanceof Position and $pos->isValid() and $pos->getWorld() !== $this->getWorld()){
if(!$this->switchWorld($pos->getWorld())){
return false;
}
}
@ -1410,7 +1410,7 @@ abstract class Entity{
$pitch = $pitch ?? $pos->pitch;
}
$from = $this->location->asPosition();
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getWorldNonNull() : $this->getWorld());
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getWorld() : $this->getWorld());
$ev = new EntityTeleportEvent($this, $from, $to);
$ev->call();
if($ev->isCancelled()){

View File

@ -63,7 +63,7 @@ class Location extends Position{
}
public function __toString(){
return "Location (world=" . ($this->isValid() ? $this->getWorldNonNull()->getDisplayName() : "null") . ", x=$this->x, y=$this->y, z=$this->z, yaw=$this->yaw, pitch=$this->pitch)";
return "Location (world=" . ($this->isValid() ? $this->getWorld()->getDisplayName() : "null") . ", x=$this->x, y=$this->y, z=$this->z, yaw=$this->yaw, pitch=$this->pitch)";
}
public function equals(Vector3 $v) : bool{

View File

@ -103,7 +103,7 @@ class Bow extends Tool{
}
$ev->getProjectile()->spawnToAll();
$location->getWorldNonNull()->addSound($location, new BowShootSound());
$location->getWorld()->addSound($location, new BowShootSound());
}else{
$entity->spawnToAll();
}

View File

@ -75,7 +75,7 @@ class PaintingItem extends Item{
$replacePos = $blockReplace->getPos();
$clickedPos = $blockClicked->getPos();
$entity = new Painting(Location::fromObject($replacePos, $replacePos->getWorldNonNull()), $clickedPos, $face, $motive);
$entity = new Painting(Location::fromObject($replacePos, $replacePos->getWorld()), $clickedPos, $face, $motive);
$this->pop();
$entity->spawnToAll();

View File

@ -51,7 +51,7 @@ abstract class ProjectileItem extends Item{
$projectile->spawnToAll();
$location->getWorldNonNull()->addSound($location, new ThrowSound());
$location->getWorld()->addSound($location, new ThrowSound());
$this->pop();

View File

@ -822,7 +822,7 @@ class NetworkSession{
public function startUsingChunk(int $chunkX, int $chunkZ, \Closure $onCompletion) : void{
Utils::validateCallableSignature(function(int $chunkX, int $chunkZ) : void{}, $onCompletion);
$world = $this->player->getLocation()->getWorldNonNull();
$world = $this->player->getLocation()->getWorld();
ChunkCache::getInstance($world, $this->compressor)->request($chunkX, $chunkZ)->onResolve(
//this callback may be called synchronously or asynchronously, depending on whether the promise is resolved yet
@ -830,7 +830,7 @@ class NetworkSession{
if(!$this->isConnected()){
return;
}
$currentWorld = $this->player->getLocation()->getWorldNonNull();
$currentWorld = $this->player->getLocation()->getWorld();
if($world !== $currentWorld or !$this->player->isUsingChunk($chunkX, $chunkZ)){
$this->logger->debug("Tried to send no-longer-active chunk $chunkX $chunkZ in world " . $world->getFolderName());
return;

View File

@ -359,7 +359,7 @@ class InGamePacketHandler extends PacketHandler{
}else{
$blocks[] = $blockPos;
}
$this->player->getLocation()->getWorldNonNull()->sendBlocks([$this->player], $blocks);
$this->player->getLocation()->getWorld()->sendBlocks([$this->player], $blocks);
}
}
@ -563,7 +563,7 @@ class InGamePacketHandler extends PacketHandler{
return false;
}
$block = $this->player->getLocation()->getWorldNonNull()->getBlock($pos);
$block = $this->player->getLocation()->getWorld()->getBlock($pos);
$nbt = $packet->namedtag->getRoot();
if(!($nbt instanceof CompoundTag)) throw new AssumptionFailedError("PHPStan should ensure this is a CompoundTag"); //for phpstorm's benefit

View File

@ -68,12 +68,12 @@ class PreSpawnPacketHandler extends PacketHandler{
$pk->seed = -1;
$pk->spawnSettings = new SpawnSettings(SpawnSettings::BIOME_TYPE_DEFAULT, "", DimensionIds::OVERWORLD); //TODO: implement this properly
$pk->worldGamemode = TypeConverter::getInstance()->coreGameModeToProtocol($this->server->getGamemode());
$pk->difficulty = $location->getWorldNonNull()->getDifficulty();
$pk->difficulty = $location->getWorld()->getDifficulty();
$pk->spawnX = $spawnPosition->getFloorX();
$pk->spawnY = $spawnPosition->getFloorY();
$pk->spawnZ = $spawnPosition->getFloorZ();
$pk->hasAchievementsDisabled = true;
$pk->time = $location->getWorldNonNull()->getTime();
$pk->time = $location->getWorld()->getTime();
$pk->eduEditionOffer = 0;
$pk->rainLevel = 0; //TODO: implement these properly
$pk->lightningLevel = 0;

View File

@ -713,7 +713,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
}
protected function switchWorld(World $targetWorld) : bool{
$oldWorld = $this->location->isValid() ? $this->location->getWorldNonNull() : null;
$oldWorld = $this->location->isValid() ? $this->location->getWorld() : null;
if(parent::switchWorld($targetWorld)){
if($oldWorld !== null){
foreach($this->usedChunks as $index => $status){
@ -959,7 +959,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
if(!($pos instanceof Position)){
$world = $this->getWorld();
}else{
$world = $pos->getWorldNonNull();
$world = $pos->getWorld();
}
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $world);
$this->networkSession->syncPlayerSpawnPoint($this->spawnPosition);
@ -2082,7 +2082,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
}
if($this->hasValidSpawnPosition()){
$nbt->setString("SpawnLevel", $this->spawnPosition->getWorldNonNull()->getFolderName());
$nbt->setString("SpawnLevel", $this->spawnPosition->getWorld()->getFolderName());
$nbt->setInt("SpawnX", $this->spawnPosition->getFloorX());
$nbt->setInt("SpawnY", $this->spawnPosition->getFloorY());
$nbt->setInt("SpawnZ", $this->spawnPosition->getFloorZ());
@ -2152,7 +2152,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$ev = new PlayerRespawnEvent($this, $this->getSpawn());
$ev->call();
$realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getWorldNonNull());
$realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getWorld());
$this->teleport($realSpawn);
$this->setSprinting(false);

View File

@ -73,7 +73,7 @@ class Explosion{
throw new \InvalidArgumentException("Position does not have a valid world");
}
$this->source = $center;
$this->world = $center->getWorldNonNull();
$this->world = $center->getWorld();
if($size <= 0){
throw new \InvalidArgumentException("Explosion radius must be greater than 0, got $size");

View File

@ -61,32 +61,16 @@ class Position extends Vector3{
}
/**
* Returns the target world, or null if the target is not valid.
* If a reference exists to a world which is closed, the reference will be destroyed and null will be returned.
*
* @return World|null
*/
public function getWorld(){
if($this->world !== null and $this->world->isClosed()){
\GlobalLogger::get()->debug("Position was holding a reference to an unloaded world");
$this->world = null;
}
return $this->world;
}
/**
* Returns the position's world if valid. Throws an error if the world is unexpectedly null.
* Returns the position's world if valid. Throws an error if the world is unexpectedly invalid.
*
* @throws AssumptionFailedError
*/
public function getWorldNonNull() : World{
$world = $this->getWorld();
if($world === null){
throw new AssumptionFailedError("Position world is null");
public function getWorld() : World{
if($this->world === null || $this->world->isClosed()){
throw new AssumptionFailedError("Position world is null or has been unloaded");
}
return $world;
return $this->world;
}
/**
@ -114,7 +98,7 @@ class Position extends Vector3{
}
public function __toString(){
return "Position(level=" . ($this->isValid() ? $this->getWorldNonNull()->getDisplayName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
return "Position(level=" . ($this->isValid() ? $this->getWorld()->getDisplayName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
}
public function equals(Vector3 $v) : bool{

View File

@ -2043,7 +2043,7 @@ class World implements ChunkManager{
throw new \InvalidArgumentException("Attempted to add a garbage closed Tile to world");
}
$pos = $tile->getPos();
if(!$pos->isValid() || $pos->getWorldNonNull() !== $this){
if(!$pos->isValid() || $pos->getWorld() !== $this){
throw new \InvalidArgumentException("Invalid Tile world");
}
@ -2065,7 +2065,7 @@ class World implements ChunkManager{
*/
public function removeTile(Tile $tile) : void{
$pos = $tile->getPos();
if(!$pos->isValid() || $pos->getWorldNonNull() !== $this){
if(!$pos->isValid() || $pos->getWorld() !== $this){
throw new \InvalidArgumentException("Invalid Tile world");
}