Added VanillaItems::AIR()

we don't usually add VanillaItems entries for blocks since they already exist in VanillaBlocks, but air has a special use case specifically as an itemstack, so we make an exception for this case.
This commit is contained in:
Dylan K. Taylor 2021-12-07 00:41:07 +00:00
parent ce54d268f2
commit ed4978c31b
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
14 changed files with 32 additions and 25 deletions

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block\tile;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\world\World;
@ -46,7 +46,7 @@ class ItemFrame extends Spawnable{
private $itemDropChance = 1.0;
public function __construct(World $world, Vector3 $pos){
$this->item = ItemFactory::air();
$this->item = VanillaItems::AIR();
parent::__construct($world, $pos);
}
@ -76,7 +76,7 @@ class ItemFrame extends Spawnable{
if($item !== null and !$item->isNull()){
$this->item = clone $item;
}else{
$this->item = ItemFactory::air();
$this->item = VanillaItems::AIR();
}
}

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\crafting;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use pocketmine\utils\Utils;
use function array_values;
use function count;
@ -155,7 +155,7 @@ class ShapedRecipe implements CraftingRecipe{
public function getIngredient(int $x, int $y) : Item{
$exists = $this->ingredientList[$this->shape[$y][$x]] ?? null;
return $exists !== null ? clone $exists : ItemFactory::air();
return $exists !== null ? clone $exists : VanillaItems::AIR();
}
/**

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\inventory;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use pocketmine\player\Player;
use pocketmine\utils\ObjectSet;
use function array_slice;
@ -89,7 +89,7 @@ abstract class BaseInventory implements Inventory{
public function setItem(int $index, Item $item) : void{
if($item->isNull()){
$item = ItemFactory::air();
$item = VanillaItems::AIR();
}else{
$item = clone $item;
}
@ -290,7 +290,7 @@ abstract class BaseInventory implements Inventory{
}
public function clear(int $index) : void{
$this->setItem($index, ItemFactory::air());
$this->setItem($index, VanillaItems::AIR());
}
public function clearAll() : void{

View File

@ -24,7 +24,7 @@ declare(strict_types=1);
namespace pocketmine\inventory;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
/**
* This class provides a complete implementation of a regular inventory.
@ -49,7 +49,7 @@ class SimpleInventory extends BaseInventory{
}
public function getItem(int $index) : Item{
return $this->slots[$index] !== null ? clone $this->slots[$index] : ItemFactory::air();
return $this->slots[$index] !== null ? clone $this->slots[$index] : VanillaItems::AIR();
}
/**
@ -62,7 +62,7 @@ class SimpleInventory extends BaseInventory{
if($slot !== null){
$contents[$i] = clone $slot;
}elseif($includeEmpty){
$contents[$i] = ItemFactory::air();
$contents[$i] = VanillaItems::AIR();
}
}

View File

@ -27,7 +27,7 @@ use pocketmine\inventory\BaseInventory;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\transaction\action\SlotChangeAction;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
/**
* This class facilitates generating SlotChangeActions to build an inventory transaction.
@ -62,7 +62,7 @@ final class TransactionBuilderInventory extends BaseInventory{
protected function internalSetItem(int $index, Item $item) : void{
if(!$item->equalsExact($this->actualInventory->getItem($index))){
$this->changedSlots[$index] = $item->isNull() ? ItemFactory::air() : clone $item;
$this->changedSlots[$index] = $item->isNull() ? VanillaItems::AIR() : clone $item;
}
}

View File

@ -26,7 +26,7 @@ namespace pocketmine\inventory\transaction\action;
use pocketmine\inventory\CreativeInventory;
use pocketmine\inventory\transaction\TransactionValidationException;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use pocketmine\player\Player;
/**
@ -36,7 +36,7 @@ use pocketmine\player\Player;
class CreateItemAction extends InventoryAction{
public function __construct(Item $sourceItem){
parent::__construct($sourceItem, ItemFactory::air());
parent::__construct($sourceItem, VanillaItems::AIR());
}
public function validate(Player $source) : void{

View File

@ -25,7 +25,7 @@ namespace pocketmine\inventory\transaction\action;
use pocketmine\inventory\transaction\TransactionValidationException;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use pocketmine\player\Player;
/**
@ -35,7 +35,7 @@ use pocketmine\player\Player;
class DestroyItemAction extends InventoryAction{
public function __construct(Item $targetItem){
parent::__construct(ItemFactory::air(), $targetItem);
parent::__construct(VanillaItems::AIR(), $targetItem);
}
public function validate(Player $source) : void{

View File

@ -26,7 +26,7 @@ namespace pocketmine\inventory\transaction\action;
use pocketmine\event\player\PlayerDropItemEvent;
use pocketmine\inventory\transaction\TransactionValidationException;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use pocketmine\player\Player;
/**
@ -35,7 +35,7 @@ use pocketmine\player\Player;
class DropItemAction extends InventoryAction{
public function __construct(Item $targetItem){
parent::__construct(ItemFactory::air(), $targetItem);
parent::__construct(VanillaItems::AIR(), $targetItem);
}
public function validate(Player $source) : void{

View File

@ -32,7 +32,7 @@ abstract class Food extends Item implements FoodSourceItem{
}
public function getResidue() : Item{
return ItemFactory::air();
return VanillaItems::AIR();
}
public function getAdditionalEffects() : array{

View File

@ -691,7 +691,7 @@ class Item implements \JsonSerializable{
$item = LegacyStringToItemParser::getInstance()->parse($idTag->getValue() . ":$meta");
}catch(LegacyStringToItemParserException $e){
//TODO: improve error handling
return ItemFactory::air();
return VanillaItems::AIR();
}
$item->setCount($count);
}else{

View File

@ -478,6 +478,10 @@ class ItemFactory{
return $item;
}
/**
* @deprecated
* @see VanillaItems::AIR()
*/
public static function air() : Item{
return self::getInstance()->get(ItemIds::AIR, 0, 0);
}

View File

@ -32,6 +32,7 @@ use pocketmine\utils\CloningRegistryTrait;
* @generate-registry-docblock
*
* @method static Boat ACACIA_BOAT()
* @method static ItemBlock AIR()
* @method static Apple APPLE()
* @method static Arrow ARROW()
* @method static Potion AWKWARD_POTION()
@ -392,6 +393,8 @@ final class VanillaItems{
protected static function setup() : void{
$factory = ItemFactory::getInstance();
self::register("air", $factory->get(ItemIds::AIR, 0, 0));
self::register("acacia_boat", $factory->get(333, 4));
self::register("apple", $factory->get(260));
self::register("arrow", $factory->get(262));

View File

@ -32,7 +32,7 @@ use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityExplodeEvent;
use pocketmine\item\ItemFactory;
use pocketmine\item\VanillaItems;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
use pocketmine\world\format\SubChunk;
@ -208,7 +208,7 @@ class Explosion{
}
}
$air = ItemFactory::air();
$air = VanillaItems::AIR();
$airBlock = VanillaBlocks::AIR();
foreach($this->affectedBlocks as $block){

View File

@ -52,9 +52,9 @@ use pocketmine\event\world\ChunkUnloadEvent;
use pocketmine\event\world\SpawnChangeEvent;
use pocketmine\event\world\WorldSaveEvent;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\item\ItemUseResult;
use pocketmine\item\LegacyStringToItemParser;
use pocketmine\item\VanillaItems;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Vector3;
@ -1687,7 +1687,7 @@ class World implements ChunkManager{
$affectedBlocks = $target->getAffectedBlocks();
if($item === null){
$item = ItemFactory::air();
$item = VanillaItems::AIR();
}
$drops = [];