TypeConverter: use SingletonTrait

This commit is contained in:
Dylan K. Taylor 2020-05-05 19:22:20 +01:00
parent 9cf410d484
commit dbd51610c3

View File

@ -39,29 +39,14 @@ use pocketmine\network\mcpe\protocol\types\inventory\ItemStack;
use pocketmine\network\mcpe\protocol\types\inventory\NetworkInventoryAction; use pocketmine\network\mcpe\protocol\types\inventory\NetworkInventoryAction;
use pocketmine\network\mcpe\protocol\types\recipe\RecipeIngredient; use pocketmine\network\mcpe\protocol\types\recipe\RecipeIngredient;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\utils\SingletonTrait;
class TypeConverter{ class TypeConverter{
use SingletonTrait;
private const DAMAGE_TAG = "Damage"; //TAG_Int private const DAMAGE_TAG = "Damage"; //TAG_Int
private const DAMAGE_TAG_CONFLICT_RESOLUTION = "___Damage_ProtocolCollisionResolution___"; private const DAMAGE_TAG_CONFLICT_RESOLUTION = "___Damage_ProtocolCollisionResolution___";
/** @var self|null */
private static $instance;
private function __construct(){
//NOOP
}
public static function getInstance() : self{
if(self::$instance === null){
self::$instance = new self;
}
return self::$instance;
}
public static function setInstance(self $instance) : void{
self::$instance = $instance;
}
public function coreItemStackToRecipeIngredient(Item $itemStack) : RecipeIngredient{ public function coreItemStackToRecipeIngredient(Item $itemStack) : RecipeIngredient{
$meta = $itemStack->getMeta(); $meta = $itemStack->getMeta();
return new RecipeIngredient($itemStack->getId(), $meta === -1 ? 0x7fff : $meta, $itemStack->getCount()); return new RecipeIngredient($itemStack->getId(), $meta === -1 ? 0x7fff : $meta, $itemStack->getCount());