From 5952e34995725c13f96584081d2dc0afde98f56a Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 7 Sep 2013 02:46:18 +0200 Subject: [PATCH] PrimedTNT Entity implemented --- src/constants/GeneralConstants.php | 1 + src/material/block/misc/TNT.php | 12 +++++++++-- src/world/Entity.php | 34 ++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/constants/GeneralConstants.php b/src/constants/GeneralConstants.php index ee973a2af..9febec891 100644 --- a/src/constants/GeneralConstants.php +++ b/src/constants/GeneralConstants.php @@ -62,6 +62,7 @@ define("ENTITY_MOB", 2); define("MOB_PIGMAN", 36); define("ENTITY_OBJECT", 3); + define("OBJECT_PRIMEDTNT", 65); define("OBJECT_ARROW", 80); define("OBJECT_PAINTING", 83); diff --git a/src/material/block/misc/TNT.php b/src/material/block/misc/TNT.php index 0940bd3fe..8ac827636 100644 --- a/src/material/block/misc/TNT.php +++ b/src/material/block/misc/TNT.php @@ -31,8 +31,16 @@ class TNTBlock extends SolidBlock{ if(($player->gamemode & 0x01) === 0){ $item->useOn($this); } - $explosion = new Explosion(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), 4); - $explosion->explode(); + $data = array( + "x" => $this->x + 0.5, + "y" => $this->y + 0.5, + "z" => $this->z + 0.5, + "power" => 4, + "fuse" => 20 * 4, //4 seconds + ); + $this->level->setBlock($this, new AirBlock(), false, false, true); + $e = ServerAPI::request()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data); + ServerAPI::request()->api->entity->spawnToAll($e); return true; } return false; diff --git a/src/world/Entity.php b/src/world/Entity.php index de2a64580..25ff2d545 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -129,6 +129,10 @@ class Entity extends Position{ $this->size = 1; if($this->type === OBJECT_PAINTING){ $this->isStatic = true; + }elseif($this->type === OBJECT_PRIMEDTNT){ + $this->setHealth(10000000, "generic"); + $this->server->schedule(5, array($this, "updateFuse"), array(), true); + $this->update(); }elseif($this->type === OBJECT_ARROW){ $this->server->schedule(1210, array($this, "update")); //Despawn $this->update(); @@ -139,6 +143,21 @@ class Entity extends Position{ $this->updatePosition(); } + public function updateFuse(){ + if($this->closed === true){ + return false; + } + if($this->type === OBJECT_PRIMEDTNT){ + $this->data["fuse"] -= 5; + $this->updateMetadata(); + if($this->data["fuse"] <= 0){ + $this->close(); + $explosion = new Explosion($this, $this->data["power"]); + $explosion->explode(); + } + } + } + public function getDrops(){ if($this->class === ENTITY_PLAYER and ($this->player->gamemode & 0x01) === 0){ $inv = array(); @@ -409,7 +428,7 @@ class Entity extends Position{ } if($this->class !== ENTITY_PLAYER){ $update = false; - if($this->class !== ENTITY_OBJECT or $support === false){ + if(($this->class !== ENTITY_OBJECT and $this->type !== OBJECT_PRIMEDTNT) or $support === false){ $drag = 0.4 * $tdiff; if($this->speedX != 0){ $this->speedX -= $this->speedX * $drag; @@ -463,7 +482,7 @@ class Entity extends Position{ $this->speedY = 0; $this->speedZ = 0; $this->server->api->handle("entity.move", $this); - if($this->class === ENTITY_OBJECT or $this->speedY <= 0.1){ + if(($this->class === ENTITY_OBJECT and $this->type !== OBJECT_PRIMEDTNT) or $this->speedY <= 0.1){ $update = false; $this->server->api->handle("entity.motion", $this); } @@ -587,6 +606,8 @@ class Entity extends Position{ $this->data["Color"] = mt_rand(0,15); } $d[16]["value"] = (($this->data["Sheared"] == 1 ? 1:0) << 4) | ($this->data["Color"] & 0x0F); + }elseif($this->type === OBJECT_PRIMEDTNT){ + $d[16]["value"] = $this->data["fuse"]; }elseif($this->class === ENTITY_PLAYER){ if($this->player->isSleeping !== false){ $d[16]["value"] = 2; @@ -681,6 +702,15 @@ class Entity extends Position{ "direction" => $this->getDirection(), "title" => $this->data["Motive"], )); + }elseif($this->type === OBJECT_PRIMEDTNT){ + $player->dataPacket(MC_ADD_ENTITY, array( + "eid" => $this->eid, + "type" => $this->type, + "x" => $this->x, + "y" => $this->y, + "z" => $this->z, + "did" => 0, + )); }elseif($this->type === OBJECT_ARROW){ $player->dataPacket(MC_ADD_ENTITY, array( "eid" => $this->eid,