Item Drop

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-05 15:17:57 +01:00
parent c2a45212dd
commit 9ebe68294b
5 changed files with 30 additions and 6 deletions

View File

@ -204,11 +204,13 @@ class BlockAPI{
$data["x"] += mt_rand(2, 8) / 10;
$data["y"] += 0.19;
$data["z"] += mt_rand(2, 8) / 10;
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);
if($this->server->api->handle("item.drop", $data) !== false){
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);
}
}
}

View File

@ -488,7 +488,22 @@ class CustomPacketHandler{
$this->raw .= Utils::writeFloat($this->data["x"]);
$this->raw .= Utils::writeFloat($this->data["y"]);
$this->raw .= Utils::writeFloat($this->data["z"]);
}
}
break;
case MC_DROP_ITEM:
if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4));
$this->data["unknown1"] = ord($this->get(1));
$this->data["block"] = Utils::readShort($this->get(2), false);
$this->data["stack"] = ord($this->get(1));
$this->data["meta"] = Utils::readShort($this->get(2), false);
}else{
$this->raw .= Utils::writeInt($this->data["eid"]);
$this->raw .= chr($this->data["unknown1"]);
$this->raw .= Utils::writeShort($this->data["block"]);
$this->raw .= chr($this->data["stack"]);
$this->raw .= Utils::writeShort($this->data["meta"]);
}
break;
case MC_CLIENT_MESSAGE:
if($this->c === false){

View File

@ -373,6 +373,9 @@ class Player{
$this->entity->setHealth(20, "respawn");
$this->entity->setPosition($data["x"], $data["y"], $data["z"], 0, 0);
break;
case MC_DROP_ITEM:
$this->server->api->block->drop($this->entity->x, $this->entity->y, $this->entity->z, $data["block"], $data["meta"], $data["stack"]);
break;
}
break;

View File

@ -75,6 +75,8 @@ $dataName = array(
MC_ANIMATE => "Animate",
MC_RESPAWN => "Respawn",
MC_DROP_ITEM => "DropItem",
MC_CLIENT_MESSAGE => "ClientMessage",
MC_SIGN_UPDATE => "SignUpdate",
MC_ADVENTURE_SETTINGS => "AdventureSettings",

View File

@ -77,6 +77,8 @@ define("MC_SET_SPAWN_POSITION", 0xa6);
define("MC_ANIMATE", 0xa7);
define("MC_RESPAWN", 0xa8);
define("MC_DROP_ITEM", 0xaa);
define("MC_CLIENT_MESSAGE", 0xb1);
define("MC_SIGN_UPDATE", 0xb2);
define("MC_ADVENTURE_SETTINGS", 0xb3);