mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Added a way to send Player's inventory directly
This commit is contained in:
parent
5e4ef9732b
commit
09301f0e5f
@ -151,7 +151,8 @@ class BlockAPI{
|
||||
}
|
||||
|
||||
if($player instanceof Player){
|
||||
$this->drop(new Vector3($player->entity->x - 0.5, $player->entity->y, $player->entity->z - 0.5), $item, true);
|
||||
$player->addItem($item->getID(), $item->getMetadata(), $item->count);
|
||||
//$this->drop(new Vector3($player->entity->x - 0.5, $player->entity->y, $player->entity->z - 0.5), $item, true);
|
||||
$output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username."\n";
|
||||
}else{
|
||||
$output .= "Unknown player\n";
|
||||
@ -170,6 +171,7 @@ class BlockAPI{
|
||||
"block" => $block->getID(),
|
||||
"meta" => $block->getMetadata()
|
||||
));
|
||||
$player->sendInventory();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -225,6 +225,7 @@ class Player{
|
||||
if($data[0] === AIR){
|
||||
$add = min(64, $count);
|
||||
$this->inventory[$s] = array($type, $damage, $add);
|
||||
$this->sendInventorySlot($s);
|
||||
break;
|
||||
}elseif($data[0] === $type and $data[1] === $damage){
|
||||
$add = min(64 - $data[2], $count);
|
||||
@ -232,6 +233,7 @@ class Player{
|
||||
continue;
|
||||
}
|
||||
$this->inventory[$s] = array($type, $damage, $data[2] + $add);
|
||||
$this->sendInventorySlot($s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -254,6 +256,7 @@ class Player{
|
||||
}else{
|
||||
$this->inventory[$s] = array(0, 0, 0);
|
||||
}
|
||||
$this->sendInventorySlot($s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -265,6 +268,29 @@ class Player{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function sendInventorySlot($s){
|
||||
$s = (int) $s;
|
||||
if(!isset($this->inventory[$s])){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$this->sendInventory(); //Fallback
|
||||
return true;
|
||||
|
||||
//Can't do this :(
|
||||
|
||||
/*$slot = BlockAPI::getItem($this->inventory[$s][0], $this->inventory[$s][1], $this->inventory[$s][2]);
|
||||
$this->dataPacket(MC_CONTAINER_SET_SLOT, array(
|
||||
"windowid" => 0,
|
||||
"slot" => (int) $s,
|
||||
"block" => $slot->getID(),
|
||||
"stack" => $slot->count,
|
||||
"meta" => $slot->getMetadata(),
|
||||
));
|
||||
return true;*/
|
||||
}
|
||||
|
||||
public function hasItem($type, $damage = false){
|
||||
if($type === AIR){
|
||||
return true;
|
||||
@ -1105,6 +1131,8 @@ class Player{
|
||||
}
|
||||
|
||||
public function sendInventory(){
|
||||
/*
|
||||
//OLD WAY
|
||||
foreach($this->inventory as $s => $data){
|
||||
if($data[0] > 0 and $data[2] >= 0){
|
||||
$e = $this->server->api->entity->add(ENTITY_ITEM, $data[0], array(
|
||||
@ -1117,7 +1145,21 @@ class Player{
|
||||
$this->server->api->entity->spawnTo($e->eid, $this);
|
||||
}
|
||||
$this->inventory[$s] = array(AIR, 0, 0);
|
||||
}
|
||||
}*/
|
||||
$inv = array();
|
||||
foreach($this->inventory as $s => $data){
|
||||
if($data[0] > 0 and $data[2] >= 0){
|
||||
$inv[] = BlockAPI::getItem($data[0], $data[1], $data[2]);
|
||||
}else{
|
||||
$inv[] = BlockAPI::getItem(AIR, 0, 0);
|
||||
$this->inventory[$s] = array(AIR, 0, 0);
|
||||
}
|
||||
}
|
||||
$this->dataPacket(MC_CONTAINER_SET_CONTENT, array(
|
||||
"windowid" => 0,
|
||||
"count" => count($inv),
|
||||
"slots" => $inv
|
||||
));
|
||||
/*
|
||||
//Future
|
||||
$inv = array();
|
||||
|
@ -88,7 +88,7 @@ define("MC_CONTAINER_OPEN", 0xae);
|
||||
define("MC_CONTAINER_CLOSE", 0xaf);
|
||||
define("MC_CONTAINER_SET_SLOT", 0xb0);
|
||||
//define("MC_CONTAINER_SET_DATA", 0xb1);
|
||||
//define("MC_CONTAINER_SET_CONTENT", 0xb2);
|
||||
define("MC_CONTAINER_SET_CONTENT", 0xb2);
|
||||
//define("MC_CONTAINER_ACK", 0xb3);
|
||||
define("MC_CLIENT_MESSAGE", 0xb4);
|
||||
define("MC_SIGN_UPDATE", 0xb5);
|
||||
|
@ -93,26 +93,27 @@ class BurningFurnaceBlock extends SolidBlock{
|
||||
if($furnace->class !== TILE_FURNACE){
|
||||
return true;
|
||||
}
|
||||
$id = $player->windowCnt = $player->windowCnt++ % 255;
|
||||
$player->windows[$id] = $furnace;
|
||||
$player->windowCnt++;
|
||||
$player->windowCnt = $id = max(1, $player->windowCnt % 255);
|
||||
$player->windows[$id] = $chest;
|
||||
$player->dataPacket(MC_CONTAINER_OPEN, array(
|
||||
"windowid" => $id,
|
||||
"type" => WINDOW_FURNACE,
|
||||
"slots" => 3,
|
||||
"slots" => FURNACE_SLOTS,
|
||||
"title" => "Furnace",
|
||||
));
|
||||
$slots = array();
|
||||
for($s = 0; $s < FURNACE_SLOTS; ++$s){
|
||||
$slot = $furnace->getSlot($s);
|
||||
$slot = $chest->getSlot($s);
|
||||
if($slot->getID() > 0 and $slot->count > 0){
|
||||
$player->dataPacket(MC_CONTAINER_SET_SLOT, array(
|
||||
"windowid" => $id,
|
||||
"slot" => $s,
|
||||
"block" => $slot->getID(),
|
||||
"stack" => $slot->count,
|
||||
"meta" => $slot->getMetadata(),
|
||||
));
|
||||
$slots[] = $slot;
|
||||
}
|
||||
}
|
||||
$player->dataPacket(MC_CONTAINER_SET_CONTENT, array(
|
||||
"windowid" => $id,
|
||||
"count" => count($slots),
|
||||
"slots" => $slots
|
||||
));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -110,27 +110,27 @@ class ChestBlock extends TransparentBlock{
|
||||
if($chest->class !== TILE_CHEST){
|
||||
return true;
|
||||
}
|
||||
|
||||
$id = $player->windowCnt = $player->windowCnt++ % 255;
|
||||
$player->windowCnt++;
|
||||
$player->windowCnt = $id = max(1, $player->windowCnt % 255);
|
||||
$player->windows[$id] = $chest;
|
||||
$player->dataPacket(MC_CONTAINER_OPEN, array(
|
||||
"windowid" => $id,
|
||||
"type" => WINDOW_CHEST,
|
||||
"slots" => 27,
|
||||
"slots" => CHEST_SLOTS,
|
||||
"title" => "Chest",
|
||||
));
|
||||
$slots = array();
|
||||
for($s = 0; $s < CHEST_SLOTS; ++$s){
|
||||
$slot = $chest->getSlot($s);
|
||||
if($slot->getID() > 0 and $slot->count > 0){
|
||||
$player->dataPacket(MC_CONTAINER_SET_SLOT, array(
|
||||
"windowid" => $id,
|
||||
"slot" => $s,
|
||||
"block" => $slot->getID(),
|
||||
"stack" => $slot->count,
|
||||
"meta" => $slot->getMetadata(),
|
||||
));
|
||||
$slots[] = $slot;
|
||||
}
|
||||
}
|
||||
$player->dataPacket(MC_CONTAINER_SET_CONTENT, array(
|
||||
"windowid" => $id,
|
||||
"count" => count($slots),
|
||||
"slots" => $slots
|
||||
));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -675,6 +675,22 @@ class CustomPacketHandler{
|
||||
$this->raw .= Utils::writeShort($this->data["meta"]);
|
||||
}
|
||||
break;
|
||||
case MC_CONTAINER_SET_CONTENT:
|
||||
if($this->c === false){
|
||||
$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));
|
||||
}
|
||||
}else{
|
||||
$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);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case MC_CLIENT_MESSAGE:
|
||||
if($this->c === false){
|
||||
$this->data["message"] = $this->get(Utils::readShort($this->get(2), false));
|
||||
|
Loading…
x
Reference in New Issue
Block a user