mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 02:38:54 +00:00
Fixed attriutes not sending
This commit is contained in:
parent
28967ca495
commit
8807617480
@ -34,7 +34,6 @@ use pocketmine\event\block\SignChangeEvent;
|
||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||
use pocketmine\event\entity\EntityDamageByEntityEvent;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||
use pocketmine\event\entity\EntityShootBowEvent;
|
||||
use pocketmine\event\entity\ProjectileLaunchEvent;
|
||||
use pocketmine\event\inventory\CraftItemEvent;
|
||||
@ -1205,16 +1204,22 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
}
|
||||
|
||||
public function entityBaseTick($tickDiff = 1){
|
||||
parent::entityBaseTick($tickDiff);
|
||||
$hasUpdate = parent::entityBaseTick($tickDiff);
|
||||
|
||||
$entries = $this->attributeMap->needSend();
|
||||
if(count($entries) > 0){
|
||||
$pk = new UpdateAttributesPacket();
|
||||
$pk->entityId = 0;
|
||||
$pk->entries = $entries;
|
||||
$this->dataPacket($pk);
|
||||
foreach($entries as $entry){
|
||||
$entry->markSynchronized();
|
||||
}
|
||||
}
|
||||
|
||||
return $hasUpdate;
|
||||
}
|
||||
|
||||
protected function checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz){
|
||||
if(!$this->onGround or $movY != 0){
|
||||
$bb = clone $this->boundingBox;
|
||||
@ -3189,9 +3194,9 @@ class Player extends Human implements CommandSender, InventoryHolder, ChunkLoade
|
||||
public function setHealth($amount){
|
||||
parent::setHealth($amount);
|
||||
if($this->spawned === true){
|
||||
$pk = new SetHealthPacket();
|
||||
$pk->health = $this->getHealth();
|
||||
$this->dataPacket($pk);
|
||||
// $pk = new SetHealthPacket();
|
||||
// $pk->health = $this->getHealth();
|
||||
// $this->dataPacket($pk);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ class Attribute{
|
||||
*
|
||||
* @return Attribute
|
||||
*/
|
||||
public static function addAttribute($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend = false){
|
||||
public static function addAttribute($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend = true){
|
||||
if($minValue > $maxValue or $defaultValue > $maxValue or $defaultValue < $minValue){
|
||||
throw new \InvalidArgumentException("Invalid ranges: min value: $minValue, max value: $maxValue, $defaultValue: $defaultValue");
|
||||
}
|
||||
@ -105,7 +105,7 @@ class Attribute{
|
||||
return null;
|
||||
}
|
||||
|
||||
private function __construct($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend = false){
|
||||
private function __construct($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend = true){
|
||||
$this->id = (int) $id;
|
||||
$this->name = (string) $name;
|
||||
$this->minValue = (float) $minValue;
|
||||
|
@ -38,6 +38,9 @@ class AttributeMap{
|
||||
return $this->attributes[$id] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Attribute[]
|
||||
*/
|
||||
public function needSend() : array{
|
||||
return array_filter($this->attributes, function (Attribute $attribute){
|
||||
return $attribute->isSyncable() and $attribute->isDesynchronized();
|
||||
|
@ -126,6 +126,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
|
||||
public function addFood(float $amount){
|
||||
$attr = $this->attributeMap->getAttribute(Attribute::HUNGER);
|
||||
$amount += $attr->getValue();
|
||||
$amount = max(min($amount, $attr->getMaxValue()), $attr->getMinValue());
|
||||
$this->setFood($amount);
|
||||
}
|
||||
@ -147,7 +148,8 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
}
|
||||
|
||||
public function addSaturation(float $amount){
|
||||
$this->attributeMap->getAttribute(Attribute::SATURATION)->setValue($amount, true);
|
||||
$attr = $this->attributeMap->getAttribute(Attribute::SATURATION);
|
||||
$attr->setValue($attr->getValue() + $amount, true);
|
||||
}
|
||||
|
||||
public function getExhaustion() : float{
|
||||
@ -175,7 +177,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
|
||||
while($exhaustion >= 4.0){
|
||||
$exhaustion -= 4.0;
|
||||
$this->setExhaustion($exhaustion);
|
||||
|
||||
$saturation = $this->getSaturation();
|
||||
if($saturation > 0){
|
||||
@ -189,6 +190,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->setExhaustion($exhaustion);
|
||||
}
|
||||
|
||||
public function getInventory(){
|
||||
@ -230,6 +232,10 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
||||
}
|
||||
|
||||
parent::initEntity();
|
||||
}
|
||||
|
||||
protected function addAttributes(){
|
||||
parent::addAttributes();
|
||||
|
||||
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::SATURATION));
|
||||
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::EXHAUSTION));
|
||||
|
@ -32,6 +32,7 @@ use pocketmine\item\Item as ItemItem;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\nbt\tag\ShortTag;
|
||||
use pocketmine\network\protocol\EntityEventPacket;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\Server;
|
||||
use pocketmine\utils\BlockIterator;
|
||||
|
||||
@ -47,6 +48,8 @@ abstract class Living extends Entity implements Damageable{
|
||||
protected function initEntity(){
|
||||
parent::initEntity();
|
||||
|
||||
$this->addAttributes();
|
||||
|
||||
if(isset($this->namedtag->HealF)){
|
||||
$this->namedtag->Health = new ShortTag("Health", (int) $this->namedtag["HealF"]);
|
||||
unset($this->namedtag->HealF);
|
||||
@ -57,7 +60,9 @@ abstract class Living extends Entity implements Damageable{
|
||||
}
|
||||
|
||||
$this->setHealth($this->namedtag["Health"]);
|
||||
}
|
||||
|
||||
protected function addAttributes(){
|
||||
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::ABSORPTION));
|
||||
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::HEALTH));
|
||||
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::MOVEMENT_SPEED));
|
||||
|
@ -37,6 +37,6 @@ class SpiderEye extends Food{
|
||||
}
|
||||
|
||||
public function getAdditionEffects() : array{
|
||||
return Effect::getEffect(Effect::POISON)->setDuration(80);
|
||||
return [Effect::getEffect(Effect::POISON)->setDuration(80)];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user