From c27cca6741049732c39cccdb5f172887bb606944 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Tue, 14 May 2013 21:54:01 +0200 Subject: [PATCH] More fixes :D --- src/API/BanAPI.php | 2 +- src/API/BlockAPI.php | 29 +++---------------------- src/API/EntityAPI.php | 33 ++++++++++++++++++++++++----- src/API/PlayerAPI.php | 4 ++-- src/API/TileEntityAPI.php | 8 +++---- src/Player.php | 17 +++++++++++---- src/material/block/GenericBlock.php | 2 +- src/pmf/Level.php | 2 +- src/world/Entity.php | 3 +++ 9 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index 1fcf9be28..279bc06dc 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -83,7 +83,7 @@ class BanAPI{ case "player.block.place"://Spawn protection detection. Allows OPs to place/break blocks in the spawn area. if(!$this->isOp($data["player"]->iusername)){ $t = new Vector2($data["target"]->x, $data["target"]->z); - $s = new Vector2($this->server->spawn["x"], $this->server->spawn["z"]); + $s = new Vector2($this->server->spawn->x, $this->server->spawn->z); if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event.".spawn", $data) !== true){ return false; } diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index a583b8272..6f00a7a59 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -282,36 +282,12 @@ class BlockAPI{ if(($player->gamemode & 0x01) === 0x00 and count($drops) > 0){ foreach($drops as $drop){ - $this->drop($target, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF)); + $this->server->api->entity->drop($target, BlockAPI::getItem($drop[0] & 0xFFFF, $drop[1] & 0xFFFF, $drop[2] & 0xFF)); } } return false; } - public function drop(Position $pos, Item $item){ - if($item->getID() === AIR or $item->count <= 0){ - return; - } - $data = array( - "x" => $pos->x + mt_rand(2, 8) / 10, - "y" => $pos->y + 0.19, - "z" => $pos->z + mt_rand(2, 8) / 10, - "item" => $item, - ); - if($this->server->api->handle("item.drop", $data) !== false){ - for($count = $item->count; $count > 0; ){ - $item->count = min($item->getMaxStackSize(), $count); - $count -= $item->count; - $server = ServerAPI::request(); - $e = $server->api->entity->add($pos->level, ENTITY_ITEM, $item->getID(), $data); - //$e->speedX = mt_rand(-10, 10) / 100; - //$e->speedY = mt_rand(0, 5) / 100; - //$e->speedZ = mt_rand(-10, 10) / 100; - $server->api->entity->spawnToAll($e->eid); - } - } - } - public function playerBlockAction(Player $player, Vector3 $vector, $face, $fx, $fy, $fz){ if($face < 0 or $face > 5){ return false; @@ -351,6 +327,7 @@ class BlockAPI{ if($item->isPlaceable()){ $hand = $item->getBlock(); + $hand->position($block); }else{ return $this->cancelAction($block, $player); } @@ -368,7 +345,7 @@ class BlockAPI{ }elseif($hand->place($item, $player, $block, $target, $face, $fx, $fy, $fz) === false){ return $this->cancelAction($block, $player); } - if($hand->getID() === SIGN_POST or $hand->getID() === WALL_POST){ + if($hand->getID() === SIGN_POST or $hand->getID() === WALL_SIGN){ $t = $this->server->api->tileentity->addSign($player->level, $block->x, $block->y, $block->z); $t->data["creator"] = $player->username; } diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 89127d545..41da1dfb4 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -49,7 +49,7 @@ class EntityAPI{ public function getAll($level = null){ if($level instanceof Level){ $entities = array(); - $l = $this->server->query("SELECT EID FROM entities WHERE level = '".$this->level->getName()."';"); + $l = $this->server->query("SELECT EID FROM entities WHERE level = '".$level->getName()."';"); if($l !== false and $l !== true){ while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ $e = $this->get($e["EID"]); @@ -90,20 +90,43 @@ class EntityAPI{ $e->spawn($player); } - public function spawnToAll($eid){ + public function spawnToAll(Level $level, $eid){ $e = $this->get($eid); if($e === false){ return false; } - foreach($this->server->api->player->getAll() as $player){ + foreach($this->server->api->player->getAll($level) as $player){ if($player->eid !== false and $player->eid !== $eid){ $e->spawn($player); } } } + + public function drop(Position $pos, Item $item){ + if($item->getID() === AIR or $item->count <= 0){ + return; + } + $data = array( + "x" => $pos->x + mt_rand(2, 8) / 10, + "y" => $pos->y + 0.19, + "z" => $pos->z + mt_rand(2, 8) / 10, + "item" => $item, + ); + if($this->server->api->handle("item.drop", $data) !== false){ + for($count = $item->count; $count > 0; ){ + $item->count = min($item->getMaxStackSize(), $count); + $count -= $item->count; + $e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data); + //$e->speedX = mt_rand(-10, 10) / 100; + //$e->speedY = mt_rand(0, 5) / 100; + //$e->speedZ = mt_rand(-10, 10) / 100; + $this->spawnToAll($pos->level, $e->eid); + } + } + } - public function spawnAll($player){ - foreach($this->getAll() as $e){ + public function spawnAll(Player $player){ + foreach($this->getAll($player->level) as $e){ $e->spawn($player); } } diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 6c21cda8c..e34f9f686 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -253,12 +253,12 @@ class PlayerAPI{ public function getAll($level = null){ if($level instanceof Level){ $clients = array(); - $l = $this->server->query("SELECT EID FROM entities WHERE level = '".$this->level->getName()."' AND class = '".ENTITY_PLAYER."';"); + $l = $this->server->query("SELECT EID FROM entities WHERE level = '".$level->getName()."' AND class = '".ENTITY_PLAYER."';"); if($l !== false and $l !== true){ while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ $e = $this->getByEID($e["EID"]); if($e instanceof Player){ - $clients[$e->clientID] = $e->player; + $clients[$e->clientID] = $e; } } } diff --git a/src/API/TileEntityAPI.php b/src/API/TileEntityAPI.php index 182451907..75f6e7330 100644 --- a/src/API/TileEntityAPI.php +++ b/src/API/TileEntityAPI.php @@ -68,7 +68,7 @@ class TileEntityAPI{ public function getAll($level = null){ if($level instanceof Level){ $tileEntities = array(); - $l = $this->server->query("SELECT ID FROM tileentities WHERE level = '".$this->level->getName()."';"); + $l = $this->server->query("SELECT ID FROM tileentities WHERE level = '".$level->getName()."';"); if($l !== false and $l !== true){ while(($t = $l->fetchArray(SQLITE3_ASSOC)) !== false){ $t = $this->get($e["ID"]); @@ -115,15 +115,15 @@ class TileEntityAPI{ if($t === false){ return false; } - foreach($this->server->api->player->getAll() as $player){ + foreach($this->server->api->player->getAll($level) as $player){ if($player->eid !== false){ $t->spawn($player); } } } - public function spawnAll($player){ - foreach($this->getAll() as $t){ + public function spawnAll(Player $player){ + foreach($this->getAll($player->level) as $t){ $t->spawn($player); } } diff --git a/src/Player.php b/src/Player.php index 25a8283d2..96bcce665 100644 --- a/src/Player.php +++ b/src/Player.php @@ -167,7 +167,7 @@ class Player{ } public function onTick($time, $event){ - if($event !== "server.tick"){ //WTF?? + if($event !== "server.tick" or $this->connected === false){ return; } if($time > $this->timeout){ @@ -394,7 +394,16 @@ class Player{ $this->dataPacket(MC_PLAYER_EQUIPMENT, $data); break; case "block.change": - $this->dataPacket(MC_UPDATE_BLOCK, $data); + if($data["position"]->level !== $this->level){ + break; + } + $this->dataPacket(MC_UPDATE_BLOCK, array( + "x" => $data["position"]->x, + "y" => $data["position"]->y, + "z" => $data["position"]->z, + "block" => $data["block"]->getID(), + "meta" => $data["block"]->getMetadata(), + )); break; case "entity.move": if($data->eid === $this->eid){ @@ -875,7 +884,7 @@ class Player{ } $this->spawned = true; $this->server->api->entity->spawnAll($this); - $this->server->api->entity->spawnToAll($this->eid); + $this->server->api->entity->spawnToAll($this->level, $this->eid); $this->server->schedule(5, array($this->entity, "update"), array(), true); $this->sendArmor(); $this->eventHandler(new Container($this->server->motd), "server.chat"); @@ -1123,7 +1132,7 @@ class Player{ $t->data["Text3"] = $data["line2"]; $t->data["Text4"] = $data["line3"]; $this->server->handle("tile.update", $t); - $this->server->api->tileentity->spawnToAll($t); + $this->server->api->tileentity->spawnToAll($this->level, $t); } } break; diff --git a/src/material/block/GenericBlock.php b/src/material/block/GenericBlock.php index 8531be22d..4f7bd46da 100644 --- a/src/material/block/GenericBlock.php +++ b/src/material/block/GenericBlock.php @@ -39,7 +39,7 @@ class GenericBlock extends Block{ } public function onBreak(Item $item, Player $player){ - return $this->level->setBlock($this, BlockAPI::getBlock(AIR, 0)); + return $this->level->setBlock($this, new AirBlock()); } public function onUpdate($type){ diff --git a/src/pmf/Level.php b/src/pmf/Level.php index b74d797ac..eb7883625 100644 --- a/src/pmf/Level.php +++ b/src/pmf/Level.php @@ -334,7 +334,7 @@ class PMFLevel extends PMF{ $bindex = $aY + ($aX << 5) + ($aZ << 9); $mindex = ($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9); $old_b = $this->chunks[$index][$Y]{$bindex}; - $old_m = ord($this->map[$X][$Z][1][$index]{$y >> 1}); + $old_m = $this->chunks[$index][$Y]{$mindex}; if(($y & 1) === 0){ $old_m = $old_m & 0x0F; $m = ($old_m << 4) | ($meta & 0x0F); diff --git a/src/world/Entity.php b/src/world/Entity.php index ce2ef2364..4e7d87d68 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -470,6 +470,9 @@ class Entity extends Position{ "x" => $this->x, "y" => $this->y, "z" => $this->z, + "yaw" => $this->yaw, + "pitch" => $this->pitch, + "roll" => 0, "block" => $this->type, "meta" => $this->meta, "stack" => $this->stack,