mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
Tile Entities & Signs
This commit is contained in:
parent
3c4888521d
commit
5c11f48270
4 changed files with 210 additions and 12 deletions
|
|
@ -25,12 +25,93 @@ the Free Software Foundation, either version 3 of the License, or
|
|||
|
||||
*/
|
||||
|
||||
class TileEntity extends stdClass{
|
||||
private $server;
|
||||
function __construct(PocketMinecraftServer $server){
|
||||
|
||||
define("TILE_SIGN", 0);
|
||||
|
||||
class TileEntity extends stdClass{
|
||||
public $name;
|
||||
public $id;
|
||||
public $x;
|
||||
public $y;
|
||||
public $z;
|
||||
public $data;
|
||||
public $class;
|
||||
public $attach;
|
||||
public $metadata;
|
||||
public $closed;
|
||||
private $server;
|
||||
function __construct(PocketMinecraftServer $server, $id, $class, $x, $y, $z, $data = array()){
|
||||
$this->server = $server;
|
||||
$this->class = (int) $class;
|
||||
$this->data = $data;
|
||||
$this->closed = false;
|
||||
$this->name = "";
|
||||
$this->id = (int) $id;
|
||||
$this->x = (int) $x;
|
||||
$this->y = (int) $y;
|
||||
$this->z = (int) $z;
|
||||
$this->server->query("INSERT OR REPLACE INTO tileentities (ID, class, x, y, z) VALUES (".$this->id.", ".$this->class.", ".$this->x.", ".$this->y.", ".$this->z.");");
|
||||
$update = false;
|
||||
switch($this->class){
|
||||
case TILE_SIGN:
|
||||
break;
|
||||
}
|
||||
if($update === true){
|
||||
$this->server->schedule(40, array($this, "update"), array(), true);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(){
|
||||
if($this->closed === true){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function spawn($player){
|
||||
if(!($player instanceof Player)){
|
||||
$player = $this->server->api->player->get($player);
|
||||
}
|
||||
switch($this->class){
|
||||
case TILE_SIGN:
|
||||
$player->dataPacket(MC_SIGN_UPDATE, array(
|
||||
"x" => $this->x,
|
||||
"y" => $this->y,
|
||||
"z" => $this->z,
|
||||
"line0" => $this->data["Text1"],
|
||||
"line1" => $this->data["Text2"],
|
||||
"line2" => $this->data["Text3"],
|
||||
"line3" => $this->data["Text4"],
|
||||
), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function close(){
|
||||
if($this->closed === false){
|
||||
$this->closed = true;
|
||||
$this->server->api->entity->remove($this->eid);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName($name){
|
||||
$this->name = $name;
|
||||
$this->server->query("UPDATE entities SET name = '".str_replace("'", "", $this->name)."' WHERE EID = ".$this->eid.";");
|
||||
}
|
||||
|
||||
|
||||
public function setPosition($x, $y, $z){
|
||||
$this->x = (int) $x;
|
||||
$this->y = (int) $y;
|
||||
$this->z = (int) $z;
|
||||
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z." WHERE EID = ".$this->eid.";");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue