PrimedTNT Entity implemented

This commit is contained in:
Shoghi Cervantes 2013-09-07 02:46:18 +02:00
parent 0ddc48ca80
commit 5952e34995
3 changed files with 43 additions and 4 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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,