mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
Better addItem for MCPE 0.5.0 and below
This commit is contained in:
parent
5b4110b285
commit
8e24f49e8a
1 changed files with 71 additions and 2 deletions
|
|
@ -826,9 +826,34 @@ class Player{
|
|||
|
||||
$this->inventory[$slot] = $item;
|
||||
|
||||
if($this->PROTOCOL >= ProtocolInfo9::CURRENT_PROTOCOL_9){
|
||||
if($send === true){
|
||||
$this->sendInventorySlot($slot);
|
||||
}
|
||||
}elseif($send && $item->getID() !== AIR){
|
||||
$dropitem = $item;
|
||||
if($item->getID() === $old->getID() && $item->getMetadata() === $old->getMetadata() && $item->count > $old->count){
|
||||
$dropitem = BlockAPI::getItem($item->getID(), $item->getMetadata(), $item->count - $old->count);
|
||||
}
|
||||
$data = [
|
||||
"x" => $this->entity->x,
|
||||
"y" => $this->entity->y - 0.3 + $this->entity->height - 0.12,
|
||||
"z" => $this->entity->z,
|
||||
"level" => $this->level,
|
||||
"speedX" => 0,
|
||||
"speedY" => 0,
|
||||
"speedZ" => 0,
|
||||
"item" => $dropitem,
|
||||
"itemID" => $dropitem->getID()
|
||||
];
|
||||
$e = $this->server->api->entity->add($this->level, ENTITY_ITEM, ENTITY_ITEM_TYPE, $data);
|
||||
$e->spawn($this);
|
||||
$pk = new TakeItemEntityPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->target = $e->eid;
|
||||
$this->entityQueueDataPacket($pk);
|
||||
$e->close();
|
||||
}
|
||||
|
||||
if($addexpected){
|
||||
$this->addExpectedSetSlotPacket($slot, $item->getID(), $item->getMetadata(), $item->count);
|
||||
|
|
@ -1314,7 +1339,29 @@ class Player{
|
|||
continue;
|
||||
}
|
||||
$item->count += $add;
|
||||
if($this->PROTOCOL >= ProtocolInfo9::CURRENT_PROTOCOL_9){
|
||||
if($send) $this->sendInventorySlot($s);
|
||||
}elseif($send){
|
||||
$dropitem = BlockAPI::getItem($type, $damage, $add);
|
||||
$data = [
|
||||
"x" => $this->entity->x,
|
||||
"y" => $this->entity->y - 0.3 + $this->entity->height - 0.12,
|
||||
"z" => $this->entity->z,
|
||||
"level" => $this->level,
|
||||
"speedX" => 0,
|
||||
"speedY" => 0,
|
||||
"speedZ" => 0,
|
||||
"item" => $dropitem,
|
||||
"itemID" => $dropitem->getID()
|
||||
];
|
||||
$e = $this->server->api->entity->add($this->level, ENTITY_ITEM, ENTITY_ITEM_TYPE, $data);
|
||||
$e->spawn($this);
|
||||
$pk = new TakeItemEntityPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->target = $e->eid;
|
||||
$this->entityQueueDataPacket($pk);
|
||||
$e->close();
|
||||
}
|
||||
if($addexpected) $this->addExpectedSetSlotPacket($s, $item->getID(), $item->getMetadata(), $item->count);
|
||||
|
||||
$count -= $add;
|
||||
|
|
@ -1327,7 +1374,29 @@ class Player{
|
|||
$add = min($toadd->getMaxStackSize(), $count);
|
||||
$this->inventory[$s] = BlockAPI::getItem($type, $damage, $add);
|
||||
|
||||
if($this->PROTOCOL >= ProtocolInfo9::CURRENT_PROTOCOL_9){
|
||||
if($send) $this->sendInventorySlot($s);
|
||||
}elseif($send){
|
||||
$dropitem = BlockAPI::getItem($type, $damage, $add);
|
||||
$data = [
|
||||
"x" => $this->entity->x,
|
||||
"y" => $this->entity->y - 0.3 + $this->entity->height - 0.12,
|
||||
"z" => $this->entity->z,
|
||||
"level" => $this->level,
|
||||
"speedX" => 0,
|
||||
"speedY" => 0,
|
||||
"speedZ" => 0,
|
||||
"item" => $dropitem,
|
||||
"itemID" => $dropitem->getID()
|
||||
];
|
||||
$e = $this->server->api->entity->add($this->level, ENTITY_ITEM, ENTITY_ITEM_TYPE, $data);
|
||||
$e->spawn($this);
|
||||
$pk = new TakeItemEntityPacket;
|
||||
$pk->eid = $this->eid;
|
||||
$pk->target = $e->eid;
|
||||
$this->entityQueueDataPacket($pk);
|
||||
$e->close();
|
||||
}
|
||||
|
||||
if($addexpected) $this->addExpectedSetSlotPacket($s, $type, $damage, $add);
|
||||
$count -= $add;
|
||||
|
|
@ -3972,7 +4041,7 @@ class Player{
|
|||
* Dont use this if the protocol version >= MCPE 0.7
|
||||
* @return Boolean
|
||||
*/
|
||||
public function setCurrentSlot(Item $heldItem){
|
||||
private function setCurrentSlot(Item $heldItem){
|
||||
return $this->slot = $this->hasItem($heldItem->getID(), $heldItem->getMetadata()) ?: 0;
|
||||
}
|
||||
|
||||
|
|
@ -4153,7 +4222,7 @@ class Player{
|
|||
return $countedItem;
|
||||
}
|
||||
|
||||
public function getAccurateItemSlot($type, $damage, $count){
|
||||
private function getAccurateItemSlot($type, $damage, $count){
|
||||
foreach($this->inventory as $s => $item){
|
||||
if($item->getID() === $type && ($item->getMetadata() === $damage || $damage === false) && $item->count === $count){
|
||||
return $s;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue