mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-08-20 10:00:31 +00:00
fixes, new Tile update algorithm
This commit is contained in:
parent
c9dfdc288d
commit
6bd91cf39e
@ -215,8 +215,23 @@ class ServerAPI{
|
|||||||
$ob->init(); //Fails sometimes!!!
|
$ob->init(); //Fails sometimes!!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->loadAPI("plugin", "PluginAPI"); //fix :(
|
$this->loadAPI("plugin", "PluginAPI"); //fix :(
|
||||||
$this->plugin->init();
|
$this->plugin->init();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkTickUpdates(){
|
||||||
|
|
||||||
|
//Update tiles that need update
|
||||||
|
if(count(Tile::$needUpdate) > 0){
|
||||||
|
foreach(Tile::$needUpdate as $id => $tile){
|
||||||
|
if($tile->update() === false){
|
||||||
|
unset(Tile::$needUpdate[$id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function async(callable $callable, $params = array(), $remove = false){
|
public function async(callable $callable, $params = array(), $remove = false){
|
||||||
@ -351,6 +366,7 @@ class ServerAPI{
|
|||||||
$this->query = new QueryHandler();
|
$this->query = new QueryHandler();
|
||||||
}
|
}
|
||||||
CraftingRecipes::init();
|
CraftingRecipes::init();
|
||||||
|
$this->schedule(2, array($this, "checkTickUpdates"), array(), true);
|
||||||
$this->server->init();
|
$this->server->init();
|
||||||
unregister_tick_function(array($this->server, "tick"));
|
unregister_tick_function(array($this->server, "tick"));
|
||||||
$this->console->__destruct();
|
$this->console->__destruct();
|
||||||
|
@ -562,13 +562,13 @@ class Player{
|
|||||||
$pk = new ContainerSetDataPacket;
|
$pk = new ContainerSetDataPacket;
|
||||||
$pk->windowid = $id;
|
$pk->windowid = $id;
|
||||||
$pk->property = 0; //Smelting
|
$pk->property = 0; //Smelting
|
||||||
$pk->value = floor($data->data["CookTime"]);
|
$pk->value = floor($data->namedtag->CookTime);
|
||||||
$this->dataPacket($pk);
|
$this->dataPacket($pk);
|
||||||
|
|
||||||
$pk = new ContainerSetDataPacket;
|
$pk = new ContainerSetDataPacket;
|
||||||
$pk->windowid = $id;
|
$pk->windowid = $id;
|
||||||
$pk->property = 1; //Fire icon
|
$pk->property = 1; //Fire icon
|
||||||
$pk->value = $data->data["BurnTicks"];
|
$pk->value = $data->namedtag->BurnTicks;
|
||||||
$this->dataPacket($pk);
|
$this->dataPacket($pk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
src/Tile.php
13
src/Tile.php
@ -41,7 +41,6 @@ abstract class Tile extends Position{
|
|||||||
public $closed;
|
public $closed;
|
||||||
public $namedtag;
|
public $namedtag;
|
||||||
private $lastUpdate;
|
private $lastUpdate;
|
||||||
private $scheduledUpdate;
|
|
||||||
private $server;
|
private $server;
|
||||||
|
|
||||||
public static function getByID($tileID){
|
public static function getByID($tileID){
|
||||||
@ -65,7 +64,6 @@ abstract class Tile extends Position{
|
|||||||
$this->closed = false;
|
$this->closed = false;
|
||||||
$this->name = "";
|
$this->name = "";
|
||||||
$this->lastUpdate = microtime(true);
|
$this->lastUpdate = microtime(true);
|
||||||
$this->scheduledUpdate = false;
|
|
||||||
$this->id = Tile::$tileCount++;
|
$this->id = Tile::$tileCount++;
|
||||||
Tile::$list[$this->id] = $this;
|
Tile::$list[$this->id] = $this;
|
||||||
$this->class = $this->namedtag->id;
|
$this->class = $this->namedtag->id;
|
||||||
@ -82,14 +80,19 @@ abstract class Tile extends Position{
|
|||||||
public function update(){
|
public function update(){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final function scheduleUpdate(){
|
||||||
|
Tile::$needUpdate[$this->id] = $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function close(){
|
public function close(){
|
||||||
if($this->closed === false){
|
if($this->closed === false){
|
||||||
$this->closed = true;
|
$this->closed = true;
|
||||||
unset(Tile::$list[$this->id]);
|
|
||||||
$index = PMFLevel::getIndex($this->x >> 4, $this->z >> 4);
|
$index = PMFLevel::getIndex($this->x >> 4, $this->z >> 4);
|
||||||
unset($this->level->tiles[$this->id]);
|
unset(Tile::$needUpdate[$this->id]);
|
||||||
unset($this->level->chunkTiles[$index][$this->id]);
|
unset($this->level->tiles[$this->id]);
|
||||||
|
unset($this->level->chunkTiles[$index][$this->id]);
|
||||||
|
unset(Tile::$list[$this->id]);
|
||||||
$this->server->api->dhandle("tile.remove", $t);
|
$this->server->api->dhandle("tile.remove", $t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,11 @@ class ChestTile extends SpawnableTile{
|
|||||||
|
|
||||||
const SLOTS = 27;
|
const SLOTS = 27;
|
||||||
|
|
||||||
|
public function __construct(Level $level, NBTTag_Compound $nbt){
|
||||||
|
$nbt->id = Tile::Chest;
|
||||||
|
parent::__construct($level, $nbt);
|
||||||
|
}
|
||||||
|
|
||||||
public function isPaired(){
|
public function isPaired(){
|
||||||
if(!isset($this->namedtag->pairx) or !isset($this->namedtag->pairz)){
|
if(!isset($this->namedtag->pairx) or !isset($this->namedtag->pairz)){
|
||||||
return false;
|
return false;
|
||||||
|
@ -170,8 +170,8 @@ trait ContainerTileTrait{
|
|||||||
"slotdata" => $item,
|
"slotdata" => $item,
|
||||||
));
|
));
|
||||||
|
|
||||||
if($update === true and $this->scheduledUpdate === false){
|
if($update === true){
|
||||||
$this->update();
|
$this->scheduleUpdate();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ class FurnaceTile extends Tile{
|
|||||||
const SLOTS = 3;
|
const SLOTS = 3;
|
||||||
|
|
||||||
public function __construct(Level $level, NBTTag_Compound $nbt){
|
public function __construct(Level $level, NBTTag_Compound $nbt){
|
||||||
|
$nbt->id = Tile::Furnace;
|
||||||
parent::__construct($level, $nbt);
|
parent::__construct($level, $nbt);
|
||||||
if(!isset($this->namedtag->BurnTime) or $this->namedtag->BurnTime < 0){
|
if(!isset($this->namedtag->BurnTime) or $this->namedtag->BurnTime < 0){
|
||||||
$this->namedtag->BurnTime = 0;
|
$this->namedtag->BurnTime = 0;
|
||||||
@ -41,14 +42,16 @@ class FurnaceTile extends Tile{
|
|||||||
$this->namedtag->BurnTicks = 0;
|
$this->namedtag->BurnTicks = 0;
|
||||||
}
|
}
|
||||||
if($this->namedtag->BurnTime > 0){
|
if($this->namedtag->BurnTime > 0){
|
||||||
$this->update();
|
$this->scheduleUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(){
|
public function update(){
|
||||||
if($this->closed === true){
|
if($this->closed === true){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$ret = false;
|
||||||
|
|
||||||
$fuel = $this->getSlot(1);
|
$fuel = $this->getSlot(1);
|
||||||
$raw = $this->getSlot(0);
|
$raw = $this->getSlot(0);
|
||||||
@ -92,8 +95,7 @@ class FurnaceTile extends Tile{
|
|||||||
}else{
|
}else{
|
||||||
$this->namedtag->CookTime = 0;
|
$this->namedtag->CookTime = 0;
|
||||||
}
|
}
|
||||||
$this->server->schedule(2, array($this, "update"));
|
$ret = true;
|
||||||
$this->scheduledUpdate = true;
|
|
||||||
}else{
|
}else{
|
||||||
$current = $this->level->getBlock($this);
|
$current = $this->level->getBlock($this);
|
||||||
if($current->getID() === BURNING_FURNACE){
|
if($current->getID() === BURNING_FURNACE){
|
||||||
@ -102,11 +104,11 @@ class FurnaceTile extends Tile{
|
|||||||
$this->namedtag->CookTime = 0;
|
$this->namedtag->CookTime = 0;
|
||||||
$this->namedtag->BurnTime = 0;
|
$this->namedtag->BurnTime = 0;
|
||||||
$this->namedtag->BurnTicks = 0;
|
$this->namedtag->BurnTicks = 0;
|
||||||
$this->scheduledUpdate = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->server->handle("tile.update", $this);
|
$this->server->handle("tile.update", $this);
|
||||||
$this->lastUpdate = microtime(true);
|
$this->lastUpdate = microtime(true);
|
||||||
|
return $ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,11 +24,13 @@ require_once("SpawnableTile.php");
|
|||||||
/***REM_END***/
|
/***REM_END***/
|
||||||
|
|
||||||
class SignTile extends SpawnableTile{
|
class SignTile extends SpawnableTile{
|
||||||
|
|
||||||
|
public function __construct(Level $level, NBTTag_Compound $nbt){
|
||||||
|
$nbt->id = Tile::Sign;
|
||||||
|
parent::__construct($level, $nbt);
|
||||||
|
}
|
||||||
|
|
||||||
public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){
|
public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){
|
||||||
if($this->class !== Tile::SIGN){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$this->namedtag->Text1 = $line1;
|
$this->namedtag->Text1 = $line1;
|
||||||
$this->namedtag->Text2 = $line2;
|
$this->namedtag->Text2 = $line2;
|
||||||
$this->namedtag->Text3 = $line3;
|
$this->namedtag->Text3 = $line3;
|
||||||
|
@ -306,7 +306,7 @@ class Level{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getTile(Vector3 $pos){
|
public function getTile(Vector3 $pos){
|
||||||
if($pos instanceof Position and $pos->level->getName() !== $this->getName()){
|
if($pos instanceof Position and $pos->level !== $this){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$tiles = $this->getChunkTiles($pos->x >> 4, $pos->z >> 4);
|
$tiles = $this->getChunkTiles($pos->x >> 4, $pos->z >> 4);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user