mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Added ItemFactory::air() sugar
This makes it easier to create air stacks without accidents, and also reduces the amount of throwaway air objects which get created.
This commit is contained in:
@ -36,7 +36,7 @@ class FlintSteel extends Tool{
|
||||
}
|
||||
|
||||
public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult{
|
||||
if($blockReplace->getId() === self::AIR){
|
||||
if($blockReplace->getId() === Block::AIR){
|
||||
$level = $player->getLevel();
|
||||
assert($level !== null);
|
||||
$level->setBlock($blockReplace, BlockFactory::get(Block::FIRE));
|
||||
|
@ -34,7 +34,7 @@ abstract class Food extends Item implements FoodSource{
|
||||
* @return Item
|
||||
*/
|
||||
public function getResidue(){
|
||||
return ItemFactory::get(Item::AIR, 0, 0);
|
||||
return ItemFactory::air();
|
||||
}
|
||||
|
||||
public function getAdditionalEffects() : array{
|
||||
|
@ -640,7 +640,7 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
* @return Block
|
||||
*/
|
||||
public function getBlock() : Block{
|
||||
return BlockFactory::get(self::AIR);
|
||||
return BlockFactory::get(Block::AIR);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -939,7 +939,7 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
$item = ItemFactory::fromString($idTag->getValue() . ":$meta");
|
||||
}catch(\InvalidArgumentException $e){
|
||||
//TODO: improve error handling
|
||||
return ItemFactory::get(Item::AIR, 0, 0);
|
||||
return ItemFactory::air();
|
||||
}
|
||||
$item->setCount($count);
|
||||
}else{
|
||||
|
@ -47,6 +47,9 @@ class ItemFactory{
|
||||
/** @var \SplFixedArray */
|
||||
private static $list = [];
|
||||
|
||||
/** @var Item|null */
|
||||
private static $air = null;
|
||||
|
||||
public static function init(){
|
||||
self::$list = []; //in case of re-initializing
|
||||
|
||||
@ -423,6 +426,10 @@ class ItemFactory{
|
||||
return $item;
|
||||
}
|
||||
|
||||
public static function air() : Item{
|
||||
return self::$air ?? (self::$air = self::get(ItemIds::AIR, 0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the specified item ID is already registered in the item factory.
|
||||
*
|
||||
|
Reference in New Issue
Block a user