From b4b888b0d8e478cbc2dd1a7dac620fd51190da87 Mon Sep 17 00:00:00 2001 From: dearminder Date: Fri, 26 Jul 2019 13:09:41 +0200 Subject: [PATCH 01/13] Changed Blaze Power Changed CaveSpider name to Cave Spider Added ZombiePigman Added ZombieVillager Added rest Chicken tempt seeds Added Ocelot Changed Tempted Pig items Added PolarBear Added Rabbit Added Skeleton Horse Added Zombie Horse Added Tempted Wolf Behaviour Changed Default gamerule for spawningmobs to true Changed Creative Inventory Egg for Zombie VIllager to Correct one --- src/pocketmine/entity/Entity.php | 14 ++ src/pocketmine/entity/hostile/Blaze.php | 2 +- src/pocketmine/entity/hostile/CaveSpider.php | 2 +- .../entity/hostile/ZombiePigman.php | 111 +++++++++++ .../entity/hostile/ZombieVillager.php | 105 ++++++++++ src/pocketmine/entity/passive/Chicken.php | 2 +- src/pocketmine/entity/passive/Ocelot.php | 125 ++++++++++++ src/pocketmine/entity/passive/Pig.php | 2 +- src/pocketmine/entity/passive/PolarBear.php | 105 ++++++++++ src/pocketmine/entity/passive/Rabbit.php | 79 ++++++++ .../entity/passive/SkeletonHorse.php | 181 ++++++++++++++++++ src/pocketmine/entity/passive/Wolf.php | 10 +- src/pocketmine/entity/passive/ZombieHorse.php | 178 +++++++++++++++++ src/pocketmine/level/GameRules.php | 2 +- 14 files changed, 909 insertions(+), 9 deletions(-) create mode 100644 src/pocketmine/entity/hostile/ZombiePigman.php create mode 100644 src/pocketmine/entity/hostile/ZombieVillager.php create mode 100644 src/pocketmine/entity/passive/Ocelot.php create mode 100644 src/pocketmine/entity/passive/PolarBear.php create mode 100644 src/pocketmine/entity/passive/Rabbit.php create mode 100644 src/pocketmine/entity/passive/SkeletonHorse.php create mode 100644 src/pocketmine/entity/passive/ZombieHorse.php diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 87023f31001..a78002a44e4 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -40,6 +40,8 @@ use pocketmine\entity\hostile\Spider; use pocketmine\entity\hostile\Stray; use pocketmine\entity\hostile\Zombie; +use pocketmine\entity\hostile\ZombiePigman; +use pocketmine\entity\hostile\ZombieVillager; use pocketmine\entity\object\ArmorStand; use pocketmine\entity\object\ExperienceOrb; use pocketmine\entity\object\FallingBlock; @@ -54,11 +56,16 @@ use pocketmine\entity\passive\Cow; use pocketmine\entity\passive\Horse; use pocketmine\entity\passive\Mooshroom; +use pocketmine\entity\passive\Ocelot; use pocketmine\entity\passive\Pig; +use pocketmine\entity\passive\PolarBear; +use pocketmine\entity\passive\Rabbit; use pocketmine\entity\passive\Sheep; +use pocketmine\entity\passive\SkeletonHorse; use pocketmine\entity\passive\Squid; use pocketmine\entity\passive\Villager; use pocketmine\entity\passive\Wolf; +use pocketmine\entity\passive\ZombieHorse; use pocketmine\entity\projectile\Arrow; use pocketmine\entity\projectile\Egg; use pocketmine\entity\projectile\EnderPearl; @@ -382,12 +389,19 @@ public static function init() : void{ Entity::registerEntity(Villager::class, false, ['Villager', 'minecraft:villager']); Entity::registerEntity(Wolf::class, false, ['Wolf', 'minecraft:wolf']); Entity::registerEntity(Zombie::class, false, ['Zombie', 'minecraft:zombie']); + Entity::registerEntity(ZombieHorse::class, false, ['ZombieHorse', 'minecraft:zombiehorse']); Entity::registerEntity(Cow::class, false, ['Cow', 'minecraft:cow']); Entity::registerEntity(Sheep::class, false, ['Sheep', 'minecraft:sheep']); Entity::registerEntity(Mooshroom::class, false, ['Mooshroom', 'minecraft:mooshroom']); + Entity::registerEntity(Ocelot::class, false, ['Ocelot', 'minecraft:ocelot']); Entity::registerEntity(Pig::class, false, ['Pig', 'minecraft:pig']); + Entity::registerEntity(ZombiePigman::class, false, ['ZombiePigman', 'minecraft:zombiepigman']); + Entity::registerEntity(ZombieVillager::class, false, ['ZombieVillager', 'minecraft:zombievillager']); + Entity::registerEntity(PolarBear::class, false, ['PolarBear', 'minecraft:polarbear']); + Entity::registerEntity(Rabbit::class, false, ['Rabbit', 'minecraft:rabbit']); Entity::registerEntity(Cat::class, false, ['Cat', 'minecraft:cat']); Entity::registerEntity(Skeleton::class, false, ['Skeleton', 'minecraft:skeleton']); + Entity::registerEntity(SkeletonHorse::class, false, ['SkeletonHorse', 'minecraft:skeletonhorse']); Entity::registerEntity(Stray::class, false, ['Stray', 'minecraft:stray']); Entity::registerEntity(Husk::class, false, ['Husk', 'minecraft:husk']); Entity::registerEntity(Chicken::class, false, ['Chicken', 'minecraft:chicken']); diff --git a/src/pocketmine/entity/hostile/Blaze.php b/src/pocketmine/entity/hostile/Blaze.php index 507702994a8..af88dc08386 100644 --- a/src/pocketmine/entity/hostile/Blaze.php +++ b/src/pocketmine/entity/hostile/Blaze.php @@ -95,7 +95,7 @@ public function onBehaviorUpdate() : void{ public function onRangedAttackToTarget(Entity $target, float $power) : void{ $dv = $target->subtract($this)->normalize(); $fireball = new SmallFireball($this->level, Entity::createBaseNBT($this->add($this->random->nextFloat() * $power, $this->getEyeHeight(), $this->random->nextFloat() * $power), $dv), $this); - $fireball->setMotion($dv->multiply($power)); + $fireball->setMotion($dv->multiply(2)); $fireball->spawnToAll(); } diff --git a/src/pocketmine/entity/hostile/CaveSpider.php b/src/pocketmine/entity/hostile/CaveSpider.php index fca33e8f798..9761e663887 100644 --- a/src/pocketmine/entity/hostile/CaveSpider.php +++ b/src/pocketmine/entity/hostile/CaveSpider.php @@ -44,7 +44,7 @@ protected function initEntity() : void{ } public function getName() : string{ - return "CaveSpider"; + return "Cave Spider"; } public function onCollideWithEntity(Entity $entity) : void{ diff --git a/src/pocketmine/entity/hostile/ZombiePigman.php b/src/pocketmine/entity/hostile/ZombiePigman.php new file mode 100644 index 00000000000..24698975e0a --- /dev/null +++ b/src/pocketmine/entity/hostile/ZombiePigman.php @@ -0,0 +1,111 @@ +setMovementSpeed($this->isBaby() ? 0.35 : 0.23); + $this->setFollowRange(35); + $this->setAttackDamage(3); + + parent::initEntity(); + + $this->equipment = new AltayEntityEquipment($this); + + $this->equipment->setItemInHand(ItemFactory::get(Item::GOLDEN_SWORD)); + } + + public function getName() : string{ + return "Zombie Pigman"; + } + + public function getDrops() : array{ + $drops = [ + ItemFactory::get(Item::ROTTEN_FLESH, 0, mt_rand(0, 1)) + ]; + + if(mt_rand(0, 199) < 5){ + switch(mt_rand(0, 2)){ + case 0: + $drops[] = ItemFactory::get(Item::IRON_INGOT, 0, 1); + break; + case 1: + $drops[] = ItemFactory::get(Item::CARROT, 0, 1); + break; + case 2: + $drops[] = ItemFactory::get(Item::POTATO, 0, 1); + break; + } + } + + return $drops; + } + + public function getXpDropAmount() : int{ + //TODO: check for equipment + return $this->isBaby() ? 12 : 5; + } + + protected function addBehaviors() : void{ + $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); + $this->behaviorPool->setBehavior(1, new MeleeAttackBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(2, new WanderBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(3, new LookAtPlayerBehavior($this, 8.0)); + $this->behaviorPool->setBehavior(4, new RandomLookAroundBehavior($this)); + + $this->targetBehaviorPool->setBehavior(1, new FindAttackableTargetBehavior($this, Player::class)); + $this->targetBehaviorPool->setBehavior(2, new FindAttackableTargetBehavior($this, Villager::class)); + } + + + public function sendSpawnPacket(Player $player) : void{ + parent::sendSpawnPacket($player); + + $this->equipment->sendContents([$player]); + } +} \ No newline at end of file diff --git a/src/pocketmine/entity/hostile/ZombieVillager.php b/src/pocketmine/entity/hostile/ZombieVillager.php new file mode 100644 index 00000000000..7f274bbe69d --- /dev/null +++ b/src/pocketmine/entity/hostile/ZombieVillager.php @@ -0,0 +1,105 @@ +setMovementSpeed($this->isBaby() ? 0.35 : 0.23); + $this->setFollowRange(35); + $this->setAttackDamage(3); + + parent::initEntity(); + } + + public function getName() : string{ + return "Zombie Villager"; + } + + public function getDrops() : array{ + $drops = [ + ItemFactory::get(Item::ROTTEN_FLESH, 0, mt_rand(0, 2)) + ]; + + if(mt_rand(0, 199) < 5){ + switch(mt_rand(0, 2)){ + case 0: + $drops[] = ItemFactory::get(Item::IRON_INGOT, 0, 1); + break; + case 1: + $drops[] = ItemFactory::get(Item::CARROT, 0, 1); + break; + case 2: + $drops[] = ItemFactory::get(Item::POTATO, 0, 1); + break; + } + } + + return $drops; + } + + public function getXpDropAmount() : int{ + //TODO: check for equipment + return $this->isBaby() ? 12 : 5; + } + + protected function addBehaviors() : void{ + $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); + $this->behaviorPool->setBehavior(1, new MeleeAttackBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(2, new WanderBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(3, new LookAtPlayerBehavior($this, 8.0)); + $this->behaviorPool->setBehavior(4, new RandomLookAroundBehavior($this)); + + $this->targetBehaviorPool->setBehavior(1, new FindAttackableTargetBehavior($this, Player::class)); + $this->targetBehaviorPool->setBehavior(2, new FindAttackableTargetBehavior($this, Villager::class)); + } + + public function entityBaseTick(int $diff = 1) : bool{ + if(!$this->isOnFire() and $this->level->isDayTime() and !$this->isImmobile()){ + if(!$this->isInsideOfWater() and $this->level->canSeeSky($this)){ + $this->setOnFire(5); + } + } + return parent::entityBaseTick($diff); + } +} \ No newline at end of file diff --git a/src/pocketmine/entity/passive/Chicken.php b/src/pocketmine/entity/passive/Chicken.php index 25972f3835a..4b33f9540e3 100644 --- a/src/pocketmine/entity/passive/Chicken.php +++ b/src/pocketmine/entity/passive/Chicken.php @@ -68,7 +68,7 @@ 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 TemptedBehavior($this, [Item::WHEAT_SEEDS], 1.0)); + $this->behaviorPool->setBehavior(3, new TemptedBehavior($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 WanderBehavior($this, 1.0)); $this->behaviorPool->setBehavior(6, new LookAtPlayerBehavior($this, 6.0)); diff --git a/src/pocketmine/entity/passive/Ocelot.php b/src/pocketmine/entity/passive/Ocelot.php new file mode 100644 index 00000000000..b37ac557787 --- /dev/null +++ b/src/pocketmine/entity/passive/Ocelot.php @@ -0,0 +1,125 @@ +behaviorPool->setBehavior(0, new FloatBehavior($this)); + $this->behaviorPool->setBehavior(1, new MateBehavior($this, 2.0)); + $this->behaviorPool->setBehavior(2, new FollowOwnerBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(3, new PanicBehavior($this, 2.0)); + $this->behaviorPool->setBehavior(4, new LookAtPlayerBehavior($this, 14.0)); + $this->behaviorPool->setBehavior(5, new RandomLookAroundBehavior($this)); + $this->behaviorPool->setBehavior(6, new TemptedBehavior($this, [Item::RAW_SALMON, Item::RAW_FISH], 1.0)); + $this->behaviorPool->setBehavior(7, new SittingBehavior($this)); + // TODO: attack turtle and rabbit + } + + protected function initEntity() : void{ + $this->setMaxHealth(10); + $this->setMovementSpeed(0.3); + $this->setFollowRange(16); + $this->setAttackDamage(3); + $this->propertyManager->setInt(self::DATA_VARIANT, intval($this->namedtag->getInt("CatType", 0))); + $this->propertyManager->setInt(self::DATA_COLOR, intval($this->namedtag->getInt("CollarColor", mt_rand(0, 15)))); + parent::initEntity(); + } + + public function getName() : string{ + return "Ocelot"; + } + + public function onInteract(Player $player, Item $item, Vector3 $clickPos) : bool{ + if(!$this->isImmobile()){ + if($item->getId() == Item::RAW_SALMON || $item->getId() == Item::RAW_FISH){ + if($player->isSurvival()){ + $item->pop(); + } + if($this->isTamed()){ + $this->setInLove(true); + $this->setHealth(min($this->getMaxHealth(), $this->getHealth() + 2)); + }elseif(mt_rand(0, 2) == 0){ + $this->setOwningEntity($player); + $this->setTamed(); + $this->setSitting(); + $this->broadcastEntityEvent(ActorEventPacket::TAME_SUCCESS); + }else{ + $this->broadcastEntityEvent(ActorEventPacket::TAME_FAIL); + } + return true; + }else{ + if($this->isTamed()){ + $this->setSitting(!$this->isSitting()); + } + } + } + return parent::onInteract($player, $item, $clickPos); + } + + public function getXpDropAmount() : int{ + $damage = $this->getLastDamageCause(); + if($damage instanceof EntityDamageByEntityEvent){ + $damager = $damage->getDamager(); + if($damager instanceof Player || ($damager instanceof Wolf && $damager->isTamed())){ + return rand(1, ($this->isInLove() ? 7 : 3)); + } + } + return 0; + } + + public function getDrops() : array{ + return [ + ItemFactory::get(Item::STRING, 0, rand(0, 2)), + ]; + } + + public function attack(EntityDamageEvent $source) : void{ + if($source->getCause() !== EntityDamageEvent::CAUSE_FALL){ + parent::attack($source); + } + } +} \ No newline at end of file diff --git a/src/pocketmine/entity/passive/Pig.php b/src/pocketmine/entity/passive/Pig.php index 5e685b7f692..f783215f570 100644 --- a/src/pocketmine/entity/passive/Pig.php +++ b/src/pocketmine/entity/passive/Pig.php @@ -52,7 +52,7 @@ protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); $this->behaviorPool->setBehavior(1, new PanicBehavior($this, 1.25)); $this->behaviorPool->setBehavior(2, new MateBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(3, new TemptedBehavior($this, [Item::WHEAT], 1.2)); + $this->behaviorPool->setBehavior(3, new TemptedBehavior($this, [Item::CARROT, Item::CARROT_ON_A_STICK, Item::POTATO, Item::BEETROOT], 1.2)); // TODO: Add ControlledByPlayerBehavior $this->behaviorPool->setBehavior(4, new FollowParentBehavior($this, 1.1)); $this->behaviorPool->setBehavior(5, new WanderBehavior($this, 1.0)); diff --git a/src/pocketmine/entity/passive/PolarBear.php b/src/pocketmine/entity/passive/PolarBear.php new file mode 100644 index 00000000000..d8e684c1a67 --- /dev/null +++ b/src/pocketmine/entity/passive/PolarBear.php @@ -0,0 +1,105 @@ +behaviorPool->setBehavior(0, new FloatBehavior($this)); + $this->behaviorPool->setBehavior(1, new MateBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(2, new MeleeAttackBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(3, new FollowParentBehavior($this, 1.1)); + $this->behaviorPool->setBehavior(4, new WanderBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(5, new LookAtPlayerBehavior($this, 16.0)); + $this->behaviorPool->setBehavior(6, new RandomLookAroundBehavior($this)); + + $this->targetBehaviorPool->setBehavior(0, new HurtByTargetBehavior($this)); + } + public + function initEntity(): void + { + $this->setMaxHealth(30); + $this->setMovementSpeed(0.30); + $this->setAttackDamage(4); + $this->setFollowRange(16); + parent::initEntity(); + } + //TODO: atack foxes + public + function getName(): string + { + return "Polar Bear"; + } + + public function setTargetEntity(?Entity $target) : void{ + parent::setTargetEntity($target); + if($target == null){ + $this->setAngry(false); + } + } + public function isAngry() : bool{ + return $this->getGenericFlag(self::DATA_FLAG_ANGRY); + } + + 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); + } + + public + function getDrops(): array + { + return [ + ItemFactory::get(Item::RAW_SALMON, 0, mt_rand(0, 2)) + ]; + } + } \ No newline at end of file diff --git a/src/pocketmine/entity/passive/Rabbit.php b/src/pocketmine/entity/passive/Rabbit.php new file mode 100644 index 00000000000..f1e20d5a5a1 --- /dev/null +++ b/src/pocketmine/entity/passive/Rabbit.php @@ -0,0 +1,79 @@ +behaviorPool->setBehavior(0, new FloatBehavior($this)); + $this->behaviorPool->setBehavior(1, new MateBehavior($this, 2.0)); + $this->behaviorPool->setBehavior(3, new PanicBehavior($this, 2.0)); + $this->behaviorPool->setBehavior(4, new LookAtPlayerBehavior($this, 14.0)); + $this->behaviorPool->setBehavior(5, new RandomLookAroundBehavior($this)); + $this->behaviorPool->setBehavior(6, new TemptedBehavior($this, [Item::CARROT], 1.0)); + // TODO: running away from player + } + + protected function initEntity() : void{ + $this->setMaxHealth(3); + $this->setMovementSpeed(0.3); + $this->setFollowRange(16); + $this->propertyManager->setInt(self::DATA_VARIANT, intval($this->namedtag->getInt("RabbitType", mt_rand(1, 6)))); + + parent::initEntity(); + } + + public function getName() : string{ + return "Rabbit"; + } + + + + public function getXpDropAmount() : int{ + return rand(1, 3); + } + + public function getDrops() : array{ + return [ + ItemFactory::get(Item::RABBIT_HIDE, 0, rand(0, 1)), + ($this->isOnFire() ? ItemFactory::get(Item::COOKED_RABBIT, 0, rand(0, 1)) : ItemFactory::get(Item::RAW_RABBIT, 0, rand(0, 1))) + ]; + } +} \ No newline at end of file diff --git a/src/pocketmine/entity/passive/SkeletonHorse.php b/src/pocketmine/entity/passive/SkeletonHorse.php new file mode 100644 index 00000000000..d2897ad117d --- /dev/null +++ b/src/pocketmine/entity/passive/SkeletonHorse.php @@ -0,0 +1,181 @@ +inventory; + } + + protected function addBehaviors() : void{ + $this->behaviorPool->setBehavior(0, new HorseRiddenBehavior($this)); + $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 WanderBehavior($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::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/Wolf.php b/src/pocketmine/entity/passive/Wolf.php index 84697b635fb..1b4e1abfcaa 100644 --- a/src/pocketmine/entity/passive/Wolf.php +++ b/src/pocketmine/entity/passive/Wolf.php @@ -34,6 +34,7 @@ use pocketmine\entity\behavior\OwnerHurtTargetBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; use pocketmine\entity\behavior\SittingBehavior; +use pocketmine\entity\behavior\TemptedBehavior; use pocketmine\entity\behavior\WanderBehavior; use pocketmine\entity\Entity; use pocketmine\entity\Tamable; @@ -54,10 +55,11 @@ protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(1, new SittingBehavior($this)); $this->behaviorPool->setBehavior(2, new JumpAttackBehavior($this, 1.0)); $this->behaviorPool->setBehavior(3, new MeleeAttackBehavior($this, 2.0)); - $this->behaviorPool->setBehavior(4, new FollowOwnerBehavior($this, 2.0)); - $this->behaviorPool->setBehavior(5, new WanderBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(6, new LookAtPlayerBehavior($this, 8.0)); - $this->behaviorPool->setBehavior(7, new RandomLookAroundBehavior($this)); + $this->behaviorPool->setBehavior(4, new TemptedBehavior($this, [Item::BONE], 0.8)); + $this->behaviorPool->setBehavior(5, new FollowOwnerBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(6, new WanderBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(7, new LookAtPlayerBehavior($this, 8.0)); + $this->behaviorPool->setBehavior(8, new RandomLookAroundBehavior($this)); $this->targetBehaviorPool->setBehavior(0, new HurtByTargetBehavior($this)); $this->targetBehaviorPool->setBehavior(1, new OwnerHurtByTargetBehavior($this)); diff --git a/src/pocketmine/entity/passive/ZombieHorse.php b/src/pocketmine/entity/passive/ZombieHorse.php new file mode 100644 index 00000000000..361897bd494 --- /dev/null +++ b/src/pocketmine/entity/passive/ZombieHorse.php @@ -0,0 +1,178 @@ +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 WanderBehavior($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)) + ]; + } +} \ No newline at end of file diff --git a/src/pocketmine/level/GameRules.php b/src/pocketmine/level/GameRules.php index c3ed40f4037..1e78eeecfad 100644 --- a/src/pocketmine/level/GameRules.php +++ b/src/pocketmine/level/GameRules.php @@ -71,7 +71,7 @@ public function __construct(){ $this->setBool(self::RULE_DO_FIRE_TICK, true); $this->setBool(self::RULE_DO_INSOMNIA, true); $this->setBool(self::RULE_DO_MOB_LOOT, true); - $this->setBool(self::RULE_DO_MOB_SPAWNING, false); + $this->setBool(self::RULE_DO_MOB_SPAWNING, true); $this->setBool(self::RULE_DO_TILE_DROPS, true); $this->setBool(self::RULE_DO_WEATHER_CYCLE, true); $this->setBool(self::RULE_DROWNING_DAMAGE, true); From d4024fa4e3487e03ba33709569d8de09a1d455a7 Mon Sep 17 00:00:00 2001 From: dearminder Date: Fri, 26 Jul 2019 19:50:06 +0200 Subject: [PATCH 02/13] Added Cod and Tropical Fish --- src/pocketmine/entity/Entity.php | 4 + src/pocketmine/entity/passive/Cod.php | 134 ++++++++++++++++++ .../entity/passive/TropicalFish.php | 134 ++++++++++++++++++ 3 files changed, 272 insertions(+) create mode 100644 src/pocketmine/entity/passive/Cod.php create mode 100644 src/pocketmine/entity/passive/TropicalFish.php diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index a78002a44e4..e4fa7d8b946 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -53,6 +53,7 @@ use pocketmine\entity\object\ItemEntity; use pocketmine\entity\passive\Cat; use pocketmine\entity\passive\Chicken; +use pocketmine\entity\passive\Cod; use pocketmine\entity\passive\Cow; use pocketmine\entity\passive\Horse; use pocketmine\entity\passive\Mooshroom; @@ -63,6 +64,7 @@ use pocketmine\entity\passive\Sheep; use pocketmine\entity\passive\SkeletonHorse; use pocketmine\entity\passive\Squid; +use pocketmine\entity\passive\TropicalFish; use pocketmine\entity\passive\Villager; use pocketmine\entity\passive\Wolf; use pocketmine\entity\passive\ZombieHorse; @@ -386,6 +388,8 @@ public static function init() : void{ Entity::registerEntity(Snowball::class, false, ['Snowball', 'minecraft:snowball']); Entity::registerEntity(SplashPotion::class, false, ['ThrownPotion', 'minecraft:potion', 'thrownpotion']); Entity::registerEntity(Squid::class, false, ['Squid', 'minecraft:squid']); + Entity::registerEntity(TropicalFish::class, false, ['TropicalFish', 'minecraft:tropicalfish']); + Entity::registerEntity(Cod::class, false, ['Cod', 'minecraft:cod']); Entity::registerEntity(Villager::class, false, ['Villager', 'minecraft:villager']); Entity::registerEntity(Wolf::class, false, ['Wolf', 'minecraft:wolf']); Entity::registerEntity(Zombie::class, false, ['Zombie', 'minecraft:zombie']); diff --git a/src/pocketmine/entity/passive/Cod.php b/src/pocketmine/entity/passive/Cod.php new file mode 100644 index 00000000000..6db4ea624f0 --- /dev/null +++ b/src/pocketmine/entity/passive/Cod.php @@ -0,0 +1,134 @@ +setMaxHealth(3); + + parent::initEntity(); + } + + public function getName() : string{ + return "Tropical Fish"; + } + + public function attack(EntityDamageEvent $source) : void{ + parent::attack($source); + if($source->isCancelled()){ + return; + } + + if($source instanceof EntityDamageByEntityEvent){ + $this->swimSpeed = mt_rand(150, 350) / 2000; + $e = $source->getDamager(); + if($e !== null){ + $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); + } + + $this->broadcastEntityEvent(ActorEventPacket::SQUID_INK_CLOUD); + } + } + + 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; + } + + if(++$this->switchDirectionTicker === 100 or $this->isCollided){ + $this->switchDirectionTicker = 0; + if(mt_rand(0, 100) < 50){ + $this->swimDirection = null; + } + } + + $hasUpdate = parent::entityBaseTick($tickDiff); + + if($this->isAlive()){ + + if($this->y > 62 and $this->swimDirection !== null){ + $this->swimDirection->y = -0.5; + } + + $inWater = $this->isUnderwater(); + if(!$inWater){ + $this->swimDirection = null; + }elseif($this->swimDirection !== null){ + if($this->motion->lengthSquared() <= $this->swimDirection->lengthSquared()){ + $this->motion = $this->swimDirection->multiply($this->swimSpeed); + } + }else{ + $this->swimDirection = $this->generateRandomDirection(); + $this->swimSpeed = mt_rand(50, 100) / 2000; + } + + $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); + $this->yaw = (-atan2($this->motion->x, $this->motion->z) * 180 / M_PI); + $this->pitch = (-atan2($f, $this->motion->y) * 180 / M_PI); + } + + return $hasUpdate; + } + + public function getDrops() : array{ + return [ + ItemFactory::get(Item::RAW_FISH, 0, 1), + //TODO: Add percentage drop for bone + ]; + } + + protected function applyGravity() : void{ + if(!$this->isUnderwater()){ + parent::applyGravity(); + } + } +} \ No newline at end of file diff --git a/src/pocketmine/entity/passive/TropicalFish.php b/src/pocketmine/entity/passive/TropicalFish.php new file mode 100644 index 00000000000..f82081aefce --- /dev/null +++ b/src/pocketmine/entity/passive/TropicalFish.php @@ -0,0 +1,134 @@ +setMaxHealth(3); + //TODO: Add diffrent styles of fish + parent::initEntity(); + } + + public function getName() : string{ + return "Tropical Fish"; + } + + public function attack(EntityDamageEvent $source) : void{ + parent::attack($source); + if($source->isCancelled()){ + return; + } + + if($source instanceof EntityDamageByEntityEvent){ + $this->swimSpeed = mt_rand(150, 350) / 2000; + $e = $source->getDamager(); + if($e !== null){ + $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); + } + + $this->broadcastEntityEvent(ActorEventPacket::SQUID_INK_CLOUD); + } + } + + 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; + } + + if(++$this->switchDirectionTicker === 100 or $this->isCollided){ + $this->switchDirectionTicker = 0; + if(mt_rand(0, 100) < 50){ + $this->swimDirection = null; + } + } + + $hasUpdate = parent::entityBaseTick($tickDiff); + + if($this->isAlive()){ + + if($this->y > 62 and $this->swimDirection !== null){ + $this->swimDirection->y = -0.5; + } + + $inWater = $this->isUnderwater(); + if(!$inWater){ + $this->swimDirection = null; + }elseif($this->swimDirection !== null){ + if($this->motion->lengthSquared() <= $this->swimDirection->lengthSquared()){ + $this->motion = $this->swimDirection->multiply($this->swimSpeed); + } + }else{ + $this->swimDirection = $this->generateRandomDirection(); + $this->swimSpeed = mt_rand(50, 100) / 2000; + } + + $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); + $this->yaw = (-atan2($this->motion->x, $this->motion->z) * 180 / M_PI); + $this->pitch = (-atan2($f, $this->motion->y) * 180 / M_PI); + } + + return $hasUpdate; + } + + public function getDrops() : array{ + return [ + ItemFactory::get(Item::CLOWNFISH, 0, 1), + //TODO: Add percentage drop for bone + ]; + } + + protected function applyGravity() : void{ + if(!$this->isUnderwater()){ + parent::applyGravity(); + } + } +} \ No newline at end of file From a5962621f90584789a95e98d11734613c680acd1 Mon Sep 17 00:00:00 2001 From: dearminder Date: Sat, 27 Jul 2019 14:44:09 +0200 Subject: [PATCH 03/13] Added WitherSkeleton, Dolphin, Pufferfish, Salmon Added percentage drop for Cod, TropicalFish, PolarBear --- src/pocketmine/entity/Entity.php | 8 + .../entity/hostile/WitherSkeleton.php | 116 +++++++++++++ src/pocketmine/entity/passive/Cod.php | 9 +- src/pocketmine/entity/passive/Dolphin.php | 139 ++++++++++++++++ src/pocketmine/entity/passive/PolarBear.php | 11 +- src/pocketmine/entity/passive/Pufferfish.php | 152 ++++++++++++++++++ src/pocketmine/entity/passive/Salmon.php | 137 ++++++++++++++++ .../entity/passive/TropicalFish.php | 9 +- 8 files changed, 572 insertions(+), 9 deletions(-) create mode 100644 src/pocketmine/entity/hostile/WitherSkeleton.php create mode 100644 src/pocketmine/entity/passive/Dolphin.php create mode 100644 src/pocketmine/entity/passive/Pufferfish.php create mode 100644 src/pocketmine/entity/passive/Salmon.php diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index e4fa7d8b946..a1d1ece4c8a 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -39,6 +39,7 @@ use pocketmine\entity\hostile\Skeleton; use pocketmine\entity\hostile\Spider; use pocketmine\entity\hostile\Stray; +use pocketmine\entity\hostile\WitherSkeleton; use pocketmine\entity\hostile\Zombie; use pocketmine\entity\hostile\ZombiePigman; use pocketmine\entity\hostile\ZombieVillager; @@ -54,6 +55,9 @@ use pocketmine\entity\passive\Cat; use pocketmine\entity\passive\Chicken; use pocketmine\entity\passive\Cod; +use pocketmine\entity\passive\Dolphin; +use pocketmine\entity\passive\Pufferfish; +use pocketmine\entity\passive\Salmon; use pocketmine\entity\passive\Cow; use pocketmine\entity\passive\Horse; use pocketmine\entity\passive\Mooshroom; @@ -390,6 +394,9 @@ public static function init() : void{ Entity::registerEntity(Squid::class, false, ['Squid', 'minecraft:squid']); Entity::registerEntity(TropicalFish::class, false, ['TropicalFish', 'minecraft:tropicalfish']); Entity::registerEntity(Cod::class, false, ['Cod', 'minecraft:cod']); + Entity::registerEntity(Pufferfish::class, false, ['Pufferfish', 'minecraft:pufferfish']); + Entity::registerEntity(Dolphin::class, false, ['Dolphin', 'minecraft:dolphin']); + Entity::registerEntity(Salmon::class, false, ['Salmon', 'minecraft:salmon']); Entity::registerEntity(Villager::class, false, ['Villager', 'minecraft:villager']); Entity::registerEntity(Wolf::class, false, ['Wolf', 'minecraft:wolf']); Entity::registerEntity(Zombie::class, false, ['Zombie', 'minecraft:zombie']); @@ -401,6 +408,7 @@ public static function init() : void{ Entity::registerEntity(Pig::class, false, ['Pig', 'minecraft:pig']); Entity::registerEntity(ZombiePigman::class, false, ['ZombiePigman', 'minecraft:zombiepigman']); Entity::registerEntity(ZombieVillager::class, false, ['ZombieVillager', 'minecraft:zombievillager']); + Entity::registerEntity(WitherSkeleton::class, false, ['WitherSkeleton', 'minecraft:witherskeleon']); Entity::registerEntity(PolarBear::class, false, ['PolarBear', 'minecraft:polarbear']); Entity::registerEntity(Rabbit::class, false, ['Rabbit', 'minecraft:rabbit']); Entity::registerEntity(Cat::class, false, ['Cat', 'minecraft:cat']); diff --git a/src/pocketmine/entity/hostile/WitherSkeleton.php b/src/pocketmine/entity/hostile/WitherSkeleton.php new file mode 100644 index 00000000000..43432f11b6d --- /dev/null +++ b/src/pocketmine/entity/hostile/WitherSkeleton.php @@ -0,0 +1,116 @@ +setMovementSpeed(0.3); + $this->setFollowRange(35); + $this->setAttackDamage(3); + + parent::initEntity(); + + $this->equipment = new AltayEntityEquipment($this); + + $this->equipment->setItemInHand(ItemFactory::get(Item::STONE_SWORD)); + } + + public function getName() : string{ + return "Wither Skeleton"; + } + + public function getDrops() : array{ + $drops = [ + ItemFactory::get(Item::BONE, 0, mt_rand(0, 1)) + ]; + + if(mt_rand(0, 2) < 1){ + $drops[] = ItemFactory::get(Item::COAL, 0, 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($entity instanceof Player){ + if($this->getTargetEntity() === $entity){ + $entity->addEffect(new EffectInstance(Effect::getEffect(Effect::WITHER), 200, 1)); + } + } + } + + + + + public function getXpDropAmount() : int{ + //TODO: check for equipment + return 5; + } + + protected function addBehaviors() : void{ + $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); + $this->behaviorPool->setBehavior(1, new MeleeAttackBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(2, new WanderBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(3, new LookAtPlayerBehavior($this, 8.0)); + $this->behaviorPool->setBehavior(4, new RandomLookAroundBehavior($this)); + + $this->targetBehaviorPool->setBehavior(1, new FindAttackableTargetBehavior($this, Player::class)); + } + + + public function sendSpawnPacket(Player $player) : void{ + parent::sendSpawnPacket($player); + + $this->equipment->sendContents([$player]); + } +} \ No newline at end of file diff --git a/src/pocketmine/entity/passive/Cod.php b/src/pocketmine/entity/passive/Cod.php index 6db4ea624f0..c8405f45e8d 100644 --- a/src/pocketmine/entity/passive/Cod.php +++ b/src/pocketmine/entity/passive/Cod.php @@ -70,7 +70,7 @@ public function attack(EntityDamageEvent $source) : void{ $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); } - $this->broadcastEntityEvent(ActorEventPacket::SQUID_INK_CLOUD); + } } @@ -120,10 +120,13 @@ public function entityBaseTick(int $tickDiff = 1) : bool{ } public function getDrops() : array{ - return [ + $drops = [ ItemFactory::get(Item::RAW_FISH, 0, 1), - //TODO: Add percentage drop for bone ]; + if(mt_rand(1, 4) ===1){ + $drops[] = ItemFactory::get(Item::BONE, 1, mt_rand(1, 2)); + } + return $drops; } protected function applyGravity() : void{ diff --git a/src/pocketmine/entity/passive/Dolphin.php b/src/pocketmine/entity/passive/Dolphin.php new file mode 100644 index 00000000000..d84cd9a894f --- /dev/null +++ b/src/pocketmine/entity/passive/Dolphin.php @@ -0,0 +1,139 @@ +setMaxHealth(10); + + parent::initEntity(); + } + + public function getName() : string{ + return "Salmon"; + } + + public function attack(EntityDamageEvent $source) : void{ + parent::attack($source); + if($source->isCancelled()){ + return; + } + + if($source instanceof EntityDamageByEntityEvent){ + $this->swimSpeed = mt_rand(150, 350) / 2000; + $e = $source->getDamager(); + if($e !== null){ + $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); + } + + } + } + + 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; + } + + if(++$this->switchDirectionTicker === 100 or $this->isCollided){ + $this->switchDirectionTicker = 0; + if(mt_rand(0, 100) < 50){ + $this->swimDirection = null; + } + } + + $hasUpdate = parent::entityBaseTick($tickDiff); + + if($this->isAlive()){ + + if($this->y > 62 and $this->swimDirection !== null){ + $this->swimDirection->y = -0.5; + } + + $inWater = $this->isUnderwater(); + if(!$inWater){ + $this->swimDirection = null; + }elseif($this->swimDirection !== null){ + if($this->motion->lengthSquared() <= $this->swimDirection->lengthSquared()){ + $this->motion = $this->swimDirection->multiply($this->swimSpeed); + } + }else{ + $this->swimDirection = $this->generateRandomDirection(); + $this->swimSpeed = mt_rand(50, 100) / 2000; + } + + $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); + $this->yaw = (-atan2($this->motion->x, $this->motion->z) * 180 / M_PI); + $this->pitch = (-atan2($f, $this->motion->y) * 1 / M_PI); + } + + return $hasUpdate; + } + + public function getDrops() : array{ + return [ + ItemFactory::get(Item::RAW_SALMON, 0, 1), + //TODO: Add percentage drop for bone + ]; + } + + protected function applyGravity() : void{ + if(!$this->isUnderwater()){ + parent::applyGravity(); + } + } + + +} \ No newline at end of file diff --git a/src/pocketmine/entity/passive/PolarBear.php b/src/pocketmine/entity/passive/PolarBear.php index d8e684c1a67..7446a46030f 100644 --- a/src/pocketmine/entity/passive/PolarBear.php +++ b/src/pocketmine/entity/passive/PolarBear.php @@ -98,8 +98,13 @@ public function getXpDropAmount() : int{ public function getDrops(): array { - return [ - ItemFactory::get(Item::RAW_SALMON, 0, mt_rand(0, 2)) - ]; + $drops = []; + if(mt_rand(1, 4) >1){ + $drops[] = ItemFactory::get(Item::RAW_FISH, 1, mt_rand(0, 2)); + return $drops; + } + else{ + $drops[] = ItemFactory::get(Item::RAW_SALMON, 1, mt_rand(0, 2)); + return $drops;} } } \ No newline at end of file diff --git a/src/pocketmine/entity/passive/Pufferfish.php b/src/pocketmine/entity/passive/Pufferfish.php new file mode 100644 index 00000000000..6cc6859f5f4 --- /dev/null +++ b/src/pocketmine/entity/passive/Pufferfish.php @@ -0,0 +1,152 @@ +setMaxHealth(3); + + parent::initEntity(); + } + + public function getName() : string{ + return "Pufferfish"; + } + + public function attack(EntityDamageEvent $source) : void{ + parent::attack($source); + if($source->isCancelled()){ + return; + } + + if($source instanceof EntityDamageByEntityEvent){ + $this->swimSpeed = mt_rand(150, 350) / 2000; + $e = $source->getDamager(); + if($e !== null){ + $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); + } + + } + } + + 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; + } + + if(++$this->switchDirectionTicker === 100 or $this->isCollided){ + $this->switchDirectionTicker = 0; + if(mt_rand(0, 100) < 50){ + $this->swimDirection = null; + } + } + + $hasUpdate = parent::entityBaseTick($tickDiff); + + if($this->isAlive()){ + + if($this->y > 62 and $this->swimDirection !== null){ + $this->swimDirection->y = -0.5; + } + + $inWater = $this->isUnderwater(); + if(!$inWater){ + $this->swimDirection = null; + }elseif($this->swimDirection !== null){ + if($this->motion->lengthSquared() <= $this->swimDirection->lengthSquared()){ + $this->motion = $this->swimDirection->multiply($this->swimSpeed); + } + }else{ + $this->swimDirection = $this->generateRandomDirection(); + $this->swimSpeed = mt_rand(50, 100) / 2000; + } + + $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); + $this->yaw = (-atan2($this->motion->x, $this->motion->z) * 180 / M_PI); + $this->pitch = (-atan2($f, $this->motion->y) * 180 / M_PI); + } + + return $hasUpdate; + } + + public function onCollideWithEntity(Entity $entity) : void{ + parent::onCollideWithEntity($entity); + + if($entity instanceof Player){ + if($this->getTargetEntity() === $entity){ + $entity->addEffect(new EffectInstance(Effect::getEffect(Effect::POISON), 7 * 20, 1)); + } + } + } + + + + + public function getDrops() : array{ + $drops = [ + ItemFactory::get(Item::PUFFERFISH, 0, 1), + ]; + if(mt_rand(1, 4) ===1){ + $drops[] = ItemFactory::get(Item::BONE, 1, mt_rand(1, 2)); + } + return $drops; + } + + protected function applyGravity() : void{ + if(!$this->isUnderwater()){ + parent::applyGravity(); + } + } +} \ No newline at end of file diff --git a/src/pocketmine/entity/passive/Salmon.php b/src/pocketmine/entity/passive/Salmon.php new file mode 100644 index 00000000000..ebc41ceb2f9 --- /dev/null +++ b/src/pocketmine/entity/passive/Salmon.php @@ -0,0 +1,137 @@ +setMaxHealth(3); + + parent::initEntity(); + } + + public function getName() : string{ + return "Salmon"; + } + + public function attack(EntityDamageEvent $source) : void{ + parent::attack($source); + if($source->isCancelled()){ + return; + } + + if($source instanceof EntityDamageByEntityEvent){ + $this->swimSpeed = mt_rand(150, 350) / 2000; + $e = $source->getDamager(); + if($e !== null){ + $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); + } + + + } + } + + 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; + } + + if(++$this->switchDirectionTicker === 100 or $this->isCollided){ + $this->switchDirectionTicker = 0; + if(mt_rand(0, 100) < 50){ + $this->swimDirection = null; + } + } + + $hasUpdate = parent::entityBaseTick($tickDiff); + + if($this->isAlive()){ + + if($this->y > 62 and $this->swimDirection !== null){ + $this->swimDirection->y = -0.5; + } + + $inWater = $this->isUnderwater(); + if(!$inWater){ + $this->swimDirection = null; + }elseif($this->swimDirection !== null){ + if($this->motion->lengthSquared() <= $this->swimDirection->lengthSquared()){ + $this->motion = $this->swimDirection->multiply($this->swimSpeed); + } + }else{ + $this->swimDirection = $this->generateRandomDirection(); + $this->swimSpeed = mt_rand(50, 100) / 2000; + } + + $f = sqrt(($this->motion->x ** 2) + ($this->motion->z ** 2)); + $this->yaw = (-atan2($this->motion->x, $this->motion->z) * 180 / M_PI); + $this->pitch = (-atan2($f, $this->motion->y) * 180 / M_PI); + } + + return $hasUpdate; + } + + public function getDrops() : array{ + $drops = [ + ItemFactory::get(Item::RAW_SALMON, 0, 1), + ]; + if(mt_rand(1, 4) ===1){ + $drops[] = ItemFactory::get(Item::BONE, 1, mt_rand(1, 2)); + } + return $drops; + } + + protected function applyGravity() : void{ + if(!$this->isUnderwater()){ + parent::applyGravity(); + } + } +} \ No newline at end of file diff --git a/src/pocketmine/entity/passive/TropicalFish.php b/src/pocketmine/entity/passive/TropicalFish.php index f82081aefce..d1ebd0e8568 100644 --- a/src/pocketmine/entity/passive/TropicalFish.php +++ b/src/pocketmine/entity/passive/TropicalFish.php @@ -70,7 +70,7 @@ public function attack(EntityDamageEvent $source) : void{ $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); } - $this->broadcastEntityEvent(ActorEventPacket::SQUID_INK_CLOUD); + } } @@ -120,10 +120,13 @@ public function entityBaseTick(int $tickDiff = 1) : bool{ } public function getDrops() : array{ - return [ + $drops = [ ItemFactory::get(Item::CLOWNFISH, 0, 1), - //TODO: Add percentage drop for bone ]; + if(mt_rand(1, 4) ===1){ + $drops[] = ItemFactory::get(Item::BONE, 1, mt_rand(1, 2)); + } + return $drops; } protected function applyGravity() : void{ From c0006eef645898036e7cda71d4af303584f56f6b Mon Sep 17 00:00:00 2001 From: dearminder Date: Wed, 31 Jul 2019 11:17:21 +0200 Subject: [PATCH 04/13] Tempt Fix --- src/pocketmine/entity/passive/Ocelot.php | 4 ++-- src/pocketmine/entity/passive/Rabbit.php | 4 ++-- src/pocketmine/entity/passive/Wolf.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pocketmine/entity/passive/Ocelot.php b/src/pocketmine/entity/passive/Ocelot.php index b37ac557787..eab4af7ca54 100644 --- a/src/pocketmine/entity/passive/Ocelot.php +++ b/src/pocketmine/entity/passive/Ocelot.php @@ -30,7 +30,7 @@ use pocketmine\entity\behavior\PanicBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; use pocketmine\entity\behavior\SittingBehavior; -use pocketmine\entity\behavior\TemptedBehavior; +use pocketmine\entity\behavior\TemptBehavior; use pocketmine\entity\Tamable; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; @@ -54,7 +54,7 @@ protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(3, new PanicBehavior($this, 2.0)); $this->behaviorPool->setBehavior(4, new LookAtPlayerBehavior($this, 14.0)); $this->behaviorPool->setBehavior(5, new RandomLookAroundBehavior($this)); - $this->behaviorPool->setBehavior(6, new TemptedBehavior($this, [Item::RAW_SALMON, Item::RAW_FISH], 1.0)); + $this->behaviorPool->setBehavior(6, new TemptBehavior($this, [Item::RAW_SALMON, Item::RAW_FISH], 1.0)); $this->behaviorPool->setBehavior(7, new SittingBehavior($this)); // TODO: attack turtle and rabbit } diff --git a/src/pocketmine/entity/passive/Rabbit.php b/src/pocketmine/entity/passive/Rabbit.php index f1e20d5a5a1..c940025a270 100644 --- a/src/pocketmine/entity/passive/Rabbit.php +++ b/src/pocketmine/entity/passive/Rabbit.php @@ -28,7 +28,7 @@ use pocketmine\entity\behavior\MateBehavior; use pocketmine\entity\behavior\PanicBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; -use pocketmine\entity\behavior\TemptedBehavior; +use pocketmine\entity\behavior\TemptBehavior; use pocketmine\entity\Tamable; use pocketmine\item\Item; use pocketmine\item\ItemFactory; @@ -47,7 +47,7 @@ protected function addBehaviors() : void $this->behaviorPool->setBehavior(3, new PanicBehavior($this, 2.0)); $this->behaviorPool->setBehavior(4, new LookAtPlayerBehavior($this, 14.0)); $this->behaviorPool->setBehavior(5, new RandomLookAroundBehavior($this)); - $this->behaviorPool->setBehavior(6, new TemptedBehavior($this, [Item::CARROT], 1.0)); + $this->behaviorPool->setBehavior(6, new TemptBehavior($this, [Item::CARROT], 1.0)); // TODO: running away from player } diff --git a/src/pocketmine/entity/passive/Wolf.php b/src/pocketmine/entity/passive/Wolf.php index 5b13f9b2d28..b0c9e0a8fbe 100644 --- a/src/pocketmine/entity/passive/Wolf.php +++ b/src/pocketmine/entity/passive/Wolf.php @@ -61,7 +61,7 @@ protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(5, new RandomStrollBehavior($this, 1.0)); $this->behaviorPool->setBehavior(6, new LookAtPlayerBehavior($this, 8.0)); $this->behaviorPool->setBehavior(7, new RandomLookAroundBehavior($this)); - $this->behaviorPool->setBehavior(4, new TemptedBehavior($this, [Item::BONE], 0.8)); + $this->behaviorPool->setBehavior(4, new TemptBehavior($this, [Item::BONE], 0.8)); $this->targetBehaviorPool->setBehavior(0, new HurtByTargetBehavior($this, true)); $this->targetBehaviorPool->setBehavior(1, new OwnerHurtByTargetBehavior($this)); From 160e771128424a5162ec9cd7b14a1a81e45d0410 Mon Sep 17 00:00:00 2001 From: dearminder Date: Fri, 2 Aug 2019 12:10:40 +0200 Subject: [PATCH 05/13] . --- src/pocketmine/entity/Entity.php | 2 +- src/pocketmine/entity/hostile/Blaze.php | 2 +- src/pocketmine/entity/{passive => hostile}/Dolphin.php | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/pocketmine/entity/{passive => hostile}/Dolphin.php (97%) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 83793c1a670..07331102287 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -45,6 +45,7 @@ use pocketmine\entity\hostile\Zombie; use pocketmine\entity\hostile\ZombiePigman; use pocketmine\entity\hostile\ZombieVillager; +use pocketmine\entity\hostile\Dolphin; use pocketmine\entity\object\ArmorStand; use pocketmine\entity\object\ExperienceOrb; use pocketmine\entity\object\FallingBlock; @@ -57,7 +58,6 @@ use pocketmine\entity\passive\Cat; use pocketmine\entity\passive\Chicken; use pocketmine\entity\passive\Cod; -use pocketmine\entity\passive\Dolphin; use pocketmine\entity\passive\Pufferfish; use pocketmine\entity\passive\Salmon; use pocketmine\entity\passive\Cow; diff --git a/src/pocketmine/entity/hostile/Blaze.php b/src/pocketmine/entity/hostile/Blaze.php index 06260c92d58..e45f87e0fd9 100644 --- a/src/pocketmine/entity/hostile/Blaze.php +++ b/src/pocketmine/entity/hostile/Blaze.php @@ -95,7 +95,7 @@ public function onBehaviorUpdate() : void{ public function onRangedAttackToTarget(Entity $target, float $power) : void{ $dv = $target->subtract($this)->normalize(); $fireball = new SmallFireball($this->level, Entity::createBaseNBT($this->add($this->random->nextFloat() * $power, $this->getEyeHeight(), $this->random->nextFloat() * $power), $dv), $this); - $fireball->setMotion($dv->multiply(2)); + $fireball->setMotion($dv->multiply($power)); $fireball->spawnToAll(); } diff --git a/src/pocketmine/entity/passive/Dolphin.php b/src/pocketmine/entity/hostile/Dolphin.php similarity index 97% rename from src/pocketmine/entity/passive/Dolphin.php rename to src/pocketmine/entity/hostile/Dolphin.php index d84cd9a894f..134398f5fd4 100644 --- a/src/pocketmine/entity/passive/Dolphin.php +++ b/src/pocketmine/entity/hostile/Dolphin.php @@ -21,7 +21,7 @@ declare(strict_types=1); -namespace pocketmine\entity\passive; +namespace pocketmine\entity\hostile; use pocketmine\entity\behavior\JumpAttackBehavior; use pocketmine\entity\behavior\MeleeAttackBehavior; @@ -58,7 +58,7 @@ public function initEntity() : void{ } public function getName() : string{ - return "Salmon"; + return "Dolphin"; } public function attack(EntityDamageEvent $source) : void{ @@ -68,7 +68,7 @@ public function attack(EntityDamageEvent $source) : void{ } if($source instanceof EntityDamageByEntityEvent){ - $this->swimSpeed = mt_rand(150, 350) / 2000; + $this->swimSpeed = mt_rand(350, 650) / 2000; $e = $source->getDamager(); if($e !== null){ $this->swimDirection = (new Vector3($this->x - $e->x, $this->y - $e->y, $this->z - $e->z))->normalize(); From 91915acf40493a6b1b662318315ad69faad9a252 Mon Sep 17 00:00:00 2001 From: dearminder Date: Fri, 2 Aug 2019 12:27:35 +0200 Subject: [PATCH 06/13] Updated To latest Behaviours --- .../entity/hostile/WitherSkeleton.php | 4 +- .../entity/hostile/ZombiePigman.php | 4 +- .../entity/hostile/ZombieVillager.php | 4 +- src/pocketmine/entity/passive/Cat.php | 2 +- src/pocketmine/entity/passive/Ocelot.php | 32 ++- src/pocketmine/entity/passive/PolarBear.php | 4 +- .../entity/passive/SkeletonHorse.php | 254 +++++++++--------- src/pocketmine/entity/passive/ZombieHorse.php | 4 +- 8 files changed, 159 insertions(+), 149 deletions(-) diff --git a/src/pocketmine/entity/hostile/WitherSkeleton.php b/src/pocketmine/entity/hostile/WitherSkeleton.php index 43432f11b6d..1f4b69f27f6 100644 --- a/src/pocketmine/entity/hostile/WitherSkeleton.php +++ b/src/pocketmine/entity/hostile/WitherSkeleton.php @@ -29,7 +29,7 @@ use pocketmine\entity\behavior\LookAtPlayerBehavior; use pocketmine\entity\behavior\MeleeAttackBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; -use pocketmine\entity\behavior\WanderBehavior; +use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\entity\Effect; use pocketmine\entity\EffectInstance; use pocketmine\entity\Entity; @@ -100,7 +100,7 @@ public function getXpDropAmount() : int{ protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); $this->behaviorPool->setBehavior(1, new MeleeAttackBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(2, new WanderBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(2, new RandomStrollBehavior($this, 1.0)); $this->behaviorPool->setBehavior(3, new LookAtPlayerBehavior($this, 8.0)); $this->behaviorPool->setBehavior(4, new RandomLookAroundBehavior($this)); diff --git a/src/pocketmine/entity/hostile/ZombiePigman.php b/src/pocketmine/entity/hostile/ZombiePigman.php index 24698975e0a..199bc079747 100644 --- a/src/pocketmine/entity/hostile/ZombiePigman.php +++ b/src/pocketmine/entity/hostile/ZombiePigman.php @@ -30,7 +30,7 @@ use pocketmine\entity\behavior\LookAtPlayerBehavior; use pocketmine\entity\behavior\MeleeAttackBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; -use pocketmine\entity\behavior\WanderBehavior; +use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\entity\Monster; use pocketmine\entity\passive\Villager; use pocketmine\inventory\AltayEntityEquipment; @@ -94,7 +94,7 @@ public function getXpDropAmount() : int{ protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); $this->behaviorPool->setBehavior(1, new MeleeAttackBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(2, new WanderBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(2, new RandomStrollBehavior($this, 1.0)); $this->behaviorPool->setBehavior(3, new LookAtPlayerBehavior($this, 8.0)); $this->behaviorPool->setBehavior(4, new RandomLookAroundBehavior($this)); diff --git a/src/pocketmine/entity/hostile/ZombieVillager.php b/src/pocketmine/entity/hostile/ZombieVillager.php index 7f274bbe69d..0aa9100bf89 100644 --- a/src/pocketmine/entity/hostile/ZombieVillager.php +++ b/src/pocketmine/entity/hostile/ZombieVillager.php @@ -30,7 +30,7 @@ use pocketmine\entity\behavior\LookAtPlayerBehavior; use pocketmine\entity\behavior\MeleeAttackBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; -use pocketmine\entity\behavior\WanderBehavior; +use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\entity\Monster; use pocketmine\entity\passive\Villager; use pocketmine\item\Item; @@ -86,7 +86,7 @@ public function getXpDropAmount() : int{ protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); $this->behaviorPool->setBehavior(1, new MeleeAttackBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(2, new WanderBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(2, new RandomStrollBehavior($this, 1.0)); $this->behaviorPool->setBehavior(3, new LookAtPlayerBehavior($this, 8.0)); $this->behaviorPool->setBehavior(4, new RandomLookAroundBehavior($this)); diff --git a/src/pocketmine/entity/passive/Cat.php b/src/pocketmine/entity/passive/Cat.php index 29b353fef65..045e8d57ddb 100644 --- a/src/pocketmine/entity/passive/Cat.php +++ b/src/pocketmine/entity/passive/Cat.php @@ -71,7 +71,7 @@ protected function initEntity() : void{ $this->setMovementSpeed(0.3); $this->setFollowRange(16); $this->setAttackDamage(3); - $this->propertyManager->setInt(self::DATA_VARIANT, intval($this->namedtag->getInt("CatType", mt_rand(0, 10)))); + $this->propertyManager->setInt(self::DATA_VARIANT, intval($this->namedtag->getInt("CatType", mt_rand(1, 10)))); $this->propertyManager->setInt(self::DATA_COLOR, intval($this->namedtag->getInt("CollarColor", mt_rand(0, 15)))); parent::initEntity(); diff --git a/src/pocketmine/entity/passive/Ocelot.php b/src/pocketmine/entity/passive/Ocelot.php index eab4af7ca54..9b1fc751728 100644 --- a/src/pocketmine/entity/passive/Ocelot.php +++ b/src/pocketmine/entity/passive/Ocelot.php @@ -29,7 +29,7 @@ use pocketmine\entity\behavior\MateBehavior; use pocketmine\entity\behavior\PanicBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; -use pocketmine\entity\behavior\SittingBehavior; +use pocketmine\entity\behavior\StayWhileSittingBehavior; use pocketmine\entity\behavior\TemptBehavior; use pocketmine\entity\Tamable; use pocketmine\event\entity\EntityDamageByEntityEvent; @@ -46,16 +46,23 @@ class Ocelot extends Tamable{ public $width = 0.6; public $height = 0.7; + /** @var StayWhileSittingBehavior */ + protected $behaviorSitting; protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); - $this->behaviorPool->setBehavior(1, new MateBehavior($this, 2.0)); - $this->behaviorPool->setBehavior(2, new FollowOwnerBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(3, new PanicBehavior($this, 2.0)); - $this->behaviorPool->setBehavior(4, new LookAtPlayerBehavior($this, 14.0)); - $this->behaviorPool->setBehavior(5, new RandomLookAroundBehavior($this)); - $this->behaviorPool->setBehavior(6, new TemptBehavior($this, [Item::RAW_SALMON, Item::RAW_FISH], 1.0)); - $this->behaviorPool->setBehavior(7, new SittingBehavior($this)); + $this->behaviorPool->setBehavior(1, new PanicBehavior($this, 2.0)); + $this->behaviorPool->setBehavior(2, $this->behaviorSitting = new StayWhileSittingBehavior($this)); + $this->behaviorPool->setBehavior(3, new MateBehavior($this, 2.0)); + $this->behaviorPool->setBehavior(4, new TemptBehavior($this, [ + Item::RAW_SALMON, + Item::RAW_FISH + ], 1.0)); + $this->behaviorPool->setBehavior(5, new FollowOwnerBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(6, new LookAtPlayerBehavior($this, 14.0)); + $this->behaviorPool->setBehavior(7, new RandomLookAroundBehavior($this)); + + // TODO: attack turtle and rabbit } @@ -66,6 +73,7 @@ protected function initEntity() : void{ $this->setAttackDamage(3); $this->propertyManager->setInt(self::DATA_VARIANT, intval($this->namedtag->getInt("CatType", 0))); $this->propertyManager->setInt(self::DATA_COLOR, intval($this->namedtag->getInt("CollarColor", mt_rand(0, 15)))); + parent::initEntity(); } @@ -85,7 +93,7 @@ public function onInteract(Player $player, Item $item, Vector3 $clickPos) : bool }elseif(mt_rand(0, 2) == 0){ $this->setOwningEntity($player); $this->setTamed(); - $this->setSitting(); + $this->setSittingFromBehavior(true); $this->broadcastEntityEvent(ActorEventPacket::TAME_SUCCESS); }else{ $this->broadcastEntityEvent(ActorEventPacket::TAME_FAIL); @@ -93,7 +101,7 @@ public function onInteract(Player $player, Item $item, Vector3 $clickPos) : bool return true; }else{ if($this->isTamed()){ - $this->setSitting(!$this->isSitting()); + $this->setSittingFromBehavior(!$this->isSitting()); } } } @@ -117,6 +125,10 @@ public function getDrops() : array{ ]; } + public function setSittingFromBehavior(bool $value) : void{ + $this->behaviorSitting->setSitting($value); + } + public function attack(EntityDamageEvent $source) : void{ if($source->getCause() !== EntityDamageEvent::CAUSE_FALL){ parent::attack($source); diff --git a/src/pocketmine/entity/passive/PolarBear.php b/src/pocketmine/entity/passive/PolarBear.php index 7446a46030f..c2f95de0f92 100644 --- a/src/pocketmine/entity/passive/PolarBear.php +++ b/src/pocketmine/entity/passive/PolarBear.php @@ -31,7 +31,7 @@ use pocketmine\entity\behavior\MateBehavior; use pocketmine\entity\behavior\MeleeAttackBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; -use pocketmine\entity\behavior\WanderBehavior; +use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\entity\Entity; use pocketmine\item\Item; use pocketmine\item\ItemFactory; @@ -50,7 +50,7 @@ protected function addBehaviors(): void $this->behaviorPool->setBehavior(1, new MateBehavior($this, 1.0)); $this->behaviorPool->setBehavior(2, new MeleeAttackBehavior($this, 1.0)); $this->behaviorPool->setBehavior(3, new FollowParentBehavior($this, 1.1)); - $this->behaviorPool->setBehavior(4, new WanderBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(4, new RandomStrollBehavior($this, 1.0)); $this->behaviorPool->setBehavior(5, new LookAtPlayerBehavior($this, 16.0)); $this->behaviorPool->setBehavior(6, new RandomLookAroundBehavior($this)); diff --git a/src/pocketmine/entity/passive/SkeletonHorse.php b/src/pocketmine/entity/passive/SkeletonHorse.php index d2897ad117d..c9555cadfdc 100644 --- a/src/pocketmine/entity/passive/SkeletonHorse.php +++ b/src/pocketmine/entity/passive/SkeletonHorse.php @@ -27,16 +27,15 @@ use pocketmine\entity\Attribute; use pocketmine\entity\behavior\FloatBehavior; use pocketmine\entity\behavior\FollowParentBehavior; -use pocketmine\entity\behavior\HorseRiddenBehavior; +use pocketmine\entity\behavior\MountPathingBehavior; use pocketmine\entity\behavior\LookAtPlayerBehavior; use pocketmine\entity\behavior\MateBehavior; use pocketmine\entity\behavior\PanicBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; -use pocketmine\entity\behavior\WanderBehavior; +use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\inventory\HorseInventory; use pocketmine\inventory\InventoryHolder; use pocketmine\item\Item; -use pocketmine\item\ItemFactory; use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\IntTag; @@ -44,132 +43,131 @@ 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; - - /** @var HorseInventory */ - protected $inventory; - - public function getName() : string{ - return "Skeleton Horse"; - } - - /** - * @return HorseInventory - */ - public function getInventory() : HorseInventory{ - return $this->inventory; - } - - protected function addBehaviors() : void{ - $this->behaviorPool->setBehavior(0, new HorseRiddenBehavior($this)); - $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 WanderBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(7, new LookAtPlayerBehavior($this, 6.0)); - $this->behaviorPool->setBehavior(8, new RandomLookAroundBehavior($this)); - } - - protected function initEntity() : void{ + 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; + + /** @var HorseInventory */ + protected $inventory; + + public function getName() : string{ + return "Skeleton Horse"; + } + + /** + * @return HorseInventory + */ + public function getInventory() : HorseInventory{ + return $this->inventory; + } + + protected function addBehaviors() : void{ + $this->behaviorPool->setBehavior(0, new MountPathingBehavior($this)); + $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")); - } - } + $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 { diff --git a/src/pocketmine/entity/passive/ZombieHorse.php b/src/pocketmine/entity/passive/ZombieHorse.php index 361897bd494..8f56ca81c76 100644 --- a/src/pocketmine/entity/passive/ZombieHorse.php +++ b/src/pocketmine/entity/passive/ZombieHorse.php @@ -31,7 +31,7 @@ use pocketmine\entity\behavior\MateBehavior; use pocketmine\entity\behavior\PanicBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; -use pocketmine\entity\behavior\WanderBehavior; +use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\inventory\HorseInventory; use pocketmine\inventory\InventoryHolder; use pocketmine\item\Item; @@ -81,7 +81,7 @@ protected function addBehaviors() : void{ $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 WanderBehavior($this, 1.0)); + $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)); } From 69abb598898faed9d0c57c2f95edd609f8977815 Mon Sep 17 00:00:00 2001 From: dearminder Date: Fri, 2 Aug 2019 12:32:24 +0200 Subject: [PATCH 07/13] fix --- src/pocketmine/entity/passive/SkeletonHorse.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pocketmine/entity/passive/SkeletonHorse.php b/src/pocketmine/entity/passive/SkeletonHorse.php index c9555cadfdc..30458e4228e 100644 --- a/src/pocketmine/entity/passive/SkeletonHorse.php +++ b/src/pocketmine/entity/passive/SkeletonHorse.php @@ -34,6 +34,7 @@ use pocketmine\entity\behavior\RandomLookAroundBehavior; use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\inventory\HorseInventory; +use pocketmine\item\ItemFactory; use pocketmine\inventory\InventoryHolder; use pocketmine\item\Item; use pocketmine\math\Vector3; From fabb3a11ea7dff9f6749dbaca12ff1417f856474 Mon Sep 17 00:00:00 2001 From: dearminder Date: Sat, 3 Aug 2019 12:17:05 +0200 Subject: [PATCH 08/13] Creeper runawawy from ocelots Cat And Ocelot walks randomly Rabbits avoid Player (but now dont come for carrot) --- src/pocketmine/entity/hostile/Creeper.php | 2 ++ src/pocketmine/entity/passive/Cat.php | 6 ++++-- src/pocketmine/entity/passive/Ocelot.php | 22 +++++++++++----------- src/pocketmine/entity/passive/Rabbit.php | 13 ++++++++----- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/pocketmine/entity/hostile/Creeper.php b/src/pocketmine/entity/hostile/Creeper.php index 0478f403be4..8f0d8e981f9 100644 --- a/src/pocketmine/entity/hostile/Creeper.php +++ b/src/pocketmine/entity/hostile/Creeper.php @@ -37,6 +37,7 @@ use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\entity\Monster; use pocketmine\entity\passive\Cat; +use pocketmine\entity\passive\Ocelot; use pocketmine\item\FlintSteel; use pocketmine\item\Item; use pocketmine\item\ItemFactory; @@ -96,6 +97,7 @@ protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(1, new CreeperSwellBehavior($this)); // TODO: Avoid from ocelot $this->behaviorPool->setBehavior(2, new AvoidMobTypeBehavior($this, Cat::class, null, 6, 1, 1.2)); + $this->behaviorPool->setBehavior(2, new AvoidMobTypeBehavior($this, Ocelot::class, null, 6, 1, 1.2)); $this->behaviorPool->setBehavior(3, new MeleeAttackBehavior($this, 1.0)); $this->behaviorPool->setBehavior(4, new RandomStrollBehavior($this, 0.8)); $this->behaviorPool->setBehavior(5, new LookAtPlayerBehavior($this, 8.0)); diff --git a/src/pocketmine/entity/passive/Cat.php b/src/pocketmine/entity/passive/Cat.php index e9aa587a53d..032e3c89a3f 100644 --- a/src/pocketmine/entity/passive/Cat.php +++ b/src/pocketmine/entity/passive/Cat.php @@ -29,6 +29,7 @@ use pocketmine\entity\behavior\MateBehavior; use pocketmine\entity\behavior\PanicBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; +use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\entity\behavior\StayWhileSittingBehavior; use pocketmine\entity\behavior\TemptBehavior; use pocketmine\entity\Tamable; @@ -60,7 +61,8 @@ protected function addBehaviors() : void{ ], 1.0)); $this->behaviorPool->setBehavior(5, new FollowOwnerBehavior($this, 1, 10, 2)); $this->behaviorPool->setBehavior(6, new LookAtPlayerBehavior($this, 14.0)); - $this->behaviorPool->setBehavior(7, new RandomLookAroundBehavior($this)); + $this->behaviorPool->setBehavior(7, new RandomStrollBehavior($this, 1)); + $this->behaviorPool->setBehavior(8, new RandomLookAroundBehavior($this)); // TODO: attack turtle and rabbit @@ -83,7 +85,7 @@ public function getName() : string{ public function onInteract(Player $player, Item $item, Vector3 $clickPos) : bool{ if(!$this->isImmobile()){ - if($item->getId() == Item::RAW_SALMON || $item->getId() == Item::RAW_FISH){ + if($item->getId() == Item::RAW_SALMON || $item->getId() == Item::RAW_FISH || $item->getId() == Item::CLOWNFISH){ if($player->isSurvival()){ $item->pop(); } diff --git a/src/pocketmine/entity/passive/Ocelot.php b/src/pocketmine/entity/passive/Ocelot.php index 9b1fc751728..4139eb7e1e2 100644 --- a/src/pocketmine/entity/passive/Ocelot.php +++ b/src/pocketmine/entity/passive/Ocelot.php @@ -27,10 +27,14 @@ use pocketmine\entity\behavior\FollowOwnerBehavior; use pocketmine\entity\behavior\LookAtPlayerBehavior; use pocketmine\entity\behavior\MateBehavior; +use pocketmine\entity\behavior\MeleeAttackBehavior; +use pocketmine\entity\behavior\NearestAttackableTargetBehavior; use pocketmine\entity\behavior\PanicBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; +use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\entity\behavior\StayWhileSittingBehavior; use pocketmine\entity\behavior\TemptBehavior; +use pocketmine\entity\passive\Chicken; use pocketmine\entity\Tamable; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; @@ -58,12 +62,15 @@ protected function addBehaviors() : void{ Item::RAW_SALMON, Item::RAW_FISH ], 1.0)); - $this->behaviorPool->setBehavior(5, new FollowOwnerBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(5, new FollowOwnerBehavior($this, 1, 10, 2)); $this->behaviorPool->setBehavior(6, new LookAtPlayerBehavior($this, 14.0)); $this->behaviorPool->setBehavior(7, new RandomLookAroundBehavior($this)); + $this->behaviorPool->setBehavior(8, new RandomStrollBehavior($this, 0.8)); + $this->behaviorPool->setBehavior(9, new MeleeAttackBehavior($this, 1.0)); - - // TODO: attack turtle and rabbit + $this->targetBehaviorPool->setBehavior(1, new NearestAttackableTargetBehavior($this, Chicken::class, false)); + //$this->targetBehaviorPool->setBehavior(9, new NearestAttackableTargetBehavior($this, SeaTurtle::class, false)); + //Also i have no idea why attack dont works } protected function initEntity() : void{ @@ -88,21 +95,17 @@ public function onInteract(Player $player, Item $item, Vector3 $clickPos) : bool $item->pop(); } if($this->isTamed()){ + $this->setTargetEntity(null); $this->setInLove(true); $this->setHealth(min($this->getMaxHealth(), $this->getHealth() + 2)); }elseif(mt_rand(0, 2) == 0){ $this->setOwningEntity($player); $this->setTamed(); - $this->setSittingFromBehavior(true); $this->broadcastEntityEvent(ActorEventPacket::TAME_SUCCESS); }else{ $this->broadcastEntityEvent(ActorEventPacket::TAME_FAIL); } return true; - }else{ - if($this->isTamed()){ - $this->setSittingFromBehavior(!$this->isSitting()); - } } } return parent::onInteract($player, $item, $clickPos); @@ -125,9 +128,6 @@ public function getDrops() : array{ ]; } - public function setSittingFromBehavior(bool $value) : void{ - $this->behaviorSitting->setSitting($value); - } public function attack(EntityDamageEvent $source) : void{ if($source->getCause() !== EntityDamageEvent::CAUSE_FALL){ diff --git a/src/pocketmine/entity/passive/Rabbit.php b/src/pocketmine/entity/passive/Rabbit.php index c940025a270..e88c9ab8e7c 100644 --- a/src/pocketmine/entity/passive/Rabbit.php +++ b/src/pocketmine/entity/passive/Rabbit.php @@ -23,6 +23,7 @@ namespace pocketmine\entity\passive; +use pocketmine\entity\behavior\AvoidMobTypeBehavior; use pocketmine\entity\behavior\FloatBehavior; use pocketmine\entity\behavior\LookAtPlayerBehavior; use pocketmine\entity\behavior\MateBehavior; @@ -32,6 +33,7 @@ use pocketmine\entity\Tamable; use pocketmine\item\Item; use pocketmine\item\ItemFactory; +use pocketmine\Player; use function mt_rand; class Rabbit extends Tamable{ @@ -44,11 +46,12 @@ protected function addBehaviors() : void { $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); $this->behaviorPool->setBehavior(1, new MateBehavior($this, 2.0)); - $this->behaviorPool->setBehavior(3, new PanicBehavior($this, 2.0)); - $this->behaviorPool->setBehavior(4, new LookAtPlayerBehavior($this, 14.0)); - $this->behaviorPool->setBehavior(5, new RandomLookAroundBehavior($this)); - $this->behaviorPool->setBehavior(6, new TemptBehavior($this, [Item::CARROT], 1.0)); - // TODO: running away from player + $this->behaviorPool->setBehavior(2, new PanicBehavior($this, 2.0)); + $this->behaviorPool->setBehavior(3, new LookAtPlayerBehavior($this, 14.0)); + $this->behaviorPool->setBehavior(4, new RandomLookAroundBehavior($this)); + $this->behaviorPool->setBehavior(5, new TemptBehavior($this, [Item::CARROT], 1.0)); + $this->behaviorPool->setBehavior(6, new AvoidMobTypeBehavior($this, Player::class, null, 8, 1, 1)); + // TODO: going back to player when they see carrot, and movement fix so they dont SLIDE On ground } protected function initEntity() : void{ From f5cec61fbe2394a41fae81631576e1e221a024ea Mon Sep 17 00:00:00 2001 From: dearminder Date: Sat, 3 Aug 2019 12:17:05 +0200 Subject: [PATCH 09/13] Creeper runaway from ocelots Cat And Ocelot walks randomly Rabbits avoid Player (but now dont come for carrot) --- src/pocketmine/entity/hostile/Creeper.php | 2 ++ src/pocketmine/entity/passive/Cat.php | 6 ++++-- src/pocketmine/entity/passive/Ocelot.php | 22 +++++++++++----------- src/pocketmine/entity/passive/Rabbit.php | 13 ++++++++----- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/pocketmine/entity/hostile/Creeper.php b/src/pocketmine/entity/hostile/Creeper.php index 0478f403be4..8f0d8e981f9 100644 --- a/src/pocketmine/entity/hostile/Creeper.php +++ b/src/pocketmine/entity/hostile/Creeper.php @@ -37,6 +37,7 @@ use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\entity\Monster; use pocketmine\entity\passive\Cat; +use pocketmine\entity\passive\Ocelot; use pocketmine\item\FlintSteel; use pocketmine\item\Item; use pocketmine\item\ItemFactory; @@ -96,6 +97,7 @@ protected function addBehaviors() : void{ $this->behaviorPool->setBehavior(1, new CreeperSwellBehavior($this)); // TODO: Avoid from ocelot $this->behaviorPool->setBehavior(2, new AvoidMobTypeBehavior($this, Cat::class, null, 6, 1, 1.2)); + $this->behaviorPool->setBehavior(2, new AvoidMobTypeBehavior($this, Ocelot::class, null, 6, 1, 1.2)); $this->behaviorPool->setBehavior(3, new MeleeAttackBehavior($this, 1.0)); $this->behaviorPool->setBehavior(4, new RandomStrollBehavior($this, 0.8)); $this->behaviorPool->setBehavior(5, new LookAtPlayerBehavior($this, 8.0)); diff --git a/src/pocketmine/entity/passive/Cat.php b/src/pocketmine/entity/passive/Cat.php index e9aa587a53d..032e3c89a3f 100644 --- a/src/pocketmine/entity/passive/Cat.php +++ b/src/pocketmine/entity/passive/Cat.php @@ -29,6 +29,7 @@ use pocketmine\entity\behavior\MateBehavior; use pocketmine\entity\behavior\PanicBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; +use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\entity\behavior\StayWhileSittingBehavior; use pocketmine\entity\behavior\TemptBehavior; use pocketmine\entity\Tamable; @@ -60,7 +61,8 @@ protected function addBehaviors() : void{ ], 1.0)); $this->behaviorPool->setBehavior(5, new FollowOwnerBehavior($this, 1, 10, 2)); $this->behaviorPool->setBehavior(6, new LookAtPlayerBehavior($this, 14.0)); - $this->behaviorPool->setBehavior(7, new RandomLookAroundBehavior($this)); + $this->behaviorPool->setBehavior(7, new RandomStrollBehavior($this, 1)); + $this->behaviorPool->setBehavior(8, new RandomLookAroundBehavior($this)); // TODO: attack turtle and rabbit @@ -83,7 +85,7 @@ public function getName() : string{ public function onInteract(Player $player, Item $item, Vector3 $clickPos) : bool{ if(!$this->isImmobile()){ - if($item->getId() == Item::RAW_SALMON || $item->getId() == Item::RAW_FISH){ + if($item->getId() == Item::RAW_SALMON || $item->getId() == Item::RAW_FISH || $item->getId() == Item::CLOWNFISH){ if($player->isSurvival()){ $item->pop(); } diff --git a/src/pocketmine/entity/passive/Ocelot.php b/src/pocketmine/entity/passive/Ocelot.php index 9b1fc751728..4139eb7e1e2 100644 --- a/src/pocketmine/entity/passive/Ocelot.php +++ b/src/pocketmine/entity/passive/Ocelot.php @@ -27,10 +27,14 @@ use pocketmine\entity\behavior\FollowOwnerBehavior; use pocketmine\entity\behavior\LookAtPlayerBehavior; use pocketmine\entity\behavior\MateBehavior; +use pocketmine\entity\behavior\MeleeAttackBehavior; +use pocketmine\entity\behavior\NearestAttackableTargetBehavior; use pocketmine\entity\behavior\PanicBehavior; use pocketmine\entity\behavior\RandomLookAroundBehavior; +use pocketmine\entity\behavior\RandomStrollBehavior; use pocketmine\entity\behavior\StayWhileSittingBehavior; use pocketmine\entity\behavior\TemptBehavior; +use pocketmine\entity\passive\Chicken; use pocketmine\entity\Tamable; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; @@ -58,12 +62,15 @@ protected function addBehaviors() : void{ Item::RAW_SALMON, Item::RAW_FISH ], 1.0)); - $this->behaviorPool->setBehavior(5, new FollowOwnerBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(5, new FollowOwnerBehavior($this, 1, 10, 2)); $this->behaviorPool->setBehavior(6, new LookAtPlayerBehavior($this, 14.0)); $this->behaviorPool->setBehavior(7, new RandomLookAroundBehavior($this)); + $this->behaviorPool->setBehavior(8, new RandomStrollBehavior($this, 0.8)); + $this->behaviorPool->setBehavior(9, new MeleeAttackBehavior($this, 1.0)); - - // TODO: attack turtle and rabbit + $this->targetBehaviorPool->setBehavior(1, new NearestAttackableTargetBehavior($this, Chicken::class, false)); + //$this->targetBehaviorPool->setBehavior(9, new NearestAttackableTargetBehavior($this, SeaTurtle::class, false)); + //Also i have no idea why attack dont works } protected function initEntity() : void{ @@ -88,21 +95,17 @@ public function onInteract(Player $player, Item $item, Vector3 $clickPos) : bool $item->pop(); } if($this->isTamed()){ + $this->setTargetEntity(null); $this->setInLove(true); $this->setHealth(min($this->getMaxHealth(), $this->getHealth() + 2)); }elseif(mt_rand(0, 2) == 0){ $this->setOwningEntity($player); $this->setTamed(); - $this->setSittingFromBehavior(true); $this->broadcastEntityEvent(ActorEventPacket::TAME_SUCCESS); }else{ $this->broadcastEntityEvent(ActorEventPacket::TAME_FAIL); } return true; - }else{ - if($this->isTamed()){ - $this->setSittingFromBehavior(!$this->isSitting()); - } } } return parent::onInteract($player, $item, $clickPos); @@ -125,9 +128,6 @@ public function getDrops() : array{ ]; } - public function setSittingFromBehavior(bool $value) : void{ - $this->behaviorSitting->setSitting($value); - } public function attack(EntityDamageEvent $source) : void{ if($source->getCause() !== EntityDamageEvent::CAUSE_FALL){ diff --git a/src/pocketmine/entity/passive/Rabbit.php b/src/pocketmine/entity/passive/Rabbit.php index c940025a270..e88c9ab8e7c 100644 --- a/src/pocketmine/entity/passive/Rabbit.php +++ b/src/pocketmine/entity/passive/Rabbit.php @@ -23,6 +23,7 @@ namespace pocketmine\entity\passive; +use pocketmine\entity\behavior\AvoidMobTypeBehavior; use pocketmine\entity\behavior\FloatBehavior; use pocketmine\entity\behavior\LookAtPlayerBehavior; use pocketmine\entity\behavior\MateBehavior; @@ -32,6 +33,7 @@ use pocketmine\entity\Tamable; use pocketmine\item\Item; use pocketmine\item\ItemFactory; +use pocketmine\Player; use function mt_rand; class Rabbit extends Tamable{ @@ -44,11 +46,12 @@ protected function addBehaviors() : void { $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); $this->behaviorPool->setBehavior(1, new MateBehavior($this, 2.0)); - $this->behaviorPool->setBehavior(3, new PanicBehavior($this, 2.0)); - $this->behaviorPool->setBehavior(4, new LookAtPlayerBehavior($this, 14.0)); - $this->behaviorPool->setBehavior(5, new RandomLookAroundBehavior($this)); - $this->behaviorPool->setBehavior(6, new TemptBehavior($this, [Item::CARROT], 1.0)); - // TODO: running away from player + $this->behaviorPool->setBehavior(2, new PanicBehavior($this, 2.0)); + $this->behaviorPool->setBehavior(3, new LookAtPlayerBehavior($this, 14.0)); + $this->behaviorPool->setBehavior(4, new RandomLookAroundBehavior($this)); + $this->behaviorPool->setBehavior(5, new TemptBehavior($this, [Item::CARROT], 1.0)); + $this->behaviorPool->setBehavior(6, new AvoidMobTypeBehavior($this, Player::class, null, 8, 1, 1)); + // TODO: going back to player when they see carrot, and movement fix so they dont SLIDE On ground } protected function initEntity() : void{ From fa5d87e4eb21b05b26283f670f50d83669fbe612 Mon Sep 17 00:00:00 2001 From: dearminder Date: Sat, 3 Aug 2019 16:41:42 +0200 Subject: [PATCH 10/13] CTRL + ALT + L --- src/pocketmine/entity/passive/PolarBear.php | 136 ++++++++++---------- 1 file changed, 65 insertions(+), 71 deletions(-) diff --git a/src/pocketmine/entity/passive/PolarBear.php b/src/pocketmine/entity/passive/PolarBear.php index c2f95de0f92..06cc1fa49f6 100644 --- a/src/pocketmine/entity/passive/PolarBear.php +++ b/src/pocketmine/entity/passive/PolarBear.php @@ -37,74 +37,68 @@ use pocketmine\item\ItemFactory; use pocketmine\math\Vector3; -class PolarBear extends Animal -{ - public const NETWORK_ID = self::POLAR_BEAR; - - public $width = 1.3; - public $height = 1.4; - - protected function addBehaviors(): void - { - $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); - $this->behaviorPool->setBehavior(1, new MateBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(2, new MeleeAttackBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(3, new FollowParentBehavior($this, 1.1)); - $this->behaviorPool->setBehavior(4, new RandomStrollBehavior($this, 1.0)); - $this->behaviorPool->setBehavior(5, new LookAtPlayerBehavior($this, 16.0)); - $this->behaviorPool->setBehavior(6, new RandomLookAroundBehavior($this)); - - $this->targetBehaviorPool->setBehavior(0, new HurtByTargetBehavior($this)); - } - public - function initEntity(): void - { - $this->setMaxHealth(30); - $this->setMovementSpeed(0.30); - $this->setAttackDamage(4); - $this->setFollowRange(16); - parent::initEntity(); - } - //TODO: atack foxes - public - function getName(): string - { - return "Polar Bear"; - } - - public function setTargetEntity(?Entity $target) : void{ - parent::setTargetEntity($target); - if($target == null){ - $this->setAngry(false); - } - } - public function isAngry() : bool{ - return $this->getGenericFlag(self::DATA_FLAG_ANGRY); - } - - 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); - } - - public - function getDrops(): array - { - $drops = []; - if(mt_rand(1, 4) >1){ - $drops[] = ItemFactory::get(Item::RAW_FISH, 1, mt_rand(0, 2)); - return $drops; - } - else{ - $drops[] = ItemFactory::get(Item::RAW_SALMON, 1, mt_rand(0, 2)); - return $drops;} - } - } \ No newline at end of file +class PolarBear extends Animal{ + public const NETWORK_ID = self::POLAR_BEAR; + + public $width = 1.3; + public $height = 1.4; + + protected function addBehaviors() : void{ + $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); + $this->behaviorPool->setBehavior(1, new MateBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(2, new MeleeAttackBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(3, new FollowParentBehavior($this, 1.1)); + $this->behaviorPool->setBehavior(4, new RandomStrollBehavior($this, 1.0)); + $this->behaviorPool->setBehavior(5, new LookAtPlayerBehavior($this, 16.0)); + $this->behaviorPool->setBehavior(6, new RandomLookAroundBehavior($this)); + + $this->targetBehaviorPool->setBehavior(0, new HurtByTargetBehavior($this)); + } + + public function initEntity() : void{ + $this->setMaxHealth(30); + $this->setMovementSpeed(0.30); + $this->setAttackDamage(4); + $this->setFollowRange(16); + parent::initEntity(); + } + + //TODO: atack foxes + public function getName() : string{ + return "Polar Bear"; + } + + public function setTargetEntity(?Entity $target) : void{ + parent::setTargetEntity($target); + if($target == null){ + $this->setAngry(false); + } + } + + public function isAngry() : bool{ + return $this->getGenericFlag(self::DATA_FLAG_ANGRY); + } + + 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); + } + + public function getDrops() : array{ + $drops = []; + if(mt_rand(1, 4) > 1){ + $drops[] = ItemFactory::get(Item::RAW_FISH, 1, mt_rand(0, 2)); + return $drops; + }else{ + $drops[] = ItemFactory::get(Item::RAW_SALMON, 1, mt_rand(0, 2)); + return $drops; + } + } +} \ No newline at end of file From d502eabd3beddf322ee4533dc950907dc7cc1329 Mon Sep 17 00:00:00 2001 From: dearminder Date: Sat, 3 Aug 2019 16:44:55 +0200 Subject: [PATCH 11/13] CTRL + ALT + L --- src/pocketmine/entity/passive/Rabbit.php | 40 +++++++++++------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/pocketmine/entity/passive/Rabbit.php b/src/pocketmine/entity/passive/Rabbit.php index e88c9ab8e7c..1c4d45a20c8 100644 --- a/src/pocketmine/entity/passive/Rabbit.php +++ b/src/pocketmine/entity/passive/Rabbit.php @@ -39,20 +39,19 @@ class Rabbit extends Tamable{ public const NETWORK_ID = self::RABBIT; - public $width = 0.4; + public $width = 0.4; public $height = 0.5; - protected function addBehaviors() : void - { - $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); - $this->behaviorPool->setBehavior(1, new MateBehavior($this, 2.0)); - $this->behaviorPool->setBehavior(2, new PanicBehavior($this, 2.0)); - $this->behaviorPool->setBehavior(3, new LookAtPlayerBehavior($this, 14.0)); - $this->behaviorPool->setBehavior(4, new RandomLookAroundBehavior($this)); - $this->behaviorPool->setBehavior(5, new TemptBehavior($this, [Item::CARROT], 1.0)); - $this->behaviorPool->setBehavior(6, new AvoidMobTypeBehavior($this, Player::class, null, 8, 1, 1)); - // TODO: going back to player when they see carrot, and movement fix so they dont SLIDE On ground - } + protected function addBehaviors() : void{ + $this->behaviorPool->setBehavior(0, new FloatBehavior($this)); + $this->behaviorPool->setBehavior(1, new MateBehavior($this, 2.0)); + $this->behaviorPool->setBehavior(2, new PanicBehavior($this, 2.0)); + $this->behaviorPool->setBehavior(3, new LookAtPlayerBehavior($this, 14.0)); + $this->behaviorPool->setBehavior(4, new RandomLookAroundBehavior($this)); + $this->behaviorPool->setBehavior(5, new TemptBehavior($this, [Item::CARROT], 1.0)); + $this->behaviorPool->setBehavior(6, new AvoidMobTypeBehavior($this, Player::class, null, 8, 1, 1)); + // TODO: going back to player when they see carrot, and movement fix so they dont SLIDE On ground + } protected function initEntity() : void{ $this->setMaxHealth(3); @@ -68,15 +67,14 @@ public function getName() : string{ } + public function getXpDropAmount() : int{ + return rand(1, 3); + } - public function getXpDropAmount() : int{ - return rand(1, 3); - } - - public function getDrops() : array{ - return [ - ItemFactory::get(Item::RABBIT_HIDE, 0, rand(0, 1)), - ($this->isOnFire() ? ItemFactory::get(Item::COOKED_RABBIT, 0, rand(0, 1)) : ItemFactory::get(Item::RAW_RABBIT, 0, rand(0, 1))) - ]; + public function getDrops() : array{ + return [ + ItemFactory::get(Item::RABBIT_HIDE, 0, rand(0, 1)), + ($this->isOnFire() ? ItemFactory::get(Item::COOKED_RABBIT, 0, rand(0, 1)) : ItemFactory::get(Item::RAW_RABBIT, 0, rand(0, 1))) + ]; } } \ No newline at end of file From 0ad56d9df6adb1a40d0458a042a51b8c975251d9 Mon Sep 17 00:00:00 2001 From: dearminder Date: Sat, 3 Aug 2019 16:55:46 +0200 Subject: [PATCH 12/13] Revert it --- src/pocketmine/level/GameRules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/level/GameRules.php b/src/pocketmine/level/GameRules.php index 1e78eeecfad..c3ed40f4037 100644 --- a/src/pocketmine/level/GameRules.php +++ b/src/pocketmine/level/GameRules.php @@ -71,7 +71,7 @@ public function __construct(){ $this->setBool(self::RULE_DO_FIRE_TICK, true); $this->setBool(self::RULE_DO_INSOMNIA, true); $this->setBool(self::RULE_DO_MOB_LOOT, true); - $this->setBool(self::RULE_DO_MOB_SPAWNING, true); + $this->setBool(self::RULE_DO_MOB_SPAWNING, false); $this->setBool(self::RULE_DO_TILE_DROPS, true); $this->setBool(self::RULE_DO_WEATHER_CYCLE, true); $this->setBool(self::RULE_DROWNING_DAMAGE, true); From b37df0ba51df447c14353d053821325e5b0f399b Mon Sep 17 00:00:00 2001 From: dearminder Date: Mon, 5 Aug 2019 14:36:25 +0200 Subject: [PATCH 13/13] Better Effect --- src/pocketmine/entity/hostile/WitherSkeleton.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/entity/hostile/WitherSkeleton.php b/src/pocketmine/entity/hostile/WitherSkeleton.php index 1f4b69f27f6..a97e5264624 100644 --- a/src/pocketmine/entity/hostile/WitherSkeleton.php +++ b/src/pocketmine/entity/hostile/WitherSkeleton.php @@ -33,6 +33,7 @@ use pocketmine\entity\Effect; use pocketmine\entity\EffectInstance; use pocketmine\entity\Entity; +use pocketmine\entity\Living; use pocketmine\entity\Monster; use pocketmine\inventory\AltayEntityEquipment; use pocketmine\item\Item; @@ -82,12 +83,10 @@ public function getDrops() : array{ public function onCollideWithEntity(Entity $entity) : void{ parent::onCollideWithEntity($entity); - if($entity instanceof Player){ - if($this->getTargetEntity() === $entity){ + if($this->getTargetEntityId() === $entity->getId() and $entity instanceof Living){ $entity->addEffect(new EffectInstance(Effect::getEffect(Effect::WITHER), 200, 1)); } } - }