diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 012d47258..919757105 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2063,12 +2063,12 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } $result = $item->onClickAir($this, $directionVector); - if($result === ItemUseResult::success()){ + if($result === ItemUseResult::SUCCESS()){ $this->resetItemCooldown($item); if($this->isSurvival()){ $this->inventory->setItemInHand($item); } - }elseif($result === ItemUseResult::fail()){ + }elseif($result === ItemUseResult::FAIL()){ $this->inventory->sendHeldItem($this); } @@ -2125,12 +2125,12 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, return false; } $result = $item->onReleaseUsing($this); - if($result === ItemUseResult::success()){ + if($result === ItemUseResult::SUCCESS()){ $this->resetItemCooldown($item); $this->inventory->setItemInHand($item); return true; } - if($result === ItemUseResult::fail()){ + if($result === ItemUseResult::FAIL()){ $this->inventory->sendContents($this); return true; } diff --git a/src/pocketmine/block/BlockFactory.php b/src/pocketmine/block/BlockFactory.php index 77761361e..11643f7cc 100644 --- a/src/pocketmine/block/BlockFactory.php +++ b/src/pocketmine/block/BlockFactory.php @@ -375,7 +375,7 @@ class BlockFactory{ } foreach($slabTypes as $type){ self::register($type); - self::register((clone $type)->setSlabType(SlabType::double())); //flattening hack + self::register((clone $type)->setSlabType(SlabType::DOUBLE())); //flattening hack } static $wallTypes = [ diff --git a/src/pocketmine/block/Slab.php b/src/pocketmine/block/Slab.php index 1b34e5f5d..92cb7d791 100644 --- a/src/pocketmine/block/Slab.php +++ b/src/pocketmine/block/Slab.php @@ -40,23 +40,23 @@ abstract class Slab extends Transparent{ public function __construct(int $id, int $doubleId, int $variant = 0, ?string $name = null){ parent::__construct($id, $variant, $name . " Slab", $id); $this->doubleId = $doubleId; - $this->slabType = SlabType::bottom(); + $this->slabType = SlabType::BOTTOM(); } public function getId() : int{ - return $this->slabType === SlabType::double() ? $this->doubleId : parent::getId(); + return $this->slabType === SlabType::DOUBLE() ? $this->doubleId : parent::getId(); } protected function writeStateToMeta() : int{ - if($this->slabType !== SlabType::double()){ - return ($this->slabType === SlabType::top() ? 0x08 : 0); + if($this->slabType !== SlabType::DOUBLE()){ + return ($this->slabType === SlabType::TOP() ? 0x08 : 0); } return 0; } public function readStateFromMeta(int $meta) : void{ - if($this->slabType !== SlabType::double()){ - $this->slabType = ($meta & 0x08) !== 0 ? SlabType::top() : SlabType::bottom(); + if($this->slabType !== SlabType::DOUBLE()){ + $this->slabType = ($meta & 0x08) !== 0 ? SlabType::TOP() : SlabType::BOTTOM(); } } @@ -65,7 +65,7 @@ abstract class Slab extends Transparent{ } public function isTransparent() : bool{ - return $this->slabType !== SlabType::double(); + return $this->slabType !== SlabType::DOUBLE(); } /** @@ -92,8 +92,8 @@ abstract class Slab extends Transparent{ return true; } - if($blockReplace instanceof Slab and $blockReplace->slabType !== SlabType::double() and $blockReplace->isSameType($this)){ - if($blockReplace->slabType === SlabType::top()){ //Trying to combine with top slab + if($blockReplace instanceof Slab and $blockReplace->slabType !== SlabType::DOUBLE() and $blockReplace->isSameType($this)){ + if($blockReplace->slabType === SlabType::TOP()){ //Trying to combine with top slab return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Facing::UP); }else{ return $clickVector->y >= 0.5 or (!$isClickedBlock and $face === Facing::DOWN); @@ -106,35 +106,35 @@ abstract class Slab extends Transparent{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ /* note these conditions can't be merged, since one targets clicked and the other replace */ - if($blockClicked instanceof Slab and $blockClicked->slabType !== SlabType::double() and $blockClicked->isSameType($this) and ( - ($face === Facing::DOWN and $blockClicked->slabType === SlabType::top()) or - ($face === Facing::UP and $blockClicked->slabType === SlabType::bottom()) + if($blockClicked instanceof Slab and $blockClicked->slabType !== SlabType::DOUBLE() and $blockClicked->isSameType($this) and ( + ($face === Facing::DOWN and $blockClicked->slabType === SlabType::TOP()) or + ($face === Facing::UP and $blockClicked->slabType === SlabType::BOTTOM()) )){ - $this->slabType = SlabType::double(); + $this->slabType = SlabType::DOUBLE(); return $this->level->setBlock($blockClicked, $this); } - if($blockReplace instanceof Slab and $blockReplace->slabType !== SlabType::double() and $blockReplace->isSameType($this) and ( - ($blockReplace->slabType === SlabType::top() and ($clickVector->y <= 0.5 or $face === Facing::UP)) or - ($blockReplace->slabType === SlabType::bottom() and ($clickVector->y >= 0.5 or $face === Facing::DOWN)) + if($blockReplace instanceof Slab and $blockReplace->slabType !== SlabType::DOUBLE() and $blockReplace->isSameType($this) and ( + ($blockReplace->slabType === SlabType::TOP() and ($clickVector->y <= 0.5 or $face === Facing::UP)) or + ($blockReplace->slabType === SlabType::BOTTOM() and ($clickVector->y >= 0.5 or $face === Facing::DOWN)) )){ //Clicked in empty half of existing slab - $this->slabType = SlabType::double(); + $this->slabType = SlabType::DOUBLE(); }else{ - $this->slabType = (($face !== Facing::UP && $clickVector->y > 0.5) || $face === Facing::DOWN) ? SlabType::top() : SlabType::bottom(); + $this->slabType = (($face !== Facing::UP && $clickVector->y > 0.5) || $face === Facing::DOWN) ? SlabType::TOP() : SlabType::BOTTOM(); } return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } protected function recalculateBoundingBox() : ?AxisAlignedBB{ - if($this->slabType === SlabType::double()){ + if($this->slabType === SlabType::DOUBLE()){ return parent::recalculateBoundingBox(); } - return AxisAlignedBB::one()->trim($this->slabType === SlabType::top() ? Facing::DOWN : Facing::UP, 0.5); + return AxisAlignedBB::one()->trim($this->slabType === SlabType::TOP() ? Facing::DOWN : Facing::UP, 0.5); } public function getDropsForCompatibleTool(Item $item) : array{ - return [$this->getItem()->setCount($this->slabType === SlabType::double() ? 2 : 1)]; + return [$this->getItem()->setCount($this->slabType === SlabType::DOUBLE() ? 2 : 1)]; } } diff --git a/src/pocketmine/block/utils/SlabType.php b/src/pocketmine/block/utils/SlabType.php index e3ba9d040..57fa535ca 100644 --- a/src/pocketmine/block/utils/SlabType.php +++ b/src/pocketmine/block/utils/SlabType.php @@ -30,19 +30,19 @@ final class SlabType{ */ private $name; - public static function bottom() : self{ + public static function BOTTOM() : self{ /** @var SlabType $ret */ static $ret = null; return $ret ?? ($ret = new self("bottom")); } - public static function top() : self{ + public static function TOP() : self{ /** @var SlabType $ret */ static $ret = null; return $ret ?? ($ret = new self("top")); } - public static function double() : self{ + public static function DOUBLE() : self{ /** @var SlabType $ret */ static $ret = null; return $ret ?? ($ret = new self("double")); diff --git a/src/pocketmine/item/Bow.php b/src/pocketmine/item/Bow.php index ec694619d..f2aefa10d 100644 --- a/src/pocketmine/item/Bow.php +++ b/src/pocketmine/item/Bow.php @@ -49,7 +49,7 @@ class Bow extends Tool{ public function onReleaseUsing(Player $player) : ItemUseResult{ if($player->isSurvival() and !$player->getInventory()->contains(ItemFactory::get(Item::ARROW, 0, 1))){ - return ItemUseResult::fail(); + return ItemUseResult::FAIL(); } $nbt = EntityFactory::createBaseNBT( @@ -92,7 +92,7 @@ class Bow extends Tool{ if($ev->isCancelled()){ $entity->flagForDespawn(); - return ItemUseResult::fail(); + return ItemUseResult::FAIL(); } $entity->setMotion($entity->getMotion()->multiply($ev->getForce())); @@ -102,7 +102,7 @@ class Bow extends Tool{ $projectileEv->call(); if($projectileEv->isCancelled()){ $ev->getProjectile()->flagForDespawn(); - return ItemUseResult::fail(); + return ItemUseResult::FAIL(); } $ev->getProjectile()->spawnToAll(); @@ -118,6 +118,6 @@ class Bow extends Tool{ $this->applyDamage(1); } - return ItemUseResult::success(); + return ItemUseResult::SUCCESS(); } } diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index 5a17c2de1..2b850f749 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -58,12 +58,12 @@ class Bucket extends Item{ }else{ $player->getInventory()->addItem($ev->getItem()); } - return ItemUseResult::success(); + return ItemUseResult::SUCCESS(); } - return ItemUseResult::fail(); + return ItemUseResult::FAIL(); } - return ItemUseResult::none(); + return ItemUseResult::NONE(); } } diff --git a/src/pocketmine/item/FlintSteel.php b/src/pocketmine/item/FlintSteel.php index bb1d94dfd..4bd735a7e 100644 --- a/src/pocketmine/item/FlintSteel.php +++ b/src/pocketmine/item/FlintSteel.php @@ -44,10 +44,10 @@ class FlintSteel extends Tool{ $this->applyDamage(1); - return ItemUseResult::success(); + return ItemUseResult::SUCCESS(); } - return ItemUseResult::none(); + return ItemUseResult::NONE(); } public function getMaxDurability() : int{ diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 743ccb81b..4f3ca5ff9 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -738,7 +738,7 @@ class Item implements ItemIds, \JsonSerializable{ * @return ItemUseResult */ public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult{ - return ItemUseResult::none(); + return ItemUseResult::NONE(); } /** @@ -751,7 +751,7 @@ class Item implements ItemIds, \JsonSerializable{ * @return ItemUseResult */ public function onClickAir(Player $player, Vector3 $directionVector) : ItemUseResult{ - return ItemUseResult::none(); + return ItemUseResult::NONE(); } /** @@ -763,7 +763,7 @@ class Item implements ItemIds, \JsonSerializable{ * @return ItemUseResult */ public function onReleaseUsing(Player $player) : ItemUseResult{ - return ItemUseResult::none(); + return ItemUseResult::NONE(); } /** diff --git a/src/pocketmine/item/ItemUseResult.php b/src/pocketmine/item/ItemUseResult.php index 78b89802c..90e8b4724 100644 --- a/src/pocketmine/item/ItemUseResult.php +++ b/src/pocketmine/item/ItemUseResult.php @@ -36,7 +36,7 @@ final class ItemUseResult{ * * @return ItemUseResult */ - public static function none() : ItemUseResult{ + public static function NONE() : ItemUseResult{ return self::$NONE ?? (self::$NONE = new self()); } @@ -46,7 +46,7 @@ final class ItemUseResult{ * * @return ItemUseResult */ - public static function fail() : ItemUseResult{ + public static function FAIL() : ItemUseResult{ return self::$FAILED ?? (self::$FAILED = new self()); } @@ -55,7 +55,7 @@ final class ItemUseResult{ * * @return ItemUseResult */ - public static function success() : ItemUseResult{ + public static function SUCCESS() : ItemUseResult{ return self::$SUCCEEDED ?? (self::$SUCCEEDED = new self()); } diff --git a/src/pocketmine/item/LiquidBucket.php b/src/pocketmine/item/LiquidBucket.php index 21a76b45e..f8d9eb5e5 100644 --- a/src/pocketmine/item/LiquidBucket.php +++ b/src/pocketmine/item/LiquidBucket.php @@ -54,7 +54,7 @@ class LiquidBucket extends Item{ public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult{ if(!$blockReplace->canBeReplaced()){ - return ItemUseResult::none(); + return ItemUseResult::NONE(); } //TODO: move this to generic placement logic @@ -69,12 +69,12 @@ class LiquidBucket extends Item{ if($player->isSurvival()){ $player->getInventory()->setItemInHand($ev->getItem()); } - return ItemUseResult::success(); + return ItemUseResult::SUCCESS(); } - return ItemUseResult::fail(); + return ItemUseResult::FAIL(); } - return ItemUseResult::none(); + return ItemUseResult::NONE(); } } diff --git a/src/pocketmine/item/PaintingItem.php b/src/pocketmine/item/PaintingItem.php index 115a462da..e577d9b49 100644 --- a/src/pocketmine/item/PaintingItem.php +++ b/src/pocketmine/item/PaintingItem.php @@ -40,7 +40,7 @@ class PaintingItem extends Item{ public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult{ if(Facing::axis($face) === Facing::AXIS_Y){ - return ItemUseResult::none(); + return ItemUseResult::NONE(); } $motives = []; @@ -68,7 +68,7 @@ class PaintingItem extends Item{ } if(empty($motives)){ //No space available - return ItemUseResult::none(); + return ItemUseResult::NONE(); } /** @var PaintingMotive $motive */ @@ -83,7 +83,7 @@ class PaintingItem extends Item{ $direction = $directions[$face] ?? -1; if($direction === -1){ - return ItemUseResult::none(); + return ItemUseResult::NONE(); } $nbt = EntityFactory::createBaseNBT($blockReplace, null, $direction * 90, 0); @@ -99,6 +99,6 @@ class PaintingItem extends Item{ $entity->spawnToAll(); $player->getLevel()->broadcastLevelEvent($blockReplace->add(0.5, 0.5, 0.5), LevelEventPacket::EVENT_SOUND_ITEMFRAME_PLACE); //item frame and painting have the same sound - return ItemUseResult::success(); + return ItemUseResult::SUCCESS(); } } diff --git a/src/pocketmine/item/ProjectileItem.php b/src/pocketmine/item/ProjectileItem.php index 02b564d13..4208434d7 100644 --- a/src/pocketmine/item/ProjectileItem.php +++ b/src/pocketmine/item/ProjectileItem.php @@ -68,7 +68,7 @@ abstract class ProjectileItem extends Item{ $projectileEv->call(); if($projectileEv->isCancelled()){ $projectile->flagForDespawn(); - return ItemUseResult::fail(); + return ItemUseResult::FAIL(); } $projectile->spawnToAll(); @@ -77,6 +77,6 @@ abstract class ProjectileItem extends Item{ $this->pop(); - return ItemUseResult::success(); + return ItemUseResult::SUCCESS(); } } diff --git a/src/pocketmine/item/SpawnEgg.php b/src/pocketmine/item/SpawnEgg.php index 364280928..6fd053a1f 100644 --- a/src/pocketmine/item/SpawnEgg.php +++ b/src/pocketmine/item/SpawnEgg.php @@ -61,6 +61,6 @@ class SpawnEgg extends Item{ $this->pop(); $entity->spawnToAll(); //TODO: what if the entity was marked for deletion? - return ItemUseResult::success(); + return ItemUseResult::SUCCESS(); } } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 297c067bd..274a0bdf6 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1798,8 +1798,8 @@ class Level implements ChunkManager, Metadatable{ if(!$player->isSneaking()){ $result = $item->onActivate($player, $blockReplace, $blockClicked, $face, $clickVector); - if($result !== ItemUseResult::none()){ - return $result === ItemUseResult::success(); + if($result !== ItemUseResult::NONE()){ + return $result === ItemUseResult::SUCCESS(); } } }else{