Removed entanglement between chunks and providers. WARNING: BREAKING API CHANGES.

- All entity and tile constructors now require a \pocketmine\level\Level instead of a \pocketmine\level\format\Chunk.
- Chunk->getProvider() and Chunk->setProvider() have been removed.
- Chunk::__construct() has had the $provider parameter removed.
- Chunk->unload() has had the unused $save parameter removed.
- ChunkEvents now take a Level parameter instead of going through the Chunk

API bump to 3.0.0-ALPHA4
This commit is contained in:
Dylan K. Taylor
2017-02-21 17:03:45 +00:00
parent 0a8826b21f
commit c21197ef17
37 changed files with 123 additions and 170 deletions

View File

@ -21,7 +21,7 @@
namespace pocketmine\entity;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\level\particle\CriticalParticle;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\protocol\AddEntityPacket;
@ -41,9 +41,9 @@ class Arrow extends Projectile{
protected $isCritical;
public function __construct(Chunk $chunk, CompoundTag $nbt, Entity $shootingEntity = null, $critical = false){
public function __construct(Level $level, CompoundTag $nbt, Entity $shootingEntity = null, $critical = false){
$this->isCritical = (bool) $critical;
parent::__construct($chunk, $nbt, $shootingEntity);
parent::__construct($level, $nbt, $shootingEntity);
}
public function onUpdate($currentTick){

View File

@ -269,10 +269,7 @@ abstract class Entity extends Location implements Metadatable{
protected $isPlayer = false;
public function __construct(Chunk $chunk, CompoundTag $nbt){
assert($chunk !== null and $chunk->getProvider() !== null);
public function __construct(Level $level, CompoundTag $nbt){
$this->timings = Timings::getEntityTimings($this);
$this->isPlayer = $this instanceof Player;
@ -287,9 +284,10 @@ abstract class Entity extends Location implements Metadatable{
$this->justCreated = true;
$this->namedtag = $nbt;
$this->chunk = $chunk;
$this->setLevel($chunk->getProvider()->getLevel());
$this->server = $chunk->getProvider()->getLevel()->getServer();
$this->chunk = $level->getChunk($this->namedtag["Pos"][0] >> 4, $this->namedtag["Pos"][2] >> 4);
assert($this->chunk !== null);
$this->setLevel($level);
$this->server = $level->getServer();
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
$this->setPositionAndRotation(
@ -301,6 +299,8 @@ abstract class Entity extends Location implements Metadatable{
$this->namedtag->Rotation[0],
$this->namedtag->Rotation[1]
);
$this->setMotion($this->temporalVector->setComponents($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
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));
@ -515,16 +515,16 @@ abstract class Entity extends Location implements Metadatable{
/**
* @param int|string $type
* @param Chunk $chunk
* @param Level $level
* @param CompoundTag $nbt
* @param $args
*
* @return Entity
*/
public static function createEntity($type, Chunk $chunk, CompoundTag $nbt, ...$args){
public static function createEntity($type, Level $level, CompoundTag $nbt, ...$args){
if(isset(self::$knownEntities[$type])){
$class = self::$knownEntities[$type];
return new $class($chunk, $nbt, ...$args);
return new $class($level, $nbt, ...$args);
}
return null;

View File

@ -26,7 +26,7 @@ use pocketmine\event\entity\EntityDamageByChildEntityEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\level\MovingObjectPosition;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
@ -42,12 +42,12 @@ abstract class Projectile extends Entity{
public $hadCollision = false;
public function __construct(Chunk $chunk, CompoundTag $nbt, Entity $shootingEntity = null){
public function __construct(Level $level, CompoundTag $nbt, Entity $shootingEntity = null){
$this->shootingEntity = $shootingEntity;
if($shootingEntity !== null){
$this->setDataProperty(self::DATA_SHOOTER_ID, self::DATA_TYPE_LONG, $shootingEntity->getId());
}
parent::__construct($chunk, $nbt);
parent::__construct($level, $nbt);
}
public function attack($damage, EntityDamageEvent $source){

View File

@ -21,7 +21,7 @@
namespace pocketmine\entity;
use pocketmine\level\format\Chunk;
use pocketmine\level\Level;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\protocol\AddEntityPacket;
use pocketmine\Player;
@ -36,8 +36,8 @@ class Snowball extends Projectile{
protected $gravity = 0.03;
protected $drag = 0.01;
public function __construct(Chunk $chunk, CompoundTag $nbt, Entity $shootingEntity = null){
parent::__construct($chunk, $nbt, $shootingEntity);
public function __construct(Level $level, CompoundTag $nbt, Entity $shootingEntity = null){
parent::__construct($level, $nbt, $shootingEntity);
}
public function onUpdate($currentTick){