mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
Fixed Inventory::addItem() not adding items properly
This commit is contained in:
parent
b9ec63f016
commit
70e340086d
@ -1227,8 +1227,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->inventory->addItem(clone $item);
|
|
||||||
|
|
||||||
$pk = new TakeItemEntityPacket;
|
$pk = new TakeItemEntityPacket;
|
||||||
$pk->eid = 0;
|
$pk->eid = 0;
|
||||||
$pk->target = $entity->getID();
|
$pk->target = $entity->getID();
|
||||||
@ -1238,6 +1236,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$pk->eid = $this->getID();
|
$pk->eid = $this->getID();
|
||||||
$pk->target = $entity->getID();
|
$pk->target = $entity->getID();
|
||||||
$this->server->broadcastPacket($entity->getViewers(), $pk);
|
$this->server->broadcastPacket($entity->getViewers(), $pk);
|
||||||
|
$this->inventory->addItem(clone $item);
|
||||||
$entity->kill();
|
$entity->kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,33 +228,29 @@ abstract class BaseInventory implements Inventory{
|
|||||||
/** @var Item[] $slots */
|
/** @var Item[] $slots */
|
||||||
$slots = func_get_args();
|
$slots = func_get_args();
|
||||||
foreach($slots as $i => $slot){
|
foreach($slots as $i => $slot){
|
||||||
while($slot->getCount() > $slot->getMaxStackSize()){
|
$slots[$i] = clone $slot;
|
||||||
$slots[] = Item::get($slot->getID(), $slot->getDamage(), $slot->getMaxStackSize());
|
|
||||||
$slot->setCount($slot->getCount() - $slot->getMaxStackSize());
|
|
||||||
if(count($slots) > $this->getSize()){ //Protect against large give commands
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for($i = 0; $i < $this->getSize(); ++$i){
|
for($i = 0; $i < $this->getSize(); ++$i){
|
||||||
$item = $this->getItem($i);
|
$item = $this->getItem($i);
|
||||||
if($item->getID() === Item::AIR){
|
|
||||||
$this->setItem($i, array_shift($slots));
|
|
||||||
$item = $this->getItem($i);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($slots as $index => $slot){
|
foreach($slots as $index => $slot){
|
||||||
if($slot->equals($item, $slot->getDamage() === null ? false : true)){
|
if($item->getID() === Item::AIR){
|
||||||
if($item->getCount() < $item->getMaxStackSize()){
|
$amount = min($slot->getMaxStackSize(), $slot->getCount(), $this->getMaxStackSize());
|
||||||
$amount = min($item->getMaxStackSize() - $item->getCount(), $slot->getCount(), $this->getMaxStackSize());
|
|
||||||
$slot->setCount($slot->getCount() - $amount);
|
$slot->setCount($slot->getCount() - $amount);
|
||||||
$old = clone $item;
|
$item = clone $slot;
|
||||||
$item->setCount($item->getCount() + $amount);
|
$item->setCount($amount);
|
||||||
$this->onSlotChange($i, $old);
|
$this->setItem($i, $item);
|
||||||
|
$item = $this->getItem($i);
|
||||||
if($slot->getCount() <= 0){
|
if($slot->getCount() <= 0){
|
||||||
unset($slots[$index]);
|
unset($slots[$index]);
|
||||||
}
|
}
|
||||||
|
}elseif($slot->equals($item, true) and $item->getCount() < $item->getMaxStackSize()){
|
||||||
|
$amount = min($item->getMaxStackSize() - $item->getCount(), $slot->getCount(), $this->getMaxStackSize());
|
||||||
|
$slot->setCount($slot->getCount() - $amount);
|
||||||
|
$item->setCount($item->getCount() + $amount);
|
||||||
|
$this->setItem($i, $item);
|
||||||
|
if($slot->getCount() <= 0){
|
||||||
|
unset($slots[$index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user