From c2a45212dd9c0ec1e4b85230c34beb732752c5e0 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sat, 5 Jan 2013 15:01:21 +0100 Subject: [PATCH] Fixed item spawning --- src/API/BlockAPI.php | 18 +++++++++++------- src/classes/Entity.class.php | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 629a3ccc7..6bf6d43cb 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -57,16 +57,16 @@ class BlockAPI{ if(!isset($b[1])){ $meta = 0; }else{ - $meta = ((int) $b[1]) & 0x0F; + $meta = (int) $b[1]; } - $block = ((int) $b[0]) & 0xFF; + $block = ((int) $b[0]) & 0xFFFF; if(!isset($params[2])){ $amount = 64; }else{ - $amount = $params[2] & 0xFF; + $amount = (int) $params[2]; } if(isset($params[3])){ - $meta = $params[3] & 0x0F; + $meta = (int) $params[3]; } if(($player = $this->server->api->player->get($username)) !== false){ $this->drop($player->entity->x, $player->entity->y, $player->entity->z, $block, $meta, $amount); @@ -202,10 +202,14 @@ class BlockAPI{ "stack" => $stack, ); $data["x"] += mt_rand(2, 8) / 10; - $data["y"] += mt_rand(2, 8) / 10; + $data["y"] += 0.19; $data["z"] += mt_rand(2, 8) / 10; - $e = $this->server->api->entity->add(ENTITY_ITEM, $block, $data); - $this->server->api->entity->spawnToAll($e->eid); + for($count = $stack; $count > 0; ){ + $data["stack"] = min(64, $count); + $count -= $data["stack"]; + $e = $this->server->api->entity->add(ENTITY_ITEM, $block, $data); + $this->server->api->entity->spawnToAll($e->eid); + } } public function blockAction($data, $event){ diff --git a/src/classes/Entity.class.php b/src/classes/Entity.class.php index 5a7310b45..01af3b8cc 100644 --- a/src/classes/Entity.class.php +++ b/src/classes/Entity.class.php @@ -77,6 +77,7 @@ class Entity extends stdClass{ public function update(){ if($this->class === ENTITY_ITEM){ + $this->server->api->dhandle("entity.move", $this->eid); $player = $this->server->query("SELECT EID FROM entities WHERE class == ".ENTITY_PLAYER." AND abs(x - {$this->x}) <= 1.5 AND abs(y - {$this->y}) <= 1.5 AND abs(z - {$this->z}) <= 1.5 LIMIT 1;", true); if($player !== true and $player !== false){ if($this->server->api->dhandle("player.item.pick", array(