mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 10:53:05 +00:00
Type-hinted NBT tag constructors, made getValue() and setValue() more strict, fix dozens of assorted related bugs
This commit is contained in:
@ -738,7 +738,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->namedtag->id = new StringTag("id", $this->getSaveId());
|
||||
if($this->getNameTag() !== ""){
|
||||
$this->namedtag->CustomName = new StringTag("CustomName", $this->getNameTag());
|
||||
$this->namedtag->CustomNameVisible = new StringTag("CustomNameVisible", $this->isNameTagVisible());
|
||||
$this->namedtag->CustomNameVisible = new ByteTag("CustomNameVisible", $this->isNameTagVisible() ? 1 : 0);
|
||||
}else{
|
||||
unset($this->namedtag->CustomName);
|
||||
unset($this->namedtag->CustomNameVisible);
|
||||
@ -746,20 +746,20 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
$this->namedtag->Pos = new ListTag("Pos", [
|
||||
new DoubleTag(0, $this->x),
|
||||
new DoubleTag(1, $this->y),
|
||||
new DoubleTag(2, $this->z)
|
||||
new DoubleTag("", $this->x),
|
||||
new DoubleTag("", $this->y),
|
||||
new DoubleTag("", $this->z)
|
||||
]);
|
||||
|
||||
$this->namedtag->Motion = new ListTag("Motion", [
|
||||
new DoubleTag(0, $this->motionX),
|
||||
new DoubleTag(1, $this->motionY),
|
||||
new DoubleTag(2, $this->motionZ)
|
||||
new DoubleTag("", $this->motionX),
|
||||
new DoubleTag("", $this->motionY),
|
||||
new DoubleTag("", $this->motionZ)
|
||||
]);
|
||||
|
||||
$this->namedtag->Rotation = new ListTag("Rotation", [
|
||||
new FloatTag(0, $this->yaw),
|
||||
new FloatTag(1, $this->pitch)
|
||||
new FloatTag("", $this->yaw),
|
||||
new FloatTag("", $this->pitch)
|
||||
]);
|
||||
|
||||
$this->namedtag->FallDistance = new FloatTag("FallDistance", $this->fallDistance);
|
||||
@ -771,7 +771,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
if(count($this->effects) > 0){
|
||||
$effects = [];
|
||||
foreach($this->effects as $effect){
|
||||
$effects[$effect->getId()] = new CompoundTag($effect->getId(), [
|
||||
$effects[] = new CompoundTag("", [
|
||||
"Id" => new ByteTag("Id", $effect->getId()),
|
||||
"Amplifier" => new ByteTag("Amplifier", $effect->getAmplifier()),
|
||||
"Duration" => new IntTag("Duration", $effect->getDuration()),
|
||||
|
@ -36,8 +36,11 @@ use pocketmine\Player;
|
||||
class Item extends Entity{
|
||||
const NETWORK_ID = 64;
|
||||
|
||||
protected $owner = null;
|
||||
protected $thrower = null;
|
||||
/** @var string */
|
||||
protected $owner = "";
|
||||
/** @var string */
|
||||
protected $thrower = "";
|
||||
/** @var int */
|
||||
protected $pickupDelay = 0;
|
||||
/** @var ItemItem */
|
||||
protected $item;
|
||||
|
@ -32,6 +32,7 @@ use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||
use pocketmine\event\Timings;
|
||||
use pocketmine\item\Item as ItemItem;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\tag\FloatTag;
|
||||
use pocketmine\nbt\tag\ShortTag;
|
||||
use pocketmine\network\mcpe\protocol\EntityEventPacket;
|
||||
use pocketmine\utils\BlockIterator;
|
||||
@ -51,10 +52,12 @@ abstract class Living extends Entity implements Damageable{
|
||||
parent::initEntity();
|
||||
|
||||
if(isset($this->namedtag->HealF)){
|
||||
$this->namedtag->Health = new ShortTag("Health", (int) $this->namedtag["HealF"]);
|
||||
$this->namedtag->Health = new FloatTag("Health", (float) $this->namedtag["HealF"]);
|
||||
unset($this->namedtag->HealF);
|
||||
}elseif(!isset($this->namedtag->Health) or !($this->namedtag->Health instanceof ShortTag)){
|
||||
$this->namedtag->Health = new ShortTag("Health", $this->getMaxHealth());
|
||||
}elseif(isset($this->namedtag->Health) and !($this->namedtag->Health instanceof FloatTag)){
|
||||
$this->namedtag->Health = new FloatTag("Health", (float) $this->namedtag->Health->getValue());
|
||||
}else{
|
||||
$this->namedtag->Health = new FloatTag("Health", (float) $this->getMaxHealth());
|
||||
}
|
||||
|
||||
$this->setHealth($this->namedtag["Health"]);
|
||||
|
Reference in New Issue
Block a user