From f2b4769576c236d66a0eb9e04fc54af2ff772745 Mon Sep 17 00:00:00 2001 From: EmreTr1 Date: Mon, 21 Oct 2019 20:54:33 +0300 Subject: [PATCH] Updates from me 2 --- src/pocketmine/entity/hostile/Blaze.php | 3 +- src/pocketmine/entity/hostile/Dolphin.php | 2 +- src/pocketmine/entity/hostile/Skeleton.php | 3 +- .../entity/hostile/WitherSkeleton.php | 10 +- .../entity/hostile/ZombiePigman.php | 16 +- src/pocketmine/entity/passive/Chicken.php | 7 +- src/pocketmine/entity/passive/Cod.php | 7 +- src/pocketmine/entity/passive/Horse.php | 10 +- src/pocketmine/entity/passive/PolarBear.php | 6 +- src/pocketmine/entity/passive/Pufferfish.php | 9 +- src/pocketmine/entity/passive/Rabbit.php | 1 - src/pocketmine/entity/passive/Salmon.php | 7 +- .../entity/passive/SkeletonHorse.php | 38 +-- .../entity/passive/TropicalFish.php | 2 +- src/pocketmine/entity/passive/ZombieHorse.php | 237 ++++++++---------- 15 files changed, 154 insertions(+), 204 deletions(-) diff --git a/src/pocketmine/entity/hostile/Blaze.php b/src/pocketmine/entity/hostile/Blaze.php index e45f87e0fd9..05c4e47c7d3 100644 --- a/src/pocketmine/entity/hostile/Blaze.php +++ b/src/pocketmine/entity/hostile/Blaze.php @@ -75,7 +75,8 @@ public function getXpDropAmount() : int{ public function getDrops() : array{ return [ - ItemFactory::get(Item::BLAZE_ROD, 0, rand(0, 1)), ItemFactory::get(Item::GLOWSTONE_DUST, 0, rand(0, 2)) + ItemFactory::get(Item::BLAZE_ROD, 0, rand(0, 1)), + ItemFactory::get(Item::GLOWSTONE_DUST, 0, rand(0, 2)) ]; } diff --git a/src/pocketmine/entity/hostile/Dolphin.php b/src/pocketmine/entity/hostile/Dolphin.php index 134398f5fd4..66e41200b3d 100644 --- a/src/pocketmine/entity/hostile/Dolphin.php +++ b/src/pocketmine/entity/hostile/Dolphin.php @@ -53,6 +53,7 @@ class Dolphin extends WaterAnimal{ public function initEntity() : void{ $this->setMaxHealth(10); + $this->swimSpeed = 0.12; parent::initEntity(); } @@ -111,7 +112,6 @@ public function entityBaseTick(int $tickDiff = 1) : bool{ } }else{ $this->swimDirection = $this->generateRandomDirection(); - $this->swimSpeed = mt_rand(50, 100) / 2000; } $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); diff --git a/src/pocketmine/entity/hostile/Skeleton.php b/src/pocketmine/entity/hostile/Skeleton.php index b0a1d66362f..5f7045c624d 100644 --- a/src/pocketmine/entity/hostile/Skeleton.php +++ b/src/pocketmine/entity/hostile/Skeleton.php @@ -76,7 +76,8 @@ public function getName() : string{ public function getDrops() : array{ return [ - ItemFactory::get(Item::BONE, 0, rand(0, 2)), ItemFactory::get(Item::ARROW, 0, rand(0, 2)) + ItemFactory::get(Item::BONE, 0, rand(0, 2)), + ItemFactory::get(Item::ARROW, 0, rand(0, 2)) ]; } diff --git a/src/pocketmine/entity/hostile/WitherSkeleton.php b/src/pocketmine/entity/hostile/WitherSkeleton.php index a97e5264624..42eeff86670 100644 --- a/src/pocketmine/entity/hostile/WitherSkeleton.php +++ b/src/pocketmine/entity/hostile/WitherSkeleton.php @@ -74,21 +74,19 @@ public function getDrops() : array{ if(mt_rand(0, 2) < 1){ $drops[] = ItemFactory::get(Item::COAL, 0, 1); } - if(mt_rand(1, 40) ===1){ + if(mt_rand(1, 40) === 1){ $drops[] = ItemFactory::get(Item::MOB_HEAD, 1, 1); } return $drops; -} + } public function onCollideWithEntity(Entity $entity) : void{ parent::onCollideWithEntity($entity); if($this->getTargetEntityId() === $entity->getId() and $entity instanceof Living){ - $entity->addEffect(new EffectInstance(Effect::getEffect(Effect::WITHER), 200, 1)); - } + $entity->addEffect(new EffectInstance(Effect::getEffect(Effect::WITHER), 200, 1)); } - - + } public function getXpDropAmount() : int{ diff --git a/src/pocketmine/entity/hostile/ZombiePigman.php b/src/pocketmine/entity/hostile/ZombiePigman.php index 199bc079747..9b11dea8945 100644 --- a/src/pocketmine/entity/hostile/ZombiePigman.php +++ b/src/pocketmine/entity/hostile/ZombiePigman.php @@ -45,8 +45,8 @@ class ZombiePigman extends Monster implements Ageable{ public $width = 0.6; public $height = 1.95; - /** @var AltayEntityEquipment */ - protected $equipment; + /** @var AltayEntityEquipment */ + protected $equipment; protected function initEntity() : void{ $this->setMovementSpeed($this->isBaby() ? 0.35 : 0.23); @@ -55,9 +55,9 @@ protected function initEntity() : void{ parent::initEntity(); - $this->equipment = new AltayEntityEquipment($this); + $this->equipment = new AltayEntityEquipment($this); - $this->equipment->setItemInHand(ItemFactory::get(Item::GOLDEN_SWORD)); + $this->equipment->setItemInHand(ItemFactory::get(Item::GOLDEN_SWORD)); } public function getName() : string{ @@ -103,9 +103,9 @@ protected function addBehaviors() : void{ } - public function sendSpawnPacket(Player $player) : void{ - parent::sendSpawnPacket($player); + public function sendSpawnPacket(Player $player) : void{ + parent::sendSpawnPacket($player); - $this->equipment->sendContents([$player]); - } + $this->equipment->sendContents([$player]); + } } \ No newline at end of file diff --git a/src/pocketmine/entity/passive/Chicken.php b/src/pocketmine/entity/passive/Chicken.php index b843f677ecd..942ba87ed0e 100644 --- a/src/pocketmine/entity/passive/Chicken.php +++ b/src/pocketmine/entity/passive/Chicken.php @@ -68,7 +68,12 @@ protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); $this->behaviorPool->setBehavior(1, new PanicBehavior($this, 1.4)); $this->behaviorPool->setBehavior(2, new MateBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(3, new TemptBehavior($this, [Item::WHEAT_SEEDS, Item::PUMPKIN_SEEDS, Item::MELON_SEEDS, Item::BEETROOT_SEEDS], 1.0)); + $this->behaviorPool->setBehavior(3, new TemptBehavior($this, [ + Item::WHEAT_SEEDS, + Item::PUMPKIN_SEEDS, + Item::MELON_SEEDS, + Item::BEETROOT_SEEDS + ], 1.0)); $this->behaviorPool->setBehavior(4, new FollowParentBehavior($this, 1.1)); $this->behaviorPool->setBehavior(5, new RandomStrollBehavior($this, 1.0)); $this->behaviorPool->setBehavior(6, new LookAtPlayerBehavior($this, 6.0)); diff --git a/src/pocketmine/entity/passive/Cod.php b/src/pocketmine/entity/passive/Cod.php index c8405f45e8d..2ac8a80cb67 100644 --- a/src/pocketmine/entity/passive/Cod.php +++ b/src/pocketmine/entity/passive/Cod.php @@ -69,8 +69,6 @@ public function attack(EntityDamageEvent $source) : void{ if($e !== null){ $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); } - - } } @@ -94,7 +92,6 @@ public function entityBaseTick(int $tickDiff = 1) : bool{ $hasUpdate = parent::entityBaseTick($tickDiff); if($this->isAlive()){ - if($this->y > 62 and $this->swimDirection !== null){ $this->swimDirection->y = -0.5; } @@ -108,7 +105,7 @@ public function entityBaseTick(int $tickDiff = 1) : bool{ } }else{ $this->swimDirection = $this->generateRandomDirection(); - $this->swimSpeed = mt_rand(50, 100) / 2000; + $this->swimSpeed = 0.05; } $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); @@ -123,7 +120,7 @@ public function getDrops() : array{ $drops = [ ItemFactory::get(Item::RAW_FISH, 0, 1), ]; - if(mt_rand(1, 4) ===1){ + if(mt_rand(1, 4) === 1){ $drops[] = ItemFactory::get(Item::BONE, 1, mt_rand(1, 2)); } return $drops; diff --git a/src/pocketmine/entity/passive/Horse.php b/src/pocketmine/entity/passive/Horse.php index fe18c8cd590..5780b9e1d70 100644 --- a/src/pocketmine/entity/passive/Horse.php +++ b/src/pocketmine/entity/passive/Horse.php @@ -82,7 +82,15 @@ protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(1, new FloatBehavior($this)); $this->behaviorPool->setBehavior(2, new PanicBehavior($this, 1.25)); $this->behaviorPool->setBehavior(3, new MateBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(4, new TemptBehavior($this, [Item::WHEAT, Item::APPLE, Item::WHEAT_BLOCK, Item::GOLDEN_APPLE, Item::ENCHANTED_GOLDEN_APPLE, Item::GOLDEN_CARROT, Item::SUGAR], 1.2)); + $this->behaviorPool->setBehavior(4, new TemptBehavior($this, [ + Item::WHEAT, + Item::APPLE, + Item::WHEAT_BLOCK, + Item::GOLDEN_APPLE, + Item::ENCHANTED_GOLDEN_APPLE, + Item::GOLDEN_CARROT, + Item::SUGAR + ], 1.2)); $this->behaviorPool->setBehavior(5, new FollowParentBehavior($this, 1.1)); $this->behaviorPool->setBehavior(6, new RandomStrollBehavior($this, 1.0)); $this->behaviorPool->setBehavior(7, new LookAtPlayerBehavior($this, 6.0)); diff --git a/src/pocketmine/entity/passive/PolarBear.php b/src/pocketmine/entity/passive/PolarBear.php index 06cc1fa49f6..0cb1c4b8e27 100644 --- a/src/pocketmine/entity/passive/PolarBear.php +++ b/src/pocketmine/entity/passive/PolarBear.php @@ -63,7 +63,7 @@ public function initEntity() : void{ parent::initEntity(); } - //TODO: atack foxes + //TODO: attack fixes public function getName() : string{ return "Polar Bear"; } @@ -83,10 +83,6 @@ public function setAngry(bool $angry = true) : void{ $this->setGenericFlag(self::DATA_FLAG_ANGRY, $angry); } - private function generateRandomDirection() : Vector3{ - return new Vector3(mt_rand(-1000, 1000) / 1000, mt_rand(-500, 500) / 1000, mt_rand(-1000, 1000) / 1000); - } - public function getXpDropAmount() : int{ return rand(1, 3); } diff --git a/src/pocketmine/entity/passive/Pufferfish.php b/src/pocketmine/entity/passive/Pufferfish.php index 6cc6859f5f4..f6465f81874 100644 --- a/src/pocketmine/entity/passive/Pufferfish.php +++ b/src/pocketmine/entity/passive/Pufferfish.php @@ -33,6 +33,7 @@ use pocketmine\item\ItemFactory; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\ActorEventPacket; +use pocketmine\Player; use function atan2; use function mt_rand; use function sqrt; @@ -72,7 +73,6 @@ public function attack(EntityDamageEvent $source) : void{ if($e !== null){ $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); } - } } @@ -80,7 +80,6 @@ private function generateRandomDirection() : Vector3{ return new Vector3(mt_rand(-1000, 1000) / 1000, mt_rand(-500, 500) / 1000, mt_rand(-1000, 1000) / 1000); } - public function entityBaseTick(int $tickDiff = 1) : bool{ if($this->closed){ return false; @@ -110,7 +109,7 @@ public function entityBaseTick(int $tickDiff = 1) : bool{ } }else{ $this->swimDirection = $this->generateRandomDirection(); - $this->swimSpeed = mt_rand(50, 100) / 2000; + $this->swimSpeed = 0.05; } $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); @@ -132,13 +131,11 @@ public function onCollideWithEntity(Entity $entity) : void{ } - - public function getDrops() : array{ $drops = [ ItemFactory::get(Item::PUFFERFISH, 0, 1), ]; - if(mt_rand(1, 4) ===1){ + if(mt_rand(1, 4) === 1){ $drops[] = ItemFactory::get(Item::BONE, 1, mt_rand(1, 2)); } return $drops; diff --git a/src/pocketmine/entity/passive/Rabbit.php b/src/pocketmine/entity/passive/Rabbit.php index 1c4d45a20c8..d4a9a68d116 100644 --- a/src/pocketmine/entity/passive/Rabbit.php +++ b/src/pocketmine/entity/passive/Rabbit.php @@ -66,7 +66,6 @@ public function getName() : string{ return "Rabbit"; } - public function getXpDropAmount() : int{ return rand(1, 3); } diff --git a/src/pocketmine/entity/passive/Salmon.php b/src/pocketmine/entity/passive/Salmon.php index ebc41ceb2f9..4d5c96111eb 100644 --- a/src/pocketmine/entity/passive/Salmon.php +++ b/src/pocketmine/entity/passive/Salmon.php @@ -69,8 +69,6 @@ public function attack(EntityDamageEvent $source) : void{ if($e !== null){ $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); } - - } } @@ -78,7 +76,6 @@ private function generateRandomDirection() : Vector3{ return new Vector3(mt_rand(-1000, 1000) / 1000, mt_rand(-500, 500) / 1000, mt_rand(-1000, 1000) / 1000); } - public function entityBaseTick(int $tickDiff = 1) : bool{ if($this->closed){ return false; @@ -108,7 +105,7 @@ public function entityBaseTick(int $tickDiff = 1) : bool{ } }else{ $this->swimDirection = $this->generateRandomDirection(); - $this->swimSpeed = mt_rand(50, 100) / 2000; + $this->swimSpeed = 0.05; } $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); @@ -123,7 +120,7 @@ public function getDrops() : array{ $drops = [ ItemFactory::get(Item::RAW_SALMON, 0, 1), ]; - if(mt_rand(1, 4) ===1){ + if(mt_rand(1, 4) === 1){ $drops[] = ItemFactory::get(Item::BONE, 1, mt_rand(1, 2)); } return $drops; diff --git a/src/pocketmine/entity/passive/SkeletonHorse.php b/src/pocketmine/entity/passive/SkeletonHorse.php index 30458e4228e..bba85372233 100644 --- a/src/pocketmine/entity/passive/SkeletonHorse.php +++ b/src/pocketmine/entity/passive/SkeletonHorse.php @@ -46,20 +46,6 @@ class SkeletonHorse extends AbstractHorse implements InventoryHolder{ public const NETWORK_ID = self::SKELETON_HORSE; - public const HORSE_VARIANT_WHITE = 0; - public const HORSE_VARIANT_CREAMY = 1; - public const HORSE_VARIANT_CHESTNUT = 2; - public const HORSE_VARIANT_BROWN = 3; - public const HORSE_VARIANT_BLACK = 4; - public const HORSE_VARIANT_GRAY = 5; - public const HORSE_VARIANT_DARK_BROWN = 6; - - public const HORSE_MARK_VARIANT_NONE = 0; - public const HORSE_MARK_VARIANT_WHITE = 1; - public const HORSE_MARK_VARIANT_WHITE_FIELD = 2; - public const HORSE_MARK_VARIANT_WHITE_DOTS = 3; - public const HORSE_MARK_VARIANT_BLACK_DOTS = 4; - public $width = 1.4; public $height = 1.6; @@ -89,18 +75,11 @@ protected function addBehaviors() : void{ } protected function initEntity() : void{ - $this->setMaxHealth(15); + $this->setMaxHealth(15); $this->setMovementSpeed($this->getModifiedMovementSpeed()); $this->setJumpStrength($this->getModifiedJumpStrength()); $this->setFollowRange(35); - if($this->namedtag->hasTag("Variant", IntTag::class) and $this->namedtag->hasTag("MarkVariant", IntTag::class)){ - $this->setVariant($this->namedtag->getInt("Variant")); - $this->setMarkVariant($this->namedtag->getInt("MarkVariant")); - }else{ - $this->setVariant($this->random->nextBoundedInt(7)); - $this->setMarkVariant($this->random->nextBoundedInt(5)); - } $this->inventory = new HorseInventory($this); if($this->namedtag->hasTag("ArmorItem", CompoundTag::class)){ @@ -169,12 +148,11 @@ public function saveNBT() : void{ $this->namedtag->setTag($this->inventory->getArmor()->nbtSerialize(-1, "ArmorItem")); } } - public - function getDrops(): array - { - return [ - ItemFactory::get(Item::BONE, 0, mt_rand(0, 2)) - ]; - } - //TODO: add changing normal horse to skeleton by lightning + + public function getDrops() : array{ + return [ + ItemFactory::get(Item::BONE, 0, mt_rand(0, 2)) + ]; + } + //TODO: add changing normal horse to skeleton by lightning } \ No newline at end of file diff --git a/src/pocketmine/entity/passive/TropicalFish.php b/src/pocketmine/entity/passive/TropicalFish.php index 1808dd558ae..4f518fca403 100644 --- a/src/pocketmine/entity/passive/TropicalFish.php +++ b/src/pocketmine/entity/passive/TropicalFish.php @@ -103,7 +103,6 @@ public function initEntity() : void{ } $this->setMovementSpeed(0.12); - $this->swimSpeed = 0.12; parent::initEntity(); } @@ -161,6 +160,7 @@ public function entityBaseTick(int $tickDiff = 1) : bool{ } }else{ $this->swimDirection = $this->generateRandomDirection(); + $this->swimSpeed = 0.05; } $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); diff --git a/src/pocketmine/entity/passive/ZombieHorse.php b/src/pocketmine/entity/passive/ZombieHorse.php index 8f56ca81c76..bbc004ddbf0 100644 --- a/src/pocketmine/entity/passive/ZombieHorse.php +++ b/src/pocketmine/entity/passive/ZombieHorse.php @@ -43,136 +43,109 @@ class ZombieHorse extends AbstractHorse implements InventoryHolder{ - public const NETWORK_ID = self::ZOMBIE_HORSE; - - public const HORSE_VARIANT_WHITE = 0; - public const HORSE_VARIANT_CREAMY = 1; - public const HORSE_VARIANT_CHESTNUT = 2; - public const HORSE_VARIANT_BROWN = 3; - public const HORSE_VARIANT_BLACK = 4; - public const HORSE_VARIANT_GRAY = 5; - public const HORSE_VARIANT_DARK_BROWN = 6; - - public const HORSE_MARK_VARIANT_NONE = 0; - public const HORSE_MARK_VARIANT_WHITE = 1; - public const HORSE_MARK_VARIANT_WHITE_FIELD = 2; - public const HORSE_MARK_VARIANT_WHITE_DOTS = 3; - public const HORSE_MARK_VARIANT_BLACK_DOTS = 4; - - public $width = 1.4; - public $height = 1.6; - - /** @var HorseInventory */ - protected $inventory; - - public function getName() : string{ - return "Zombie Horse"; - } - - /** - * @return HorseInventory - */ - public function getInventory() : HorseInventory{ - return $this->inventory; - } - - protected function addBehaviors() : void{ - $this->behaviorPool->setBehavior(1, new FloatBehavior($this)); - $this->behaviorPool->setBehavior(2, new PanicBehavior($this, 1.25)); - $this->behaviorPool->setBehavior(3, new MateBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(5, new FollowParentBehavior($this, 1.1)); - $this->behaviorPool->setBehavior(6, new RandomStrollBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(7, new LookAtPlayerBehavior($this, 6.0)); - $this->behaviorPool->setBehavior(8, new RandomLookAroundBehavior($this)); - } - - protected function initEntity() : void{ - $this->setMaxHealth(15); - $this->setMovementSpeed($this->getModifiedMovementSpeed()); - $this->setJumpStrength($this->getModifiedJumpStrength()); - $this->setFollowRange(35); - - if($this->namedtag->hasTag("Variant", IntTag::class) and $this->namedtag->hasTag("MarkVariant", IntTag::class)){ - $this->setVariant($this->namedtag->getInt("Variant")); - $this->setMarkVariant($this->namedtag->getInt("MarkVariant")); - }else{ - $this->setVariant($this->random->nextBoundedInt(7)); - $this->setMarkVariant($this->random->nextBoundedInt(5)); - } - - $this->inventory = new HorseInventory($this); - - if($this->namedtag->hasTag("ArmorItem", CompoundTag::class)){ - $this->inventory->setArmor(Item::nbtDeserialize($this->namedtag->getCompoundTag("ArmorItem"))); - } - - if($this->namedtag->hasTag("SaddleItem", CompoundTag::class)){ - $this->inventory->setSaddle(Item::nbtDeserialize($this->namedtag->getCompoundTag("SaddleItem"))); - } - - parent::initEntity(); - } - - public function addAttributes() : void{ - parent::addAttributes(); - - $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::HORSE_JUMP_STRENGTH)); - } - - public function getRiderSeatPosition(int $seatNumber = 0) : Vector3{ - return new Vector3(0, 1.1, -0.2); - } - - public function setSaddled(bool $value = true) : void{ - parent::setSaddled($value); - - $this->setGenericFlag(self::DATA_FLAG_CAN_POWER_JUMP, $value); - } - - public function onInteract(Player $player, Item $item, Vector3 $clickPos) : bool{ - if(!$this->isImmobile()){ - // TODO: feeding - - if($player->isSneaking()){ - if($this->isTamed()){ - $player->addWindow($this->inventory); - }else{ - $this->rearUp(); - } - - return true; - } - } - return parent::onInteract($player, $item, $clickPos); - } - - public function sendSpawnPacket(Player $player) : void{ - parent::sendSpawnPacket($player); - - $this->inventory->sendArmor($player); - } - - public function doHitAnimation() : void{ - parent::doHitAnimation(); - - foreach($this->getViewers() as $player){ // WTF - $this->inventory->sendArmor($player); - } - } - - public function saveNBT() : void{ - parent::saveNBT(); - - if($this->inventory !== null){ - $this->namedtag->setTag($this->inventory->getSaddle()->nbtSerialize(-1, "SaddleItem")); - $this->namedtag->setTag($this->inventory->getArmor()->nbtSerialize(-1, "ArmorItem")); - } - } - public - function getDrops(): array - { - return [ - ItemFactory::get(Item::ROTTEN_FLESH, 0, mt_rand(0, 2)) - ]; - } + public const NETWORK_ID = self::ZOMBIE_HORSE; + + public $width = 1.4; + public $height = 1.6; + + /** @var HorseInventory */ + protected $inventory; + + public function getName() : string{ + return "Zombie Horse"; + } + + /** + * @return HorseInventory + */ + public function getInventory() : HorseInventory{ + return $this->inventory; + } + + protected function addBehaviors() : void{ + $this->behaviorPool->setBehavior(1, new FloatBehavior($this)); + $this->behaviorPool->setBehavior(2, new PanicBehavior($this, 1.25)); + $this->behaviorPool->setBehavior(3, new MateBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(5, new FollowParentBehavior($this, 1.1)); + $this->behaviorPool->setBehavior(6, new RandomStrollBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(7, new LookAtPlayerBehavior($this, 6.0)); + $this->behaviorPool->setBehavior(8, new RandomLookAroundBehavior($this)); + } + + protected function initEntity() : void{ + $this->setMaxHealth(15); + $this->setMovementSpeed($this->getModifiedMovementSpeed()); + $this->setJumpStrength($this->getModifiedJumpStrength()); + $this->setFollowRange(35); + + $this->inventory = new HorseInventory($this); + + if($this->namedtag->hasTag("SaddleItem", CompoundTag::class)){ + $this->inventory->setSaddle(Item::nbtDeserialize($this->namedtag->getCompoundTag("SaddleItem"))); + } + + parent::initEntity(); + } + + public function addAttributes() : void{ + parent::addAttributes(); + + $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::HORSE_JUMP_STRENGTH)); + } + + public function getRiderSeatPosition(int $seatNumber = 0) : Vector3{ + return new Vector3(0, 1.1, -0.2); + } + + public function setSaddled(bool $value = true) : void{ + parent::setSaddled($value); + + $this->setGenericFlag(self::DATA_FLAG_CAN_POWER_JUMP, $value); + } + + public function onInteract(Player $player, Item $item, Vector3 $clickPos) : bool{ + if(!$this->isImmobile()){ + // TODO: feeding + + if($player->isSneaking()){ + if($this->isTamed()){ + $player->addWindow($this->inventory); + }else{ + $this->rearUp(); + } + + return true; + } + } + return parent::onInteract($player, $item, $clickPos); + } + + public function sendSpawnPacket(Player $player) : void{ + parent::sendSpawnPacket($player); + + $this->inventory->sendArmor($player); + } + + public function doHitAnimation() : void{ + parent::doHitAnimation(); + + foreach($this->getViewers() as $player){ // WTF + $this->inventory->sendArmor($player); + } + } + + public function saveNBT() : void{ + parent::saveNBT(); + + if($this->inventory !== null){ + $this->namedtag->setTag($this->inventory->getSaddle()->nbtSerialize(-1, "SaddleItem")); + $this->namedtag->setTag($this->inventory->getArmor()->nbtSerialize(-1, "ArmorItem")); + } + } + + public function getDrops() : array{ + return [ + ItemFactory::get(Item::ROTTEN_FLESH, 0, mt_rand(0, 2)) + ]; + } } \ No newline at end of file