Added Player block place/break (to be rewritten soon)

This commit is contained in:
Shoghi Cervantes 2014-03-02 17:56:54 +01:00
parent 9cc9de8dae
commit df20467f3b

View File

@ -253,6 +253,21 @@ class Player extends PlayerEntity{
} }
asort($newOrder); asort($newOrder);
$this->chunksOrder = $newOrder; $this->chunksOrder = $newOrder;
$index = key($this->chunksOrder);
PMFLevel::getXZ($index, $X, $Z);
$this->level->loadChunk($X, $Z);
if(!$this->level->isChunkPopulated($X, $Z)){
$this->level->loadChunk($X - 1, $Z);
$this->level->loadChunk($X + 1, $Z);
$this->level->loadChunk($X, $Z - 1);
$this->level->loadChunk($X, $Z + 1);
$this->level->loadChunk($X + 1, $Z + 1);
$this->level->loadChunk($X + 1, $Z - 1);
$this->level->loadChunk($X - 1, $Z - 1);
$this->level->loadChunk($X - 1, $Z + 1);
}
foreach($lastChunk as $index => $Yndex){ foreach($lastChunk as $index => $Yndex){
if($Yndex !== 0xff){ if($Yndex !== 0xff){
$X = null; $X = null;
@ -314,15 +329,23 @@ class Player extends PlayerEntity{
} }
return false; return false;
} }
$X = null;
$Z = null;
PMFLevel::getXZ($index, $X, $Z);
if(!$this->level->isChunkPopulated($X, $Z)){
$this->orderChunks();
if($this->chunkScheduled === 0 or $force === true){
$this->server->schedule(MAX_CHUNK_RATE, array($this, "getNextChunk"));
++$this->chunkScheduled;
}
return false;
}
unset($this->chunksOrder[$index]); unset($this->chunksOrder[$index]);
if(!isset($this->chunksLoaded[$index])){ if(!isset($this->chunksLoaded[$index])){
$this->chunksLoaded[$index] = 0xff; $this->chunksLoaded[$index] = 0xff;
} }
$Yndex = $this->chunksLoaded[$index]; $Yndex = $this->chunksLoaded[$index];
$this->chunksLoaded[$index] = 0; //Load them all $this->chunksLoaded[$index] = 0; //Load them all
$X = null;
$Z = null;
PMFLevel::getXZ($index, $X, $Z);
$this->level->useChunk($X, $Z, $this); $this->level->useChunk($X, $Z, $this);
$pk = new ChunkDataPacket; $pk = new ChunkDataPacket;
$pk->chunkX = $X; $pk->chunkX = $X;
@ -1608,11 +1631,7 @@ class Player extends PlayerEntity{
break;*/ break;*/
case ProtocolInfo::REQUEST_CHUNK_PACKET: case ProtocolInfo::REQUEST_CHUNK_PACKET:
break; break;
/*case ProtocolInfo::USE_ITEM_PACKET: case ProtocolInfo::USE_ITEM_PACKET:
if(!($this->entity instanceof Entity)){
break;
}
$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){
@ -1656,12 +1675,12 @@ class Player extends PlayerEntity{
$data["posZ"] = $packet->posZ; $data["posZ"] = $packet->posZ;
if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place
if($this->entity->inAction === true){ if($this->inAction === true){
$this->entity->inAction = false; $this->inAction = false;
$this->entity->updateMetadata(); //$this->entity->updateMetadata();
} }
if($this->blocked === true or ($this->entity instanceof Entity and $blockVector->distance($this->entity) > 10)){ if($this->blocked === true or $blockVector->distance($this) > 10){
}elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)){ }elseif($this->getSlot($this->slot)->getID() !== $packet->item or ($this->getSlot($this->slot)->isTool() === false and $this->getSlot($this->slot)->getMetadata() !== $packet->meta)){
$this->sendInventorySlot($this->slot); $this->sendInventorySlot($this->slot);
@ -1689,11 +1708,11 @@ class Player extends PlayerEntity{
$this->dataPacket($pk); $this->dataPacket($pk);
break; break;
}elseif($packet->face === 0xff and $this->server->handle("player.action", $data) !== false){ }elseif($packet->face === 0xff and $this->server->handle("player.action", $data) !== false){
$this->entity->inAction = true; $this->inAction = true;
$this->startAction = microtime(true); $this->startAction = microtime(true);
$this->entity->updateMetadata(); //$this->updateMetadata();
} }
break;*/ break;
/*case ProtocolInfo::PLAYER_ACTION_PACKET: /*case ProtocolInfo::PLAYER_ACTION_PACKET:
if($this->spawned === false or $this->blocked === true){ if($this->spawned === false or $this->blocked === true){
break; break;
@ -1770,9 +1789,9 @@ class Player extends PlayerEntity{
$this->stopSleep(); $this->stopSleep();
} }
break;*/ break;*/
/*case ProtocolInfo::REMOVE_BLOCK_PACKET: case ProtocolInfo::REMOVE_BLOCK_PACKET:
$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 or $this->entity->distance($blockVector) > 8){ if($this->spawned === false or $this->blocked === true or $this->distance($blockVector) > 8){
$target = $this->level->getBlock($blockVector); $target = $this->level->getBlock($blockVector);
$pk = new UpdateBlockPacket; $pk = new UpdateBlockPacket;
@ -1787,7 +1806,7 @@ class Player extends PlayerEntity{
$this->craftingItems = array(); $this->craftingItems = array();
$this->toCraft = array(); $this->toCraft = array();
$this->server->api->block->playerBlockBreak($this, $blockVector); $this->server->api->block->playerBlockBreak($this, $blockVector);
break;*/ break;
/*case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET: /*case ProtocolInfo::PLAYER_ARMOR_EQUIPMENT_PACKET:
if($this->spawned === false or $this->blocked === true){ if($this->spawned === false or $this->blocked === true){
break; break;