From 218dd4ffa425cc12f12dd32a6ecae7cbd37486aa Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Tue, 12 Jul 2022 00:57:34 +0300 Subject: [PATCH] separated tnt class from all other ones --- src/entity/Animal.php | 9 ++++++ src/entity/Creature.php | 7 ++++ src/entity/Entity.php | 57 +-------------------------------- src/entity/EntityRegistry.php | 1 + src/entity/Human.php | 5 +++ src/entity/animal/Chicken.php | 2 +- src/entity/animal/Cow.php | 2 +- src/entity/animal/Pig.php | 2 +- src/entity/animal/Sheep.php | 2 +- src/entity/object/PrimedTNT.php | 51 +++++++++++++++++++++++++++++ 10 files changed, 78 insertions(+), 60 deletions(-) diff --git a/src/entity/Animal.php b/src/entity/Animal.php index 618e69d4..d6f866f0 100644 --- a/src/entity/Animal.php +++ b/src/entity/Animal.php @@ -4,6 +4,7 @@ TODO: move methods */ abstract class Animal extends Creature implements Ageable, Breedable{ + public function isBaby(){ if(!isset($this->data["IsBaby"])){ $this->data["IsBaby"] = false; @@ -25,4 +26,12 @@ abstract class Animal extends Creature implements Ageable, Breedable{ } parent::environmentUpdate(); } + + public function getDrops(){ + if($this->isBaby()){ + return array( + array(AIR, 0, 0), + ); + } + } } \ No newline at end of file diff --git a/src/entity/Creature.php b/src/entity/Creature.php index cc2e0c57..3e821027 100644 --- a/src/entity/Creature.php +++ b/src/entity/Creature.php @@ -5,4 +5,11 @@ move methods */ abstract class Creature extends Living{ const CLASS_TYPE = ENTITY_MOB; + public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ + parent::__construct($level, $eid, $class, $type, $data); + $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:1, "generic"); + $this->update(); + //$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type)); + $this->size = 1; + } } \ No newline at end of file diff --git a/src/entity/Entity.php b/src/entity/Entity.php index fb2a5432..a530e37f 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -112,15 +112,6 @@ class Entity extends Position{ $this->update(); $this->size = 0.75; break; - case ENTITY_MOB: - switch($this->type){ - default: - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:1, "generic"); - $this->update(); - //$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type)); - $this->size = 1; - } - break; case ENTITY_FALLING: $this->setHealth(PHP_INT_MAX, "generic"); $this->update(); @@ -135,13 +126,6 @@ class Entity extends Position{ $this->size = 1; if($this->type === OBJECT_PAINTING){ $this->isStatic = true; - }elseif($this->type === OBJECT_PRIMEDTNT){ - if(!isset($this->data["fuse"])){ - $this->data["fuse"] = 0; - } - $this->setHealth(10000000, "generic"); - $this->server->schedule(5, array($this, "updateFuse"), array(), true); - $this->update(); }elseif($this->type === OBJECT_SNOWBALL){ $this->server->schedule(1210, array($this, "update")); //Despawn $this->update(); @@ -157,20 +141,6 @@ class Entity extends Position{ } } - public function updateFuse(){ - if($this->closed === true){ - return false; - } - if($this->type === OBJECT_PRIMEDTNT){ - $this->updateMetadata(); - if(((microtime(true) - $this->spawntime) * 20) >= $this->data["fuse"]){ - $this->close(); - $explosion = new Explosion($this, $this->data["power"]); - $explosion->explode(); - } - } - } - public function getDrops(){ if($this->class === ENTITY_PLAYER and $this->player instanceof Player and ($this->player->gamemode & 0x01) === 0){ $inv = array(); @@ -200,12 +170,6 @@ class Entity extends Position{ array(MINECART, 0, 1), ); } - }elseif($this->class === ENTITY_MOB){ - if($this->data["IsBaby"]){ - return array( - array(AIR, 0, 0), - ); - } } return array(); } @@ -609,10 +573,7 @@ class Entity extends Position{ 16 => array("type" => 0, "value" => 0), 17 => array("type" => 6, "value" => array(0, 0, 0)), ); - if($this->class === ENTITY_OBJECT || $this->class === ENTITY_MOB){ //ladder fix 2.0 - if($this->type === OBJECT_PRIMEDTNT){ - $d[16]["value"] = (int) max(0, $this->data["fuse"] - (microtime(true) - $this->spawntime) * 20); - } + if($this->class === ENTITY_MOB){ //ladder fix 2.0 if($this->type === MOB_PIG){ /*Saddled Pig*/ $d[16]["value"] = 0; } @@ -720,22 +681,6 @@ class Entity extends Position{ $pk->direction = $this->getDirection(); $pk->title = $this->data["Motive"]; $player->dataPacket($pk); - }elseif($this->type === OBJECT_PRIMEDTNT){ - $pk = new AddEntityPacket; - $pk->eid = $this->eid; - $pk->type = $this->type; - $pk->x = $this->x; - $pk->y = $this->y; - $pk->z = $this->z; - $pk->did = 0; - $player->dataPacket($pk); - - $pk = new SetEntityMotionPacket; - $pk->eid = $this->eid; - $pk->speedX = $this->speedX; - $pk->speedY = $this->speedY; - $pk->speedZ = $this->speedZ; - $player->dataPacket($pk); }elseif($this->type === OBJECT_MINECART){ $pk = new AddEntityPacket; $pk->eid = $this->eid; diff --git a/src/entity/EntityRegistry.php b/src/entity/EntityRegistry.php index b79e2831..7a3237f2 100644 --- a/src/entity/EntityRegistry.php +++ b/src/entity/EntityRegistry.php @@ -47,6 +47,7 @@ class EntityRegistry{ self::registerEntity(Spider::class); self::registerEntity(Zombie::class); self::registerEntity(Arrow::class); + self::registerEntity(PrimedTNT::class); } /*Register an Entity*/ diff --git a/src/entity/Human.php b/src/entity/Human.php index e69de29b..99d11a32 100644 --- a/src/entity/Human.php +++ b/src/entity/Human.php @@ -0,0 +1,5 @@ +isBaby() ? array() : + return $this->isBaby() ? parent::getDrops() : array( array(FEATHER, 0, mt_rand(0,2)), array(($this->fire > 0 ? COOKED_CHICKEN : RAW_CHICKEN), 0, 1), diff --git a/src/entity/animal/Cow.php b/src/entity/animal/Cow.php index 08501949..a1d2780f 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -14,7 +14,7 @@ class Cow extends Animal{ } public function getDrops(){ - return $this->isBaby() ? array() : + return $this->isBaby() ? parent::getDrops() : array( array(LEATHER, 0, mt_rand(0,2)), array(($this->fire > 0 ? STEAK:BEEF), 0, 1), diff --git a/src/entity/animal/Pig.php b/src/entity/animal/Pig.php index 19bcc6ee..75e09580 100644 --- a/src/entity/animal/Pig.php +++ b/src/entity/animal/Pig.php @@ -12,7 +12,7 @@ class Pig extends Animal{ return $id === POTATO || $id === CARROT || $id === BEETROOT; } public function getDrops(){ - return $this->isBaby() ? array() : + return $this->isBaby() ? parent::getDrops() : array( array(($this->fire > 0 ? COOKED_PORKCHOP:RAW_PORKCHOP), 0, 1), ); diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index ae03247b..7c1302da 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -11,7 +11,7 @@ class Sheep extends Animal{ } public function getDrops(){ - return $this->isBaby() ? array() : + return $this->isBaby() ? parent::getDrops() : array( array(WOOL, $this->data["Color"] & 0x0F, 1), ); diff --git a/src/entity/object/PrimedTNT.php b/src/entity/object/PrimedTNT.php index e69de29b..9451dbba 100644 --- a/src/entity/object/PrimedTNT.php +++ b/src/entity/object/PrimedTNT.php @@ -0,0 +1,51 @@ +data["fuse"])){ + $this->data["fuse"] = 0; + } + $this->setHealth(10000000, "generic"); + $this->server->schedule(5, array($this, "updateFuse"), array(), true); + $this->update(); + } + public function getMetadata(){ + $d = parent::getMetadata(); + $d[16]["value"] = (int) max(0, $this->data["fuse"] - (microtime(true) - $this->spawntime) * 20); + return $d; + } + public function updateFuse(){ + if($this->closed === true){ + return false; + } + if($this->type === OBJECT_PRIMEDTNT){ + $this->updateMetadata(); + if(((microtime(true) - $this->spawntime) * 20) >= $this->data["fuse"]){ + $this->close(); + $explosion = new Explosion($this, $this->data["power"]); + $explosion->explode(); + } + } + } + + public function spawn($player){ + $pk = new AddEntityPacket; + $pk->eid = $this->eid; + $pk->type = $this->type; + $pk->x = $this->x; + $pk->y = $this->y; + $pk->z = $this->z; + $pk->did = 0; + $player->dataPacket($pk); + $pk = new SetEntityMotionPacket; + $pk->eid = $this->eid; + $pk->speedX = $this->speedX; + $pk->speedY = $this->speedY; + $pk->speedZ = $this->speedZ; + $player->dataPacket($pk); + } +} \ No newline at end of file