mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-21 10:26:38 +00:00
Standardise SNAKE_CASE for surrogate enums
This commit is contained in:
parent
36e9db4c07
commit
2c8a065b94
@ -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;
|
||||
}
|
||||
|
@ -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 = [
|
||||
|
@ -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)];
|
||||
}
|
||||
}
|
||||
|
@ -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"));
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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{
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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{
|
||||
|
Loading…
x
Reference in New Issue
Block a user