Renaming "Level" -> "World" (#2907)

This has been a pain point for a long time due to the misleading nature of the name "level". It's also confusing when trying to do things like getting the XP level of the player or such, and also does not translate well to other languages.

This transition was already executed on the UI some time ago (language strings) and now it's time for the same change to occur on the API.

This will burn a lot of plugins, but they'll acclimatize. Despite the scary size of this PR, there isn't actually so many changes to make. Most of this came from renaming `Position->getLevel()` to `Position->getWorld()`, or cosmetic changes like changing variable names or doc comments.
This commit is contained in:
Dylan T
2019-05-07 14:47:28 +01:00
committed by GitHub
parent 427e334426
commit 3cd6e12e71
310 changed files with 1647 additions and 1628 deletions

View File

@ -30,15 +30,11 @@ use pocketmine\block\Block;
use pocketmine\block\Water;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDespawnEvent;
use pocketmine\event\entity\EntityLevelChangeEvent;
use pocketmine\event\entity\EntityMotionEvent;
use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\event\entity\EntitySpawnEvent;
use pocketmine\event\entity\EntityTeleportEvent;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\level\Location;
use pocketmine\level\Position;
use pocketmine\event\entity\EntityWorldChangeEvent;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
use pocketmine\math\Facing;
@ -67,6 +63,10 @@ use pocketmine\plugin\Plugin;
use pocketmine\Server;
use pocketmine\timings\Timings;
use pocketmine\timings\TimingsHandler;
use pocketmine\world\format\Chunk;
use pocketmine\world\Location;
use pocketmine\world\Position;
use pocketmine\world\World;
use function abs;
use function assert;
use function cos;
@ -199,7 +199,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** @var TimingsHandler */
protected $timings;
public function __construct(Level $level, CompoundTag $nbt){
public function __construct(World $world, CompoundTag $nbt){
$this->timings = Timings::getEntityTimings($this);
$this->temporalVector = new Vector3();
@ -209,20 +209,20 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
$this->id = EntityFactory::nextRuntimeId();
$this->server = $level->getServer();
$this->server = $world->getServer();
/** @var float[] $pos */
$pos = $nbt->getListTag("Pos")->getAllValues();
/** @var float[] $rotation */
$rotation = $nbt->getListTag("Rotation")->getAllValues();
parent::__construct($pos[0], $pos[1], $pos[2], $rotation[0], $rotation[1], $level);
parent::__construct($pos[0], $pos[1], $pos[2], $rotation[0], $rotation[1], $world);
assert(!is_nan($this->x) and !is_infinite($this->x) and !is_nan($this->y) and !is_infinite($this->y) and !is_nan($this->z) and !is_infinite($this->z));
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
$this->recalculateBoundingBox();
$this->chunk = $this->level->getChunkAtPosition($this, false);
$this->chunk = $this->world->getChunkAtPosition($this, false);
if($this->chunk === null){
throw new \InvalidStateException("Cannot create entities in unloaded chunks");
}
@ -256,7 +256,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->propertyManager->clearDirtyProperties(); //Prevents resending properties that were set during construction
$this->chunk->addEntity($this);
$this->level->addEntity($this);
$this->world->addEntity($this);
$this->lastUpdate = $this->server->getTick();
(new EntitySpawnEvent($this))->call();
@ -450,7 +450,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
public function getOwningEntity() : ?Entity{
$eid = $this->getOwningEntityId();
if($eid !== null){
return $this->server->getLevelManager()->findEntity($eid);
return $this->server->getWorldManager()->findEntity($eid);
}
return null;
@ -490,7 +490,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
public function getTargetEntity() : ?Entity{
$eid = $this->getTargetEntityId();
if($eid !== null){
return $this->server->getLevelManager()->findEntity($eid);
return $this->server->getWorldManager()->findEntity($eid);
}
return null;
@ -871,7 +871,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$pk->flags |= MoveEntityAbsolutePacket::FLAG_TELEPORT;
}
$this->level->broadcastPacketToViewers($this, $pk);
$this->world->broadcastPacketToViewers($this, $pk);
}
protected function broadcastMotion() : void{
@ -879,7 +879,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$pk->entityRuntimeId = $this->id;
$pk->motion = $this->getMotion();
$this->level->broadcastPacketToViewers($this, $pk);
$this->world->broadcastPacketToViewers($this, $pk);
}
public function hasGravity() : bool{
@ -914,7 +914,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
if($this->onGround){
$friction *= $this->level->getBlockAt((int) floor($this->x), (int) floor($this->y - 1), (int) floor($this->z))->getFrictionFactor();
$friction *= $this->world->getBlockAt((int) floor($this->x), (int) floor($this->y - 1), (int) floor($this->z))->getFrictionFactor();
}
$this->motion->x *= $friction;
@ -922,7 +922,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
protected function checkObstruction(float $x, float $y, float $z) : bool{
if(count($this->level->getCollisionBoxes($this, $this->getBoundingBox(), false)) === 0){
if(count($this->world->getCollisionBoxes($this, $this->getBoundingBox(), false)) === 0){
return false;
}
@ -934,13 +934,13 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$diffY = $y - $floorY;
$diffZ = $z - $floorZ;
if($this->level->getBlockAt($floorX, $floorY, $floorZ)->isSolid()){
$westNonSolid = !$this->level->getBlockAt($floorX - 1, $floorY, $floorZ)->isSolid();
$eastNonSolid = !$this->level->getBlockAt($floorX + 1, $floorY, $floorZ)->isSolid();
$downNonSolid = !$this->level->getBlockAt($floorX, $floorY - 1, $floorZ)->isSolid();
$upNonSolid = !$this->level->getBlockAt($floorX, $floorY + 1, $floorZ)->isSolid();
$northNonSolid = !$this->level->getBlockAt($floorX, $floorY, $floorZ - 1)->isSolid();
$southNonSolid = !$this->level->getBlockAt($floorX, $floorY, $floorZ + 1)->isSolid();
if($this->world->getBlockAt($floorX, $floorY, $floorZ)->isSolid()){
$westNonSolid = !$this->world->getBlockAt($floorX - 1, $floorY, $floorZ)->isSolid();
$eastNonSolid = !$this->world->getBlockAt($floorX + 1, $floorY, $floorZ)->isSolid();
$downNonSolid = !$this->world->getBlockAt($floorX, $floorY - 1, $floorZ)->isSolid();
$upNonSolid = !$this->world->getBlockAt($floorX, $floorY + 1, $floorZ)->isSolid();
$northNonSolid = !$this->world->getBlockAt($floorX, $floorY, $floorZ - 1)->isSolid();
$southNonSolid = !$this->world->getBlockAt($floorX, $floorY, $floorZ + 1)->isSolid();
$direction = -1;
$limit = 9999;
@ -1105,7 +1105,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
if($this->closed){
throw new \InvalidStateException("Cannot schedule update on garbage entity " . get_class($this));
}
$this->level->updateEntities[$this->id] = $this;
$this->world->updateEntities[$this->id] = $this;
}
public function onNearbyBlockChange() : void{
@ -1176,7 +1176,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
public function isUnderwater() : bool{
$block = $this->level->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z));
$block = $this->world->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z));
if($block instanceof Water){
$f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
@ -1187,7 +1187,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
public function isInsideOfSolid() : bool{
$block = $this->level->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z));
$block = $this->world->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z));
return $block->isSolid() and !$block->isTransparent() and $block->collidesWithBB($this->getBoundingBox());
}
@ -1223,7 +1223,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/*$sneakFlag = $this->onGround and $this instanceof Player;
if($sneakFlag){
for($mov = 0.05; $dx != 0.0 and count($this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, -1, 0))) === 0; $movX = $dx){
for($mov = 0.05; $dx != 0.0 and count($this->world->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, -1, 0))) === 0; $movX = $dx){
if($dx < $mov and $dx >= -$mov){
$dx = 0;
}elseif($dx > 0){
@ -1233,7 +1233,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
}
for(; $dz != 0.0 and count($this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox(0, -1, $dz))) === 0; $movZ = $dz){
for(; $dz != 0.0 and count($this->world->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox(0, -1, $dz))) === 0; $movZ = $dz){
if($dz < $mov and $dz >= -$mov){
$dz = 0;
}elseif($dz > 0){
@ -1249,7 +1249,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
assert(abs($dx) <= 20 and abs($dy) <= 20 and abs($dz) <= 20, "Movement distance is excessive: dx=$dx, dy=$dy, dz=$dz");
//TODO: bad hack here will cause unexpected behaviour under heavy lag
$list = $this->level->getCollisionBoxes($this, $this->level->getTickRateTime() > 50 ? $this->boundingBox->offsetCopy($dx, $dy, $dz) : $this->boundingBox->addCoord($dx, $dy, $dz), false);
$list = $this->world->getCollisionBoxes($this, $this->world->getTickRateTime() > 50 ? $this->boundingBox->offsetCopy($dx, $dy, $dz) : $this->boundingBox->addCoord($dx, $dy, $dz), false);
foreach($list as $bb){
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
@ -1284,7 +1284,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->boundingBox->setBB($axisalignedbb);
$list = $this->level->getCollisionBoxes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false);
$list = $this->world->getCollisionBoxes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false);
foreach($list as $bb){
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
@ -1367,7 +1367,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
for($z = $minZ; $z <= $maxZ; ++$z){
for($x = $minX; $x <= $maxX; ++$x){
for($y = $minY; $y <= $maxY; ++$y){
$block = $this->level->getBlockAt($x, $y, $z);
$block = $this->world->getBlockAt($x, $y, $z);
if($block->hasEntityCollision()){
$this->blocksAround[] = $block;
}
@ -1418,8 +1418,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return false;
}
if($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level){
if(!$this->switchLevel($pos->getLevel())){
if($pos instanceof Position and $pos->world !== null and $pos->world !== $this->world){
if(!$this->switchWorld($pos->getWorld())){
return false;
}
}
@ -1460,10 +1460,10 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
if($this->chunk !== null){
$this->chunk->removeEntity($this);
}
$this->chunk = $this->level->getChunk($chunkX, $chunkZ, true);
$this->chunk = $this->world->getChunk($chunkX, $chunkZ, true);
if(!$this->justCreated){
$newChunk = $this->level->getViewersForPosition($this);
$newChunk = $this->world->getViewersForPosition($this);
foreach($this->hasSpawned as $player){
if(!isset($newChunk[spl_object_id($player)])){
$this->despawnFrom($player);
@ -1540,8 +1540,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$yaw = $yaw ?? $pos->yaw;
$pitch = $pitch ?? $pos->pitch;
}
$from = Position::fromObject($this, $this->level);
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level);
$from = Position::fromObject($this, $this->world);
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getWorld() : $this->world);
$ev = new EntityTeleportEvent($this, $from, $to);
$ev->call();
if($ev->isCancelled()){
@ -1563,27 +1563,27 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
return false;
}
protected function switchLevel(Level $targetLevel) : bool{
protected function switchWorld(World $targetWorld) : bool{
if($this->closed){
return false;
}
if($this->isValid()){
$ev = new EntityLevelChangeEvent($this, $this->level, $targetLevel);
$ev = new EntityWorldChangeEvent($this, $this->world, $targetWorld);
$ev->call();
if($ev->isCancelled()){
return false;
}
$this->level->removeEntity($this);
$this->world->removeEntity($this);
if($this->chunk !== null){
$this->chunk->removeEntity($this);
}
$this->despawnFromAll();
}
$this->setLevel($targetLevel);
$this->level->addEntity($this);
$this->setWorld($targetWorld);
$this->world->addEntity($this);
$this->chunk = null;
return true;
@ -1636,7 +1636,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
if($this->chunk === null or $this->closed){
return;
}
foreach($this->level->getViewersForPosition($this) as $player){
foreach($this->world->getViewersForPosition($this) as $player){
if($player->isOnline()){
$this->spawnTo($player);
}
@ -1717,7 +1717,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->chunk->removeEntity($this);
}
if($this->isValid()){
$this->level->removeEntity($this);
$this->world->removeEntity($this);
}
}
@ -1729,7 +1729,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
*/
protected function destroyCycles() : void{
$this->chunk = null;
$this->setLevel(null);
$this->setWorld(null);
$this->lastDamageCause = null;
}

View File

@ -36,7 +36,6 @@ use pocketmine\entity\projectile\EnderPearl;
use pocketmine\entity\projectile\ExperienceBottle;
use pocketmine\entity\projectile\Snowball;
use pocketmine\entity\projectile\SplashPotion;
use pocketmine\level\Level;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
@ -45,6 +44,7 @@ use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\utils\Utils;
use pocketmine\world\World;
use function array_keys;
use function assert;
use function in_array;
@ -174,20 +174,20 @@ final class EntityFactory{
}
/**
* Creates an entity with the specified type, level and NBT, with optional additional arguments to pass to the
* Creates an entity with the specified type, world and NBT, with optional additional arguments to pass to the
* entity's constructor.
*
* TODO: make this NBT-independent
*
* @param string $baseClass
* @param Level $level
* @param World $world
* @param CompoundTag $nbt
* @param mixed ...$args
*
* @return Entity instanceof $baseClass
* @throws \InvalidArgumentException if the class doesn't exist or is not registered
*/
public static function create(string $baseClass, Level $level, CompoundTag $nbt, ...$args) : Entity{
public static function create(string $baseClass, World $world, CompoundTag $nbt, ...$args) : Entity{
if(isset(self::$classMapping[$baseClass])){
$class = self::$classMapping[$baseClass];
assert(is_a($class, $baseClass, true));
@ -195,7 +195,7 @@ final class EntityFactory{
* @var Entity $entity
* @see Entity::__construct()
*/
$entity = new $class($level, $nbt, ...$args);
$entity = new $class($world, $nbt, ...$args);
return $entity;
}
@ -205,15 +205,16 @@ final class EntityFactory{
/**
* Creates an entity from data stored on a chunk.
* @internal
*
* @param Level $level
* @param World $world
* @param CompoundTag $nbt
*
* @return Entity|null
* @throws \RuntimeException
*@internal
*
*/
public static function createFromData(Level $level, CompoundTag $nbt) : ?Entity{
public static function createFromData(World $world, CompoundTag $nbt) : ?Entity{
$saveId = $nbt->getTag("id") ?? $nbt->getTag("identifier");
$baseClass = null;
if($saveId instanceof StringTag){
@ -230,7 +231,7 @@ final class EntityFactory{
* @var Entity $entity
* @see Entity::__construct()
*/
$entity = new $class($level, $nbt);
$entity = new $class($world, $nbt);
return $entity;
}

View File

@ -42,10 +42,6 @@ use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\FoodSource;
use pocketmine\item\Item;
use pocketmine\item\Totem;
use pocketmine\level\Level;
use pocketmine\level\sound\TotemUseSound;
use pocketmine\level\sound\XpCollectSound;
use pocketmine\level\sound\XpLevelUpSound;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\ByteArrayTag;
use pocketmine\nbt\tag\CompoundTag;
@ -62,6 +58,10 @@ use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
use pocketmine\network\mcpe\protocol\types\PlayerMetadataFlags;
use pocketmine\Player;
use pocketmine\utils\UUID;
use pocketmine\world\sound\TotemUseSound;
use pocketmine\world\sound\XpCollectSound;
use pocketmine\world\sound\XpLevelUpSound;
use pocketmine\world\World;
use function array_filter;
use function array_merge;
use function array_rand;
@ -101,7 +101,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
protected $baseOffset = 1.62;
public function __construct(Level $level, CompoundTag $nbt){
public function __construct(World $world, CompoundTag $nbt){
if($this->skin === null){
$skinTag = $nbt->getCompoundTag("Skin");
if($skinTag === null or !self::isValidSkin($skinTag->hasTag("Data", ByteArrayTag::class) ?
@ -112,7 +112,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
}
}
parent::__construct($level, $nbt);
parent::__construct($world, $nbt);
}
/**
@ -350,7 +350,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($playSound){
$newLevel = $this->getXpLevel();
if((int) ($newLevel / 5) > (int) ($oldLevel / 5)){
$this->level->addSound($this, new XpLevelUpSound($newLevel));
$this->world->addSound($this, new XpLevelUpSound($newLevel));
}
}
@ -442,9 +442,9 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($playSound){
$newLevel = $this->getXpLevel();
if((int) ($newLevel / 5) > (int) ($oldLevel / 5)){
$this->level->addSound($this, new XpLevelUpSound($newLevel));
$this->world->addSound($this, new XpLevelUpSound($newLevel));
}elseif($this->getCurrentTotalXp() > $oldTotal){
$this->level->addSound($this, new XpCollectSound());
$this->world->addSound($this, new XpCollectSound());
}
}
@ -696,14 +696,14 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($this->isAlive()){
$food = $this->getFood();
$health = $this->getHealth();
$difficulty = $this->level->getDifficulty();
$difficulty = $this->world->getDifficulty();
$this->foodTickTimer += $tickDiff;
if($this->foodTickTimer >= 80){
$this->foodTickTimer = 0;
}
if($difficulty === Level::DIFFICULTY_PEACEFUL and $this->foodTickTimer % 10 === 0){
if($difficulty === World::DIFFICULTY_PEACEFUL and $this->foodTickTimer % 10 === 0){
if($food < $this->getMaxFood()){
$this->addFood(1.0);
$food = $this->getFood();
@ -720,7 +720,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN);
}
}elseif($food <= 0){
if(($difficulty === Level::DIFFICULTY_EASY and $health > 10) or ($difficulty === Level::DIFFICULTY_NORMAL and $health > 1) or $difficulty === Level::DIFFICULTY_HARD){
if(($difficulty === World::DIFFICULTY_EASY and $health > 10) or ($difficulty === World::DIFFICULTY_NORMAL and $health > 1) or $difficulty === World::DIFFICULTY_HARD){
$this->attack(new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1));
}
}
@ -761,7 +761,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$this->addEffect(new EffectInstance(Effect::ABSORPTION(), 5 * 20, 1));
$this->broadcastEntityEvent(EntityEventPacket::CONSUME_TOTEM);
$this->level->addSound($this->add(0, $this->eyeHeight, 0), new TotemUseSound());
$this->world->addSound($this->add(0, $this->eyeHeight, 0), new TotemUseSound());
$hand = $this->inventory->getItemInHand();
if($hand instanceof Totem){

View File

@ -40,7 +40,6 @@ use pocketmine\item\Consumable;
use pocketmine\item\Durable;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\Item;
use pocketmine\level\sound\ItemBreakSound;
use pocketmine\math\Vector3;
use pocketmine\math\VoxelRayTrace;
use pocketmine\nbt\tag\CompoundTag;
@ -54,6 +53,7 @@ use pocketmine\Player;
use pocketmine\timings\Timings;
use pocketmine\utils\Binary;
use pocketmine\utils\Color;
use pocketmine\world\sound\ItemBreakSound;
use function abs;
use function array_shift;
use function atan2;
@ -546,7 +546,7 @@ abstract class Living extends Entity implements Damageable{
private function damageItem(Durable $item, int $durabilityRemoved) : void{
$item->applyDamage($durabilityRemoved);
if($item->isBroken()){
$this->level->addSound($this, new ItemBreakSound());
$this->world->addSound($this, new ItemBreakSound());
}
}
@ -598,7 +598,7 @@ abstract class Living extends Entity implements Damageable{
$source->getCause() === EntityDamageEvent::CAUSE_PROJECTILE or
$source->getCause() === EntityDamageEvent::CAUSE_ENTITY_ATTACK
) and $e->isOnFire()){
$this->setOnFire(2 * $this->level->getDifficulty());
$this->setOnFire(2 * $this->world->getDifficulty());
}
$deltaX = $this->x - $e->x;
@ -646,11 +646,11 @@ abstract class Living extends Entity implements Damageable{
$ev = new EntityDeathEvent($this, $this->getDrops(), $this->getXpDropAmount());
$ev->call();
foreach($ev->getDrops() as $item){
$this->getLevel()->dropItem($this, $item);
$this->getWorld()->dropItem($this, $item);
}
//TODO: check death conditions (must have been damaged by player < 5 seconds from death)
$this->level->dropExperience($this, $ev->getXpDropAmount());
$this->world->dropExperience($this, $ev->getXpDropAmount());
$this->startDeathAnimation();
}
@ -864,7 +864,7 @@ abstract class Living extends Entity implements Damageable{
$nextIndex = 0;
foreach(VoxelRayTrace::inDirection($this->add(0, $this->eyeHeight, 0), $this->getDirectionVector(), $maxDistance) as $vector3){
$block = $this->level->getBlockAt($vector3->x, $vector3->y, $vector3->z);
$block = $this->world->getBlockAt($vector3->x, $vector3->y, $vector3->z);
$blocks[$nextIndex++] = $block;
if($maxLength !== 0 and count($blocks) > $maxLength){

View File

@ -152,7 +152,7 @@ class ExperienceOrb extends Entity{
return null;
}
$entity = $this->level->getEntity($this->targetPlayerRuntimeId);
$entity = $this->world->getEntity($this->targetPlayerRuntimeId);
if($entity instanceof Human){
return $entity;
}
@ -180,7 +180,7 @@ class ExperienceOrb extends Entity{
if($this->lookForTargetTime >= 20){
if($currentTarget === null){
$newTarget = $this->level->getNearestEntity($this, self::MAX_TARGET_DISTANCE, Human::class);
$newTarget = $this->world->getNearestEntity($this, self::MAX_TARGET_DISTANCE, Human::class);
if($newTarget instanceof Human and !($newTarget instanceof Player and $newTarget->isSpectator())){
$currentTarget = $newTarget;

View File

@ -98,7 +98,7 @@ class FallingBlock extends Entity{
if(!$this->isFlaggedForDespawn()){
$pos = $this->add(-$this->width / 2, $this->height, -$this->width / 2)->floor();
$this->block->position($this->level, $pos->x, $pos->y, $pos->z);
$this->block->position($this->world, $pos->x, $pos->y, $pos->z);
$blockTarget = null;
if($this->block instanceof Fallable){
@ -108,15 +108,15 @@ class FallingBlock extends Entity{
if($this->onGround or $blockTarget !== null){
$this->flagForDespawn();
$block = $this->level->getBlock($pos);
$block = $this->world->getBlock($pos);
if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){
//FIXME: anvils are supposed to destroy torches
$this->getLevel()->dropItem($this, $this->block->asItem());
$this->getWorld()->dropItem($this, $this->block->asItem());
}else{
$ev = new EntityBlockChangeEvent($this, $block, $blockTarget ?? $this->block);
$ev->call();
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($pos, $ev->getTo());
$this->getWorld()->setBlock($pos, $ev->getTo());
}
}
$hasUpdate = true;

View File

@ -29,8 +29,6 @@ use pocketmine\entity\Entity;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level;
use pocketmine\level\particle\DestroyBlockParticle;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Bearing;
use pocketmine\math\Facing;
@ -39,6 +37,8 @@ use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\AddPaintingPacket;
use pocketmine\Player;
use pocketmine\world\particle\DestroyBlockParticle;
use pocketmine\world\World;
use function ceil;
class Painting extends Entity{
@ -62,7 +62,7 @@ class Painting extends Entity{
/** @var string */
protected $motive;
public function __construct(Level $level, CompoundTag $nbt){
public function __construct(World $world, CompoundTag $nbt){
$this->motive = $nbt->getString("Motive");
$this->blockIn = new Vector3($nbt->getInt("TileX"), $nbt->getInt("TileY"), $nbt->getInt("TileZ"));
if($nbt->hasTag("Direction", ByteTag::class)){
@ -70,7 +70,7 @@ class Painting extends Entity{
}elseif($nbt->hasTag("Facing", ByteTag::class)){
$this->direction = $nbt->getByte("Facing");
}
parent::__construct($level, $nbt);
parent::__construct($world, $nbt);
}
protected function initEntity(CompoundTag $nbt) : void{
@ -107,9 +107,9 @@ class Painting extends Entity{
if($drops){
//non-living entities don't have a way to create drops generically yet
$this->level->dropItem($this, ItemFactory::get(Item::PAINTING));
$this->world->dropItem($this, ItemFactory::get(Item::PAINTING));
}
$this->level->addParticle($this->add(0.5, 0.5, 0.5), new DestroyBlockParticle(BlockFactory::get(BlockLegacyIds::PLANKS)));
$this->world->addParticle($this->add(0.5, 0.5, 0.5), new DestroyBlockParticle(BlockFactory::get(BlockLegacyIds::PLANKS)));
}
protected function recalculateBoundingBox() : void{
@ -121,7 +121,7 @@ class Painting extends Entity{
parent::onNearbyBlockChange();
$face = Bearing::toFacing($this->direction);
if(!self::canFit($this->level, $this->blockIn->getSide($face), $face, false, $this->getMotive())){
if(!self::canFit($this->world, $this->blockIn->getSide($face), $face, false, $this->getMotive())){
$this->kill();
}
}
@ -226,7 +226,7 @@ class Painting extends Entity{
/**
* Returns whether a painting with the specified motive can be placed at the given position.
*
* @param Level $level
* @param World $world
* @param Vector3 $blockIn
* @param int $facing
* @param bool $checkOverlap
@ -234,7 +234,7 @@ class Painting extends Entity{
*
* @return bool
*/
public static function canFit(Level $level, Vector3 $blockIn, int $facing, bool $checkOverlap, PaintingMotive $motive) : bool{
public static function canFit(World $world, Vector3 $blockIn, int $facing, bool $checkOverlap, PaintingMotive $motive) : bool{
$width = $motive->getWidth();
$height = $motive->getHeight();
@ -251,7 +251,7 @@ class Painting extends Entity{
for($h = 0; $h < $height; ++$h){
$pos = $startPos->getSide($rotatedFace, $w)->getSide(Facing::UP, $h);
$block = $level->getBlockAt($pos->x, $pos->y, $pos->z);
$block = $world->getBlockAt($pos->x, $pos->y, $pos->z);
if($block->isSolid() or !$block->getSide($oppositeSide)->isSolid()){
return false;
}
@ -261,7 +261,7 @@ class Painting extends Entity{
if($checkOverlap){
$bb = self::getPaintingBB($blockIn, $facing, $motive);
foreach($level->getNearbyEntities($bb) as $entity){
foreach($world->getNearbyEntities($bb) as $entity){
if($entity instanceof self){
return false;
}

View File

@ -27,12 +27,12 @@ use pocketmine\entity\Entity;
use pocketmine\entity\Explosive;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\ExplosionPrimeEvent;
use pocketmine\level\Explosion;
use pocketmine\level\sound\IgniteSound;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ShortTag;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
use pocketmine\world\Explosion;
use pocketmine\world\sound\IgniteSound;
class PrimedTNT extends Entity implements Explosive{
public const NETWORK_ID = self::TNT;
@ -68,7 +68,7 @@ class PrimedTNT extends Entity implements Explosive{
$this->setGenericFlag(EntityMetadataFlags::IGNITED, true);
$this->propertyManager->setInt(EntityMetadataProperties::FUSE_LENGTH, $this->fuse);
$this->level->addSound($this, new IgniteSound());
$this->world->addSound($this, new IgniteSound());
}

View File

@ -29,14 +29,14 @@ use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\event\inventory\InventoryPickupArrowEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level;
use pocketmine\level\sound\ArrowHitSound;
use pocketmine\math\RayTraceResult;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\EntityEventPacket;
use pocketmine\network\mcpe\protocol\TakeItemEntityPacket;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
use pocketmine\Player;
use pocketmine\world\sound\ArrowHitSound;
use pocketmine\world\World;
use function mt_rand;
use function sqrt;
@ -67,8 +67,8 @@ class Arrow extends Projectile{
/** @var int */
protected $collideTicks = 0;
public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null, bool $critical = false){
parent::__construct($level, $nbt, $shootingEntity);
public function __construct(World $world, CompoundTag $nbt, ?Entity $shootingEntity = null, bool $critical = false){
parent::__construct($world, $nbt, $shootingEntity);
$this->setCritical($critical);
}
@ -139,7 +139,7 @@ class Arrow extends Projectile{
protected function onHit(ProjectileHitEvent $event) : void{
$this->setCritical(false);
$this->level->addSound($this, new ArrowHitSound());
$this->world->addSound($this, new ArrowHitSound());
}
protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{

View File

@ -26,7 +26,7 @@ namespace pocketmine\entity\projectile;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\particle\ItemBreakParticle;
use pocketmine\world\particle\ItemBreakParticle;
class Egg extends Throwable{
public const NETWORK_ID = self::EGG;
@ -35,7 +35,7 @@ class Egg extends Throwable{
protected function onHit(ProjectileHitEvent $event) : void{
for($i = 0; $i < 6; ++$i){
$this->level->addParticle($this, new ItemBreakParticle(ItemFactory::get(Item::EGG)));
$this->world->addParticle($this, new ItemBreakParticle(ItemFactory::get(Item::EGG)));
}
}
}

View File

@ -27,11 +27,11 @@ use pocketmine\block\Block;
use pocketmine\block\BlockLegacyIds;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\level\particle\EndermanTeleportParticle;
use pocketmine\level\sound\EndermanTeleportSound;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\RayTraceResult;
use pocketmine\math\Vector3;
use pocketmine\world\particle\EndermanTeleportParticle;
use pocketmine\world\sound\EndermanTeleportSound;
class EnderPearl extends Throwable{
public const NETWORK_ID = self::ENDER_PEARL;
@ -51,10 +51,10 @@ class EnderPearl extends Throwable{
//TODO: check end gateways (when they are added)
//TODO: spawn endermites at origin
$this->level->addParticle($owner, new EndermanTeleportParticle());
$this->level->addSound($owner, new EndermanTeleportSound());
$this->world->addParticle($owner, new EndermanTeleportParticle());
$this->world->addSound($owner, new EndermanTeleportSound());
$owner->teleport($target = $event->getRayTraceResult()->getHitVector());
$this->level->addSound($target, new EndermanTeleportSound());
$this->world->addSound($target, new EndermanTeleportSound());
$owner->attack(new EntityDamageEvent($owner, EntityDamageEvent::CAUSE_FALL, 5));
}

View File

@ -24,8 +24,8 @@ declare(strict_types=1);
namespace pocketmine\entity\projectile;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\level\particle\PotionSplashParticle;
use pocketmine\level\sound\PotionSplashSound;
use pocketmine\world\particle\PotionSplashParticle;
use pocketmine\world\sound\PotionSplashSound;
use function mt_rand;
class ExperienceBottle extends Throwable{
@ -38,9 +38,9 @@ class ExperienceBottle extends Throwable{
}
public function onHit(ProjectileHitEvent $event) : void{
$this->level->addParticle($this, new PotionSplashParticle(PotionSplashParticle::DEFAULT_COLOR()));
$this->level->addSound($this, new PotionSplashSound());
$this->world->addParticle($this, new PotionSplashParticle(PotionSplashParticle::DEFAULT_COLOR()));
$this->world->addSound($this, new PotionSplashSound());
$this->level->dropExperience($this, mt_rand(3, 11));
$this->world->dropExperience($this, mt_rand(3, 11));
}
}

View File

@ -34,8 +34,6 @@ use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\ProjectileHitBlockEvent;
use pocketmine\event\entity\ProjectileHitEntityEvent;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\level\Level;
use pocketmine\level\Position;
use pocketmine\math\RayTraceResult;
use pocketmine\math\Vector3;
use pocketmine\math\VoxelRayTrace;
@ -43,6 +41,8 @@ use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\timings\Timings;
use pocketmine\world\Position;
use pocketmine\world\World;
use function assert;
use function atan2;
use function ceil;
@ -58,8 +58,8 @@ abstract class Projectile extends Entity{
/** @var Block|null */
protected $blockHit;
public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null){
parent::__construct($level, $nbt);
public function __construct(World $world, CompoundTag $nbt, ?Entity $shootingEntity = null){
parent::__construct($world, $nbt);
if($shootingEntity !== null){
$this->setOwningEntity($shootingEntity);
}
@ -84,7 +84,7 @@ abstract class Projectile extends Entity{
$blockData = null;
if($nbt->hasTag("tileX", IntTag::class) and $nbt->hasTag("tileY", IntTag::class) and $nbt->hasTag("tileZ", IntTag::class)){
$blockPos = new Position($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"), $this->level);
$blockPos = new Position($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"), $this->world);
}else{
break;
}
@ -163,7 +163,7 @@ abstract class Projectile extends Entity{
}
public function onNearbyBlockChange() : void{
if($this->blockHit !== null and $this->level->isInLoadedTerrain($this->blockHit) and !$this->blockHit->isSameState($this->level->getBlock($this->blockHit))){
if($this->blockHit !== null and $this->world->isInLoadedTerrain($this->blockHit) and !$this->blockHit->isSameState($this->world->getBlock($this->blockHit))){
$this->blockHit = null;
}
@ -187,7 +187,7 @@ abstract class Projectile extends Entity{
$hitResult = null;
foreach(VoxelRayTrace::betweenPoints($start, $end) as $vector3){
$block = $this->level->getBlockAt($vector3->x, $vector3->y, $vector3->z);
$block = $this->world->getBlockAt($vector3->x, $vector3->y, $vector3->z);
$blockHitResult = $this->calculateInterceptWithBlock($block, $start, $end);
if($blockHitResult !== null){
@ -201,7 +201,7 @@ abstract class Projectile extends Entity{
$entityDistance = PHP_INT_MAX;
$newDiff = $end->subtract($start);
foreach($this->level->getCollidingEntities($this->boundingBox->addCoord($newDiff->x, $newDiff->y, $newDiff->z)->expand(1, 1, 1), $this) as $entity){
foreach($this->world->getCollidingEntities($this->boundingBox->addCoord($newDiff->x, $newDiff->y, $newDiff->z)->expand(1, 1, 1), $this) as $entity){
if($entity->getId() === $this->getOwningEntityId() and $this->ticksLived < 5){
continue;
}

View File

@ -24,14 +24,14 @@ declare(strict_types=1);
namespace pocketmine\entity\projectile;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\level\particle\SnowballPoofParticle;
use pocketmine\world\particle\SnowballPoofParticle;
class Snowball extends Throwable{
public const NETWORK_ID = self::SNOWBALL;
protected function onHit(ProjectileHitEvent $event) : void{
for($i = 0; $i < 6; ++$i){
$this->level->addParticle($this, new SnowballPoofParticle());
$this->world->addParticle($this, new SnowballPoofParticle());
}
}
}

View File

@ -32,12 +32,12 @@ use pocketmine\event\entity\ProjectileHitBlockEvent;
use pocketmine\event\entity\ProjectileHitEntityEvent;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\item\Potion;
use pocketmine\level\particle\PotionSplashParticle;
use pocketmine\level\sound\PotionSplashSound;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
use pocketmine\utils\Color;
use pocketmine\world\particle\PotionSplashParticle;
use pocketmine\world\sound\PotionSplashSound;
use function round;
use function sqrt;
@ -83,12 +83,12 @@ class SplashPotion extends Throwable{
$particle = new PotionSplashParticle(Color::mix(...$colors));
}
$this->level->addParticle($this, $particle);
$this->level->addSound($this, new PotionSplashSound());
$this->world->addParticle($this, $particle);
$this->world->addSound($this, new PotionSplashSound());
if($hasEffects){
if(!$this->willLinger()){
foreach($this->level->getNearbyEntities($this->boundingBox->expandedCopy(4.125, 2.125, 4.125), $this) as $entity){
foreach($this->world->getNearbyEntities($this->boundingBox->expandedCopy(4.125, 2.125, 4.125), $this) as $entity){
if($entity instanceof Living and $entity->isAlive()){
$distanceSquared = $entity->add(0, $entity->getEyeHeight(), 0)->distanceSquared($this);
if($distanceSquared > 16){ //4 blocks
@ -123,11 +123,11 @@ class SplashPotion extends Throwable{
$blockIn = $event->getBlockHit()->getSide($event->getRayTraceResult()->getHitFace());
if($blockIn->getId() === BlockLegacyIds::FIRE){
$this->level->setBlock($blockIn, BlockFactory::get(BlockLegacyIds::AIR));
$this->world->setBlock($blockIn, BlockFactory::get(BlockLegacyIds::AIR));
}
foreach($blockIn->getHorizontalSides() as $horizontalSide){
if($horizontalSide->getId() === BlockLegacyIds::FIRE){
$this->level->setBlock($horizontalSide, BlockFactory::get(BlockLegacyIds::AIR));
$this->world->setBlock($horizontalSide, BlockFactory::get(BlockLegacyIds::AIR));
}
}
}