Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Added New mobs #165

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b4b888b
Changed Blaze Power
Jul 26, 2019
d4024fa
Added Cod and Tropical Fish
Jul 26, 2019
a596262
Added WitherSkeleton, Dolphin, Pufferfish, Salmon
Jul 27, 2019
ee2aa7e
Merge branch 'dearmaster' into stable
dearminder Jul 29, 2019
81d6c53
Merge remote-tracking branch 'upstream/stable' into stable
Jul 30, 2019
8f18615
Merge pull request #2 from TuranicTeam/stable
dearminder Jul 31, 2019
c0006ee
Tempt Fix
Jul 31, 2019
6b352e7
Fixes for behavior executing
dearminder Aug 1, 2019
39a7230
Merge remote-tracking branch 'upstream/stable' into stable
Aug 2, 2019
160e771
.
Aug 2, 2019
91915ac
Updated To latest Behaviours
Aug 2, 2019
69abb59
fix
Aug 2, 2019
823af0c
Merge remote-tracking branch 'upstream/stable' into stable
Aug 3, 2019
fabb3a1
Creeper runawawy from ocelots
Aug 3, 2019
f5cec61
Creeper runaway from ocelots
Aug 3, 2019
fa5d87e
CTRL + ALT + L
Aug 3, 2019
d502eab
CTRL + ALT + L
Aug 3, 2019
3876c5d
Merge remote-tracking branch 'origin/stable' into stable
Aug 3, 2019
0ad56d9
Revert it
Aug 3, 2019
b37df0b
Better Effect
Aug 5, 2019
c29befa
Merge remote-tracking branch 'upstream/stable' into stable
Aug 9, 2019
a36659a
Merge remote-tracking branch 'upstream/stable' into stable
Aug 12, 2019
1fc28a4
Merge remote-tracking branch 'upstream/stable' into stable
Aug 14, 2019
9726378
Merge remote-tracking branch 'upstream/stable' into stable
Aug 20, 2019
99e984d
Merge remote-tracking branch 'upstream/stable' into stable
Aug 22, 2019
b28c71a
Merge remote-tracking branch 'upstream/stable' into stable
Sep 6, 2019
4156897
Merge remote-tracking branch 'upstream/stable' into stable
Sep 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/pocketmine/entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
use pocketmine\entity\hostile\Slime;
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;
use pocketmine\entity\hostile\Dolphin;
use pocketmine\entity\object\ArmorStand;
use pocketmine\entity\object\ExperienceOrb;
use pocketmine\entity\object\FallingBlock;
Expand All @@ -53,14 +57,23 @@
use pocketmine\entity\object\ItemEntity;
use pocketmine\entity\passive\Cat;
use pocketmine\entity\passive\Chicken;
use pocketmine\entity\passive\Cod;
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;
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\TropicalFish;
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;
Expand Down Expand Up @@ -381,15 +394,28 @@ 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(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']);
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(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']);
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']);
Expand Down
2 changes: 1 addition & 1 deletion src/pocketmine/entity/hostile/CaveSpider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function initEntity() : void{
}

public function getName() : string{
return "CaveSpider";
return "Cave Spider";
}

public function onCollideWithEntity(Entity $entity) : void{
Expand Down
2 changes: 2 additions & 0 deletions src/pocketmine/entity/hostile/Creeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
139 changes: 139 additions & 0 deletions src/pocketmine/entity/hostile/Dolphin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php

/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/

declare(strict_types=1);

namespace pocketmine\entity\hostile;

use pocketmine\entity\behavior\JumpAttackBehavior;
use pocketmine\entity\behavior\MeleeAttackBehavior;
use pocketmine\entity\Entity;
use pocketmine\entity\WaterAnimal;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\ActorEventPacket;
use function atan2;
use function mt_rand;
use function sqrt;
use const M_PI;

class Dolphin extends WaterAnimal{
public const NETWORK_ID = self::DOLPHIN;

public $width = 0.9;
public $height = 0.6;
//TODO: Add Jumping from water and attacking

/** @var Vector3 */
public $swimDirection = null;
public $swimSpeed = 1;

private $switchDirectionTicker = 0;

public function initEntity() : void{
$this->setMaxHealth(10);

parent::initEntity();
}

public function getName() : string{
return "Dolphin";
}

public function attack(EntityDamageEvent $source) : void{
parent::attack($source);
if($source->isCancelled()){
return;
}

if($source instanceof EntityDamageByEntityEvent){
$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();
}

}
}

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();
}
}


}
116 changes: 116 additions & 0 deletions src/pocketmine/entity/hostile/WitherSkeleton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

/*
* _ _
* /\ | | |
* / \ | | |_ __ _ _ _
* / /\ \ | | __/ _` | | | |
* / ____ \| | || (_| | |_| |
* /_/ \_|_|\__\__,_|\__, |
* __/ |
* |___/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author TuranicTeam
* @link https://github.com/TuranicTeam/Altay
*
*/

declare(strict_types=1);

namespace pocketmine\entity\hostile;

use pocketmine\entity\behavior\FindAttackableTargetBehavior;
use pocketmine\entity\behavior\FloatBehavior;
use pocketmine\entity\behavior\LookAtPlayerBehavior;
use pocketmine\entity\behavior\MeleeAttackBehavior;
use pocketmine\entity\behavior\RandomLookAroundBehavior;
use pocketmine\entity\behavior\RandomStrollBehavior;
use pocketmine\entity\Effect;
use pocketmine\entity\EffectInstance;
use pocketmine\entity\Entity;
use pocketmine\entity\Monster;
use pocketmine\inventory\AltayEntityEquipment;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\Player;
use function mt_rand;

class WitherSkeleton extends Monster{
public const NETWORK_ID = self::WITHER_SKELETON;

public $width = 0.7;
public $height = 2.4;

/** @var AltayEntityEquipment */
protected $equipment;

protected function initEntity() : void{
$this->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 RandomStrollBehavior($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]);
}
}
Loading