Merge branch 'api3/network' into api3/network-mcpe-1.1

This commit is contained in:
Dylan K. Taylor 2017-04-24 13:56:19 +01:00
commit 7a2ed232cc
3 changed files with 49 additions and 9 deletions

View File

@ -1722,6 +1722,20 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
return true; return true;
} }
public function doFoodTick(int $tickDiff = 1){
if($this->isSurvival()){
parent::doFoodTick($tickDiff);
}
}
public function exhaust(float $amount, int $cause = PlayerExhaustEvent::CAUSE_CUSTOM) : float{
if($this->isSurvival()){
return parent::exhaust($amount, $cause);
}
return 0.0;
}
public function checkNetwork(){ public function checkNetwork(){
if(!$this->isOnline()){ if(!$this->isOnline()){
return; return;
@ -4108,7 +4122,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
} }
public function onChunkChanged(Chunk $chunk){ public function onChunkChanged(Chunk $chunk){
unset($this->usedChunks[Level::chunkHash($chunk->getX(), $chunk->getZ())]); if(isset($this->usedChunks[$hash = Level::chunkHash($chunk->getX(), $chunk->getZ())])){
$this->usedChunks[$hash] = false;
}
} }
public function onChunkLoaded(Chunk $chunk){ public function onChunkLoaded(Chunk $chunk){

View File

@ -27,6 +27,7 @@ use pocketmine\event\player\PlayerExhaustEvent;
use pocketmine\inventory\InventoryHolder; use pocketmine\inventory\InventoryHolder;
use pocketmine\inventory\PlayerInventory; use pocketmine\inventory\PlayerInventory;
use pocketmine\item\Item as ItemItem; use pocketmine\item\Item as ItemItem;
use pocketmine\level\Level;
use pocketmine\nbt\NBT; use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\ByteTag; use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
@ -61,13 +62,21 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public $eyeHeight = 1.62; public $eyeHeight = 1.62;
protected $skinId; protected $skinId;
protected $skin; protected $skin = null;
protected $foodTickTimer = 0; protected $foodTickTimer = 0;
protected $totalXp = 0; protected $totalXp = 0;
protected $xpSeed; protected $xpSeed;
public function __construct(Level $level, CompoundTag $nbt){
if($this->skin === null and (!isset($nbt->Skin) or !isset($nbt->Skin->Data) or !Player::isValidSkin($nbt->Skin->Data->getValue()))){
throw new \InvalidStateException((new \ReflectionClass($this))->getShortName() . " must have a valid skin set");
}
parent::__construct($level, $nbt);
}
public function getSkinData(){ public function getSkinData(){
return $this->skin; return $this->skin;
} }
@ -95,6 +104,10 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
* @param string $skinId * @param string $skinId
*/ */
public function setSkin($str, $skinId){ public function setSkin($str, $skinId){
if(!Player::isValidSkin($str)){
throw new \InvalidStateException("Specified skin is not valid, must be 8KiB or 16KiB");
}
$this->skin = $str; $this->skin = $str;
$this->skinId = $skinId; $this->skinId = $skinId;
} }
@ -361,12 +374,18 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public function entityBaseTick($tickDiff = 1){ public function entityBaseTick($tickDiff = 1){
$hasUpdate = parent::entityBaseTick($tickDiff); $hasUpdate = parent::entityBaseTick($tickDiff);
$this->doFoodTick($tickDiff);
return $hasUpdate;
}
public function doFoodTick(int $tickDiff = 1){
if($this->isAlive()){ if($this->isAlive()){
$food = $this->getFood(); $food = $this->getFood();
$health = $this->getHealth(); $health = $this->getHealth();
$difficulty = $this->server->getDifficulty(); $difficulty = $this->server->getDifficulty();
$this->foodTickTimer++; $this->foodTickTimer += $tickDiff;
if($this->foodTickTimer >= 80){ if($this->foodTickTimer >= 80){
$this->foodTickTimer = 0; $this->foodTickTimer = 0;
} }
@ -399,8 +418,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
} }
} }
} }
return $hasUpdate;
} }
public function getName(){ public function getName(){
@ -483,7 +500,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($player !== $this and !isset($this->hasSpawned[$player->getLoaderId()])){ if($player !== $this and !isset($this->hasSpawned[$player->getLoaderId()])){
$this->hasSpawned[$player->getLoaderId()] = $player; $this->hasSpawned[$player->getLoaderId()] = $player;
if(strlen($this->skin) < 64 * 32 * 4){ if(!Player::isValidSkin($this->skin)){
throw new \InvalidStateException((new \ReflectionClass($this))->getShortName() . " must have a valid skin set"); throw new \InvalidStateException((new \ReflectionClass($this))->getShortName() . " must have a valid skin set");
} }

View File

@ -709,9 +709,16 @@ class Chunk{
continue; //Fixes entities allocated in wrong chunks. continue; //Fixes entities allocated in wrong chunks.
} }
if(($entity = Entity::createEntity($nbt["id"], $level, $nbt)) instanceof Entity){ try{
$entity->spawnToAll(); $entity = Entity::createEntity($nbt["id"], $level, $nbt);
}else{ if($entity instanceof Entity){
$entity->spawnToAll();
}else{
$changed = true;
continue;
}
}catch(\Throwable $t){
$level->getServer()->getLogger()->logException($t);
$changed = true; $changed = true;
continue; continue;
} }