mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 11:57:10 +00:00
Send Inventory Support
This commit is contained in:
parent
506b9f4a4f
commit
967a929723
@ -48,7 +48,7 @@ class Item{
|
||||
protected $block;
|
||||
protected $id;
|
||||
protected $meta;
|
||||
protected $count;
|
||||
public $count;
|
||||
protected $maxStackSize = 64;
|
||||
protected $durability = 0;
|
||||
protected $name;
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user