mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 11:18:52 +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!!!
|
||||
}
|
||||
}
|
||||
|
||||
$this->loadAPI("plugin", "PluginAPI"); //fix :(
|
||||
$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){
|
||||
@ -351,6 +366,7 @@ class ServerAPI{
|
||||
$this->query = new QueryHandler();
|
||||
}
|
||||
CraftingRecipes::init();
|
||||
$this->schedule(2, array($this, "checkTickUpdates"), array(), true);
|
||||
$this->server->init();
|
||||
unregister_tick_function(array($this->server, "tick"));
|
||||
$this->console->__destruct();
|
||||
|
@ -562,13 +562,13 @@ class Player{
|
||||
$pk = new ContainerSetDataPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->property = 0; //Smelting
|
||||
$pk->value = floor($data->data["CookTime"]);
|
||||
$pk->value = floor($data->namedtag->CookTime);
|
||||
$this->dataPacket($pk);
|
||||
|
||||
$pk = new ContainerSetDataPacket;
|
||||
$pk->windowid = $id;
|
||||
$pk->property = 1; //Fire icon
|
||||
$pk->value = $data->data["BurnTicks"];
|
||||
$pk->value = $data->namedtag->BurnTicks;
|
||||
$this->dataPacket($pk);
|
||||
}
|
||||
}
|
||||
|
13
src/Tile.php
13
src/Tile.php
@ -41,7 +41,6 @@ abstract class Tile extends Position{
|
||||
public $closed;
|
||||
public $namedtag;
|
||||
private $lastUpdate;
|
||||
private $scheduledUpdate;
|
||||
private $server;
|
||||
|
||||
public static function getByID($tileID){
|
||||
@ -65,7 +64,6 @@ abstract class Tile extends Position{
|
||||
$this->closed = false;
|
||||
$this->name = "";
|
||||
$this->lastUpdate = microtime(true);
|
||||
$this->scheduledUpdate = false;
|
||||
$this->id = Tile::$tileCount++;
|
||||
Tile::$list[$this->id] = $this;
|
||||
$this->class = $this->namedtag->id;
|
||||
@ -82,14 +80,19 @@ abstract class Tile extends Position{
|
||||
public function update(){
|
||||
return false;
|
||||
}
|
||||
|
||||
public final function scheduleUpdate(){
|
||||
Tile::$needUpdate[$this->id] = $this;
|
||||
}
|
||||
|
||||
public function close(){
|
||||
if($this->closed === false){
|
||||
$this->closed = true;
|
||||
unset(Tile::$list[$this->id]);
|
||||
$index = PMFLevel::getIndex($this->x >> 4, $this->z >> 4);
|
||||
unset($this->level->tiles[$this->id]);
|
||||
unset($this->level->chunkTiles[$index][$this->id]);
|
||||
unset(Tile::$needUpdate[$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);
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,11 @@ class ChestTile extends SpawnableTile{
|
||||
|
||||
const SLOTS = 27;
|
||||
|
||||
public function __construct(Level $level, NBTTag_Compound $nbt){
|
||||
$nbt->id = Tile::Chest;
|
||||
parent::__construct($level, $nbt);
|
||||
}
|
||||
|
||||
public function isPaired(){
|
||||
if(!isset($this->namedtag->pairx) or !isset($this->namedtag->pairz)){
|
||||
return false;
|
||||
|
@ -170,8 +170,8 @@ trait ContainerTileTrait{
|
||||
"slotdata" => $item,
|
||||
));
|
||||
|
||||
if($update === true and $this->scheduledUpdate === false){
|
||||
$this->update();
|
||||
if($update === true){
|
||||
$this->scheduleUpdate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ class FurnaceTile extends Tile{
|
||||
const SLOTS = 3;
|
||||
|
||||
public function __construct(Level $level, NBTTag_Compound $nbt){
|
||||
$nbt->id = Tile::Furnace;
|
||||
parent::__construct($level, $nbt);
|
||||
if(!isset($this->namedtag->BurnTime) or $this->namedtag->BurnTime < 0){
|
||||
$this->namedtag->BurnTime = 0;
|
||||
@ -41,14 +42,16 @@ class FurnaceTile extends Tile{
|
||||
$this->namedtag->BurnTicks = 0;
|
||||
}
|
||||
if($this->namedtag->BurnTime > 0){
|
||||
$this->update();
|
||||
$this->scheduleUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public function update(){
|
||||
if($this->closed === true){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$ret = false;
|
||||
|
||||
$fuel = $this->getSlot(1);
|
||||
$raw = $this->getSlot(0);
|
||||
@ -92,8 +95,7 @@ class FurnaceTile extends Tile{
|
||||
}else{
|
||||
$this->namedtag->CookTime = 0;
|
||||
}
|
||||
$this->server->schedule(2, array($this, "update"));
|
||||
$this->scheduledUpdate = true;
|
||||
$ret = true;
|
||||
}else{
|
||||
$current = $this->level->getBlock($this);
|
||||
if($current->getID() === BURNING_FURNACE){
|
||||
@ -102,11 +104,11 @@ class FurnaceTile extends Tile{
|
||||
$this->namedtag->CookTime = 0;
|
||||
$this->namedtag->BurnTime = 0;
|
||||
$this->namedtag->BurnTicks = 0;
|
||||
$this->scheduledUpdate = false;
|
||||
}
|
||||
|
||||
|
||||
$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***/
|
||||
|
||||
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 = ""){
|
||||
if($this->class !== Tile::SIGN){
|
||||
return false;
|
||||
}
|
||||
$this->namedtag->Text1 = $line1;
|
||||
$this->namedtag->Text2 = $line2;
|
||||
$this->namedtag->Text3 = $line3;
|
||||
|
@ -306,7 +306,7 @@ class Level{
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
$tiles = $this->getChunkTiles($pos->x >> 4, $pos->z >> 4);
|
||||
|
Loading…
x
Reference in New Issue
Block a user