mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
block: added constants for various integer property bounds
This commit is contained in:
@ -40,14 +40,17 @@ use function max;
|
||||
class SnowLayer extends Flowable implements Fallable{
|
||||
use FallableTrait;
|
||||
|
||||
protected int $layers = 1;
|
||||
public const MIN_LAYERS = 1;
|
||||
public const MAX_LAYERS = 8;
|
||||
|
||||
protected int $layers = self::MIN_LAYERS;
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->layers - 1;
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->layers = BlockDataSerializer::readBoundedInt("layers", $stateMeta + 1, 1, 8);
|
||||
$this->layers = BlockDataSerializer::readBoundedInt("layers", $stateMeta + 1, self::MIN_LAYERS, self::MAX_LAYERS);
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
@ -58,15 +61,15 @@ class SnowLayer extends Flowable implements Fallable{
|
||||
|
||||
/** @return $this */
|
||||
public function setLayers(int $layers) : self{
|
||||
if($layers < 1 || $layers > 8){
|
||||
throw new \InvalidArgumentException("Layers must be in range 1-8");
|
||||
if($layers < self::MIN_LAYERS || $layers > self::MAX_LAYERS){
|
||||
throw new \InvalidArgumentException("Layers must be in range " . self::MIN_LAYERS . " ... " . self::MAX_LAYERS);
|
||||
}
|
||||
$this->layers = $layers;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function canBeReplaced() : bool{
|
||||
return $this->layers < 8;
|
||||
return $this->layers < self::MAX_LAYERS;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,12 +81,12 @@ class SnowLayer extends Flowable implements Fallable{
|
||||
}
|
||||
|
||||
private function canBeSupportedBy(Block $b) : bool{
|
||||
return $b->isSolid() || ($b instanceof SnowLayer && $b->isSameType($this) && $b->layers === 8);
|
||||
return $b->isSolid() || ($b instanceof SnowLayer && $b->isSameType($this) && $b->layers === self::MAX_LAYERS);
|
||||
}
|
||||
|
||||
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||
if($blockReplace instanceof SnowLayer){
|
||||
if($blockReplace->layers >= 8){
|
||||
if($blockReplace->layers >= self::MAX_LAYERS){
|
||||
return false;
|
||||
}
|
||||
$this->layers = $blockReplace->layers + 1;
|
||||
|
Reference in New Issue
Block a user