mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
fix
This commit is contained in:
parent
0d1fb47898
commit
8bb5667a55
2 changed files with 47 additions and 1 deletions
46
src/entity/ai/tasks/TaskEatTileGoal.php
Normal file
46
src/entity/ai/tasks/TaskEatTileGoal.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
class TaskEatTileGoal extends TaskBase
|
||||
{
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->selfCounter = 40;
|
||||
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, new EntityEventPacket($ai->entity->eid, EntityEventPacket::ENTITY_ANIM_10));
|
||||
}
|
||||
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if (--$this->selfCounter === 4)
|
||||
{
|
||||
$id = $ai->entity->level->getBlock($ai->entity->floor());
|
||||
$idb = $ai->entity->level->getBlock($id->getSide(0));
|
||||
if($id->getID() === TALL_GRASS){
|
||||
$ai->entity->level->setBlock($idb, BlockAPI::get(AIR));
|
||||
$ai->entity->eatGrass();
|
||||
|
||||
}elseif($idb->getID() === GRASS){
|
||||
$ai->entity->level->setBlock($idb, BlockAPI::get(DIRT));
|
||||
$ai->entity->eatGrass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
if($ai->isStarted("TaskRandomWalk")) return false;
|
||||
if(mt_rand(0, ($ai->entity instanceof Ageable && $ai->entity->isBaby()) ? 50 : 1000) == 0){
|
||||
$b = $ai->entity->level->getBlock($ai->entity->floor());
|
||||
$bu = $ai->entity->level->getBlock($b->getSide(0));
|
||||
return ($b->getID() === TALL_GRASS && $b->getMetadata() === 1) || $bu->getID() === GRASS;
|
||||
}
|
||||
return false;
|
||||
//this.theEntity.getRNG().nextInt(this.theEntity.isChild() ? 50 : 1000) != 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ class Sheep extends Animal{
|
|||
}elseif($this->isBaby() and Entity::$updateOnTick){
|
||||
$this->server->schedule(mt_rand(400, 1000), [$this, "eatGrass"], null, true); //unknown time
|
||||
}*/
|
||||
$this->ai->addTask(new TasKEatTileGoal());
|
||||
$this->ai->addTask(new TaskEatTileGoal());
|
||||
}
|
||||
public function createSaveData(){
|
||||
$data = parent::createSaveData();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue