mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 06:55:29 +00:00
Added API method Item->pop()
This commit is contained in:
parent
7a77bb0402
commit
c47f1f572c
@ -112,14 +112,8 @@ class FlowerPot extends Flowable{
|
|||||||
|
|
||||||
$this->setDamage(self::STATE_FULL); //specific damage value is unnecessary, it just needs to be non-zero to show an item.
|
$this->setDamage(self::STATE_FULL); //specific damage value is unnecessary, it just needs to be non-zero to show an item.
|
||||||
$this->getLevel()->setBlock($this, $this, true, false);
|
$this->getLevel()->setBlock($this, $this, true, false);
|
||||||
$pot->setItem($item);
|
$pot->setItem($item->pop());
|
||||||
|
|
||||||
if($player instanceof Player){
|
|
||||||
if($player->isSurvival()){
|
|
||||||
$item->setCount($item->getCount() - 1);
|
|
||||||
$player->getInventory()->setItemInHand($item->getCount() > 0 ? $item : ItemFactory::get(Item::AIR));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,16 +63,8 @@ class ItemFrame extends Flowable{
|
|||||||
|
|
||||||
if($tile->hasItem()){
|
if($tile->hasItem()){
|
||||||
$tile->setItemRotation(($tile->getItemRotation() + 1) % 8);
|
$tile->setItemRotation(($tile->getItemRotation() + 1) % 8);
|
||||||
}else{
|
}elseif(!$item->isNull()){
|
||||||
if($item->getCount() > 0){
|
$tile->setItem($item->pop());
|
||||||
$frameItem = clone $item;
|
|
||||||
$frameItem->setCount(1);
|
|
||||||
$item->setCount($item->getCount() - 1);
|
|
||||||
$tile->setItem($frameItem);
|
|
||||||
if($player instanceof Player and $player->isSurvival()){
|
|
||||||
$player->getInventory()->setItemInHand($item->getCount() <= 0 ? ItemFactory::get(Item::AIR) : $item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -82,12 +82,8 @@ class ShapelessRecipe implements CraftingRecipe{
|
|||||||
throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients");
|
throw new \InvalidArgumentException("Shapeless recipes cannot have more than 9 ingredients");
|
||||||
}
|
}
|
||||||
|
|
||||||
$it = clone $item;
|
|
||||||
$it->setCount(1);
|
|
||||||
|
|
||||||
while($item->getCount() > 0){
|
while($item->getCount() > 0){
|
||||||
$this->ingredients[] = clone $it;
|
$this->ingredients[] = $item->pop();
|
||||||
$item->setCount($item->getCount() - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -105,7 +101,7 @@ class ShapelessRecipe implements CraftingRecipe{
|
|||||||
}
|
}
|
||||||
if($ingredient->equals($item, !$item->hasAnyDamageValue(), $item->hasCompoundTag())){
|
if($ingredient->equals($item, !$item->hasAnyDamageValue(), $item->hasCompoundTag())){
|
||||||
unset($this->ingredients[$index]);
|
unset($this->ingredients[$index]);
|
||||||
$item->setCount($item->getCount() - 1);
|
$item->pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,6 +643,25 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pops an item from the stack and returns it, decreasing the stack count of this item stack by one.
|
||||||
|
* @return Item
|
||||||
|
*
|
||||||
|
* @throws \InvalidStateException if the count is less than or equal to zero, or if the stack is air.
|
||||||
|
*/
|
||||||
|
public function pop() : Item{
|
||||||
|
if($this->isNull()){
|
||||||
|
throw new \InvalidStateException("Cannot pop an item from a null stack");
|
||||||
|
}
|
||||||
|
|
||||||
|
$item = clone $this;
|
||||||
|
$item->setCount(1);
|
||||||
|
|
||||||
|
$this->count--;
|
||||||
|
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
|
||||||
public function isNull() : bool{
|
public function isNull() : bool{
|
||||||
return $this->count <= 0 or $this->id === Item::AIR;
|
return $this->count <= 0 or $this->id === Item::AIR;
|
||||||
}
|
}
|
||||||
|
@ -1823,10 +1823,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$this->broadcastLevelSoundEvent($hand, LevelSoundEventPacket::SOUND_PLACE, 1, $hand->getId());
|
$this->broadcastLevelSoundEvent($hand, LevelSoundEventPacket::SOUND_PLACE, 1, $hand->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
$item->setCount($item->getCount() - 1);
|
$item->pop();
|
||||||
if($item->getCount() <= 0){
|
|
||||||
$item = ItemFactory::get(Item::AIR, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -201,10 +201,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($this->namedtag->BurnTime->getValue() > 0 and $ev->isBurning()){
|
if($this->namedtag->BurnTime->getValue() > 0 and $ev->isBurning()){
|
||||||
$fuel->setCount($fuel->getCount() - 1);
|
$fuel->pop();
|
||||||
if($fuel->getCount() === 0){
|
|
||||||
$fuel = ItemFactory::get(Item::AIR, 0, 0);
|
|
||||||
}
|
|
||||||
$this->inventory->setFuel($fuel);
|
$this->inventory->setFuel($fuel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,10 +238,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
|||||||
|
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->inventory->setResult($ev->getResult());
|
$this->inventory->setResult($ev->getResult());
|
||||||
$raw->setCount($raw->getCount() - 1);
|
$raw->pop();
|
||||||
if($raw->getCount() === 0){
|
|
||||||
$raw = ItemFactory::get(Item::AIR, 0, 0);
|
|
||||||
}
|
|
||||||
$this->inventory->setSmelting($raw);
|
$this->inventory->setSmelting($raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user