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

Advanced Navigator System & New Mobs #204

Draft
wants to merge 38 commits into
base: stable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 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
66a4443
Updates from me
phoshp Oct 20, 2019
f2b4769
Updates from me 2
phoshp Oct 21, 2019
f6aae91
New Mob AI Navigation system (not finished yet)
phoshp Oct 24, 2019
208ca8f
Optimization & bug fixes (its working now)
phoshp Oct 25, 2019
9687c9d
fixes
phoshp Oct 25, 2019
0ec1ae7
uh?
phoshp Oct 27, 2019
133ea44
composer
phoshp Nov 13, 2019
42f6d08
Merge branch 'stable' of https://github.com/TuranicTeam/Altay into pu…
phoshp Nov 13, 2019
c10ac35
SwimNodeProcessor
phoshp Nov 13, 2019
28ccf54
Merge branch 'stable' into pull/165
phoshp Aug 12, 2020
ee47c52
Some fixes
phoshp Aug 22, 2020
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
4 changes: 2 additions & 2 deletions src/pocketmine/entity/Animal.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ public function saveNBT() : void{
}

public function getVariant() : int{
return $this->propertyManager->getInt(self::DATA_VARIANT);
return $this->propertyManager->getInt(self::DATA_VARIANT) ?? 0;
}

public function setVariant(int $variant) : void{
$this->propertyManager->setInt(self::DATA_VARIANT, $variant);
}

public function getMarkVariant() : int{
return $this->propertyManager->getInt(self::DATA_MARK_VARIANT);
return $this->propertyManager->getInt(self::DATA_MARK_VARIANT) ?? 0;
}

