mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
separated tnt class from all other ones
This commit is contained in:
parent
002f7f0946
commit
218dd4ffa4
10 changed files with 78 additions and 60 deletions
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
class PrimedTNT extends Entity{
|
||||
const TYPE = OBJECT_PRIMEDTNT;
|
||||
const CLASS_TYPE = ENTITY_OBJECT;
|
||||
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
if(!isset($this->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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue