mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 08:39:53 +00:00
Updated Position to use Weak / strong references for Level objects
This commit is contained in:
parent
6328834681
commit
c1546aac9c
@ -202,7 +202,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function initEntity(){
|
protected function initEntity(){
|
||||||
$this->level->players[$this->CID] = $this;
|
$this->getLevel()->players[$this->CID] = $this;
|
||||||
parent::initEntity();
|
parent::initEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,7 +371,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$this->spawnPosition = $this->server->getDefaultLevel()->getSafeSpawn();
|
$this->spawnPosition = $this->server->getDefaultLevel()->getSafeSpawn();
|
||||||
$this->timeout = microtime(true) + 20;
|
$this->timeout = microtime(true) + 20;
|
||||||
$this->gamemode = $this->server->getGamemode();
|
$this->gamemode = $this->server->getGamemode();
|
||||||
$this->level = $this->server->getDefaultLevel();
|
$this->getLevel() = $this->server->getDefaultLevel();
|
||||||
$this->viewDistance = $this->server->getViewDistance();
|
$this->viewDistance = $this->server->getViewDistance();
|
||||||
$this->slot = 0;
|
$this->slot = 0;
|
||||||
$this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1);
|
$this->hotbar = array(0, -1, -1, -1, -1, -1, -1, -1, -1);
|
||||||
@ -516,12 +516,12 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(is_array($this->lastChunk)){
|
if(is_array($this->lastChunk)){
|
||||||
foreach($this->level->getChunkEntities($this->lastChunk[0], $this->lastChunk[1]) as $entity){
|
foreach($this->getLevel()->getChunkEntities($this->lastChunk[0], $this->lastChunk[1]) as $entity){
|
||||||
if($entity !== $this){
|
if($entity !== $this){
|
||||||
$entity->spawnTo($this);
|
$entity->spawnTo($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach($this->level->getChunkTiles($this->lastChunk[0], $this->lastChunk[1]) as $tile){
|
foreach($this->getLevel()->getChunkTiles($this->lastChunk[0], $this->lastChunk[1]) as $tile){
|
||||||
if($tile instanceof Spawnable){
|
if($tile instanceof Spawnable){
|
||||||
$tile->spawnTo($this);
|
$tile->spawnTo($this);
|
||||||
}
|
}
|
||||||
@ -541,7 +541,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$X = null;
|
$X = null;
|
||||||
$Z = null;
|
$Z = null;
|
||||||
LevelFormat::getXZ($index, $X, $Z);
|
LevelFormat::getXZ($index, $X, $Z);
|
||||||
if(!$this->level->isChunkPopulated($X, $Z)){
|
if(!$this->getLevel()->isChunkPopulated($X, $Z)){
|
||||||
$this->orderChunks();
|
$this->orderChunks();
|
||||||
if($this->chunkScheduled === 0 or $force === true){
|
if($this->chunkScheduled === 0 or $force === true){
|
||||||
$this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "getNextChunk"), array(false, true)), MAX_CHUNK_RATE);
|
$this->server->getScheduler()->scheduleDelayedTask(new CallbackTask(array($this, "getNextChunk"), array(false, true)), MAX_CHUNK_RATE);
|
||||||
@ -556,11 +556,11 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
}
|
}
|
||||||
$Yndex = $this->chunksLoaded[$index];
|
$Yndex = $this->chunksLoaded[$index];
|
||||||
$this->chunksLoaded[$index] = 0; //Load them all
|
$this->chunksLoaded[$index] = 0; //Load them all
|
||||||
$this->level->useChunk($X, $Z, $this);
|
$this->getLevel()->useChunk($X, $Z, $this);
|
||||||
$pk = new ChunkDataPacket;
|
$pk = new ChunkDataPacket;
|
||||||
$pk->chunkX = $X;
|
$pk->chunkX = $X;
|
||||||
$pk->chunkZ = $Z;
|
$pk->chunkZ = $Z;
|
||||||
$pk->data = $this->level->getOrderedChunk($X, $Z, $Yndex);
|
$pk->data = $this->getLevel()->getOrderedChunk($X, $Z, $Yndex);
|
||||||
$cnt = $this->dataPacket($pk);
|
$cnt = $this->dataPacket($pk);
|
||||||
if($cnt === false){
|
if($cnt === false){
|
||||||
return false;
|
return false;
|
||||||
@ -613,16 +613,16 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
|
|
||||||
$index = key($this->chunksOrder);
|
$index = key($this->chunksOrder);
|
||||||
LevelFormat::getXZ($index, $X, $Z);
|
LevelFormat::getXZ($index, $X, $Z);
|
||||||
$this->level->loadChunk($X, $Z);
|
$this->getLevel()->loadChunk($X, $Z);
|
||||||
if(!$this->level->isChunkPopulated($X, $Z)){
|
if(!$this->getLevel()->isChunkPopulated($X, $Z)){
|
||||||
$this->level->loadChunk($X - 1, $Z);
|
$this->getLevel()->loadChunk($X - 1, $Z);
|
||||||
$this->level->loadChunk($X + 1, $Z);
|
$this->getLevel()->loadChunk($X + 1, $Z);
|
||||||
$this->level->loadChunk($X, $Z - 1);
|
$this->getLevel()->loadChunk($X, $Z - 1);
|
||||||
$this->level->loadChunk($X, $Z + 1);
|
$this->getLevel()->loadChunk($X, $Z + 1);
|
||||||
$this->level->loadChunk($X + 1, $Z + 1);
|
$this->getLevel()->loadChunk($X + 1, $Z + 1);
|
||||||
$this->level->loadChunk($X + 1, $Z - 1);
|
$this->getLevel()->loadChunk($X + 1, $Z - 1);
|
||||||
$this->level->loadChunk($X - 1, $Z - 1);
|
$this->getLevel()->loadChunk($X - 1, $Z - 1);
|
||||||
$this->level->loadChunk($X - 1, $Z + 1);
|
$this->getLevel()->loadChunk($X - 1, $Z + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($lastChunk as $index => $Yndex){
|
foreach($lastChunk as $index => $Yndex){
|
||||||
@ -630,7 +630,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$X = null;
|
$X = null;
|
||||||
$Z = null;
|
$Z = null;
|
||||||
LevelFormat::getXZ($index, $X, $Z);
|
LevelFormat::getXZ($index, $X, $Z);
|
||||||
foreach($this->level->getChunkEntities($X, $Z) as $entity){
|
foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){
|
||||||
if($entity !== $this){
|
if($entity !== $this){
|
||||||
$entity->despawnFrom($this);
|
$entity->despawnFrom($this);
|
||||||
}
|
}
|
||||||
@ -753,7 +753,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function sleepOn(Vector3 $pos){
|
public function sleepOn(Vector3 $pos){
|
||||||
foreach($this->level->getPlayers() as $p){
|
foreach($this->getLevel()->getPlayers() as $p){
|
||||||
if($p->sleeping instanceof Vector3){
|
if($p->sleeping instanceof Vector3){
|
||||||
if($pos->distance($p->sleeping) <= 0.1){
|
if($pos->distance($p->sleeping) <= 0.1){
|
||||||
return false;
|
return false;
|
||||||
@ -761,7 +761,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->sleeping = $pos;
|
$this->sleeping = $pos;
|
||||||
$this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->level));
|
$this->teleport(new Position($pos->x + 0.5, $pos->y + 1, $pos->z + 0.5, $this->getLevel()));
|
||||||
/*if($this->entity instanceof Entity){
|
/*if($this->entity instanceof Entity){
|
||||||
$this->updateMetadata();
|
$this->updateMetadata();
|
||||||
}*/
|
}*/
|
||||||
@ -778,9 +778,9 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
*/
|
*/
|
||||||
public function setSpawn(Vector3 $pos){
|
public function setSpawn(Vector3 $pos){
|
||||||
if(!($pos instanceof Position)){
|
if(!($pos instanceof Position)){
|
||||||
$level = $this->level;
|
$level = $this->getLevel();
|
||||||
}else{
|
}else{
|
||||||
$level = $pos->level;
|
$level = $pos->getLevel();
|
||||||
}
|
}
|
||||||
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level);
|
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level);
|
||||||
$pk = new SetSpawnPositionPacket;
|
$pk = new SetSpawnPositionPacket;
|
||||||
@ -804,14 +804,14 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
public function checkSleep(){
|
public function checkSleep(){
|
||||||
if($this->sleeping !== false){
|
if($this->sleeping !== false){
|
||||||
//TODO
|
//TODO
|
||||||
if($this->server->api->time->getPhase($this->level) === "night"){
|
if($this->server->api->time->getPhase($this->getLevel()) === "night"){
|
||||||
foreach($this->level->getPlayers() as $p){
|
foreach($this->getLevel()->getPlayers() as $p){
|
||||||
if($p->sleeping === false){
|
if($p->sleeping === false){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->server->api->time->set("day", $this->level);
|
$this->server->api->time->set("day", $this->getLevel());
|
||||||
foreach($this->level->getPlayers() as $p){
|
foreach($this->getLevel()->getPlayers() as $p){
|
||||||
$p->stopSleep();
|
$p->stopSleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -824,7 +824,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
switch($event){
|
switch($event){
|
||||||
//TODO, obsolete
|
//TODO, obsolete
|
||||||
case "tile.update":
|
case "tile.update":
|
||||||
if($data->level === $this->level){
|
if($data->getLevel() === $this->getLevel()){
|
||||||
if($data instanceof Furnace){
|
if($data instanceof Furnace){
|
||||||
foreach($this->windows as $id => $w){
|
foreach($this->windows as $id => $w){
|
||||||
if($w === $data){
|
if($w === $data){
|
||||||
@ -845,7 +845,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "tile.container.slot":
|
case "tile.container.slot":
|
||||||
if($data["tile"]->level === $this->level){
|
if($data["tile"]->getLevel() === $this->getLevel()){
|
||||||
foreach($this->windows as $id => $w){
|
foreach($this->windows as $id => $w){
|
||||||
if($w === $data["tile"]){
|
if($w === $data["tile"]){
|
||||||
$pk = new ContainerSetSlotPacket;
|
$pk = new ContainerSetSlotPacket;
|
||||||
@ -875,7 +875,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$this->awardAchievement("diamond");
|
$this->awardAchievement("diamond");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}elseif($data["entity"]->level === $this->level){
|
}elseif($data["entity"]->getLevel() === $this->getLevel()){
|
||||||
$pk = new TakeItemEntityPacket;
|
$pk = new TakeItemEntityPacket;
|
||||||
$pk->eid = $data["eid"];
|
$pk->eid = $data["eid"];
|
||||||
$pk->target = $data["entity"]->getID();
|
$pk->target = $data["entity"]->getID();
|
||||||
@ -883,7 +883,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "entity.animate":
|
case "entity.animate":
|
||||||
if($data["eid"] === $this->id or $data["entity"]->level !== $this->level){
|
if($data["eid"] === $this->id or $data["entity"]->getLevel() !== $this->getLevel()){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$pk = new AnimatePacket;
|
$pk = new AnimatePacket;
|
||||||
@ -897,7 +897,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
}else{
|
}else{
|
||||||
$eid = $data->getID();
|
$eid = $data->getID();
|
||||||
}
|
}
|
||||||
if($data->level === $this->level){
|
if($data->getLevel() === $this->getLevel()){
|
||||||
$pk = new SetEntityDataPacket;
|
$pk = new SetEntityDataPacket;
|
||||||
$pk->eid = $eid;
|
$pk->eid = $eid;
|
||||||
$pk->metadata = $data->getMetadata();
|
$pk->metadata = $data->getMetadata();
|
||||||
@ -910,7 +910,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
}else{
|
}else{
|
||||||
$eid = $data["entity"]->getID();
|
$eid = $data["entity"]->getID();
|
||||||
}
|
}
|
||||||
if($data["entity"]->level === $this->level){
|
if($data["entity"]->getLevel() === $this->getLevel()){
|
||||||
$pk = new EntityEventPacket;
|
$pk = new EntityEventPacket;
|
||||||
$pk->eid = $eid;
|
$pk->eid = $eid;
|
||||||
$pk->event = $data["event"];
|
$pk->event = $data["event"];
|
||||||
@ -1336,12 +1336,12 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$nbt["NameTag"] = $this->username;
|
$nbt["NameTag"] = $this->username;
|
||||||
}
|
}
|
||||||
$this->gamemode = $nbt["playerGameType"] & 0x03;
|
$this->gamemode = $nbt["playerGameType"] & 0x03;
|
||||||
if(($this->level = $this->server->getLevel($nbt["Level"])) === null){
|
if(($this->getLevel() = $this->server->getLevel($nbt["Level"])) === null){
|
||||||
$this->level = $this->server->getDefaultLevel();
|
$this->getLevel() = $this->server->getDefaultLevel();
|
||||||
$nbt["Level"] = $this->level->getName();
|
$nbt["Level"] = $this->getLevel()->getName();
|
||||||
$nbt["Pos"][0] = $this->level->getSpawn()->x;
|
$nbt["Pos"][0] = $this->getLevel()->getSpawn()->x;
|
||||||
$nbt["Pos"][1] = $this->level->getSpawn()->y;
|
$nbt["Pos"][1] = $this->getLevel()->getSpawn()->y;
|
||||||
$nbt["Pos"][2] = $this->level->getSpawn()->z;
|
$nbt["Pos"][2] = $this->getLevel()->getSpawn()->z;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!($nbt instanceof Compound)){
|
if(!($nbt instanceof Compound)){
|
||||||
@ -1357,7 +1357,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
|
|
||||||
$nbt["lastPlayed"] = floor(microtime(true) * 1000);
|
$nbt["lastPlayed"] = floor(microtime(true) * 1000);
|
||||||
$this->server->saveOfflinePlayerData($this->username, $nbt);
|
$this->server->saveOfflinePlayerData($this->username, $nbt);
|
||||||
parent::__construct($this->level, $nbt);
|
parent::__construct($this->getLevel(), $nbt);
|
||||||
$this->loggedIn = true;
|
$this->loggedIn = true;
|
||||||
|
|
||||||
if(($this->gamemode & 0x01) === 0x01){
|
if(($this->gamemode & 0x01) === 0x01){
|
||||||
@ -1379,7 +1379,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$this->dataPacket($pk);
|
$this->dataPacket($pk);
|
||||||
|
|
||||||
$pk = new StartGamePacket;
|
$pk = new StartGamePacket;
|
||||||
$pk->seed = $this->level->getSeed();
|
$pk->seed = $this->getLevel()->getSeed();
|
||||||
$pk->x = $this->x;
|
$pk->x = $this->x;
|
||||||
$pk->y = $this->y;
|
$pk->y = $this->y;
|
||||||
$pk->z = $this->z;
|
$pk->z = $this->z;
|
||||||
@ -1409,7 +1409,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$this->lastMeasure = microtime(true);
|
$this->lastMeasure = microtime(true);
|
||||||
$this->tasks[] = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "measureLag")), 50);
|
$this->tasks[] = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "measureLag")), 50);
|
||||||
|
|
||||||
console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->id . " at (" . $this->level->getName() . ", " . round($this->x, 4) . ", " . round($this->y, 4) . ", " . round($this->z, 4) . ")");
|
console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->id . " at (" . $this->getLevel()->getName() . ", " . round($this->x, 4) . ", " . round($this->y, 4) . ", " . round($this->z, 4) . ")");
|
||||||
|
|
||||||
$this->server->getPluginManager()->callEvent(new PlayerJoinEvent($this, $this->username . " joined the game"));
|
$this->server->getPluginManager()->callEvent(new PlayerJoinEvent($this, $this->username . " joined the game"));
|
||||||
|
|
||||||
@ -1436,12 +1436,12 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$this->blocked = false;
|
$this->blocked = false;
|
||||||
|
|
||||||
$pk = new SetTimePacket;
|
$pk = new SetTimePacket;
|
||||||
$pk->time = $this->level->getTime();
|
$pk->time = $this->getLevel()->getTime();
|
||||||
$pk->started = $this->level->stopTime == false;
|
$pk->started = $this->getLevel()->stopTime == false;
|
||||||
$this->dataPacket($pk);
|
$this->dataPacket($pk);
|
||||||
|
|
||||||
$pos = new Position($this->x, $this->y, $this->z, $this->level);
|
$pos = new Position($this->x, $this->y, $this->z, $this->getLevel());
|
||||||
$pos = $this->level->getSafeSpawn($pos);
|
$pos = $this->getLevel()->getSafeSpawn($pos);
|
||||||
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $pos));
|
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $pos));
|
||||||
|
|
||||||
$this->teleport($ev->getRespawnPosition());
|
$this->teleport($ev->getRespawnPosition());
|
||||||
@ -1539,7 +1539,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$blockVector = new Vector3($packet->x, $packet->y, $packet->z);
|
$blockVector = new Vector3($packet->x, $packet->y, $packet->z);
|
||||||
|
|
||||||
if(($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5){
|
if(($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5){
|
||||||
$target = $this->level->getBlock($blockVector);
|
$target = $this->getLevel()->getBlock($blockVector);
|
||||||
$block = $target->getSide($packet->face);
|
$block = $target->getSide($packet->face);
|
||||||
|
|
||||||
$pk = new UpdateBlockPacket;
|
$pk = new UpdateBlockPacket;
|
||||||
@ -1573,7 +1573,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
|
|
||||||
}elseif(($this->gamemode & 0x01) === 1){
|
}elseif(($this->gamemode & 0x01) === 1){
|
||||||
$item = Item::get(Block::$creative[$this->getCurrentEquipment()][0], Block::$creative[$this->getCurrentEquipment()][1], 1);
|
$item = Item::get(Block::$creative[$this->getCurrentEquipment()][0], Block::$creative[$this->getCurrentEquipment()][1], 1);
|
||||||
if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){
|
if($this->getLevel()->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}elseif($this->getSlot($this->getCurrentEquipment())->getID() !== $packet->item or ($this->getSlot($this->getCurrentEquipment())->isTool() === false and $this->getSlot($this->getCurrentEquipment())->getMetadata() !== $packet->meta)){
|
}elseif($this->getSlot($this->getCurrentEquipment())->getID() !== $packet->item or ($this->getSlot($this->getCurrentEquipment())->isTool() === false and $this->getSlot($this->getCurrentEquipment())->getMetadata() !== $packet->meta)){
|
||||||
@ -1581,13 +1581,13 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
}else{
|
}else{
|
||||||
$item = clone $this->getSlot($this->getCurrentEquipment());
|
$item = clone $this->getSlot($this->getCurrentEquipment());
|
||||||
//TODO: Implement adventure mode checks
|
//TODO: Implement adventure mode checks
|
||||||
if($this->level->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){
|
if($this->getLevel()->useItemOn($blockVector, $item, $packet->face, $packet->fx, $packet->fy, $packet->fz, $this) === true){
|
||||||
$this->setSlot($this->getCurrentEquipment(), $item);
|
$this->setSlot($this->getCurrentEquipment(), $item);
|
||||||
$this->sendInventorySlot($this->getCurrentEquipment());
|
$this->sendInventorySlot($this->getCurrentEquipment());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$target = $this->level->getBlock($blockVector);
|
$target = $this->getLevel()->getBlock($blockVector);
|
||||||
$block = $target->getSide($packet->face);
|
$block = $target->getSide($packet->face);
|
||||||
|
|
||||||
$pk = new UpdateBlockPacket;
|
$pk = new UpdateBlockPacket;
|
||||||
@ -1632,7 +1632,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
"y" => $this->entity->y + 1.6,
|
"y" => $this->entity->y + 1.6,
|
||||||
"z" => $this->entity->z,
|
"z" => $this->entity->z,
|
||||||
);
|
);
|
||||||
$e = $this->server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_ARROW, $d);
|
$e = $this->server->api->entity->add($this->getLevel(), ENTITY_OBJECT, OBJECT_ARROW, $d);
|
||||||
$e->yaw = $this->entity->yaw;
|
$e->yaw = $this->entity->yaw;
|
||||||
$e->pitch = $this->entity->pitch;
|
$e->pitch = $this->entity->pitch;
|
||||||
$rotation = ($this->entity->yaw - 90) % 360;
|
$rotation = ($this->entity->yaw - 90) % 360;
|
||||||
@ -1705,14 +1705,14 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$item = clone $this->getSlot($this->getCurrentEquipment());
|
$item = clone $this->getSlot($this->getCurrentEquipment());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($drops = $this->level->useBreakOn($vector, $item)) !== true){
|
if(($drops = $this->getLevel()->useBreakOn($vector, $item)) !== true){
|
||||||
if(($this->gamemode & 0x01) === 0){
|
if(($this->gamemode & 0x01) === 0){
|
||||||
//TODO: drop items
|
//TODO: drop items
|
||||||
$this->setSlot($this->getCurrentEquipment(), $item);
|
$this->setSlot($this->getCurrentEquipment(), $item);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$target = $this->level->getBlock($vector);
|
$target = $this->getLevel()->getBlock($vector);
|
||||||
$pk = new UpdateBlockPacket;
|
$pk = new UpdateBlockPacket;
|
||||||
$pk->x = $target->x;
|
$pk->x = $target->x;
|
||||||
$pk->y = $target->y;
|
$pk->y = $target->y;
|
||||||
@ -1953,7 +1953,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$data["item"] = $packet->item;
|
$data["item"] = $packet->item;
|
||||||
$data["player"] = $this;
|
$data["player"] = $this;
|
||||||
if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){
|
if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){
|
||||||
$this->server->api->entity->drop(new Position($this->entity->x - 0.5, $this->entity->y, $this->entity->z - 0.5, $this->level), $packet->item);
|
$this->server->api->entity->drop(new Position($this->entity->x - 0.5, $this->entity->y, $this->entity->z - 0.5, $this->getLevel()), $packet->item);
|
||||||
$this->setSlot($this->getCurrentEquipment(), Item::get(AIR, 0, 0), false);
|
$this->setSlot($this->getCurrentEquipment(), Item::get(AIR, 0, 0), false);
|
||||||
}
|
}
|
||||||
if($this->entity->inAction === true){
|
if($this->entity->inAction === true){
|
||||||
@ -1999,7 +1999,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$pk->z = $ob->z;
|
$pk->z = $ob->z;
|
||||||
$pk->case1 = 1;
|
$pk->case1 = 1;
|
||||||
$pk->case2 = 0;
|
$pk->case2 = 0;
|
||||||
Player::broadcastPacket($this->level->players, $pk);
|
Player::broadcastPacket($this->getLevel()->players, $pk);
|
||||||
}
|
}
|
||||||
}elseif($this->windows[$packet->windowid] instanceof Chest){
|
}elseif($this->windows[$packet->windowid] instanceof Chest){
|
||||||
$pk = new TileEventPacket;
|
$pk = new TileEventPacket;
|
||||||
@ -2008,7 +2008,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$pk->z = $this->windows[$packet->windowid]->z;
|
$pk->z = $this->windows[$packet->windowid]->z;
|
||||||
$pk->case1 = 1;
|
$pk->case1 = 1;
|
||||||
$pk->case2 = 0;
|
$pk->case2 = 0;
|
||||||
Player::broadcastPacket($this->level->players, $pk);
|
Player::broadcastPacket($this->getLevel()->players, $pk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($this->windows[$packet->windowid]);
|
unset($this->windows[$packet->windowid]);
|
||||||
@ -2208,7 +2208,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
}
|
}
|
||||||
$this->craftingItems = array();
|
$this->craftingItems = array();
|
||||||
$this->toCraft = array();
|
$this->toCraft = array();
|
||||||
$t = $this->level->getTile(new Vector3($packet->x, $packet->y, $packet->z));
|
$t = $this->getLevel()->getTile(new Vector3($packet->x, $packet->y, $packet->z));
|
||||||
if($t instanceof Sign){
|
if($t instanceof Sign){
|
||||||
if($t->namedtag->creator !== $this->username){
|
if($t->namedtag->creator !== $this->username){
|
||||||
$t->spawnTo($this);
|
$t->spawnTo($this);
|
||||||
@ -2289,7 +2289,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
*/
|
*/
|
||||||
public function close($message = "", $reason = "generic reason"){
|
public function close($message = "", $reason = "generic reason"){
|
||||||
if($this->connected === true){
|
if($this->connected === true){
|
||||||
unset($this->level->players[$this->CID]);
|
unset($this->getLevel()->players[$this->CID]);
|
||||||
if($this->username != ""){
|
if($this->username != ""){
|
||||||
$this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message));
|
$this->server->getPluginManager()->callEvent($ev = new PlayerQuitEvent($this, $message));
|
||||||
if($this->loggedIn === true){
|
if($this->loggedIn === true){
|
||||||
@ -2302,7 +2302,7 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
$this->directDataPacket(new DisconnectPacket);
|
$this->directDataPacket(new DisconnectPacket);
|
||||||
$this->connected = false;
|
$this->connected = false;
|
||||||
$this->server->removePlayer($this);
|
$this->server->removePlayer($this);
|
||||||
$this->level->freeAllChunks($this);
|
$this->getLevel()->freeAllChunks($this);
|
||||||
$this->loggedIn = false;
|
$this->loggedIn = false;
|
||||||
foreach($this->tasks as $task){
|
foreach($this->tasks as $task){
|
||||||
$task->cancel();
|
$task->cancel();
|
||||||
@ -2337,8 +2337,8 @@ class Player extends Human implements CommandSender, IPlayer{
|
|||||||
*/
|
*/
|
||||||
public function save(){
|
public function save(){
|
||||||
parent::saveNBT();
|
parent::saveNBT();
|
||||||
$this->namedtag["Level"] = $this->level->getName();
|
$this->namedtag["Level"] = $this->getLevel()->getName();
|
||||||
$this->namedtag["SpawnLevel"] = $this->level->getName();
|
$this->namedtag["SpawnLevel"] = $this->getLevel()->getName();
|
||||||
$this->namedtag["SpawnX"] = (int) $this->spawnPosition->x;
|
$this->namedtag["SpawnX"] = (int) $this->spawnPosition->x;
|
||||||
$this->namedtag["SpawnY"] = (int) $this->spawnPosition->y;
|
$this->namedtag["SpawnY"] = (int) $this->spawnPosition->y;
|
||||||
$this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z;
|
$this->namedtag["SpawnZ"] = (int) $this->spawnPosition->z;
|
||||||
|
@ -35,13 +35,13 @@ class Bed extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
if($player instanceof Player and Server::getInstance()->api->time->getPhase($this->level) !== "night"){
|
/*if($player instanceof Player and Server::getInstance()->api->time->getPhase($this->getLevel()) !== "night"){
|
||||||
$pk = new ChatPacket;
|
$pk = new ChatPacket;
|
||||||
$pk->message = "You can only sleep at night";
|
$pk->message = "You can only sleep at night";
|
||||||
$player->dataPacket($pk);
|
$player->dataPacket($pk);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$blockNorth = $this->getSide(2); //Gets the blocks around them
|
$blockNorth = $this->getSide(2); //Gets the blocks around them
|
||||||
$blockSouth = $this->getSide(3);
|
$blockSouth = $this->getSide(3);
|
||||||
@ -90,8 +90,8 @@ class Bed extends Transparent{
|
|||||||
$downNext = $this->getSide(0);
|
$downNext = $this->getSide(0);
|
||||||
if($next->isReplaceable === true and $downNext->isTransparent === false){
|
if($next->isReplaceable === true and $downNext->isTransparent === false){
|
||||||
$meta = (($d + 3) % 4) & 0x03;
|
$meta = (($d + 3) % 4) & 0x03;
|
||||||
$this->level->setBlock($block, Block::get($this->id, $meta), true, false, true);
|
$this->getLevel()->setBlock($block, Block::get($this->id, $meta), true, false, true);
|
||||||
$this->level->setBlock($next, Block::get($this->id, $meta | 0x08), true, false, true);
|
$this->getLevel()->setBlock($next, Block::get($this->id, $meta | 0x08), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -108,26 +108,26 @@ class Bed extends Transparent{
|
|||||||
|
|
||||||
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
|
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
|
||||||
if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right
|
if($blockNorth->getID() === $this->id and $blockNorth->meta !== 0x08){ //Checks if the block ID and meta are right
|
||||||
$this->level->setBlock($blockNorth, new Air(), true, false, true);
|
$this->getLevel()->setBlock($blockNorth, new Air(), true, false, true);
|
||||||
}elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){
|
}elseif($blockSouth->getID() === $this->id and $blockSouth->meta !== 0x08){
|
||||||
$this->level->setBlock($blockSouth, new Air(), true, false, true);
|
$this->getLevel()->setBlock($blockSouth, new Air(), true, false, true);
|
||||||
}elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){
|
}elseif($blockEast->getID() === $this->id and $blockEast->meta !== 0x08){
|
||||||
$this->level->setBlock($blockEast, new Air(), true, false, true);
|
$this->getLevel()->setBlock($blockEast, new Air(), true, false, true);
|
||||||
}elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){
|
}elseif($blockWest->getID() === $this->id and $blockWest->meta !== 0x08){
|
||||||
$this->level->setBlock($blockWest, new Air(), true, false, true);
|
$this->getLevel()->setBlock($blockWest, new Air(), true, false, true);
|
||||||
}
|
}
|
||||||
}else{ //Bottom Part of Bed
|
}else{ //Bottom Part of Bed
|
||||||
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
|
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
|
||||||
$this->level->setBlock($blockNorth, new Air(), true, false, true);
|
$this->getLevel()->setBlock($blockNorth, new Air(), true, false, true);
|
||||||
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
|
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
|
||||||
$this->level->setBlock($blockSouth, new Air(), true, false, true);
|
$this->getLevel()->setBlock($blockSouth, new Air(), true, false, true);
|
||||||
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
|
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
|
||||||
$this->level->setBlock($blockEast, new Air(), true, false, true);
|
$this->getLevel()->setBlock($blockEast, new Air(), true, false, true);
|
||||||
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
|
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
|
||||||
$this->level->setBlock($blockWest, new Air(), true, false, true);
|
$this->getLevel()->setBlock($blockWest, new Air(), true, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->level->setBlock($this, new Air(), true, false, true);
|
$this->getLevel()->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class Beetroot extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === self::FARMLAND){
|
if($down->getID() === self::FARMLAND){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ class Beetroot extends Flowable{
|
|||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
$this->meta = 0x07;
|
$this->meta = 0x07;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
$item->count--;
|
$item->count--;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -60,7 +60,7 @@ class Beetroot extends Flowable{
|
|||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get(BEETROOT_SEEDS, 0, 1));
|
//Server::getInstance()->api->entity->drop($this, Item::get(BEETROOT_SEEDS, 0, 1));
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ class Beetroot extends Flowable{
|
|||||||
if(mt_rand(0, 2) == 1){
|
if(mt_rand(0, 2) == 1){
|
||||||
if($this->meta < 0x07){
|
if($this->meta < 0x07){
|
||||||
++$this->meta;
|
++$this->meta;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_RANDOM;
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
}
|
}
|
||||||
|
@ -626,12 +626,17 @@ abstract class Block extends Position implements Metadatable{
|
|||||||
* Sets the block position to a new Position object
|
* Sets the block position to a new Position object
|
||||||
*
|
*
|
||||||
* @param Position $v
|
* @param Position $v
|
||||||
|
*
|
||||||
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
final public function position(Position $v){
|
final public function position(Position $v){
|
||||||
$this->level = $v->level;
|
if(!$v->isValid()){
|
||||||
|
throw new \RuntimeException("Undefined Level reference");
|
||||||
|
}
|
||||||
$this->x = (int) $v->x;
|
$this->x = (int) $v->x;
|
||||||
$this->y = (int) $v->y;
|
$this->y = (int) $v->y;
|
||||||
$this->z = (int) $v->z;
|
$this->z = (int) $v->z;
|
||||||
|
$this->setLevel($v->getLevel(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -672,8 +677,8 @@ abstract class Block extends Position implements Metadatable{
|
|||||||
*/
|
*/
|
||||||
public function getSide($side, $step = 1){
|
public function getSide($side, $step = 1){
|
||||||
$v = parent::getSide($side, $step);
|
$v = parent::getSide($side, $step);
|
||||||
if($this->level instanceof Level){
|
if($this->isValid()){
|
||||||
return $this->level->getBlock($v);
|
return $this->getLevel()->getBlock($v);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $v;
|
return $v;
|
||||||
|
@ -36,7 +36,7 @@ class BrownMushroom extends Flowable{
|
|||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ class BrownMushroom extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->isTransparent === false){
|
if($down->isTransparent === false){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ class BurningFurnace extends Solid{
|
|||||||
3 => 3,
|
3 => 3,
|
||||||
);
|
);
|
||||||
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
|
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0];
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
$nbt = new Compound(false, array(
|
$nbt = new Compound(false, array(
|
||||||
new Enum("Items", array()),
|
new Enum("Items", array()),
|
||||||
new String("id", Tile::FURNACE),
|
new String("id", Tile::FURNACE),
|
||||||
@ -55,20 +55,20 @@ class BurningFurnace extends Solid{
|
|||||||
new Int("z", $this->z)
|
new Int("z", $this->z)
|
||||||
));
|
));
|
||||||
$nbt->Items->setTagType(NBT::TAG_Compound);
|
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||||
new Furnace($this->level, $nbt);
|
new Furnace($this->getLevel(), $nbt);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onBreak(Item $item){
|
public function onBreak(Item $item){
|
||||||
$this->level->setBlock($this, new Air(), true, true, true);
|
$this->getLevel()->setBlock($this, new Air(), true, true, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
if($player instanceof Player){
|
if($player instanceof Player){
|
||||||
$t = $this->level->getTile($this);
|
$t = $this->getLevel()->getTile($this);
|
||||||
$furnace = false;
|
$furnace = false;
|
||||||
if($t instanceof Furnace){
|
if($t instanceof Furnace){
|
||||||
$furnace = $t;
|
$furnace = $t;
|
||||||
@ -81,7 +81,7 @@ class BurningFurnace extends Solid{
|
|||||||
new Int("z", $this->z)
|
new Int("z", $this->z)
|
||||||
));
|
));
|
||||||
$nbt->Items->setTagType(NBT::TAG_Compound);
|
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||||
$furnace = new Furnace($this->level, $nbt);
|
$furnace = new Furnace($this->getLevel(), $nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($player->getGamemode() & 0x01) === 0x01){
|
if(($player->getGamemode() & 0x01) === 0x01){
|
||||||
@ -116,7 +116,7 @@ class BurningFurnace extends Solid{
|
|||||||
if($item->isPickaxe() >= 1){
|
if($item->isPickaxe() >= 1){
|
||||||
$drops[] = array(Item::FURNACE, 0, 1);
|
$drops[] = array(Item::FURNACE, 0, 1);
|
||||||
}
|
}
|
||||||
$t = $this->level->getTile($this);
|
$t = $this->getLevel()->getTile($this);
|
||||||
if($t instanceof Furnace){
|
if($t instanceof Furnace){
|
||||||
for($s = 0; $s < Furnace::SLOTS; ++$s){
|
for($s = 0; $s < Furnace::SLOTS; ++$s){
|
||||||
$slot = $t->getSlot($s);
|
$slot = $t->getSlot($s);
|
||||||
|
@ -38,7 +38,7 @@ class Cactus extends Transparent{
|
|||||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() !== self::SAND and $down->getID() !== self::CACTUS){ //Replace with common break method
|
if($down->getID() !== self::SAND and $down->getID() !== self::CACTUS){ //Replace with common break method
|
||||||
$this->level->setBlock($this, new Air(), false);
|
$this->getLevel()->setBlock($this, new Air(), false);
|
||||||
Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
@ -47,17 +47,17 @@ class Cactus extends Transparent{
|
|||||||
if($this->getSide(0)->getID() !== self::CACTUS){
|
if($this->getSide(0)->getID() !== self::CACTUS){
|
||||||
if($this->meta == 0x0F){
|
if($this->meta == 0x0F){
|
||||||
for($y = 1; $y < 3; ++$y){
|
for($y = 1; $y < 3; ++$y){
|
||||||
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||||
if($b->getID() === self::AIR){
|
if($b->getID() === self::AIR){
|
||||||
$this->level->setBlock($b, new Cactus(), true, false, true);
|
$this->getLevel()->setBlock($b, new Cactus(), true, false, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->meta = 0;
|
$this->meta = 0;
|
||||||
$this->level->setBlock($this, $this, false);
|
$this->getLevel()->setBlock($this, $this, false);
|
||||||
}else{
|
}else{
|
||||||
++$this->meta;
|
++$this->meta;
|
||||||
$this->level->setBlock($this, $this, false);
|
$this->getLevel()->setBlock($this, $this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_RANDOM;
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
@ -75,7 +75,7 @@ class Cactus extends Transparent{
|
|||||||
$block2 = $this->getSide(4);
|
$block2 = $this->getSide(4);
|
||||||
$block3 = $this->getSide(5);
|
$block3 = $this->getSide(5);
|
||||||
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
|
if($block0->isTransparent === true and $block1->isTransparent === true and $block2->isTransparent === true and $block3->isTransparent === true){
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class Cake extends Transparent{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() !== self::AIR){
|
if($down->getID() !== self::AIR){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ class Cake extends Transparent{
|
|||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
$this->level->setBlock($this, new Air(), true, false, true);
|
$this->getLevel()->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -66,9 +66,9 @@ class Cake extends Transparent{
|
|||||||
++$this->meta;
|
++$this->meta;
|
||||||
$player->heal(3, "cake");
|
$player->heal(3, "cake");
|
||||||
if($this->meta >= 0x06){
|
if($this->meta >= 0x06){
|
||||||
$this->level->setBlock($this, new Air(), true, false, true);
|
$this->getLevel()->setBlock($this, new Air(), true, false, true);
|
||||||
}else{
|
}else{
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -55,7 +55,7 @@ class Carpet extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() !== self::AIR){
|
if($down->getID() !== self::AIR){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ class Carpet extends Flowable{
|
|||||||
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get($this->id, $this->meta, 1));
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id, $this->meta, 1));
|
||||||
$this->level->setBlock($this, new Air(), true, false, true);
|
$this->getLevel()->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class Carrot extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === self::FARMLAND){
|
if($down->getID() === self::FARMLAND){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ class Carrot extends Flowable{
|
|||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
$this->meta = 0x07;
|
$this->meta = 0x07;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
$item->count--;
|
$item->count--;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -60,7 +60,7 @@ class Carrot extends Flowable{
|
|||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get(CARROT, 0, 1));
|
//Server::getInstance()->api->entity->drop($this, Item::get(CARROT, 0, 1));
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ class Carrot extends Flowable{
|
|||||||
if(mt_rand(0, 2) == 1){
|
if(mt_rand(0, 2) == 1){
|
||||||
if($this->meta < 0x07){
|
if($this->meta < 0x07){
|
||||||
++$this->meta;
|
++$this->meta;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_RANDOM;
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
}
|
}
|
||||||
|
@ -60,14 +60,14 @@ class Chest extends Transparent{
|
|||||||
}
|
}
|
||||||
$c = $this->getSide($side);
|
$c = $this->getSide($side);
|
||||||
if(($c instanceof TileChest) and $c->getMetadata() === $this->meta){
|
if(($c instanceof TileChest) and $c->getMetadata() === $this->meta){
|
||||||
if((($tile = $this->level->getTile($c)) instanceof TileChest) and !$tile->isPaired()){
|
if((($tile = $this->getLevel()->getTile($c)) instanceof TileChest) and !$tile->isPaired()){
|
||||||
$chest = $tile;
|
$chest = $tile;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
$nbt = new Compound(false, array(
|
$nbt = new Compound(false, array(
|
||||||
new Enum("Items", array()),
|
new Enum("Items", array()),
|
||||||
new String("id", Tile::CHEST),
|
new String("id", Tile::CHEST),
|
||||||
@ -76,7 +76,7 @@ class Chest extends Transparent{
|
|||||||
new Int("z", $this->z)
|
new Int("z", $this->z)
|
||||||
));
|
));
|
||||||
$nbt->Items->setTagType(NBT::TAG_Compound);
|
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||||
$tile = new TileChest($this->level, $nbt);
|
$tile = new TileChest($this->getLevel(), $nbt);
|
||||||
|
|
||||||
if($chest instanceof TileChest){
|
if($chest instanceof TileChest){
|
||||||
$chest->pairWith($tile);
|
$chest->pairWith($tile);
|
||||||
@ -87,11 +87,11 @@ class Chest extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onBreak(Item $item){
|
public function onBreak(Item $item){
|
||||||
$t = $this->level->getTile($this);
|
$t = $this->getLevel()->getTile($this);
|
||||||
if($t instanceof TileChest){
|
if($t instanceof TileChest){
|
||||||
$t->unpair();
|
$t->unpair();
|
||||||
}
|
}
|
||||||
$this->level->setBlock($this, new Air(), true, true, true);
|
$this->getLevel()->setBlock($this, new Air(), true, true, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ class Chest extends Transparent{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$t = $this->level->getTile($this);
|
$t = $this->getLevel()->getTile($this);
|
||||||
$chest = false;
|
$chest = false;
|
||||||
if($t instanceof TileChest){
|
if($t instanceof TileChest){
|
||||||
$chest = $t;
|
$chest = $t;
|
||||||
@ -116,7 +116,7 @@ class Chest extends Transparent{
|
|||||||
new Int("z", $this->z)
|
new Int("z", $this->z)
|
||||||
));
|
));
|
||||||
$nbt->Items->setTagType(NBT::TAG_Compound);
|
$nbt->Items->setTagType(NBT::TAG_Compound);
|
||||||
$chest = new TileChest($this->level, $nbt);
|
$chest = new TileChest($this->getLevel(), $nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ class Chest extends Transparent{
|
|||||||
$drops = array(
|
$drops = array(
|
||||||
array($this->id, 0, 1),
|
array($this->id, 0, 1),
|
||||||
);
|
);
|
||||||
$t = $this->level->getTile($this);
|
$t = $this->getLevel()->getTile($this);
|
||||||
if($t instanceof Chest){
|
if($t instanceof Chest){
|
||||||
for($s = 0; $s < Chest::SLOTS; ++$s){
|
for($s = 0; $s < Chest::SLOTS; ++$s){
|
||||||
$slot = $t->getSlot($s);
|
$slot = $t->getSlot($s);
|
||||||
|
@ -34,7 +34,7 @@ class CyanFlower extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ class CyanFlower extends Flowable{
|
|||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class Dandelion extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
if($down->getID() === 2 or $down->getID() === 3 or $down->getID() === 60){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ class Dandelion extends Flowable{
|
|||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class DeadBush extends Flowable{
|
|||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class Dirt extends Solid{
|
|||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
if($item->isHoe()){
|
if($item->isHoe()){
|
||||||
$item->useOn($this);
|
$item->useOn($this);
|
||||||
$this->level->setBlock($this, Block::get(Item::FARMLAND, 0), true, false, true);
|
$this->getLevel()->setBlock($this, Block::get(Item::FARMLAND, 0), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -36,9 +36,9 @@ abstract class Door extends Transparent{
|
|||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
$this->level->setBlock($this, new Air(), false);
|
$this->getLevel()->setBlock($this, new Air(), false);
|
||||||
if($this->getSide(1) instanceof Door){
|
if($this->getSide(1) instanceof Door){
|
||||||
$this->level->setBlock($this->getSide(1), new Air(), false);
|
$this->getLevel()->setBlock($this->getSide(1), new Air(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
@ -68,10 +68,10 @@ abstract class Door extends Transparent{
|
|||||||
if($next->getID() === $this->id or ($next2->isTransparent === false and $next->isTransparent === true)){ //Door hinge
|
if($next->getID() === $this->id or ($next2->isTransparent === false and $next->isTransparent === true)){ //Door hinge
|
||||||
$metaUp |= 0x01;
|
$metaUp |= 0x01;
|
||||||
}
|
}
|
||||||
$this->level->setBlock($blockUp, Block::get($this->id, $metaUp), true, false, true); //Top
|
$this->getLevel()->setBlock($blockUp, Block::get($this->id, $metaUp), true, false, true); //Top
|
||||||
|
|
||||||
$this->meta = $player->getDirection() & 0x03;
|
$this->meta = $player->getDirection() & 0x03;
|
||||||
$this->level->setBlock($block, $this, true, false, true); //Bottom
|
$this->getLevel()->setBlock($block, $this, true, false, true); //Bottom
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,15 +82,15 @@ abstract class Door extends Transparent{
|
|||||||
if(($this->meta & 0x08) === 0x08){
|
if(($this->meta & 0x08) === 0x08){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === $this->id){
|
if($down->getID() === $this->id){
|
||||||
$this->level->setBlock($down, new Air(), true, false, true);
|
$this->getLevel()->setBlock($down, new Air(), true, false, true);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$up = $this->getSide(1);
|
$up = $this->getSide(1);
|
||||||
if($up->getID() === $this->id){
|
if($up->getID() === $this->id){
|
||||||
$this->level->setBlock($up, new Air(), true, false, true);
|
$this->getLevel()->setBlock($up, new Air(), true, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->level->setBlock($this, new Air(), true, false, true);
|
$this->getLevel()->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -100,8 +100,8 @@ abstract class Door extends Transparent{
|
|||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === $this->id){
|
if($down->getID() === $this->id){
|
||||||
$meta = $down->getMetadata() ^ 0x04;
|
$meta = $down->getMetadata() ^ 0x04;
|
||||||
$this->level->setBlock($down, Block::get($this->id, $meta), true, false, true);
|
$this->getLevel()->setBlock($down, Block::get($this->id, $meta), true, false, true);
|
||||||
$players = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4);
|
$players = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4);
|
||||||
if($player instanceof Player){
|
if($player instanceof Player){
|
||||||
unset($players[$player->CID]);
|
unset($players[$player->CID]);
|
||||||
}
|
}
|
||||||
@ -119,8 +119,8 @@ abstract class Door extends Transparent{
|
|||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
$this->meta ^= 0x04;
|
$this->meta ^= 0x04;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
$players = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4);
|
$players = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4);
|
||||||
if($player instanceof Player){
|
if($player instanceof Player){
|
||||||
unset($players[$player->CID]);
|
unset($players[$player->CID]);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class Fallable extends Solid{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
$ret = $this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ class FenceGate extends Transparent{
|
|||||||
3 => 2,
|
3 => 2,
|
||||||
);
|
);
|
||||||
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] & 0x03;
|
$this->meta = $faces[$player instanceof Player ? $player->getDirection() : 0] & 0x03;
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ class FenceGate extends Transparent{
|
|||||||
}else{
|
}else{
|
||||||
$this->isFullBlock = false;
|
$this->isFullBlock = false;
|
||||||
}
|
}
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -45,12 +45,12 @@ class Fire extends Flowable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->level->setBlock($this, new Air(), true, false, true);
|
$this->getLevel()->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
if($this->getSide(0)->getID() !== self::NETHERRACK){
|
if($this->getSide(0)->getID() !== self::NETHERRACK){
|
||||||
$this->level->setBlock($this, new Air(), true, false, true);
|
$this->getLevel()->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class Generic extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
return $this->level->setBlock($this, $this, true, false, true);
|
return $this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isBreakable(Item $item){
|
public function isBreakable(Item $item){
|
||||||
@ -46,7 +46,7 @@ class Generic extends Block{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onBreak(Item $item){
|
public function onBreak(Item $item){
|
||||||
return $this->level->setBlock($this, new Air(), true, false, true);
|
return $this->getLevel()->setBlock($this, new Air(), true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
@ -60,9 +60,9 @@ class Generic extends Block{
|
|||||||
"Tile" => $this->id,
|
"Tile" => $this->id,
|
||||||
);
|
);
|
||||||
$server = Server::getInstance();
|
$server = Server::getInstance();
|
||||||
/*$this->level->setBlock($this, new Air(), false, false, true);
|
/*$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
//TODO
|
//TODO
|
||||||
//$e = $server->api->entity->add($this->level, ENTITY_FALLING, FALLING_SAND, $data);
|
//$e = $server->api->entity->add($this->getLevel(), ENTITY_FALLING, FALLING_SAND, $data);
|
||||||
//$e->spawnToAll();
|
//$e->spawnToAll();
|
||||||
$server->api->block->blockUpdateAround(clone $this, Level::BLOCK_UPDATE_NORMAL, 1);*/
|
$server->api->block->blockUpdateAround(clone $this, Level::BLOCK_UPDATE_NORMAL, 1);*/
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class GlowingRedstoneOre extends Solid{
|
|||||||
|
|
||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === Level::BLOCK_UPDATE_SCHEDULED or $type === Level::BLOCK_UPDATE_RANDOM){
|
if($type === Level::BLOCK_UPDATE_SCHEDULED or $type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
$this->level->setBlock($this, Block::get(Item::REDSTONE_ORE, $this->meta), false, false, true);
|
$this->getLevel()->setBlock($this, Block::get(Item::REDSTONE_ORE, $this->meta), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_WEAK;
|
return Level::BLOCK_UPDATE_WEAK;
|
||||||
}
|
}
|
||||||
|
@ -42,12 +42,12 @@ class Grass extends Solid{
|
|||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){
|
||||||
$item->count--;
|
$item->count--;
|
||||||
TallGrass::growGrass($this->level, $this, new Random(mt_rand()), 8, 2);
|
TallGrass::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($item->isHoe()){
|
}elseif($item->isHoe()){
|
||||||
$item->useOn($this);
|
$item->useOn($this);
|
||||||
$this->level->setBlock($this, new Farmland());
|
$this->getLevel()->setBlock($this, new Farmland());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class HayBale extends Solid{
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->meta = ($this->meta & 0x03) | $faces[$face];
|
$this->meta = ($this->meta & 0x03) | $faces[$face];
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class Ice extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onBreak(Item $item){
|
public function onBreak(Item $item){
|
||||||
$this->level->setBlock($this, new Water(), true, false, true);
|
$this->getLevel()->setBlock($this, new Water(), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class Ladder extends Transparent{
|
|||||||
);
|
);
|
||||||
if(isset($faces[$face])){
|
if(isset($faces[$face])){
|
||||||
$this->meta = $faces[$face];
|
$this->meta = $faces[$face];
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ class Ladder extends Transparent{
|
|||||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
/*if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
/*if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
Server::getInstance()->api->entity->drop($this, Item::get(LADDER, 0, 1));
|
Server::getInstance()->api->entity->drop($this, Item::get(LADDER, 0, 1));
|
||||||
$this->level->setBlock($this, new Air(), true, true, true);
|
$this->getLevel()->setBlock($this, new Air(), true, true, true);
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class Lava extends Liquid{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
$ret = $this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
Server::getInstance()->api->block->scheduleBlockUpdate(clone $this, 40, Level::BLOCK_UPDATE_NORMAL);
|
Server::getInstance()->api->block->scheduleBlockUpdate(clone $this, 40, Level::BLOCK_UPDATE_NORMAL);
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
@ -61,9 +61,9 @@ class Lava extends Liquid{
|
|||||||
if($b instanceof Water){
|
if($b instanceof Water){
|
||||||
$level = $this->meta & 0x07;
|
$level = $this->meta & 0x07;
|
||||||
if($level == 0x00){
|
if($level == 0x00){
|
||||||
$this->level->setBlock($this, new Obsidian(), false, false, true);
|
$this->getLevel()->setBlock($this, new Obsidian(), false, false, true);
|
||||||
}else{
|
}else{
|
||||||
$this->level->setBlock($this, new Cobblestone(), false, false, true);
|
$this->getLevel()->setBlock($this, new Cobblestone(), false, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ class Lava extends Liquid{
|
|||||||
if($from !== null || $level == 0x00){
|
if($from !== null || $level == 0x00){
|
||||||
if($level !== 0x07){
|
if($level !== 0x07){
|
||||||
if($down instanceof Air || $down instanceof Lava){
|
if($down instanceof Air || $down instanceof Lava){
|
||||||
$this->level->setBlock($down, new Lava(0x01), false, false, true);
|
$this->getLevel()->setBlock($down, new Lava(0x01), false, false, true);
|
||||||
Server::getInstance()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
Server::getInstance()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
||||||
}else{
|
}else{
|
||||||
for($side = 2; $side <= 5; ++$side){
|
for($side = 2; $side <= 5; ++$side){
|
||||||
@ -111,7 +111,7 @@ class Lava extends Liquid{
|
|||||||
if($b instanceof Lava){
|
if($b instanceof Lava){
|
||||||
|
|
||||||
}elseif($b->isFlowable === true){
|
}elseif($b->isFlowable === true){
|
||||||
$this->level->setBlock($b, new Lava(min($level + 2, 7)), false, false, true);
|
$this->getLevel()->setBlock($b, new Lava(min($level + 2, 7)), false, false, true);
|
||||||
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ class Lava extends Liquid{
|
|||||||
$ssb = $sb->getSide($s);
|
$ssb = $sb->getSide($s);
|
||||||
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
||||||
}
|
}
|
||||||
$this->level->setBlock($sb, new Air(), false, false, true);
|
$this->getLevel()->setBlock($sb, new Air(), false, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$b = $this->getSide(0)->getSide($side);
|
$b = $this->getSide(0)->getSide($side);
|
||||||
@ -139,13 +139,13 @@ class Lava extends Liquid{
|
|||||||
$ssb = $sb->getSide($s);
|
$ssb = $sb->getSide($s);
|
||||||
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 40, Level::BLOCK_UPDATE_NORMAL);
|
||||||
}
|
}
|
||||||
$this->level->setBlock($b, new Air(), false, false, true);
|
$this->getLevel()->setBlock($b, new Air(), false, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -112,7 +112,7 @@ class Leaves extends Transparent{
|
|||||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
if(($this->meta & 0b00001100) === 0){
|
if(($this->meta & 0b00001100) === 0){
|
||||||
$this->meta |= 0x08;
|
$this->meta |= 0x08;
|
||||||
$this->level->setBlock($this, $this, false, false, true);
|
$this->getLevel()->setBlock($this, $this, false, false, true);
|
||||||
}
|
}
|
||||||
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||||
if(($this->meta & 0b00001100) === 0x08){
|
if(($this->meta & 0b00001100) === 0x08){
|
||||||
@ -120,9 +120,9 @@ class Leaves extends Transparent{
|
|||||||
$visited = array();
|
$visited = array();
|
||||||
$check = 0;
|
$check = 0;
|
||||||
if($this->findLog($this, $visited, 0, $check) === true){
|
if($this->findLog($this, $visited, 0, $check) === true){
|
||||||
$this->level->setBlock($this, $this, false, false, true);
|
$this->getLevel()->setBlock($this, $this, false, false, true);
|
||||||
}else{
|
}else{
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
if(mt_rand(1, 20) === 1){ //Saplings
|
if(mt_rand(1, 20) === 1){ //Saplings
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get(Item::SAPLING, $this->meta & 0x03, 1));
|
//Server::getInstance()->api->entity->drop($this, Item::get(Item::SAPLING, $this->meta & 0x03, 1));
|
||||||
@ -142,7 +142,7 @@ class Leaves extends Transparent{
|
|||||||
|
|
||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$this->meta |= 0x04;
|
$this->meta |= 0x04;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item){
|
public function getDrops(Item $item){
|
||||||
|
@ -38,7 +38,7 @@ class LitPumpkin extends Solid{
|
|||||||
3 => 3,
|
3 => 3,
|
||||||
);
|
);
|
||||||
$this->meta = $faces[$player->getDirection()];
|
$this->meta = $faces[$player->getDirection()];
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class MelonStem extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === self::FARMLAND){
|
if($down->getID() === self::FARMLAND){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ class MelonStem extends Flowable{
|
|||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get(MELON_SEEDS, 0, mt_rand(0, 2)));
|
//Server::getInstance()->api->entity->drop($this, Item::get(MELON_SEEDS, 0, mt_rand(0, 2)));
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ class MelonStem extends Flowable{
|
|||||||
if(mt_rand(0, 2) == 1){
|
if(mt_rand(0, 2) == 1){
|
||||||
if($this->meta < 0x07){
|
if($this->meta < 0x07){
|
||||||
++$this->meta;
|
++$this->meta;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_RANDOM;
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
}else{
|
}else{
|
||||||
@ -69,7 +69,7 @@ class MelonStem extends Flowable{
|
|||||||
$side = $this->getSide(mt_rand(2, 5));
|
$side = $this->getSide(mt_rand(2, 5));
|
||||||
$d = $side->getSide(0);
|
$d = $side->getSide(0);
|
||||||
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
|
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
|
||||||
$this->level->setBlock($side, new Melon(), true, false, true);
|
$this->getLevel()->setBlock($side, new Melon(), true, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ class MelonStem extends Flowable{
|
|||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
$this->meta = 0x07;
|
$this->meta = 0x07;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
if(($player->gamemode & 0x01) === 0){
|
if(($player->gamemode & 0x01) === 0){
|
||||||
$item->count--;
|
$item->count--;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class Potato extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === self::FARMLAND){
|
if($down->getID() === self::FARMLAND){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ class Potato extends Flowable{
|
|||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
$this->meta = 0x07;
|
$this->meta = 0x07;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
if(($player->gamemode & 0x01) === 0){
|
if(($player->gamemode & 0x01) === 0){
|
||||||
$item->count--;
|
$item->count--;
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ class Potato extends Flowable{
|
|||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get(POTATO, 0, 1));
|
//Server::getInstance()->api->entity->drop($this, Item::get(POTATO, 0, 1));
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ class Potato extends Flowable{
|
|||||||
if(mt_rand(0, 2) == 1){
|
if(mt_rand(0, 2) == 1){
|
||||||
if($this->meta < 0x07){
|
if($this->meta < 0x07){
|
||||||
++$this->meta;
|
++$this->meta;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_RANDOM;
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class PumpkinStem extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === self::FARMLAND){
|
if($down->getID() === self::FARMLAND){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ class PumpkinStem extends Flowable{
|
|||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
|
//Server::getInstance()->api->entity->drop($this, Item::get(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ class PumpkinStem extends Flowable{
|
|||||||
if(mt_rand(0, 2) == 1){
|
if(mt_rand(0, 2) == 1){
|
||||||
if($this->meta < 0x07){
|
if($this->meta < 0x07){
|
||||||
++$this->meta;
|
++$this->meta;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_RANDOM;
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
}else{
|
}else{
|
||||||
@ -69,7 +69,7 @@ class PumpkinStem extends Flowable{
|
|||||||
$side = $this->getSide(mt_rand(2, 5));
|
$side = $this->getSide(mt_rand(2, 5));
|
||||||
$d = $side->getSide(0);
|
$d = $side->getSide(0);
|
||||||
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
|
if($side->getID() === self::AIR and ($d->getID() === self::FARMLAND or $d->getID() === self::GRASS or $d->getID() === self::DIRT)){
|
||||||
$this->level->setBlock($side, new Pumpkin(), true, false, true);
|
$this->getLevel()->setBlock($side, new Pumpkin(), true, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ class PumpkinStem extends Flowable{
|
|||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
$this->meta = 0x07;
|
$this->meta = 0x07;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
if(($player->gamemode & 0x01) === 0){
|
if(($player->gamemode & 0x01) === 0){
|
||||||
$item->count--;
|
$item->count--;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class RedMushroom extends Flowable{
|
|||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
$this->level->setBlock($this, new Air(), false);
|
$this->getLevel()->setBlock($this, new Air(), false);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ class RedMushroom extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->isTransparent === false){
|
if($down->isTransparent === false){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class RedstoneOre extends Solid{
|
|||||||
|
|
||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === Level::BLOCK_UPDATE_NORMAL or $type === Level::BLOCK_UPDATE_TOUCH){
|
if($type === Level::BLOCK_UPDATE_NORMAL or $type === Level::BLOCK_UPDATE_TOUCH){
|
||||||
$this->level->setBlock($this, Block::get(Item::GLOWING_REDSTONE_ORE, $this->meta), false, false, true);
|
$this->getLevel()->setBlock($this, Block::get(Item::GLOWING_REDSTONE_ORE, $this->meta), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_WEAK;
|
return Level::BLOCK_UPDATE_WEAK;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ class Sapling extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === self::GRASS or $down->getID() === self::DIRT or $down->getID() === self::FARMLAND){
|
if($down->getID() === self::GRASS or $down->getID() === self::DIRT or $down->getID() === self::FARMLAND){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ class Sapling extends Flowable{
|
|||||||
|
|
||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
Tree::growTree($this->level, $this, new Random(mt_rand()), $this->meta & 0x03);
|
Tree::growTree($this->getLevel(), $this, new Random(mt_rand()), $this->meta & 0x03);
|
||||||
if(($player->gamemode & 0x01) === 0){
|
if(($player->gamemode & 0x01) === 0){
|
||||||
$item->count--;
|
$item->count--;
|
||||||
}
|
}
|
||||||
@ -76,17 +76,17 @@ class Sapling extends Flowable{
|
|||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id));
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
}elseif($type === Level::BLOCK_UPDATE_RANDOM){ //Growth
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){ //Growth
|
||||||
if(mt_rand(1, 7) === 1){
|
if(mt_rand(1, 7) === 1){
|
||||||
if(($this->meta & 0x08) === 0x08){
|
if(($this->meta & 0x08) === 0x08){
|
||||||
Tree::growTree($this->level, $this, new Random(mt_rand()), $this->meta & 0x03);
|
Tree::growTree($this->getLevel(), $this, new Random(mt_rand()), $this->meta & 0x03);
|
||||||
}else{
|
}else{
|
||||||
$this->meta |= 0x08;
|
$this->meta |= 0x08;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_RANDOM;
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
}
|
}
|
||||||
|
@ -43,12 +43,12 @@ class SignPost extends Transparent{
|
|||||||
);
|
);
|
||||||
if(!isset($faces[$face])){
|
if(!isset($faces[$face])){
|
||||||
$this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0F;
|
$this->meta = floor((($player->yaw + 180) * 16 / 360) + 0.5) & 0x0F;
|
||||||
$this->level->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($block, Block::get(Item::SIGN_POST, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
$this->meta = $faces[$face];
|
$this->meta = $faces[$face];
|
||||||
$this->level->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($block, Block::get(Item::WALL_SIGN, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ class SignPost extends Transparent{
|
|||||||
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get(SIGN, 0, 1));
|
//Server::getInstance()->api->entity->drop($this, Item::get(SIGN, 0, 1));
|
||||||
$this->level->setBlock($this, new Air(), true, true, true);
|
$this->getLevel()->setBlock($this, new Air(), true, true, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ class SignPost extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onBreak(Item $item){
|
public function onBreak(Item $item){
|
||||||
$this->level->setBlock($this, new Air(), true, true, true);
|
$this->getLevel()->setBlock($this, new Air(), true, true, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,11 @@ class Slab extends Transparent{
|
|||||||
$this->meta &= 0x07;
|
$this->meta &= 0x07;
|
||||||
if($face === 0){
|
if($face === 0){
|
||||||
if($target->getID() === self::SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
if($target->getID() === self::SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
$this->level->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
}elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
$this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
@ -62,18 +62,18 @@ class Slab extends Transparent{
|
|||||||
}
|
}
|
||||||
}elseif($face === 1){
|
}elseif($face === 1){
|
||||||
if($target->getID() === self::SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
if($target->getID() === self::SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
$this->level->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
}elseif($block->getID() === self::SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
$this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}elseif(!($player instanceof Player) or !$player->inBlock($block)){
|
}elseif(!($player instanceof Player) or !$player->inBlock($block)){
|
||||||
if($block->getID() === self::SLAB){
|
if($block->getID() === self::SLAB){
|
||||||
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
$this->level->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ class Slab extends Transparent{
|
|||||||
if($block->getID() === self::SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
|
if($block->getID() === self::SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ class SnowLayer extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down instanceof Solid){
|
if($down instanceof Solid){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ class SnowLayer extends Flowable{
|
|||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
if($this->getSide(0)->getID() === self::AIR){ //Replace with common break method
|
||||||
$this->level->setBlock($this, new Air(), true, false, true);
|
$this->getLevel()->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class Stair extends Transparent{
|
|||||||
if(($fy > 0.5 and $face !== 1) or $face === 0){
|
if(($fy > 0.5 and $face !== 1) or $face === 0){
|
||||||
$this->meta |= 0x04; //Upside-down stairs
|
$this->meta |= 0x04; //Upside-down stairs
|
||||||
}
|
}
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -42,14 +42,14 @@ class Sugarcane extends Flowable{
|
|||||||
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){
|
if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){
|
||||||
for($y = 1; $y < 3; ++$y){
|
for($y = 1; $y < 3; ++$y){
|
||||||
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||||
if($b->getID() === self::AIR){
|
if($b->getID() === self::AIR){
|
||||||
$this->level->setBlock($b, new Sugarcane(), true, false, true);
|
$this->getLevel()->setBlock($b, new Sugarcane(), true, false, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->meta = 0;
|
$this->meta = 0;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
}
|
}
|
||||||
if(($player->gamemode & 0x01) === 0){
|
if(($player->gamemode & 0x01) === 0){
|
||||||
$item->count--;
|
$item->count--;
|
||||||
@ -67,7 +67,7 @@ class Sugarcane extends Flowable{
|
|||||||
if($down->isTransparent === true and $down->getID() !== self::SUGARCANE_BLOCK){ //Replace with common break method
|
if($down->isTransparent === true and $down->getID() !== self::SUGARCANE_BLOCK){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get(SUGARCANE));
|
//Server::getInstance()->api->entity->drop($this, Item::get(SUGARCANE));
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -75,17 +75,17 @@ class Sugarcane extends Flowable{
|
|||||||
if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){
|
if($this->getSide(0)->getID() !== self::SUGARCANE_BLOCK){
|
||||||
if($this->meta === 0x0F){
|
if($this->meta === 0x0F){
|
||||||
for($y = 1; $y < 3; ++$y){
|
for($y = 1; $y < 3; ++$y){
|
||||||
$b = $this->level->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||||
if($b->getID() === self::AIR){
|
if($b->getID() === self::AIR){
|
||||||
$this->level->setBlock($b, new Sugarcane(), true, false, true);
|
$this->getLevel()->setBlock($b, new Sugarcane(), true, false, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->meta = 0;
|
$this->meta = 0;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
}else{
|
}else{
|
||||||
++$this->meta;
|
++$this->meta;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_RANDOM;
|
return Level::BLOCK_UPDATE_RANDOM;
|
||||||
@ -98,7 +98,7 @@ class Sugarcane extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === self::SUGARCANE_BLOCK){
|
if($down->getID() === self::SUGARCANE_BLOCK){
|
||||||
$this->level->setBlock($block, new Sugarcane(), true, false, true);
|
$this->getLevel()->setBlock($block, new Sugarcane(), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($down->getID() === self::GRASS or $down->getID() === self::DIRT or $down->getID() === self::SAND){
|
}elseif($down->getID() === self::GRASS or $down->getID() === self::DIRT or $down->getID() === self::SAND){
|
||||||
@ -107,7 +107,7 @@ class Sugarcane extends Flowable{
|
|||||||
$block2 = $down->getSide(4);
|
$block2 = $down->getSide(4);
|
||||||
$block3 = $down->getSide(5);
|
$block3 = $down->getSide(5);
|
||||||
if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){
|
if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){
|
||||||
$this->level->setBlock($block, new Sugarcane(), true, false, true);
|
$this->getLevel()->setBlock($block, new Sugarcane(), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class TNT extends Solid{
|
|||||||
"power" => 4,
|
"power" => 4,
|
||||||
"fuse" => 20 * 4, //4 seconds
|
"fuse" => 20 * 4, //4 seconds
|
||||||
);
|
);
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
//TODO
|
//TODO
|
||||||
//$e = Server::getInstance()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
|
//$e = Server::getInstance()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
|
||||||
//$e->spawnToAll();
|
//$e->spawnToAll();
|
||||||
|
@ -40,7 +40,7 @@ class TallGrass extends Flowable{
|
|||||||
public function onUpdate($type){
|
public function onUpdate($type){
|
||||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ class Torch extends Flowable{
|
|||||||
if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === self::FENCE)){ //Replace with common break method
|
if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === self::FENCE)){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get($this->id, 0, 1));
|
//Server::getInstance()->api->entity->drop($this, Item::get($this->id, 0, 1));
|
||||||
$this->level->setBlock($this, new Air(), true, false, true);
|
$this->getLevel()->setBlock($this, new Air(), true, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -66,12 +66,12 @@ class Torch extends Flowable{
|
|||||||
5 => 1,
|
5 => 1,
|
||||||
);
|
);
|
||||||
$this->meta = $faces[$face];
|
$this->meta = $faces[$face];
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($this->getSide(0)->isTransparent === false or $this->getSide(0)->getID() === self::FENCE){
|
}elseif($this->getSide(0)->isTransparent === false or $this->getSide(0)->getID() === self::FENCE){
|
||||||
$this->meta = 0;
|
$this->meta = 0;
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ class Trapdoor extends Transparent{
|
|||||||
if($fy > 0.5){
|
if($fy > 0.5){
|
||||||
$this->meta |= 0x08;
|
$this->meta |= 0x08;
|
||||||
}
|
}
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ class Trapdoor extends Transparent{
|
|||||||
|
|
||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
$this->meta ^= 0x04;
|
$this->meta ^= 0x04;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class Water extends Liquid{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
$ret = $this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
Server::getInstance()->api->block->scheduleBlockUpdate(clone $this, 10, Level::BLOCK_UPDATE_NORMAL);
|
Server::getInstance()->api->block->scheduleBlockUpdate(clone $this, 10, Level::BLOCK_UPDATE_NORMAL);
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
@ -64,9 +64,9 @@ class Water extends Liquid{
|
|||||||
if($b instanceof Lava){
|
if($b instanceof Lava){
|
||||||
$level = $b->meta & 0x07;
|
$level = $b->meta & 0x07;
|
||||||
if($level == 0x00){
|
if($level == 0x00){
|
||||||
$this->level->setBlock($b, new Obsidian(), false, false, true);
|
$this->getLevel()->setBlock($b, new Obsidian(), false, false, true);
|
||||||
}else{
|
}else{
|
||||||
$this->level->setBlock($b, new Cobblestone(), false, false, true);
|
$this->getLevel()->setBlock($b, new Cobblestone(), false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -109,17 +109,17 @@ class Water extends Liquid{
|
|||||||
if($from !== null || $level == 0x00){
|
if($from !== null || $level == 0x00){
|
||||||
if($level !== 0x07){
|
if($level !== 0x07){
|
||||||
if($down instanceof Air || $down instanceof Water){
|
if($down instanceof Air || $down instanceof Water){
|
||||||
$this->level->setBlock($down, new Water(0x01), false, false, true);
|
$this->getLevel()->setBlock($down, new Water(0x01), false, false, true);
|
||||||
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($down, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($down, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
||||||
}else{
|
}else{
|
||||||
for($side = 2; $side <= 5; ++$side){
|
for($side = 2; $side <= 5; ++$side){
|
||||||
$b = $this->getSide($side);
|
$b = $this->getSide($side);
|
||||||
if($b instanceof Water){
|
if($b instanceof Water){
|
||||||
if($this->getSourceCount() >= 2 && $level != 0x00){
|
if($this->getSourceCount() >= 2 && $level != 0x00){
|
||||||
$this->level->setBlock($this, new Water(0), false, false, true);
|
$this->getLevel()->setBlock($this, new Water(0), false, false, true);
|
||||||
}
|
}
|
||||||
}elseif($b->isFlowable === true){
|
}elseif($b->isFlowable === true){
|
||||||
$this->level->setBlock($b, new Water($level + 1), false, false, true);
|
$this->getLevel()->setBlock($b, new Water($level + 1), false, false, true);
|
||||||
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ class Water extends Liquid{
|
|||||||
$ssb = $sb->getSide($s);
|
$ssb = $sb->getSide($s);
|
||||||
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
||||||
}
|
}
|
||||||
$this->level->setBlock($sb, new Air(), false, false, true);
|
$this->getLevel()->setBlock($sb, new Air(), false, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$b = $this->getSide(0)->getSide($side);
|
$b = $this->getSide(0)->getSide($side);
|
||||||
@ -147,12 +147,12 @@ class Water extends Liquid{
|
|||||||
$ssb = $sb->getSide($s);
|
$ssb = $sb->getSide($s);
|
||||||
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
||||||
}
|
}
|
||||||
$this->level->setBlock($b, new Air(), false, false, true);
|
$this->getLevel()->setBlock($b, new Air(), false, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
|
||||||
}
|
}
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -35,7 +35,7 @@ class Wheat extends Flowable{
|
|||||||
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){
|
||||||
$down = $this->getSide(0);
|
$down = $this->getSide(0);
|
||||||
if($down->getID() === self::FARMLAND){
|
if($down->getID() === self::FARMLAND){
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ class Wheat extends Flowable{
|
|||||||
public function onActivate(Item $item, Player $player = null){
|
public function onActivate(Item $item, Player $player = null){
|
||||||
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
if($item->getID() === Item::DYE and $item->getMetadata() === 0x0F){ //Bonemeal
|
||||||
$this->meta = 0x07;
|
$this->meta = 0x07;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
if(($player->gamemode & 0x01) === 0){
|
if(($player->gamemode & 0x01) === 0){
|
||||||
$item->count--;
|
$item->count--;
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ class Wheat extends Flowable{
|
|||||||
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
|
||||||
//TODO
|
//TODO
|
||||||
//Server::getInstance()->api->entity->drop($this, Item::get(WHEAT_SEEDS, 0, 1));
|
//Server::getInstance()->api->entity->drop($this, Item::get(WHEAT_SEEDS, 0, 1));
|
||||||
$this->level->setBlock($this, new Air(), false, false, true);
|
$this->getLevel()->setBlock($this, new Air(), false, false, true);
|
||||||
|
|
||||||
return Level::BLOCK_UPDATE_NORMAL;
|
return Level::BLOCK_UPDATE_NORMAL;
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ class Wheat extends Flowable{
|
|||||||
if(mt_rand(0, 2) == 1){
|
if(mt_rand(0, 2) == 1){
|
||||||
if($this->meta < 0x07){
|
if($this->meta < 0x07){
|
||||||
++$this->meta;
|
++$this->meta;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->getLevel()->setBlock($this, $this, true, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ class Wood extends Solid{
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->meta = ($this->meta & 0x03) | $faces[$face];
|
$this->meta = ($this->meta & 0x03) | $faces[$face];
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -46,11 +46,11 @@ class WoodSlab extends Transparent{
|
|||||||
$this->meta &= 0x07;
|
$this->meta &= 0x07;
|
||||||
if($face === 0){
|
if($face === 0){
|
||||||
if($target->getID() === self::WOOD_SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
if($target->getID() === self::WOOD_SLAB and ($target->getMetadata() & 0x08) === 0x08 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
$this->level->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($block->getID() === self::WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
}elseif($block->getID() === self::WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
$this->level->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
@ -58,18 +58,18 @@ class WoodSlab extends Transparent{
|
|||||||
}
|
}
|
||||||
}elseif($face === 1){
|
}elseif($face === 1){
|
||||||
if($target->getID() === self::WOOD_SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
if($target->getID() === self::WOOD_SLAB and ($target->getMetadata() & 0x08) === 0 and ($target->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
$this->level->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($target, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($block->getID() === self::WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
}elseif($block->getID() === self::WOOD_SLAB and ($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
$this->level->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}elseif(!($player instanceof Player) or !$player->inBlock($block)){
|
}elseif(!($player instanceof Player) or !$player->inBlock($block)){
|
||||||
if($block->getID() === self::WOOD_SLAB){
|
if($block->getID() === self::WOOD_SLAB){
|
||||||
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
if(($block->getMetadata() & 0x07) === ($this->meta & 0x07)){
|
||||||
$this->level->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
|
$this->getLevel()->setBlock($block, Block::get(Item::DOUBLE_WOOD_SLAB, $this->meta), true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ class WoodSlab extends Transparent{
|
|||||||
if($block->getID() === self::WOOD_SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
|
if($block->getID() === self::WOOD_SLAB and ($target->getMetadata() & 0x07) !== ($this->meta & 0x07)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->level->setBlock($block, $this, true, false, true);
|
$this->getLevel()->setBlock($block, $this, true, false, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
$this->justCreated = true;
|
$this->justCreated = true;
|
||||||
$this->closed = false;
|
$this->closed = false;
|
||||||
$this->namedtag = $nbt;
|
$this->namedtag = $nbt;
|
||||||
$this->level = $level;
|
$this->setLevel($level, true); //Create a hard reference
|
||||||
$this->server = Server::getInstance();
|
$this->server = Server::getInstance();
|
||||||
|
|
||||||
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
|
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
|
||||||
@ -148,8 +148,8 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
$index = LevelFormat::getIndex($this->x >> 4, $this->z >> 4);
|
$index = LevelFormat::getIndex($this->x >> 4, $this->z >> 4);
|
||||||
$this->chunkIndex = $index;
|
$this->chunkIndex = $index;
|
||||||
Entity::$list[$this->id] = $this;
|
Entity::$list[$this->id] = $this;
|
||||||
$this->level->entities[$this->id] = $this;
|
$this->getLevel()->entities[$this->id] = $this;
|
||||||
$this->level->chunkEntities[$this->chunkIndex][$this->id] = $this;
|
$this->getLevel()->chunkEntities[$this->chunkIndex][$this->id] = $this;
|
||||||
$this->lastUpdate = microtime(true);
|
$this->lastUpdate = microtime(true);
|
||||||
$this->initEntity();
|
$this->initEntity();
|
||||||
Server::getInstance()->getPluginManager()->callEvent(new EntitySpawnEvent($this));
|
Server::getInstance()->getPluginManager()->callEvent(new EntitySpawnEvent($this));
|
||||||
@ -399,13 +399,13 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function switchLevel(Level $targetLevel){
|
protected function switchLevel(Level $targetLevel){
|
||||||
if($this->level instanceof Level){
|
if($this->isValid()){
|
||||||
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityLevelChangeEvent($this, $this->level, $targetLevel));
|
Server::getInstance()->getPluginManager()->callEvent($ev = new EntityLevelChangeEvent($this, $this->getLevel(), $targetLevel));
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
unset($this->level->entities[$this->id]);
|
unset($this->getLevel()->entities[$this->id]);
|
||||||
unset($this->level->chunkEntities[$this->chunkIndex][$this->id]);
|
unset($this->getLevel()->chunkEntities[$this->chunkIndex][$this->id]);
|
||||||
$this->despawnFromAll();
|
$this->despawnFromAll();
|
||||||
if($this instanceof Player){
|
if($this instanceof Player){
|
||||||
foreach($this->chunksLoaded as $index => $Yndex){
|
foreach($this->chunksLoaded as $index => $Yndex){
|
||||||
@ -413,21 +413,21 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
$X = null;
|
$X = null;
|
||||||
$Z = null;
|
$Z = null;
|
||||||
LevelFormat::getXZ($index, $X, $Z);
|
LevelFormat::getXZ($index, $X, $Z);
|
||||||
foreach($this->level->getChunkEntities($X, $Z) as $entity){
|
foreach($this->getLevel()->getChunkEntities($X, $Z) as $entity){
|
||||||
$entity->despawnFrom($this);
|
$entity->despawnFrom($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->level->freeAllChunks($this);
|
$this->getLevel()->freeAllChunks($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->level = $targetLevel;
|
$this->setLevel($targetLevel, true); //Hard reference
|
||||||
$this->level->entities[$this->id] = $this;
|
$this->getLevel()->entities[$this->id] = $this; //Oops, TODO!!
|
||||||
if($this instanceof Player){
|
if($this instanceof Player){
|
||||||
$this->chunksLoaded = array();
|
$this->chunksLoaded = array();
|
||||||
$pk = new SetTimePacket();
|
$pk = new SetTimePacket();
|
||||||
$pk->time = $this->level->getTime();
|
$pk->time = $this->getLevel()->getTime();
|
||||||
$pk->started = $this->level->stopTime == false;
|
$pk->started = $this->getLevel()->stopTime == false;
|
||||||
$this->dataPacket($pk);
|
$this->dataPacket($pk);
|
||||||
}
|
}
|
||||||
$this->spawnToAll();
|
$this->spawnToAll();
|
||||||
@ -466,8 +466,8 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setPosition(Vector3 $pos){
|
public function setPosition(Vector3 $pos){
|
||||||
if($pos instanceof Position and $pos->level instanceof Level and $pos->level !== $this->level){
|
if($pos instanceof Position and $pos->getLevel() instanceof Level and $pos->getLevel() !== $this->getLevel()){
|
||||||
if($this->switchLevel($pos->level) === false){
|
if($this->switchLevel($pos->getLevel()) === false){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -482,12 +482,12 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
$radius = $this->width / 2;
|
$radius = $this->width / 2;
|
||||||
if(($index = LevelFormat::getIndex($this->x >> 4, $this->z >> 4)) !== $this->chunkIndex){
|
if(($index = LevelFormat::getIndex($this->x >> 4, $this->z >> 4)) !== $this->chunkIndex){
|
||||||
if($this->chunkIndex !== false){
|
if($this->chunkIndex !== false){
|
||||||
unset($this->level->chunkEntities[$this->chunkIndex][$this->id]);
|
unset($this->getLevel()->chunkEntities[$this->chunkIndex][$this->id]);
|
||||||
}
|
}
|
||||||
$this->chunkIndex = $index;
|
$this->chunkIndex = $index;
|
||||||
$this->level->loadChunk($this->x >> 4, $this->z >> 4);
|
$this->getLevel()->loadChunk($this->x >> 4, $this->z >> 4);
|
||||||
|
|
||||||
$newChunk = $this->level->getUsingChunk($this->x >> 4, $this->z >> 4);
|
$newChunk = $this->getLevel()->getUsingChunk($this->x >> 4, $this->z >> 4);
|
||||||
foreach($this->hasSpawned as $player){
|
foreach($this->hasSpawned as $player){
|
||||||
if(!isset($newChunk[$player->CID])){
|
if(!isset($newChunk[$player->CID])){
|
||||||
$this->despawnFrom($player);
|
$this->despawnFrom($player);
|
||||||
@ -499,7 +499,7 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
$this->spawnTo($player);
|
$this->spawnTo($player);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->chunkEntities[$this->chunkIndex][$this->id] = $this;
|
$this->getLevel()->chunkEntities[$this->chunkIndex][$this->id] = $this;
|
||||||
}
|
}
|
||||||
$this->boundingBox->setBounds($pos->x - $radius, $pos->y, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height, $pos->z + $radius);
|
$this->boundingBox->setBounds($pos->x - $radius, $pos->y, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height, $pos->z + $radius);
|
||||||
|
|
||||||
@ -531,10 +531,6 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
$this->dead = true;
|
$this->dead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLevel(){
|
|
||||||
return $this->level;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function teleport(Vector3 $pos, $yaw = false, $pitch = false){
|
public function teleport(Vector3 $pos, $yaw = false, $pitch = false){
|
||||||
$this->setMotion(new Vector3(0, 0, 0));
|
$this->setMotion(new Vector3(0, 0, 0));
|
||||||
if($this->setPositionAndRotation($pos, $yaw === false ? $this->yaw : $yaw, $pitch === false ? $this->pitch : $pitch) !== false){
|
if($this->setPositionAndRotation($pos, $yaw === false ? $this->yaw : $yaw, $pitch === false ? $this->pitch : $pitch) !== false){
|
||||||
@ -567,7 +563,7 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function spawnToAll(){
|
public function spawnToAll(){
|
||||||
foreach($this->level->getPlayers() as $player){
|
foreach($this->getLevel()->getPlayers() as $player){
|
||||||
if(isset($player->id) and $player->spawned === true){
|
if(isset($player->id) and $player->spawned === true){
|
||||||
$this->spawnTo($player);
|
$this->spawnTo($player);
|
||||||
}
|
}
|
||||||
@ -584,8 +580,8 @@ abstract class Entity extends Position implements Metadatable{
|
|||||||
if($this->closed === false){
|
if($this->closed === false){
|
||||||
$this->closed = true;
|
$this->closed = true;
|
||||||
unset(Entity::$needUpdate[$this->id]);
|
unset(Entity::$needUpdate[$this->id]);
|
||||||
unset($this->level->entities[$this->id]);
|
unset($this->getLevel()->entities[$this->id]);
|
||||||
unset($this->level->chunkEntities[$this->chunkIndex][$this->id]);
|
unset($this->getLevel()->chunkEntities[$this->chunkIndex][$this->id]);
|
||||||
unset(Entity::$list[$this->id]);
|
unset(Entity::$list[$this->id]);
|
||||||
$this->despawnFromAll();
|
$this->despawnFromAll();
|
||||||
Server::getInstance()->getPluginManager()->callEvent(new EntityDespawnEvent($this));
|
Server::getInstance()->getPluginManager()->callEvent(new EntityDespawnEvent($this));
|
||||||
|
@ -25,7 +25,7 @@ use pocketmine\math\Vector3 as Vector3;
|
|||||||
|
|
||||||
class Position extends Vector3{
|
class Position extends Vector3{
|
||||||
|
|
||||||
/** @var Level */
|
/** @var \WeakRef<Level> */
|
||||||
public $level = null;
|
public $level = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,20 +33,63 @@ class Position extends Vector3{
|
|||||||
* @param int $y
|
* @param int $y
|
||||||
* @param int $z
|
* @param int $z
|
||||||
* @param Level $level
|
* @param Level $level
|
||||||
|
* @param bool $strong
|
||||||
*/
|
*/
|
||||||
public function __construct($x = 0, $y = 0, $z = 0, Level $level){
|
public function __construct($x = 0, $y = 0, $z = 0, Level $level, $strong = false){
|
||||||
$this->x = $x;
|
$this->x = $x;
|
||||||
$this->y = $y;
|
$this->y = $y;
|
||||||
$this->z = $z;
|
$this->z = $z;
|
||||||
$this->level = $level;
|
$this->level = new \WeakRef($level);
|
||||||
|
if($strong === true){
|
||||||
|
$this->level->acquire();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromObject(Vector3 $pos, Level $level){
|
public static function fromObject(Vector3 $pos, Level $level, $strong = false){
|
||||||
return new Position($pos->x, $pos->y, $pos->z, $level);
|
return new Position($pos->x, $pos->y, $pos->z, $level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Level
|
||||||
|
*/
|
||||||
public function getLevel(){
|
public function getLevel(){
|
||||||
return $this->level;
|
return $this->level->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLevel(Level $level, $strong = false){
|
||||||
|
$this->level = new \WeakRef($level);
|
||||||
|
if($strong === true){
|
||||||
|
$this->level->acquire();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this object has a valid reference to a Level
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isValid(){
|
||||||
|
return isset($this->level) and $this->level->valid();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the level reference as strong so it won't be collected
|
||||||
|
* by the garbage collector.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function setStrong(){
|
||||||
|
return $this->level->acquire();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the level reference as weak so it won't have effect against
|
||||||
|
* the garbage collector decision.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function setWeak(){
|
||||||
|
return $this->level->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,9 +99,14 @@ class Position extends Vector3{
|
|||||||
* @param int $step
|
* @param int $step
|
||||||
*
|
*
|
||||||
* @return Position
|
* @return Position
|
||||||
|
*
|
||||||
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function getSide($side, $step = 1){
|
public function getSide($side, $step = 1){
|
||||||
return Position::fromObject(parent::getSide($side, $step), $this->level);
|
if(!$this->isValid()){
|
||||||
|
throw new \RuntimeException("Undefined Level reference");
|
||||||
|
}
|
||||||
|
return Position::fromObject(parent::getSide($side, $step), $this->getLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,7 +117,7 @@ class Position extends Vector3{
|
|||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function distance(Vector3 $pos){
|
public function distance(Vector3 $pos){
|
||||||
if(($pos instanceof Position) and $pos->level !== $this->level){
|
if(($pos instanceof Position) and $pos->getLevel() !== $this->getLevel()){
|
||||||
return PHP_INT_MAX;
|
return PHP_INT_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +125,7 @@ class Position extends Vector3{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(){
|
public function __toString(){
|
||||||
return "Position(level=" . $this->level->getName() . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
|
return "Position(level=" . ($this->isValid() ? $this->getLevel()->getID() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -60,6 +60,40 @@ interface Chunk{
|
|||||||
*/
|
*/
|
||||||
public function setBlock($x, $y, $z, $blockId = null, $meta = null);
|
public function setBlock($x, $y, $z, $blockId = null, $meta = null);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x 0-15
|
||||||
|
* @param int $y 0-127
|
||||||
|
* @param int $z 0-15
|
||||||
|
*
|
||||||
|
* @return int 0-255
|
||||||
|
*/
|
||||||
|
public function getBlockId($x, $y, $z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x 0-15
|
||||||
|
* @param int $y 0-127
|
||||||
|
* @param int $z 0-15
|
||||||
|
* @param int $id 0-255
|
||||||
|
*/
|
||||||
|
public function setBlockId($x, $y, $z, $id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x 0-15
|
||||||
|
* @param int $y 0-127
|
||||||
|
* @param int $z 0-15
|
||||||
|
*
|
||||||
|
* @return int 0-15
|
||||||
|
*/
|
||||||
|
public function getBlockData($x, $y, $z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $x 0-15
|
||||||
|
* @param int $y 0-127
|
||||||
|
* @param int $z 0-15
|
||||||
|
* @param int $data 0-15
|
||||||
|
*/
|
||||||
|
public function setBlockData($x, $y, $z, $data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $x 0-15
|
* @param int $x 0-15
|
||||||
* @param int $y 0-127
|
* @param int $y 0-127
|
||||||
|
@ -20,6 +20,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
namespace pocketmine\level\format;
|
namespace pocketmine\level\format;
|
||||||
|
use pocketmine\Server;
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All Level formats must implement this interface
|
* All Level formats must implement this interface
|
||||||
@ -27,13 +29,14 @@ namespace pocketmine\level\format;
|
|||||||
interface LevelFormat{
|
interface LevelFormat{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param Server $server
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param string $levelName
|
|
||||||
*/
|
*/
|
||||||
public function __construct($path, $levelName);
|
public function __construct(Server $server, $path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells if the path is a valid level
|
* Tells if the path is a valid level.
|
||||||
|
* This must tell if the current format supports opening the files in the directory
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
*
|
*
|
||||||
@ -42,6 +45,9 @@ interface LevelFormat{
|
|||||||
public static function isValid($path);
|
public static function isValid($path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the Chunk object
|
||||||
|
* This method must be implemented by all the level formats.
|
||||||
|
*
|
||||||
* @param int $X absolute Chunk X value
|
* @param int $X absolute Chunk X value
|
||||||
* @param int $Z absolute Chunk Z value
|
* @param int $Z absolute Chunk Z value
|
||||||
* @param bool $create Whether to generate the chunk if it does not exist
|
* @param bool $create Whether to generate the chunk if it does not exist
|
||||||
@ -61,6 +67,13 @@ interface LevelFormat{
|
|||||||
|
|
||||||
public function unloadChunk($X, $Z);
|
public function unloadChunk($X, $Z);
|
||||||
|
|
||||||
|
public function isChunkLoaded($X, $Z);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Vector3
|
||||||
|
*/
|
||||||
|
public function getSpawn();
|
||||||
|
|
||||||
public function getName();
|
public function getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,6 +56,20 @@ class Chunk extends BaseChunk{
|
|||||||
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
|
$this->nbt->TileTicks->setTagType(NBT::TAG_Compound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->nbt->Sections instanceof Enum){
|
||||||
|
$this->nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||||
|
}else{
|
||||||
|
$this->nbt->Sections = new Enum("Sections", array());
|
||||||
|
$this->nbt->Sections->setTagType(NBT::TAG_Compound);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sections = array();
|
||||||
|
foreach($this->nbt->Sections as $section){
|
||||||
|
if($section instanceof Compound){
|
||||||
|
$sections[(int) $section["Y"]] = new ChunkSection($section);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $sections);
|
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $sections);
|
||||||
}
|
}
|
||||||
}
|
}
|
153
src/pocketmine/level/format/anvil/ChunkSection.php
Normal file
153
src/pocketmine/level/format/anvil/ChunkSection.php
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
<?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/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace pocketmine\level\format\anvil;
|
||||||
|
|
||||||
|
use pocketmine\nbt\tag\Compound;
|
||||||
|
|
||||||
|
class ChunkSection implements \pocketmine\level\format\ChunkSection{
|
||||||
|
|
||||||
|
private $y;
|
||||||
|
private $blocks;
|
||||||
|
private $data;
|
||||||
|
private $blockLight;
|
||||||
|
private $skyLight;
|
||||||
|
|
||||||
|
public function __construct(Compound $nbt){
|
||||||
|
$this->y = (int) $nbt["Y"];
|
||||||
|
$this->blocks = (string) $nbt["Blocks"];
|
||||||
|
$this->data = (string) $nbt["Data"];
|
||||||
|
$this->blockLight = (string) $nbt["BlockLight"];
|
||||||
|
$this->skyLight = (string) $nbt["SkyLight"];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockId($x, $y, $z){
|
||||||
|
return ord($this->blocks{($y << 8) + ($z << 4) + $x});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockId($x, $y, $z, $id){
|
||||||
|
$this->blocks{($y << 8) + ($z << 4) + $x} = chr($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockData($x, $y, $z){
|
||||||
|
$m = ord($this->data{($y << 7) + ($z << 3) + ($x >> 1)});
|
||||||
|
if(($y & 1) === 0){
|
||||||
|
return $m & 0x0F;
|
||||||
|
}else{
|
||||||
|
return $m >> 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockData($x, $y, $z, $data){
|
||||||
|
$i = ($y << 7) + ($z << 3) + ($x >> 1);
|
||||||
|
$old_m = ord($this->data{$i});
|
||||||
|
if(($y & 1) === 0){
|
||||||
|
$this->data{$i} = chr(($old_m & 0xf0) | ($data & 0x0f));
|
||||||
|
}else{
|
||||||
|
$this->data{$i} = chr((($data & 0x0f) << 4) | ($old_m & 0x0f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlock($x, $y, $z, &$blockId, &$meta = null){
|
||||||
|
$i = ($y << 8) + ($z << 4) + $x;
|
||||||
|
$blockId = ord($this->blocks{$i});
|
||||||
|
$m = ord($this->data{$i >> 1});
|
||||||
|
if(($y & 1) === 0){
|
||||||
|
$meta = $m & 0x0F;
|
||||||
|
}else{
|
||||||
|
$meta = $m >> 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlock($x, $y, $z, $blockId = null, $meta = null){
|
||||||
|
$i = ($y << 8) + ($z << 4) + $x;
|
||||||
|
if($blockId !== null){
|
||||||
|
$this->blocks{$i} = chr($blockId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($meta !== null){
|
||||||
|
$i >>= 1;
|
||||||
|
$old_m = ord($this->data{$i});
|
||||||
|
if(($y & 1) === 0){
|
||||||
|
$this->data{$i} = chr(($old_m & 0xf0) | ($meta & 0x0f));
|
||||||
|
}else{
|
||||||
|
$this->data{$i} = chr((($meta & 0x0f) << 4) | ($old_m & 0x0f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockSkyLight($x, $y, $z){
|
||||||
|
$sl = ord($this->skyLight{($y << 7) + ($z << 3) + ($x >> 1)});
|
||||||
|
if(($y & 1) === 0){
|
||||||
|
return $sl & 0x0F;
|
||||||
|
}else{
|
||||||
|
return $sl >> 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockSkyLight($x, $y, $z, $level){
|
||||||
|
$i = ($y << 7) + ($z << 3) + ($x >> 1);
|
||||||
|
$old_sl = ord($this->skyLight{$i});
|
||||||
|
if(($y & 1) === 0){
|
||||||
|
$this->skyLight{$i} = chr(($old_sl & 0xf0) | ($level & 0x0f));
|
||||||
|
}else{
|
||||||
|
$this->skyLight{$i} = chr((($level & 0x0f) << 4) | ($old_sl & 0x0f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockLight($x, $y, $z){
|
||||||
|
$l = ord($this->blockLight{($y << 7) + ($z << 3) + ($x >> 1)});
|
||||||
|
if(($y & 1) === 0){
|
||||||
|
return $l & 0x0F;
|
||||||
|
}else{
|
||||||
|
return $l >> 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockLight($x, $y, $z, $level){
|
||||||
|
$i = ($y << 7) + ($z << 3) + ($x >> 1);
|
||||||
|
$old_l = ord($this->blockLight{$i});
|
||||||
|
if(($y & 1) === 0){
|
||||||
|
$this->blockLight{$i} = chr(($old_l & 0xf0) | ($level & 0x0f));
|
||||||
|
}else{
|
||||||
|
$this->blockLight{$i} = chr((($level & 0x0f) << 4) | ($old_l & 0x0f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockIdColumn($x, $z){
|
||||||
|
$i = ($z << 4) + $x;
|
||||||
|
$column = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||||
|
for($y = 15; $y >= 0; --$y){
|
||||||
|
$column{15 - $y} = $this->blocks{($y << 8) + $i};
|
||||||
|
}
|
||||||
|
return $column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockDataColumn($x, $z){
|
||||||
|
$i = ($z << 3) + ($x >> 1);
|
||||||
|
$column = "\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||||
|
for($y = 7; $y >= 0; --$y){
|
||||||
|
$column{7 - $y} = $this->data{($y << 7) + $i};
|
||||||
|
}
|
||||||
|
return $column;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -45,10 +45,10 @@ class RegionLoader{
|
|||||||
protected $lastSector;
|
protected $lastSector;
|
||||||
protected $locationTable = array();
|
protected $locationTable = array();
|
||||||
|
|
||||||
public function __construct($path, $regionX, $regionZ){
|
public function __construct($path,/*Level $level, */$regionX, $regionZ){
|
||||||
$this->x = $regionX;
|
$this->x = $regionX;
|
||||||
$this->z = $regionZ;
|
$this->z = $regionZ;
|
||||||
$this->filePath = $path . "region/r.$regionX.$regionZ.mca";
|
$this->filePath = /*$level->getPath()*/$path . "region/r.$regionX.$regionZ.mca";
|
||||||
touch($this->filePath);
|
touch($this->filePath);
|
||||||
$this->filePointer = fopen($this->filePath, "r+b");
|
$this->filePointer = fopen($this->filePath, "r+b");
|
||||||
flock($this->filePointer, LOCK_EX);
|
flock($this->filePointer, LOCK_EX);
|
||||||
@ -113,6 +113,8 @@ class RegionLoader{
|
|||||||
if(!$chunk instanceof Compound){
|
if(!$chunk instanceof Compound){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return $chunk;
|
||||||
|
//$chunk = new Chunk($level, $chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateChunk($x, $z){
|
public function generateChunk($x, $z){
|
||||||
@ -138,7 +140,7 @@ class RegionLoader{
|
|||||||
$writer->setData(new Compound("", array($nbt)));
|
$writer->setData(new Compound("", array($nbt)));
|
||||||
$chunkData = $writer->writeCompressed(self::COMPRESSION_ZLIB, self::$COMPRESSION_LEVEL);
|
$chunkData = $writer->writeCompressed(self::COMPRESSION_ZLIB, self::$COMPRESSION_LEVEL);
|
||||||
$length = strlen($chunkData) + 1;
|
$length = strlen($chunkData) + 1;
|
||||||
$sectors = ($length + 4) >> 12;
|
$sectors = (int) ceil(($length + 4) / 4096);
|
||||||
$index = self::getChunkOffset($x, $z);
|
$index = self::getChunkOffset($x, $z);
|
||||||
if($this->locationTable[$index][1] < $sectors){
|
if($this->locationTable[$index][1] < $sectors){
|
||||||
$this->locationTable[$index][0] = $this->lastSector += $sectors; //The GC will clean this shift later
|
$this->locationTable[$index][0] = $this->lastSector += $sectors; //The GC will clean this shift later
|
||||||
@ -153,11 +155,42 @@ class RegionLoader{
|
|||||||
return $x + ($z << 5);
|
return $x + ($z << 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function doSlowCleanUp(){
|
||||||
|
for($i = 0; $i < 1024; ++$i){
|
||||||
|
if($this->locationTable[$i][0] === 0 or $this->locationTable[$i][1] === 0){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fseek($this->filePointer, $this->locationTable[$i][0] << 12);
|
||||||
|
$chunk = fread($this->filePointer, $this->locationTable[$i][1] << 12);
|
||||||
|
$length = Binary::readInt(substr($chunk, 0, 4));
|
||||||
|
if($length <= 1){
|
||||||
|
$this->locationTable[$i] = array(0, 0, 0); //Non-generated chunk, remove it from index
|
||||||
|
}
|
||||||
|
$chunk = zlib_decode(substr($chunk, 5));
|
||||||
|
if(strlen($chunk) <= 1){
|
||||||
|
$this->locationTable[$i] = array(0, 0, 0); //Corrupted chunk, remove it
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$chunk = chr(self::COMPRESSION_ZLIB) . zlib_encode($chunk, 15, 9);
|
||||||
|
$chunk = Binary::writeInt(strlen($chunk)) . $chunk;
|
||||||
|
$sectors = (int) ceil(strlen($chunk) / 4096);
|
||||||
|
if($sectors > $this->locationTable[$i][1]){
|
||||||
|
$this->locationTable[$i][0] = $this->lastSector += $sectors;
|
||||||
|
}
|
||||||
|
fseek($this->filePointer, $this->locationTable[$i][0] << 12);
|
||||||
|
fwrite($this->filePointer, str_pad($chunk, $sectors << 12, "\x00", STR_PAD_RIGHT));
|
||||||
|
}
|
||||||
|
$this->writeLocationTable();
|
||||||
|
$n = $this->cleanGarbage();
|
||||||
|
$this->writeLocationTable();
|
||||||
|
return $n;
|
||||||
|
}
|
||||||
|
|
||||||
private function cleanGarbage(){
|
private function cleanGarbage(){
|
||||||
$sectors = array();
|
$sectors = array();
|
||||||
foreach($this->locationTable as $index => $data){ //Calculate file usage
|
foreach($this->locationTable as $index => $data){ //Calculate file usage
|
||||||
if($data[0] === 0 or $data[1] === 0){
|
if($data[0] === 0 or $data[1] === 0){
|
||||||
$this->locationTable[$index] = array(0, 0);
|
$this->locationTable[$index] = array(0, 0, 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for($i = 0; $i < $data[1]; ++$i){
|
for($i = 0; $i < $data[1]; ++$i){
|
||||||
@ -186,9 +219,9 @@ class RegionLoader{
|
|||||||
fwrite($this->filePointer, $old, 4096);
|
fwrite($this->filePointer, $old, 4096);
|
||||||
}
|
}
|
||||||
$this->locationTable[$index][0] -= $shift;
|
$this->locationTable[$index][0] -= $shift;
|
||||||
|
$lastSector = $sector;
|
||||||
}
|
}
|
||||||
ftruncate($this->filePointer, ($sector + 1) << 12); //Truncate to the end of file written
|
ftruncate($this->filePointer, ($sector + 1) << 12); //Truncate to the end of file written
|
||||||
|
|
||||||
return $shift;
|
return $shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,20 +231,16 @@ class RegionLoader{
|
|||||||
$table = fread($this->filePointer, 4 * 1024 * 2);
|
$table = fread($this->filePointer, 4 * 1024 * 2);
|
||||||
for($i = 0; $i < 1024; ++$i){
|
for($i = 0; $i < 1024; ++$i){
|
||||||
$index = Binary::readInt(substr($table, $i << 2, 4));
|
$index = Binary::readInt(substr($table, $i << 2, 4));
|
||||||
$this->locationTable[$i] = array(($index & ~0xff) >> 8, $index & 0xff);
|
$this->locationTable[$i] = array(($index & ~0xff) >> 8, $index & 0xff, Binary::readInt(substr($table, 4096 + ($i << 2), 4)));
|
||||||
if(($this->locationTable[$i][0] + $this->locationTable[$i][1] - 1) > $this->lastSector){
|
if(($this->locationTable[$i][0] + $this->locationTable[$i][1] - 1) > $this->lastSector){
|
||||||
$this->lastSector = $this->locationTable[$i][0] + $this->locationTable[$i][1] - 1;
|
$this->lastSector = $this->locationTable[$i][0] + $this->locationTable[$i][1] - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Time of modification
|
|
||||||
for($i = 0; $i < 1024; ++$i){
|
|
||||||
$this->locationTable[$i][2] = Binary::readInt(substr($table, 4096 + ($i << 2), 4));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function writeLocationTable(){
|
private function writeLocationTable(){
|
||||||
$table = "";
|
$table = "";
|
||||||
|
|
||||||
for($i = 0; $i < 1024; ++$i){
|
for($i = 0; $i < 1024; ++$i){
|
||||||
$table .= Binary::writeInt(($this->locationTable[$i][0] << 8) | $this->locationTable[$i][1]);
|
$table .= Binary::writeInt(($this->locationTable[$i][0] << 8) | $this->locationTable[$i][1]);
|
||||||
}
|
}
|
||||||
@ -241,6 +270,7 @@ class RegionLoader{
|
|||||||
|
|
||||||
$time = time();
|
$time = time();
|
||||||
for($i = 0; $i < 1024; ++$i){
|
for($i = 0; $i < 1024; ++$i){
|
||||||
|
$this->locationTable[$i][2] = $time;
|
||||||
$table .= Binary::writeInt($time);
|
$table .= Binary::writeInt($time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,7 @@ abstract class BaseChunk implements Chunk{
|
|||||||
$this->level = $level;
|
$this->level = $level;
|
||||||
$this->x = (int) $x;
|
$this->x = (int) $x;
|
||||||
$this->z = (int) $z;
|
$this->z = (int) $z;
|
||||||
$Y = 0;
|
foreach($sections as $Y => $section){
|
||||||
foreach($sections as $section){
|
|
||||||
if($section instanceof ChunkSection){
|
if($section instanceof ChunkSection){
|
||||||
$this->sections[$Y] = $section;
|
$this->sections[$Y] = $section;
|
||||||
}else{
|
}else{
|
||||||
@ -52,7 +51,6 @@ abstract class BaseChunk implements Chunk{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
++$Y;
|
|
||||||
if($section >= self::SECTION_COUNT){
|
if($section >= self::SECTION_COUNT){
|
||||||
trigger_error("Invalid amount of chunks", E_USER_WARNING);
|
trigger_error("Invalid amount of chunks", E_USER_WARNING);
|
||||||
return;
|
return;
|
||||||
|
@ -50,13 +50,13 @@ class Chest extends Spawnable{
|
|||||||
|
|
||||||
public function getPair(){
|
public function getPair(){
|
||||||
if($this->isPaired()){
|
if($this->isPaired()){
|
||||||
return $this->level->getTile(new Vector3((int) $this->namedtag->pairx, $this->y, (int) $this->namedtag->pairz));
|
return $this->getLevel()->getTile(new Vector3((int) $this->namedtag->pairx, $this->y, (int) $this->namedtag->pairz));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pairWith(Tile $tile){
|
public function pairWith(Chest $tile){
|
||||||
if($this->isPaired() or $tile->isPaired()){
|
if($this->isPaired() or $tile->isPaired()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -69,6 +69,8 @@ class Chest extends Spawnable{
|
|||||||
|
|
||||||
$this->spawnToAll();
|
$this->spawnToAll();
|
||||||
$tile->spawnToAll();
|
$tile->spawnToAll();
|
||||||
|
|
||||||
|
//TODO: Update to new events
|
||||||
$this->server->handle("tile.update", $this);
|
$this->server->handle("tile.update", $this);
|
||||||
$this->server->handle("tile.update", $tile);
|
$this->server->handle("tile.update", $tile);
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ trait Container{
|
|||||||
$slots = array();
|
$slots = array();
|
||||||
|
|
||||||
if(is_array($player->windows[$id])){
|
if(is_array($player->windows[$id])){
|
||||||
$all = $this->level->getPlayers();
|
$all = $this->getLevel()->getPlayers();
|
||||||
foreach($player->windows[$id] as $ob){
|
foreach($player->windows[$id] as $ob){
|
||||||
$pk = new TileEventPacket();
|
$pk = new TileEventPacket();
|
||||||
$pk->x = $ob->x;
|
$pk->x = $ob->x;
|
||||||
@ -90,7 +90,7 @@ trait Container{
|
|||||||
$pk->z = $this->z;
|
$pk->z = $this->z;
|
||||||
$pk->case1 = 1;
|
$pk->case1 = 1;
|
||||||
$pk->case2 = 2;
|
$pk->case2 = 2;
|
||||||
Player::broadcastPacket($this->level->getPlayers(), $pk);
|
Player::broadcastPacket($this->getLevel()->getPlayers(), $pk);
|
||||||
for($s = 0; $s < Chest::SLOTS; ++$s){
|
for($s = 0; $s < Chest::SLOTS; ++$s){
|
||||||
$slot = $this->getSlot($s);
|
$slot = $this->getSlot($s);
|
||||||
if($slot->getID() > Item::AIR and $slot->getCount() > 0){
|
if($slot->getID() > Item::AIR and $slot->getCount() > 0){
|
||||||
|
@ -70,9 +70,9 @@ class Furnace extends Tile{
|
|||||||
$fuel = Item::get(Item::AIR, 0, 0);
|
$fuel = Item::get(Item::AIR, 0, 0);
|
||||||
}
|
}
|
||||||
$this->setSlot(1, $fuel, false);
|
$this->setSlot(1, $fuel, false);
|
||||||
$current = $this->level->getBlock($this);
|
$current = $this->getLevel()->getBlock($this);
|
||||||
if($current->getID() === Item::FURNACE){
|
if($current->getID() === Item::FURNACE){
|
||||||
$this->level->setBlock($this, Block::get(Item::BURNING_FURNACE, $current->getMetadata()), true, false, true);
|
$this->getLevel()->setBlock($this, Block::get(Item::BURNING_FURNACE, $current->getMetadata()), true, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($this->namedtag->BurnTime > 0){
|
if($this->namedtag->BurnTime > 0){
|
||||||
@ -100,9 +100,9 @@ class Furnace extends Tile{
|
|||||||
}
|
}
|
||||||
$ret = true;
|
$ret = true;
|
||||||
}else{
|
}else{
|
||||||
$current = $this->level->getBlock($this);
|
$current = $this->getLevel()->getBlock($this);
|
||||||
if($current->getID() === Item::BURNING_FURNACE){
|
if($current->getID() === Item::BURNING_FURNACE){
|
||||||
$this->level->setBlock($this, Block::get(Item::FURNACE, $current->getMetadata()), true, false, true);
|
$this->getLevel()->setBlock($this, Block::get(Item::FURNACE, $current->getMetadata()), true, false, true);
|
||||||
}
|
}
|
||||||
$this->namedtag->CookTime = 0;
|
$this->namedtag->CookTime = 0;
|
||||||
$this->namedtag->BurnTime = 0;
|
$this->namedtag->BurnTime = 0;
|
||||||
|
@ -27,7 +27,7 @@ abstract class Spawnable extends Tile{
|
|||||||
public abstract function spawnTo(Player $player);
|
public abstract function spawnTo(Player $player);
|
||||||
|
|
||||||
public function spawnToAll(){
|
public function spawnToAll(){
|
||||||
foreach($this->level->getPlayers() as $player){
|
foreach($this->getLevel()->getPlayers() as $player){
|
||||||
if($player->eid !== false or $player->spawned !== true){
|
if($player->eid !== false or $player->spawned !== true){
|
||||||
$this->spawnTo($player);
|
$this->spawnTo($player);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ abstract class Tile extends Position{
|
|||||||
|
|
||||||
public function __construct(Level $level, Compound $nbt){
|
public function __construct(Level $level, Compound $nbt){
|
||||||
$this->server = Server::getInstance();
|
$this->server = Server::getInstance();
|
||||||
$this->level = $level;
|
$this->setLevel($level, true); //Strong reference
|
||||||
$this->namedtag = $nbt;
|
$this->namedtag = $nbt;
|
||||||
$this->closed = false;
|
$this->closed = false;
|
||||||
$this->name = "";
|
$this->name = "";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user