Standardise SNAKE_CASE for surrogate enums

This commit is contained in:
Dylan K. Taylor 2019-02-20 11:14:07 +00:00
parent 36e9db4c07
commit 2c8a065b94
14 changed files with 57 additions and 57 deletions

View File

@ -2063,12 +2063,12 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
} }
$result = $item->onClickAir($this, $directionVector); $result = $item->onClickAir($this, $directionVector);
if($result === ItemUseResult::success()){ if($result === ItemUseResult::SUCCESS()){
$this->resetItemCooldown($item); $this->resetItemCooldown($item);
if($this->isSurvival()){ if($this->isSurvival()){
$this->inventory->setItemInHand($item); $this->inventory->setItemInHand($item);
} }
}elseif($result === ItemUseResult::fail()){ }elseif($result === ItemUseResult::FAIL()){
$this->inventory->sendHeldItem($this); $this->inventory->sendHeldItem($this);
} }
@ -2125,12 +2125,12 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
return false; return false;
} }
$result = $item->onReleaseUsing($this); $result = $item->onReleaseUsing($this);
if($result === ItemUseResult::success()){ if($result === ItemUseResult::SUCCESS()){
$this->resetItemCooldown($item); $this->resetItemCooldown($item);
$this->inventory->setItemInHand($item); $this->inventory->setItemInHand($item);
return true; return true;
} }
if($result === ItemUseResult::fail()){ if($result === ItemUseResult::FAIL()){
$this->inventory->sendContents($this); $this->inventory->sendContents($this);
return true; return true;
} }

View File

