Send Inventory Support

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-08 14:17:52 +01:00
parent 506b9f4a4f
commit 967a929723
3 changed files with 45 additions and 1 deletions

View File

@ -48,7 +48,7 @@ class Item{
protected $block;
protected $id;
protected $meta;
protected $count;
public $count;
protected $maxStackSize = 64;
protected $durability = 0;
protected $name;

View File

@ -575,6 +575,38 @@ class CustomPacketHandler{
$this->raw .= Utils::writeFloat($this->data["z"]);
}
break;
case MC_SEND_INVENTORY:
if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4));
$this->data["windowid"] = ord($this->get(1));
$this->data["count"] = Utils::readShort($this->get(2), false);
$this->data["slots"] = array();
for($s = 0; $s < $this->data["count"]; ++$s){
$this->data["slots"][$s] = Utils::readSlot($this->get(5));
}
if($this->data["windowid"] === 1){ //Armor is also sent
$this->data["armor"] = array(
Utils::readSlot($this->get(5)),
Utils::readSlot($this->get(5)),
Utils::readSlot($this->get(5)),
Utils::readSlot($this->get(5))
);
}
}else{
$this->raw .= Utils::writeInt($this->data["eid"]);
$this->raw .= chr($this->data["windowid"]);
$this->raw .= Utils::writeShort(count($this->data["slots"]));
foreach($this->data["slots"] as $slot){
$this->raw .= Utils::writeSlot($slot);
}
if($this->data["windowid"] === 1 and isset($this->data["armor"])){
$this->raw .= Utils::writeSlot($this->data["armor"][0]);
$this->raw .= Utils::writeSlot($this->data["armor"][1]);
$this->raw .= Utils::writeSlot($this->data["armor"][2]);
$this->raw .= Utils::writeSlot($this->data["armor"][3]);
}
}
break;
case MC_DROP_ITEM:
if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4));

View File

@ -148,6 +148,18 @@ class Utils extends Thread{
$m .= "\x7f";
return $m;
}
public static function writeSlot(Item $item){
return Utils::writeShort($item->getID()).chr($item->count).Utils::writeShort($item->getMetadata());
}
public static function readSlot($str){
return BlockAPI::getItem(
Utils::readShort(substr($str, 0, 2), false),
Utils::readShort(substr($str, 3, 2), false),
ord($str{2})
);
}
public static function readMetadata($value, $types = false){
$offset = 0;