public function setMarkVariant(int $markVariant) : void{
Expand Down
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\EnderCrystal;
use pocketmine\entity\object\ExperienceOrb;
Expand All @@ -54,14 +58,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 @@ -398,15 +411,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:zombie_horse']);
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:zombie_pigman']);
Entity::registerEntity(ZombieVillager::class, false, ['ZombieVillager', 'minecraft:zombie_villager']);
Entity::registerEntity(WitherSkeleton::class, false, ['WitherSkeleton', 'minecraft:wither_skeleon']);
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:skeleton_horse']);
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
27 changes: 14 additions & 13 deletions src/pocketmine/entity/Mob.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
use pocketmine\entity\helper\EntityJumpHelper;
use pocketmine\entity\helper\EntityLookHelper;
use pocketmine\entity\helper\EntityMoveHelper;
use pocketmine\entity\pathfinder\EntityNavigator;
use pocketmine\entity\pathfinding\navigate\PathNavigate;
use pocketmine\entity\pathfinding\navigate\PathNavigateGround;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\Player;
Expand All @@ -49,7 +50,7 @@ abstract class Mob extends Living{
protected $behaviorPool;
/** @var BehaviorPool */
protected $targetBehaviorPool;
/** @var EntityNavigator */
/** @var PathNavigate */
protected $navigator;
/** @var Entity[] */
protected $seenEntities = [];
Expand Down Expand Up @@ -145,7 +146,7 @@ protected function initEntity() : void{

$this->targetBehaviorPool = new BehaviorPool();
$this->behaviorPool = new BehaviorPool();
$this->navigator = new EntityNavigator($this);
$this->navigator = $this->createNavigator();
$this->moveHelper = new EntityMoveHelper($this);
$this->jumpHelper = new EntityJumpHelper($this);
$this->lookHelper = new EntityLookHelper($this);
Expand Down Expand Up @@ -184,7 +185,7 @@ protected function onBehaviorUpdate() : void{
Timings::$mobBehaviorUpdateTimer->stopTiming();

Timings::$mobNavigationUpdateTimer->startTiming();
$this->navigator->onNavigateUpdate();
$this->navigator->tick();
Timings::$mobNavigationUpdateTimer->stopTiming();

$this->moveHelper->onUpdate();
Expand All @@ -211,10 +212,14 @@ protected function onBehaviorUpdate() : void{
$this->moveWithHeading($this->moveStrafing, $this->moveForward);

$this->bodyHelper->onUpdate();

$this->tryToDespawn();
}

protected function createNavigator() : PathNavigate{
return new PathNavigateGround($this);
}

/**
* @param Entity $target
*
Expand All @@ -226,8 +231,7 @@ public function canSeeEntity(Entity $target) : bool{
}elseif(in_array($target->getId(), $this->seenEntities)){
return true;
}else{
// TODO: Fix seen from corners
$canSee = $this->getNavigator()->isClearBetweenPoints($this, $target);
$canSee = $this->getNavigator()->isDirectPathBetweenPoints($this, $target, new Vector3($i = ceil($this->width + 0.25), $this->height + 1, $i));

if($canSee){
$this->seenEntities[] = $target->getId();
Expand Down Expand Up @@ -270,10 +274,7 @@ public function handleLavaJump() : void{
$this->motion->y += 0.04;
}

/**
* @return EntityNavigator
*/
public function getNavigator() : EntityNavigator{
public function getNavigator() : PathNavigate{
return $this->navigator;
}

Expand Down Expand Up @@ -303,7 +304,7 @@ public function updateLeashedState() : void{
}

if($f > 4){
$this->navigator->tryMoveTo($entity, 1.0);
$this->navigator->tryMoveToEntity($entity, 1.0);
}

if($f > 6){
Expand All @@ -321,7 +322,7 @@ public function updateLeashedState() : void{
}
}
}

protected function tryToDespawn() : void{
if($this->canDespawn() and $this->level->getNearestEntity($this, 128, Player::class, true) === null){
$this->flagForDespawn();
Expand Down
6 changes: 6 additions & 0 deletions src/pocketmine/entity/WaterAnimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

namespace pocketmine\entity;

use pocketmine\block\Water;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\math\Vector3;

abstract class WaterAnimal extends Mob implements Ageable{

Expand All @@ -41,6 +43,10 @@ public function canSpawnHere() : bool{
return true;
}

public function getBlockPathWeight(Vector3 $pos) : float{
return $this->level->getBlock($pos) instanceof Water ? 10 : 0;
}

public function onAirExpired() : void{
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 2);
$this->attack($ev);
Expand Down
11 changes: 5 additions & 6 deletions src/pocketmine/entity/behavior/AvoidMobTypeBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function canStart() : bool{
$vec = RandomPositionGenerator::findRandomTargetBlockAwayFrom($this->mob, 16, 7, $nearest);

if($vec !== null and $nearest->distanceSquared($vec) >= $nearest->distanceSquared($this->mob)){
$this->path = $this->mob->getNavigator()->findPath($vec);
$this->path = $this->mob->getNavigator()->getPathToPos($vec);

return $this->path !== null;
}
Expand All @@ -77,19 +77,18 @@ public function canStart() : bool{
}

public function canContinue() : bool{
return $this->mob->getNavigator()->isBusy();
return !$this->mob->getNavigator()->noPath();
}

public function onStart() : void{
$this->mob->getNavigator()->setPath($this->path);
$this->mob->getNavigator()->setSpeedMultiplier($this->farSpeed);
$this->mob->getNavigator()->setPath($this->path, $this->farSpeed);
}

public function onTick() : void{
if($this->mob->distanceSquared($this->nearestEntity) < 49){
$this->mob->getNavigator()->setSpeedMultiplier($this->nearSpeed);
$this->mob->getNavigator()->setSpeed($this->nearSpeed);
}else{
$this->mob->getNavigator()->setSpeedMultiplier($this->farSpeed);
$this->mob->getNavigator()->setSpeed($this->farSpeed);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/pocketmine/entity/behavior/EatBlockBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function canStart() : bool{
public function onStart() : void{
$this->mob->broadcastEntityEvent(ActorEventPacket::EAT_GRASS_ANIMATION);
$this->duration = 40;
$this->mob->getNavigator()->clearPath();
$this->mob->getNavigator()->clearPathEntity();
}

public function canContinue() : bool{
Expand Down
4 changes: 2 additions & 2 deletions src/pocketmine/entity/behavior/FleeSunBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public function canStart() : bool{
}

public function onStart() : void{
$this->mob->getNavigator()->tryMoveTo($this->shelter, $this->speedMultiplier);
$this->mob->getNavigator()->tryMoveToPos($this->shelter, $this->speedMultiplier);
}

public function canContinue() : bool{
return $this->mob->getNavigator()->isBusy();
return !$this->mob->getNavigator()->noPath();
}

public function findPossibleShelter() : ?Block{
Expand Down
7 changes: 6 additions & 1 deletion src/pocketmine/entity/behavior/FloatBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@
namespace pocketmine\entity\behavior;

use pocketmine\entity\Mob;
use pocketmine\math\Vector3;
use pocketmine\entity\pathfinding\navigate\PathNavigateGround;

class FloatBehavior extends Behavior{

public function __construct(Mob $mob){
parent::__construct($mob);
$this->mutexBits = 4;

$navigator = $this->mob->getNavigator();
if($navigator instanceof PathNavigateGround){
$navigator->setCanSwim(true);
}
}

public function canStart() : bool{
Expand Down
22 changes: 15 additions & 7 deletions src/pocketmine/entity/behavior/FollowOwnerBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
namespace pocketmine\entity\behavior;

use pocketmine\entity\Entity;
use pocketmine\entity\pathfinding\navigate\PathNavigateGround;
use pocketmine\entity\Tamable;
use pocketmine\Player;


class FollowOwnerBehavior extends Behavior{

/** @var float */
Expand Down Expand Up @@ -66,11 +66,15 @@ public function canStart() : bool{

public function onStart() : void{
$this->followDelay = 0;
$this->mob->getNavigator()->setAvoidsWater(false);

$navigator = $this->mob->getNavigator();
if($navigator instanceof PathNavigateGround){
$navigator->setAvoidsWater(true);
}
}

public function canContinue() : bool{
return $this->mob->getNavigator()->isBusy() and $this->mob->distanceSquared($this->owner) > ($this->maxDistance ** 2) and !$this->mob->isSitting();
return !$this->mob->getNavigator()->noPath() and $this->mob->distanceSquared($this->owner) > ($this->maxDistance ** 2) and !$this->mob->isSitting();
}

public function onTick() : void{
Expand All @@ -80,21 +84,25 @@ public function onTick() : void{
if(--$this->followDelay <= 0){
$this->followDelay = 10;

$this->mob->getNavigator()->tryMoveTo($this->owner, $this->speedMultiplier);
$this->mob->getNavigator()->tryMoveToEntity($this->owner, $this->speedMultiplier);

if(!$this->mob->isLeashed()){
if($this->mob->distanceSquared($this->owner) > 144){
$this->mob->teleport($this->owner);
$this->mob->getNavigator()->clearPath(true);
$this->mob->getNavigator()->clearPathEntity();
}
}
}
}
}

public function onEnd() : void{
$this->mob->getNavigator()->clearPath(true);
$this->mob->getNavigator()->clearPathEntity();
$this->owner = null;
$this->mob->getNavigator()->setAvoidsWater(true);

$navigator = $this->mob->getNavigator();
if($navigator instanceof PathNavigateGround){
$navigator->setAvoidsWater(true);
}
}
}
2 changes: 1 addition & 1 deletion src/pocketmine/entity/behavior/FollowParentBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function onStart() : void{
public function onTick() : void{
if($this->delay-- <= 0){
$this->delay = 10;
$this->mob->getNavigator()->tryMoveTo($this->parentAnimal, $this->speedMultiplier);
$this->mob->getNavigator()->tryMoveToEntity($this->parentAnimal, $this->speedMultiplier);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/pocketmine/entity/behavior/MateBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function canContinue() : bool{

public function onTick() : void{
$this->mob->getLookHelper()->setLookPositionWithEntity($this->targetMate, 10, $this->mob->getVerticalFaceSpeed());
$this->mob->getNavigator()->tryMoveTo($this->targetMate, $this->speedMultiplier);
$this->mob->getNavigator()->tryMoveToEntity($this->targetMate, $this->speedMultiplier);

$this->spawnBabyDelay++;

Expand Down
11 changes: 5 additions & 6 deletions src/pocketmine/entity/behavior/MeleeAttackBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ public function canStart() : bool{

$this->lastPlayerPos = $target->asVector3();

$this->path = $this->mob->getNavigator()->findPath($target);
return $this->path->havePath();
$this->path = $this->mob->getNavigator()->getPathToEntity($target);
return $this->path !== null;
}

public function onStart() : void{
$this->delay = 0;
$this->mob->getNavigator()->setPath($this->path);
$this->mob->getNavigator()->setSpeedMultiplier($this->speedMultiplier);
$this->mob->getNavigator()->setPath($this->path, $this->speedMultiplier);
}

public function canContinue() : bool{
Expand Down Expand Up @@ -95,7 +94,7 @@ public function onTick() : void{
$this->delay += 5;
}

if(!$this->mob->getNavigator()->tryMoveTo($target, $this->speedMultiplier)){
if(!$this->mob->getNavigator()->tryMoveToEntity($target, $this->speedMultiplier)){
$this->delay += 15;
}
}
Expand All @@ -118,7 +117,7 @@ public function onEnd() : void{
$this->mob->pitch = 0;
$this->attackCooldown = $this->delay = 0;
$this->path = null;
$this->mob->getNavigator()->clearPath();
$this->mob->getNavigator()->clearPathEntity();
}

}
2 changes: 1 addition & 1 deletion src/pocketmine/entity/behavior/MountPathingBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function onTick() : void{
$pos = RandomPositionGenerator::findRandomTargetBlock($this->mob, 10, 7);

if($pos !== null){
$this->mob->getNavigator()->tryMoveTo($pos, 1, $this->mob->distanceSquared($pos) + 2);
$this->mob->getNavigator()->tryMoveToPos($pos, 1);
}
}

Expand Down
Loading