@ -375,7 +375,7 @@ class BlockFactory{
} }
foreach($slabTypes as $type){ foreach($slabTypes as $type){
self::register($type); self::register($type);
self::register((clone $type)->setSlabType(SlabType::double())); //flattening hack self::register((clone $type)->setSlabType(SlabType::DOUBLE())); //flattening hack
} }
static $wallTypes = [ static $wallTypes = [

View File

@ -40,23 +40,23 @@ abstract class Slab extends Transparent{
public function __construct(int $id, int $doubleId, int $variant = 0, ?string $name = null){ public function __construct(int $id, int $doubleId, int $variant = 0, ?string $name = null){
parent::__construct($id, $variant, $name . " Slab", $id); parent::__construct($id, $variant, $name . " Slab", $id);
$this->doubleId = $doubleId; $this->doubleId = $doubleId;
$this->slabType = SlabType::bottom(); $this->slabType = SlabType::BOTTOM();
} }
public function getId() : int{ 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{ protected function writeStateToMeta() : int{
if($this->slabType !== SlabType::double()){ if($this->slabType !== SlabType::DOUBLE()){
return ($this->slabType === SlabType::top() ? 0x08 : 0); return ($this->slabType === SlabType::TOP() ? 0x08 : 0);
} }
return 0; return 0;
} }
public function readStateFromMeta(int $meta) : void{ public function readStateFromMeta(int $meta) : void{
if($this->slabType !== SlabType::double()){ if($this->slabType !== SlabType::DOUBLE()){
$this->slabType = ($meta & 0x08) !== 0 ? SlabType::top() : SlabType::bottom(); $this->slabType = ($meta & 0x08) !== 0 ? SlabType::TOP() : SlabType::BOTTOM();
} }
} }
@ -65,7 +65,7 @@ abstract class Slab extends Transparent{
} }
public function isTransparent() : bool{ 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; return true;
} }
if($blockReplace instanceof Slab and $blockReplace->slabType !== SlabType::double() and $blockReplace->isSameType($this)){ 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->slabType === SlabType::TOP()){ //Trying to combine with top slab
return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Facing::UP); return $clickVector->y <= 0.5 or (!$isClickedBlock and $face === Facing::UP);
}else{ }else{
return $clickVector->y >= 0.5 or (!$isClickedBlock and $face === Facing::DOWN); 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{ 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 */ /* 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 ( 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::DOWN and $blockClicked->slabType === SlabType::TOP()) or
($face === Facing::UP and $blockClicked->slabType === SlabType::bottom()) ($face === Facing::UP and $blockClicked->slabType === SlabType::BOTTOM())
)){ )){
$this->slabType = SlabType::double(); $this->slabType = SlabType::DOUBLE();
return $this->level->setBlock($blockClicked, $this); return $this->level->setBlock($blockClicked, $this);
} }
if($blockReplace instanceof Slab and $blockReplace->slabType !== SlabType::double() and $blockReplace->isSameType($this) and ( 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::TOP() and ($clickVector->y <= 0.5 or $face === Facing::UP)) or
($blockReplace->slabType === SlabType::bottom() and ($clickVector->y >= 0.5 or $face === Facing::DOWN)) ($blockReplace->slabType === SlabType::BOTTOM() and ($clickVector->y >= 0.5 or $face === Facing::DOWN))
)){ )){
//Clicked in empty half of existing slab //Clicked in empty half of existing slab
$this->slabType = SlabType::double(); $this->slabType = SlabType::DOUBLE();
}else{ }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); return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
if($this->slabType === SlabType::double()){ if($this->slabType === SlabType::DOUBLE()){
return parent::recalculateBoundingBox(); 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{ 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)];
} }
} }

View File

@ -30,19 +30,19 @@ final class SlabType{
*/ */
private $name; private $name;
public static function bottom() : self{ public static function BOTTOM() : self{
/** @var SlabType $ret */ /** @var SlabType $ret */
static $ret = null; static $ret = null;
return $ret ?? ($ret = new self("bottom")); return $ret ?? ($ret = new self("bottom"));
} }
public static function top() : self{ public static function TOP() : self{
/** @var SlabType $ret */ /** @var SlabType $ret */
static $ret = null; static $ret = null;
return $ret ?? ($ret = new self("top")); return $ret ?? ($ret = new self("top"));
} }
public static function double() : self{ public static function DOUBLE() : self{
/** @var SlabType $ret */ /** @var SlabType $ret */
static $ret = null; static $ret = null;
return $ret ?? ($ret = new self("double")); return $ret ?? ($ret = new self("double"));

View File

@ -49,7 +49,7 @@ class Bow extends Tool{
public function onReleaseUsing(Player $player) : ItemUseResult{ public function onReleaseUsing(Player $player) : ItemUseResult{
if($player->isSurvival() and !$player->getInventory()->contains(ItemFactory::get(Item::ARROW, 0, 1))){ if($player->isSurvival() and !$player->getInventory()->contains(ItemFactory::get(Item::ARROW, 0, 1))){
return ItemUseResult::fail(); return ItemUseResult::FAIL();
} }
$nbt = EntityFactory::createBaseNBT( $nbt = EntityFactory::createBaseNBT(
@ -92,7 +92,7 @@ class Bow extends Tool{
if($ev->isCancelled()){ if($ev->isCancelled()){
$entity->flagForDespawn(); $entity->flagForDespawn();
return ItemUseResult::fail(); return ItemUseResult::FAIL();
} }
$entity->setMotion($entity->getMotion()->multiply($ev->getForce())); $entity->setMotion($entity->getMotion()->multiply($ev->getForce()));
@ -102,7 +102,7 @@ class Bow extends Tool{
$projectileEv->call(); $projectileEv->call();
if($projectileEv->isCancelled()){ if($projectileEv->isCancelled()){
$ev->getProjectile()->flagForDespawn(); $ev->getProjectile()->flagForDespawn();
return ItemUseResult::fail(); return ItemUseResult::FAIL();
} }
$ev->getProjectile()->spawnToAll(); $ev->getProjectile()->spawnToAll();
@ -118,6 +118,6 @@ class Bow extends Tool{
$this->applyDamage(1); $this->applyDamage(1);
} }
return ItemUseResult::success(); return ItemUseResult::SUCCESS();
} }
} }

View File

@ -58,12 +58,12 @@ class Bucket extends Item{
}else{ }else{
$player->getInventory()->addItem($ev->getItem()); $player->getInventory()->addItem($ev->getItem());
} }
return ItemUseResult::success(); return ItemUseResult::SUCCESS();
} }
return ItemUseResult::fail(); return ItemUseResult::FAIL();
} }
return ItemUseResult::none(); return ItemUseResult::NONE();
} }
} }

View File

