mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
Sheep can eat grass, zombie can burn on day
This commit is contained in:
parent
a4c1f1e995
commit
c0f4821fbc
3 changed files with 58 additions and 8 deletions
|
|
@ -1278,10 +1278,14 @@ class Entity extends Position
|
|||
$this->health = min(127, max(- 127, $health));
|
||||
$this->server->query("UPDATE entities SET health = " . $this->health . " WHERE EID = " . $this->eid . ";");
|
||||
if($harm === true){
|
||||
$this->server->api->dhandle("entity.event", array(
|
||||
$pk = new EntityEventPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->event = 2;
|
||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
/*$this->server->api->dhandle("entity.event", array(
|
||||
"entity" => $this,
|
||||
"event" => 2
|
||||
)); // Ouch! sound
|
||||
)); // Ouch! sound*/
|
||||
}
|
||||
if($this->player instanceof Player){
|
||||
$pk = new SetHealthPacket();
|
||||
|
|
@ -1306,18 +1310,22 @@ class Entity extends Position
|
|||
$pk->yaw = 0;
|
||||
$pk->pitch = 0;
|
||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
} else{
|
||||
$this->server->api->dhandle("entity.event", array(
|
||||
}else{
|
||||
$pk = new EntityEventPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->event = 3;
|
||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
/*$this->server->api->dhandle("entity.event", [
|
||||
"entity" => $this,
|
||||
"event" => 3
|
||||
)); // Entity dead
|
||||
]); // Entity dead*/
|
||||
}
|
||||
if($this->player instanceof Player){
|
||||
$this->player->blocked = true;
|
||||
$this->server->api->dhandle("player.death", array(
|
||||
$this->server->api->dhandle("player.death", [
|
||||
"player" => $this->player,
|
||||
"cause" => $cause
|
||||
));
|
||||
]);
|
||||
if($this->server->api->getProperty("hardcore") == 1){
|
||||
$this->server->api->ban->ban($this->player->username);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,25 @@ class Sheep extends Animal{
|
|||
$this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.675 : 1.3);
|
||||
$this->setSpeed(0.25);
|
||||
$this->update();
|
||||
if($this->isSheared() and Entity::$updateOnTick){ //if ai enabled
|
||||
$this->server->schedule(mt_rand(60, 400), [$this, "eatGrass"], null, true); //unknown time
|
||||
}elseif($this->isBaby() and Entity::$updateOnTick){
|
||||
$this->server->schedule(mt_rand(400, 1000), [$this, "eatGrass"], null, true); //unknown time
|
||||
}
|
||||
}
|
||||
|
||||
public function eatGrass(){
|
||||
$downBlock = $this->level->getBlock(new Vector3($this->x, $this->y-1, $this->z));
|
||||
if($downBlock->getID() !== GRASS){
|
||||
//console("eww i don't wanna eat this $downBlock");
|
||||
return false;
|
||||
}
|
||||
$pk = new EntityEventPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->event = 10;
|
||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
$this->server->schedule(38, [$this, "setSheared"], false);
|
||||
$this->level->setblock(new Position($this->x, $this->y-1, $this->z, $this->level), new DirtBlock());
|
||||
}
|
||||
|
||||
public function setSheared($v = null){
|
||||
|
|
@ -28,7 +47,7 @@ class Sheep extends Animal{
|
|||
|
||||
public function getDrops(){
|
||||
return $this->isBaby() ? parent::getDrops() : [
|
||||
[WOOL, $this->getColor() & 0x0F, 1],
|
||||
[WOOL, $this->getColor() & 0x0F, 1]
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -43,6 +62,7 @@ class Sheep extends Animal{
|
|||
if(!$this->isSheared()){
|
||||
$this->setSheared(1);
|
||||
$this->server->api->entity->drop($this, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3)));
|
||||
//$this->server->schedule(20, [$this, "eatGrass"]);
|
||||
if($slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,28 @@ class Zombie extends Monster{
|
|||
$this->setSize(0.6, 1.85);
|
||||
$this->setSpeed(0.23);
|
||||
$this->update();
|
||||
//$this->server->schedule(20, [$this, "burnable"], null, true); //todo
|
||||
}
|
||||
|
||||
public function burnable(){
|
||||
if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) == "day"){
|
||||
return;
|
||||
}
|
||||
$y = $this->y;
|
||||
for(; $y < 129; $y++){
|
||||
$block = $this->level->getBlock(new Vector3($this->x, $y, $this->z));
|
||||
if($block->isSolid){ //?
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$block = $this->level->getBlock(new Vector3($this->x, $y, $this->z))->getID();
|
||||
if($block === AIR){
|
||||
$this->fire = 200;
|
||||
$this->updateMetadata();
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue