mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 07:39:57 +00:00
Removed EntityAPI
This commit is contained in:
parent
e314f46b5b
commit
2bf3f0de73
@ -500,7 +500,6 @@ class BlockAPI{
|
||||
$level = $block->onUpdate($type);
|
||||
if($level === BLOCK_UPDATE_NORMAL){
|
||||
$this->blockUpdateAround($block, $level);
|
||||
$this->server->api->entity->updateRadius($pos, 1);
|
||||
}elseif($level === BLOCK_UPDATE_RANDOM){
|
||||
$this->nextRandomUpdate($pos);
|
||||
}
|
||||
|
@ -1,174 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class EntityAPI{
|
||||
private $server;
|
||||
private $entities;
|
||||
private $eCnt = 1;
|
||||
|
||||
function __construct(){
|
||||
$this->entities = array();
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
public function get($eid){
|
||||
if(isset($this->entities[$eid])){
|
||||
return $this->entities[$eid];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->schedule(25, array($this, "updateEntities"), array(), true);
|
||||
}
|
||||
|
||||
public function updateEntities(){
|
||||
$l = $this->server->query("SELECT EID FROM entities WHERE hasUpdate = 1;");
|
||||
|
||||
if($l !== false and $l !== true){
|
||||
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$e = $this->get($e["EID"]);
|
||||
if($e instanceof Entity){
|
||||
$e->update();
|
||||
$this->server->query("UPDATE entities SET hasUpdate = 0 WHERE EID = ".$e->eid.";");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updateRadius(Position $center, $radius = 15, $class = false){
|
||||
$this->server->query("UPDATE entities SET hasUpdate = 1 WHERE level = '".$center->level->getName()."' ".($class !== false ? "AND class = $class ":"")."AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
|
||||
}
|
||||
|
||||
public function getRadius(Position $center, $radius = 15, $class = false){
|
||||
$entities = array();
|
||||
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$center->level->getName()."' ".($class !== false ? "AND class = $class ":"")."AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
|
||||
if($l !== false and $l !== true){
|
||||
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$e = $this->get($e["EID"]);
|
||||
if($e instanceof Entity){
|
||||
$entities[$e->eid] = $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public function getAll($level = null){
|
||||
if($level instanceof Level){
|
||||
$entities = array();
|
||||
$l = $this->server->query("SELECT EID FROM entities WHERE level = '".$level->getName()."';");
|
||||
if($l !== false and $l !== true){
|
||||
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$e = $this->get($e["EID"]);
|
||||
if($e instanceof Entity){
|
||||
$entities[$e->eid] = $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $entities;
|
||||
}
|
||||
return $this->entities;
|
||||
}
|
||||
|
||||
public function heal($eid, $heal = 1, $cause){
|
||||
$this->harm($eid, -$heal, $cause);
|
||||
}
|
||||
|
||||
public function harm($eid, $attack = 1, $cause, $force = false){
|
||||
$e = $this->get($eid);
|
||||
if($e === false or $e->dead === true){
|
||||
return false;
|
||||
}
|
||||
$e->setHealth($e->getHealth() - $attack, $cause, $force);
|
||||
}
|
||||
|
||||
public function add(Level $level, $class, $type = 0, $data = array()){
|
||||
$eid = $this->eCnt++;
|
||||
$this->entities[$eid] = new Entity($level, $eid, $class, $type, $data);
|
||||
$this->server->handle("entity.add", $this->entities[$eid]);
|
||||
return $this->entities[$eid];
|
||||
}
|
||||
|
||||
public function spawnToAll(Entity $e){
|
||||
foreach($this->server->api->player->getAll($e->level) as $player){
|
||||
if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function drop(Position $pos, Item $item){
|
||||
if($item->getID() === AIR or $item->count <= 0){
|
||||
return;
|
||||
}
|
||||
$data = array(
|
||||
"x" => $pos->x + mt_rand(-10, 10) / 50,
|
||||
"y" => $pos->y + 0.19,
|
||||
"z" => $pos->z + mt_rand(-10, 10) / 50,
|
||||
"level" => $pos->level,
|
||||
//"speedX" => mt_rand(-3, 3) / 8,
|
||||
"speedY" => mt_rand(5, 8) / 2,
|
||||
//"speedZ" => mt_rand(-3, 3) / 8,
|
||||
"item" => $item,
|
||||
);
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
for($count = $item->count; $count > 0; ){
|
||||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
$count -= $item->count;
|
||||
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
|
||||
$this->spawnToAll($e);
|
||||
$this->server->api->handle("entity.motion", $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function spawnAll(Player $player){
|
||||
foreach($this->getAll($player->level) as $e){
|
||||
if($e->class !== ENTITY_PLAYER){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function remove($eid){
|
||||
if(isset($this->entities[$eid])){
|
||||
$entity = $this->entities[$eid];
|
||||
$this->entities[$eid] = null;
|
||||
unset($this->entities[$eid]);
|
||||
$entity->closed = true;
|
||||
$this->server->query("DELETE FROM entities WHERE EID = ".$eid.";");
|
||||
if($entity->class === ENTITY_PLAYER){
|
||||
$pk = new RemovePlayerPacket;
|
||||
$pk->eid = $entity->eid;
|
||||
$pk->clientID = 0;
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll(), $pk);
|
||||
}else{
|
||||
$pk = new RemoveEntityPacket;
|
||||
$pk->eid = $entity->eid;
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($entity->level), $pk);
|
||||
}
|
||||
$this->server->api->dhandle("entity.remove", $entity);
|
||||
$entity = null;
|
||||
unset($entity);
|
||||
}
|
||||
}
|
||||
}
|
@ -155,13 +155,13 @@ class LevelAPI{
|
||||
console("[ERROR] Could not load level \"".$name."\"");
|
||||
return false;
|
||||
}
|
||||
$entities = new Config($path."entities.yml", Config::YAML);
|
||||
//$entities = new Config($path."entities.yml", Config::YAML);
|
||||
if(file_exists($path."tileEntities.yml")){
|
||||
@rename($path."tileEntities.yml", $path."tiles.yml");
|
||||
}
|
||||
$blockUpdates = new Config($path."bupdates.yml", Config::YAML);
|
||||
$this->levels[$name] = new Level($level, $name);
|
||||
foreach($entities->getAll() as $entity){
|
||||
/*foreach($entities->getAll() as $entity){
|
||||
if(!isset($entity["id"])){
|
||||
break;
|
||||
}
|
||||
@ -188,7 +188,7 @@ class LevelAPI{
|
||||
$e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
|
||||
$e->setHealth($entity["Health"]);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if(file_exists($path ."tiles.yml")){
|
||||
$tiles = new Config($path."tiles.yml", Config::YAML);
|
||||
|
@ -51,7 +51,7 @@ class PlayerAPI{
|
||||
$result = $this->server->preparedSQL->selectPlayersToHeal->execute();
|
||||
if($result !== false){
|
||||
while(($player = $result->fetchArray()) !== false){
|
||||
if(($player = $this->server->api->entity->get($player["EID"])) !== false){
|
||||
if(($player = Entity::get($player["EID"])) !== false){
|
||||
if($player->getHealth() <= 0){
|
||||
continue;
|
||||
}
|
||||
@ -64,7 +64,7 @@ class PlayerAPI{
|
||||
break;
|
||||
case "player.death":
|
||||
if(is_numeric($data["cause"])){
|
||||
$e = $this->server->api->entity->get($data["cause"]);
|
||||
$e = Entity::get($data["cause"]);
|
||||
if($e instanceof Entity){
|
||||
switch($e->class){
|
||||
case ENTITY_PLAYER:
|
||||
@ -422,7 +422,7 @@ class PlayerAPI{
|
||||
public function spawnAllPlayers(Player $player){
|
||||
foreach($this->getAll() as $p){
|
||||
if($p !== $player and ($p->entity instanceof Entity)){
|
||||
$p->entity->spawn($player);
|
||||
$p->entity->spawnTo($player);
|
||||
if($p->level !== $player->level){
|
||||
$pk = new MoveEntityPacket_PosRot;
|
||||
$pk->eid = $p->entity->eid;
|
||||
@ -440,7 +440,7 @@ class PlayerAPI{
|
||||
public function spawnToAllPlayers(Player $player){
|
||||
foreach($this->getAll() as $p){
|
||||
if($p !== $player and ($p->entity instanceof Entity) and ($player->entity instanceof Entity)){
|
||||
$player->entity->spawn($p);
|
||||
$player->entity->spawnTo($p);
|
||||
if($p->level !== $player->level){
|
||||
$pk = new MoveEntityPacket_PosRot;
|
||||
$pk->eid = $player->entity->eid;
|
||||
@ -467,8 +467,8 @@ class PlayerAPI{
|
||||
if($player->entity instanceof Entity){
|
||||
unset($player->entity->player);
|
||||
//unset($player->entity);
|
||||
$player->entity->close();
|
||||
}
|
||||
$this->server->api->entity->remove($player->eid);
|
||||
$player = null;
|
||||
unset($player);
|
||||
}
|
||||
|
@ -205,8 +205,7 @@ class ServerAPI{
|
||||
$this->loadAPI("level", "LevelAPI");
|
||||
$this->loadAPI("block", "BlockAPI");
|
||||
$this->loadAPI("chat", "ChatAPI");
|
||||
$this->loadAPI("ban", "BanAPI");
|
||||
$this->loadAPI("entity", "EntityAPI");
|
||||
$this->loadAPI("ban", "BanAPI");
|
||||
$this->loadAPI("player", "PlayerAPI");
|
||||
$this->loadAPI("time", "TimeAPI");
|
||||
|
||||
@ -226,7 +225,7 @@ class ServerAPI{
|
||||
//Update tiles that need update
|
||||
if(count(Tile::$needUpdate) > 0){
|
||||
foreach(Tile::$needUpdate as $id => $tile){
|
||||
if($tile->update() === false){
|
||||
if($tile->onUpdate() === false){
|
||||
unset(Tile::$needUpdate[$id]);
|
||||
}
|
||||
}
|
||||
|
@ -54,22 +54,36 @@ abstract class Entity extends Position{
|
||||
public $noDamageTicks;
|
||||
private $justCreated;
|
||||
protected $fireProof;
|
||||
private $invulnerable;
|
||||
private $invulnerable;
|
||||
|
||||
public static function getEntity($entityID){
|
||||
public $closed;
|
||||
|
||||
public static function get($entityID){
|
||||
return isset(Entity::$list[$entityID]) ? Entity::$list[$entityID]:false;
|
||||
}
|
||||
|
||||
public static function getAll(){
|
||||
return $this->list;
|
||||
}
|
||||
|
||||
public function __construct(Level $level){
|
||||
|
||||
public function __construct(Level $level, NBTTag_Compound $nbt){
|
||||
$this->id = Entity::$entityCount++;
|
||||
$this->justCreated = true;
|
||||
$this->closed = false;
|
||||
$this->namedtag = $nbt;
|
||||
$this->level = $level;
|
||||
$this->setPosition(new Vector3(0, 0, 0));
|
||||
|
||||
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
|
||||
$this->setPosition(new Vector3($this->namedtag->x, $this->namedtag->y, $this->namedtag->z));
|
||||
$index = PMFLevel::getIndex($this->x >> 4, $this->z >> 4);
|
||||
$this->chunkIndex = $index;
|
||||
Entity::$list[$this->id] = $this;
|
||||
$this->level->entities[$this->id] = $this;
|
||||
$this->level->chunkEntities[$this->chunkIndex][$this->id] = $this;
|
||||
$this->lastUpdate = microtime(true);
|
||||
$this->initEntity();
|
||||
$this->server->api->dhandle("entity.add", $this);
|
||||
}
|
||||
|
||||
protected abstract function initEntity();
|
||||
@ -78,7 +92,10 @@ abstract class Entity extends Position{
|
||||
|
||||
abstract function attackEntity($damage, $source = "generic");
|
||||
|
||||
public function onEntityUpdate(){
|
||||
public function onUpdate(){
|
||||
if($this->closed !== false){
|
||||
return false;
|
||||
}
|
||||
$timeNow = microtime(true);
|
||||
$this->ticksLived += ($now - $this->lastUpdate) * 20;
|
||||
$this->lastUpdate = $timeNow;
|
||||
@ -114,6 +131,11 @@ abstract class Entity extends Position{
|
||||
if($this->y < -64){
|
||||
$this->kill();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public final function scheduleUpdate(){
|
||||
Entity::$needUpdate[$this->id] = $this;
|
||||
}
|
||||
|
||||
public function setOnFire($seconds){
|
||||
@ -216,14 +238,43 @@ abstract class Entity extends Position{
|
||||
public function teleport(Position $pos){
|
||||
|
||||
}
|
||||
|
||||
public function equals($object){
|
||||
return $object instanceof Entity ? $object->getID() === $this->id : false;
|
||||
}
|
||||
|
||||
|
||||
public function getID(){
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function spawnToAll(){
|
||||
foreach($this->level->getPlayers() as $player){
|
||||
if($player->eid !== false or $player->spawned !== true){
|
||||
$this->spawnTo($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function close(){
|
||||
if($this->closed === false){
|
||||
$this->closed = true;
|
||||
unset(Entity::$needUpdate[$this->id]);
|
||||
unset($this->level->entities[$this->id]);
|
||||
unset($this->level->chunkEntities[$this->chunkIndex][$this->id]);
|
||||
unset(Entity::$list[$this->id]);
|
||||
if($this instanceof HumanEntity){
|
||||
$pk = new RemovePlayerPacket;
|
||||
$pk->eid = $this->id;
|
||||
$pk->clientID = 0;
|
||||
$this->server->api->player->broadcastPacket($this->level->getPlayers(), $pk);
|
||||
}else{
|
||||
$pk = new RemoveEntityPacket;
|
||||
$pk->eid = $this->id;
|
||||
$this->server->api->player->broadcastPacket($this->level->getPlayers(), $pk);
|
||||
}
|
||||
$this->server->api->dhandle("entity.remove", $this);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
$this->close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ class Player{
|
||||
if(is_array($this->lastChunk)){
|
||||
foreach($this->level->getChunkTiles($this->lastChunk[0], $this->lastChunk[1]) as $tile){
|
||||
if($tile instanceof SpawnableTile){
|
||||
$tile->spawn($this);
|
||||
$tile->spawnTo($this);
|
||||
}
|
||||
}
|
||||
$this->lastChunk = false;
|
||||
@ -918,7 +918,7 @@ class Player{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($this->server->api->entity->getAll($this->level) as $e){
|
||||
foreach($this->level->getEntities() as $e){
|
||||
if($e !== $this->entity){
|
||||
if($e->player instanceof Player){
|
||||
$pk = new MoveEntityPacket_PosRot;
|
||||
@ -950,7 +950,8 @@ class Player{
|
||||
$this->level->freeAllChunks($this);
|
||||
$this->level = $pos->level;
|
||||
$this->chunksLoaded = array();
|
||||
$this->server->api->entity->spawnToAll($this->entity);
|
||||
$this->entity->spawnToAll();
|
||||
//TODO
|
||||
$this->server->api->entity->spawnAll($this);
|
||||
|
||||
$pk = new SetTimePacket;
|
||||
@ -1459,11 +1460,14 @@ class Player{
|
||||
break;
|
||||
}
|
||||
$this->entity->setHealth($this->data->get("health"), "spawn", true);
|
||||
$this->spawned = true;
|
||||
$this->spawned = true;
|
||||
//TODO
|
||||
$this->server->api->player->spawnAllPlayers($this);
|
||||
//TODO
|
||||
$this->server->api->player->spawnToAllPlayers($this);
|
||||
//TODO
|
||||
$this->server->api->entity->spawnAll($this);
|
||||
$this->server->api->entity->spawnToAll($this->entity);
|
||||
$this->entity->spawnToAll();
|
||||
|
||||
$this->server->schedule(5, array($this->entity, "update"), array(), true);
|
||||
$this->server->schedule(2, array($this->entity, "updateMovement"), array(), true);
|
||||
@ -1749,7 +1753,7 @@ class Player{
|
||||
$e->speedX = $speedX;
|
||||
$e->speedZ = $speedZ;
|
||||
$e->speedY = $speedY;
|
||||
$this->server->api->entity->spawnToAll($e);
|
||||
$e->spawnToAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1828,7 +1832,7 @@ class Player{
|
||||
$data["action"] = $packet->action;
|
||||
$this->craftingItems = array();
|
||||
$this->toCraft = array();
|
||||
$target = $this->server->api->entity->get($packet->target);
|
||||
$target = Entity::get($packet->target);
|
||||
if($target instanceof Entity and $this->entity instanceof Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8){
|
||||
$data["targetentity"] = $target;
|
||||
$data["entity"] = $this->entity;
|
||||
@ -2241,12 +2245,12 @@ class Player{
|
||||
$t = $this->level->getTile(new Vector3($packet->x, $packet->y, $packet->z));
|
||||
if($t instanceof SignTile){
|
||||
if($t->namedtag->creator !== $this->username){
|
||||
$t->spawn($this);
|
||||
$t->spawnTo($this);
|
||||
}else{
|
||||
$nbt = new NBT();
|
||||
$nbt->read($packet->namedtag);
|
||||
if($nbt->id !== Tile::SIGN){
|
||||
$t->spawn($this);
|
||||
$t->spawnTo($this);
|
||||
}else{
|
||||
$t->setText($nbt->Text1, $nbt->Text2, $nbt->Text3, $nbt->Text4);
|
||||
}
|
||||
|
12
src/Tile.php
12
src/Tile.php
@ -30,7 +30,6 @@ abstract class Tile extends Position{
|
||||
|
||||
public $chunkIndex;
|
||||
public $name;
|
||||
public $normal;
|
||||
public $id;
|
||||
public $x;
|
||||
public $y;
|
||||
@ -60,7 +59,6 @@ abstract class Tile extends Position{
|
||||
$this->server = ServerAPI::request();
|
||||
$this->level = $level;
|
||||
$this->namedtag = $nbt;
|
||||
$this->normal = true;
|
||||
$this->closed = false;
|
||||
$this->name = "";
|
||||
$this->lastUpdate = microtime(true);
|
||||
@ -72,12 +70,13 @@ abstract class Tile extends Position{
|
||||
$this->z = (int) $this->namedtag->z;
|
||||
|
||||
$index = PMFLevel::getIndex($this->x >> 4, $this->z >> 4);
|
||||
$this->level->tiles[$this->id] = $this;
|
||||
$this->chunkIndex = $index;
|
||||
$this->level->chunkTiles[$index][$this->id] = $this;
|
||||
$this->level->tiles[$this->id] = $this;
|
||||
$this->level->chunkTiles[$this->chunkIndex][$this->id] = $this;
|
||||
$this->server->api->dhandle("tile.add", $this);
|
||||
}
|
||||
|
||||
public function update(){
|
||||
public function onUpdate(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -88,10 +87,9 @@ abstract class Tile extends Position{
|
||||
public function close(){
|
||||
if($this->closed === false){
|
||||
$this->closed = true;
|
||||
$index = PMFLevel::getIndex($this->x >> 4, $this->z >> 4);
|
||||
unset(Tile::$needUpdate[$this->id]);
|
||||
unset($this->level->tiles[$this->id]);
|
||||
unset($this->level->chunkTiles[$index][$this->id]);
|
||||
unset($this->level->chunkTiles[$this->chunkIndex][$this->id]);
|
||||
unset(Tile::$list[$this->id]);
|
||||
$this->server->api->dhandle("tile.remove", $t);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ if(!extension_loaded("pthreads") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":""
|
||||
if(version_compare($pthreads_version, "0.1.0") < 0){
|
||||
console("[ERROR] pthreads >= 0.1.0 is required, while you have $pthreads_version.", true, true, 0);
|
||||
++$errors;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!extension_loaded("curl") and @dl((PHP_SHLIB_SUFFIX === "dll" ? "php_":"") . "curl." . PHP_SHLIB_SUFFIX) === false){
|
||||
@ -96,7 +96,7 @@ require_once(FILE_PATH."/src/math/Vector3.php");
|
||||
require_once(FILE_PATH."/src/math/Position.php");
|
||||
require_once(FILE_PATH."/src/pmf/PMF.php");
|
||||
|
||||
require_all(FILE_PATH . "src/", array("entity", "Entity.php")); //REMOVE LATER!!!!
|
||||
require_all(FILE_PATH . "src/");
|
||||
|
||||
$inc = get_included_files();
|
||||
$inc[] = array_shift($inc);
|
||||
|
@ -83,8 +83,9 @@ class GenericBlock extends Block{
|
||||
);
|
||||
$server = ServerAPI::request();
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
//TODO
|
||||
$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
|
||||
$server->api->entity->spawnToAll($e);
|
||||
$e->spawnToAll();
|
||||
$server->api->block->blockUpdateAround(clone $this, BLOCK_UPDATE_NORMAL, 1);
|
||||
}
|
||||
return false;
|
||||
|
@ -39,8 +39,9 @@ class TNTBlock extends SolidBlock{
|
||||
"fuse" => 20 * 4, //4 seconds
|
||||
);
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
//TODO
|
||||
$e = ServerAPI::request()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
|
||||
ServerAPI::request()->api->entity->spawnToAll($e);
|
||||
$e->spawnToAll();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -28,6 +28,7 @@ class RedMushroomBlock extends FlowableBlock{
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
//TODO
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
|
@ -62,6 +62,7 @@ class SaplingBlock extends FlowableBlock{
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
//TODO
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
|
@ -56,6 +56,7 @@ class SugarcaneBlock extends FlowableBlock{
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
$down = $this->getSide(0);
|
||||
if($down->isTransparent === true and $down->getID() !== SUGARCANE_BLOCK){ //Replace with common break method
|
||||
//TODO
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SUGARCANE));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
|
@ -51,6 +51,7 @@ class WheatBlock extends FlowableBlock{
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||
//TODO
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(WHEAT_SEEDS, 0, 1));
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
|
@ -117,9 +117,11 @@ class LeavesBlock extends TransparentBlock{
|
||||
}else{
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
if(mt_rand(1,20) === 1){ //Saplings
|
||||
//TODO
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1));
|
||||
}
|
||||
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
|
||||
//TODO
|
||||
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1));
|
||||
}
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
|
@ -72,8 +72,9 @@ class PaintingItem extends Item{
|
||||
"yaw" => $faces[$face] * 90,
|
||||
"Motive" => $motive[0],
|
||||
);
|
||||
//TODO
|
||||
$e = $server->api->entity->add($level, ENTITY_OBJECT, OBJECT_PAINTING, $data);
|
||||
$server->api->entity->spawnToAll($e);
|
||||
$e->spawnToAll();
|
||||
if(($player->gamemode & 0x01) === 0x00){
|
||||
$player->removeItem($this->getID(), $this->getMetadata(), 1, false);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ class ChestTile extends SpawnableTile{
|
||||
}
|
||||
}
|
||||
|
||||
public function spawn(Player $player){
|
||||
public function spawnTo(Player $player){
|
||||
if($this->closed){
|
||||
return false;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class FurnaceTile extends Tile{
|
||||
}
|
||||
}
|
||||
|
||||
public function update(){
|
||||
public function onUpdate(){
|
||||
if($this->closed === true){
|
||||
return false;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class SignTile extends SpawnableTile{
|
||||
);
|
||||
}
|
||||
|
||||
public function spawn(Player $player){
|
||||
public function spawnTo(Player $player){
|
||||
if($this->closed){
|
||||
return false;
|
||||
}
|
||||
|
@ -20,12 +20,12 @@
|
||||
*/
|
||||
|
||||
abstract class SpawnableTile extends Tile{
|
||||
public abstract function spawn(Player $player);
|
||||
public abstract function spawnTo(Player $player);
|
||||
|
||||
public function spawnToAll(){
|
||||
foreach($this->level->getPlayers() as $player){
|
||||
if($player->eid !== false or $player->spawned !== true){
|
||||
$this->spawn($player);
|
||||
$this->spawnTo($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,6 +86,7 @@ class Explosion{
|
||||
$send = array();
|
||||
$source = $this->source->floor();
|
||||
$radius = 2 * $this->size;
|
||||
//TODO
|
||||
foreach($server->api->entity->getRadius($this->source, $radius) as $entity){
|
||||
$impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //placeholder, 0.7 should be exposure
|
||||
$damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1);
|
||||
@ -102,12 +103,15 @@ class Explosion{
|
||||
"power" => 4,
|
||||
"fuse" => mt_rand(10, 30), //0.5 to 1.5 seconds
|
||||
);
|
||||
//TODO
|
||||
$e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
|
||||
$server->api->entity->spawnToAll($e);
|
||||
$e->spawnToAll();
|
||||
}elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){
|
||||
if(isset(self::$specialDrops[$block->getID()])){
|
||||
//TODO
|
||||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem(self::$specialDrops[$block->getID()], 0));
|
||||
}else{
|
||||
//TODO
|
||||
$server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($block->getID(), $this->level->level->getBlockDamage($block->x, $block->y, $block->z)));
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
*/
|
||||
|
||||
class Level{
|
||||
public $players = array();
|
||||
|
||||
public $entities = array();
|
||||
public $chunkEntities = array();
|
||||
|
||||
@ -204,6 +206,14 @@ class Level{
|
||||
$nbt->Entities->setTagType(NBTTag::TAG_Compound);
|
||||
$nbt->TileEntities->setTagType(NBTTag::TAG_Compound);
|
||||
|
||||
$i = 0;
|
||||
foreach($this->chunkEntities[$index] as $entity){
|
||||
if($entity->closed !== true){
|
||||
$nbt->Entities[$i] = $entity->namedtag;
|
||||
++$i;
|
||||
}
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach($this->chunkTiles[$index] as $tile){
|
||||
if($tile->closed !== true){
|
||||
@ -294,7 +304,6 @@ class Level{
|
||||
|
||||
if($update === true){
|
||||
$this->server->api->block->blockUpdateAround($pos, BLOCK_UPDATE_NORMAL, 1);
|
||||
$this->server->api->entity->updateRadius($pos, 3);
|
||||
}
|
||||
if($tiles === true){
|
||||
if(($t = $this->getTile($pos)) !== false){
|
||||
@ -305,6 +314,18 @@ class Level{
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function getEntities(){
|
||||
return $this->entities;
|
||||
}
|
||||
|
||||
public function getTiles(){
|
||||
return $this->tiles;
|
||||
}
|
||||
|
||||
public function getPlayers(){
|
||||
return $this->players;
|
||||
}
|
||||
|
||||
public function getTile(Vector3 $pos){
|
||||
if($pos instanceof Position and $pos->level !== $this){
|
||||
return false;
|
||||
@ -354,6 +375,8 @@ class Level{
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function loadChunk($X, $Z){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
@ -365,6 +388,11 @@ class Level{
|
||||
$this->usedChunks[$index] = array();
|
||||
$this->chunkTiles[$index] = array();
|
||||
$this->chunkEntities[$index] = array();
|
||||
foreach($this->level->getChunkNBT($X, $Z)->Entities as $nbt){
|
||||
switch($nbt->id){
|
||||
//TODO: spawn entities
|
||||
}
|
||||
}
|
||||
foreach($this->level->getChunkNBT($X, $Z)->TileEntities as $nbt){
|
||||
switch($nbt->id){
|
||||
case Tile::CHEST:
|
||||
|
Loading…
x
Reference in New Issue
Block a user