@ -44,10 +44,10 @@ class FlintSteel extends Tool{
$this->applyDamage(1); $this->applyDamage(1);
return ItemUseResult::success(); return ItemUseResult::SUCCESS();
} }
return ItemUseResult::none(); return ItemUseResult::NONE();
} }
public function getMaxDurability() : int{ public function getMaxDurability() : int{

View File

@ -738,7 +738,7 @@ class Item implements ItemIds, \JsonSerializable{
* @return ItemUseResult * @return ItemUseResult
*/ */
public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : 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 * @return ItemUseResult
*/ */
public function onClickAir(Player $player, Vector3 $directionVector) : 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 * @return ItemUseResult
*/ */
public function onReleaseUsing(Player $player) : ItemUseResult{ public function onReleaseUsing(Player $player) : ItemUseResult{
return ItemUseResult::none(); return ItemUseResult::NONE();
} }
/** /**

View File

@ -36,7 +36,7 @@ final class ItemUseResult{
* *
* @return ItemUseResult * @return ItemUseResult
*/ */
public static function none() : ItemUseResult{ public static function NONE() : ItemUseResult{
return self::$NONE ?? (self::$NONE = new self()); return self::$NONE ?? (self::$NONE = new self());
} }
@ -46,7 +46,7 @@ final class ItemUseResult{
* *
* @return ItemUseResult * @return ItemUseResult
*/ */
public static function fail() : ItemUseResult{ public static function FAIL() : ItemUseResult{
return self::$FAILED ?? (self::$FAILED = new self()); return self::$FAILED ?? (self::$FAILED = new self());
} }
@ -55,7 +55,7 @@ final class ItemUseResult{
* *
* @return ItemUseResult * @return ItemUseResult
*/ */
public static function success() : ItemUseResult{ public static function SUCCESS() : ItemUseResult{
return self::$SUCCEEDED ?? (self::$SUCCEEDED = new self()); return self::$SUCCEEDED ?? (self::$SUCCEEDED = new self());
} }

View File

@ -54,7 +54,7 @@ class LiquidBucket extends Item{
public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult{ public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult{
if(!$blockReplace->canBeReplaced()){ if(!$blockReplace->canBeReplaced()){
return ItemUseResult::none(); return ItemUseResult::NONE();
} }
//TODO: move this to generic placement logic //TODO: move this to generic placement logic
@ -69,12 +69,12 @@ class LiquidBucket extends Item{
if($player->isSurvival()){ if($player->isSurvival()){
$player->getInventory()->setItemInHand($ev->getItem()); $player->getInventory()->setItemInHand($ev->getItem());
} }
return ItemUseResult::success(); return ItemUseResult::SUCCESS();
} }
return ItemUseResult::fail(); return ItemUseResult::FAIL();
} }
return ItemUseResult::none(); return ItemUseResult::NONE();
} }
} }

View File

@ -40,7 +40,7 @@ class PaintingItem extends Item{
public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult{ public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : ItemUseResult{
if(Facing::axis($face) === Facing::AXIS_Y){ if(Facing::axis($face) === Facing::AXIS_Y){
return ItemUseResult::none(); return ItemUseResult::NONE();
} }
$motives = []; $motives = [];
@ -68,7 +68,7 @@ class PaintingItem extends Item{
} }
if(empty($motives)){ //No space available if(empty($motives)){ //No space available
return ItemUseResult::none(); return ItemUseResult::NONE();
} }
/** @var PaintingMotive $motive */ /** @var PaintingMotive $motive */
@ -83,7 +83,7 @@ class PaintingItem extends Item{
$direction = $directions[$face] ?? -1; $direction = $directions[$face] ?? -1;
if($direction === -1){ if($direction === -1){
return ItemUseResult::none(); return ItemUseResult::NONE();
} }
$nbt = EntityFactory::createBaseNBT($blockReplace, null, $direction * 90, 0); $nbt = EntityFactory::createBaseNBT($blockReplace, null, $direction * 90, 0);
@ -99,6 +99,6 @@ class PaintingItem extends Item{
$entity->spawnToAll(); $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 $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();
} }
} }

View File

@ -68,7 +68,7 @@ abstract class ProjectileItem extends Item{
$projectileEv->call(); $projectileEv->call();
if($projectileEv->isCancelled()){ if($projectileEv->isCancelled()){
$projectile->flagForDespawn(); $projectile->flagForDespawn();
return ItemUseResult::fail(); return ItemUseResult::FAIL();
} }
$projectile->spawnToAll(); $projectile->spawnToAll();
@ -77,6 +77,6 @@ abstract class ProjectileItem extends Item{
$this->pop(); $this->pop();
return ItemUseResult::success(); return ItemUseResult::SUCCESS();
} }
} }

View File

@ -61,6 +61,6 @@ class SpawnEgg extends Item{
$this->pop(); $this->pop();
$entity->spawnToAll(); $entity->spawnToAll();
//TODO: what if the entity was marked for deletion? //TODO: what if the entity was marked for deletion?
return ItemUseResult::success(); return ItemUseResult::SUCCESS();
} }
} }

View File

@ -1798,8 +1798,8 @@ class Level implements ChunkManager, Metadatable{
if(!$player->isSneaking()){ if(!$player->isSneaking()){
$result = $item->onActivate($player, $blockReplace, $blockClicked, $face, $clickVector); $result = $item->onActivate($player, $blockReplace, $blockClicked, $face, $clickVector);
if($result !== ItemUseResult::none()){ if($result !== ItemUseResult::NONE()){
return $result === ItemUseResult::success(); return $result === ItemUseResult::SUCCESS();
} }
} }
}else{ }else{