Block: rename isSameType() to hasSameTypeId()

this should remove any ambiguity about its behaviour.
This commit is contained in:
Dylan K. Taylor 2023-04-21 20:25:21 +01:00
parent 769be8e140
commit 6c0ad9589b
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
15 changed files with 33 additions and 33 deletions

View File

@ -131,7 +131,7 @@ class Bamboo extends Transparent{
private function seekToTop() : Bamboo{ private function seekToTop() : Bamboo{
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$top = $this; $top = $this;
while(($next = $world->getBlock($top->position->up())) instanceof Bamboo && $next->isSameType($this)){ while(($next = $world->getBlock($top->position->up())) instanceof Bamboo && $next->hasSameTypeId($this)){
$top = $next; $top = $next;
} }
return $top; return $top;
@ -156,7 +156,7 @@ class Bamboo extends Transparent{
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$below = $world->getBlock($this->position->down()); $below = $world->getBlock($this->position->down());
if(!$this->canBeSupportedBy($below) && !$below->isSameType($this)){ if(!$this->canBeSupportedBy($below) && !$below->hasSameTypeId($this)){
$world->useBreakOn($this->position); $world->useBreakOn($this->position);
} }
} }
@ -168,7 +168,7 @@ class Bamboo extends Transparent{
} }
$height = 1; $height = 1;
while($world->getBlock($this->position->subtract(0, $height, 0))->isSameType($this)){ while($world->getBlock($this->position->subtract(0, $height, 0))->hasSameTypeId($this)){
if(++$height >= $maxHeight){ if(++$height >= $maxHeight){
return false; return false;
} }

View File

@ -144,7 +144,7 @@ class Block{
* Type properties (e.g. colour, skull type, etc.) are not compared. This means that different colours of wool, * Type properties (e.g. colour, skull type, etc.) are not compared. This means that different colours of wool,
* concrete, etc. will all be considered as having the same type. * concrete, etc. will all be considered as having the same type.
*/ */
public function isSameType(Block $other) : bool{ public function hasSameTypeId(Block $other) : bool{
return $this->getTypeId() === $other->getTypeId(); return $this->getTypeId() === $other->getTypeId();
} }

View File

@ -79,7 +79,7 @@ class Cactus extends Transparent{
} }
private function canBeSupportedBy(Block $block) : bool{ private function canBeSupportedBy(Block $block) : bool{
return $block->isSameType($this) || $block->hasTypeTag(BlockTypeTags::SAND); return $block->hasSameTypeId($this) || $block->hasTypeTag(BlockTypeTags::SAND);
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
@ -102,7 +102,7 @@ class Cactus extends Transparent{
} }
public function onRandomTick() : void{ public function onRandomTick() : void{
if(!$this->getSide(Facing::DOWN)->isSameType($this)){ if(!$this->getSide(Facing::DOWN)->hasSameTypeId($this)){
$world = $this->position->getWorld(); $world = $this->position->getWorld();
if($this->age === self::MAX_AGE){ if($this->age === self::MAX_AGE){
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){

View File

@ -95,7 +95,7 @@ class Candle extends Transparent{
} }
protected function getCandleIfCompatibleType(Block $block) : ?Candle{ protected function getCandleIfCompatibleType(Block $block) : ?Candle{
return $block instanceof Candle && $block->isSameType($this) ? $block : null; return $block instanceof Candle && $block->hasSameTypeId($this) ? $block : null;
} }
public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{ public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{

View File

@ -57,13 +57,13 @@ class Chest extends Transparent{
foreach([false, true] as $clockwise){ foreach([false, true] as $clockwise){
$side = Facing::rotateY($this->facing, $clockwise); $side = Facing::rotateY($this->facing, $clockwise);
$c = $this->getSide($side); $c = $this->getSide($side);
if($c instanceof Chest && $c->isSameType($this) && $c->facing === $this->facing){ if($c instanceof Chest && $c->hasSameTypeId($this) && $c->facing === $this->facing){
$pair = $world->getTile($c->position); $pair = $world->getTile($c->position);
if($pair instanceof TileChest && !$pair->isPaired()){ if($pair instanceof TileChest && !$pair->isPaired()){
[$left, $right] = $clockwise ? [$c, $this] : [$this, $c]; [$left, $right] = $clockwise ? [$c, $this] : [$this, $c];
$ev = new ChestPairEvent($left, $right); $ev = new ChestPairEvent($left, $right);
$ev->call(); $ev->call();
if(!$ev->isCancelled() && $world->getBlock($this->position)->isSameType($this) && $world->getBlock($c->position)->isSameType($c)){ if(!$ev->isCancelled() && $world->getBlock($this->position)->hasSameTypeId($this) && $world->getBlock($c->position)->hasSameTypeId($c)){
$pair->pairWith($tile); $pair->pairWith($tile);
$tile->pairWith($pair); $tile->pairWith($pair);
break; break;

View File

@ -40,7 +40,7 @@ final class ChorusPlant extends Flowable{
$bb = AxisAlignedBB::one(); $bb = AxisAlignedBB::one();
foreach($this->getAllSides() as $facing => $block){ foreach($this->getAllSides() as $facing => $block){
$id = $block->getTypeId(); $id = $block->getTypeId();
if($id !== BlockTypeIds::END_STONE && $id !== BlockTypeIds::CHORUS_FLOWER && !$block->isSameType($this)){ if($id !== BlockTypeIds::END_STONE && $id !== BlockTypeIds::CHORUS_FLOWER && !$block->hasSameTypeId($this)){
$bb->trim($facing, 2 / 16); $bb->trim($facing, 2 / 16);
} }
} }
@ -49,7 +49,7 @@ final class ChorusPlant extends Flowable{
} }
private function canBeSupportedBy(Block $block) : bool{ private function canBeSupportedBy(Block $block) : bool{
return $block->isSameType($this) || $block->getTypeId() === BlockTypeIds::END_STONE; return $block->hasSameTypeId($this) || $block->getTypeId() === BlockTypeIds::END_STONE;
} }
private function canStay(Position $position) : bool{ private function canStay(Position $position) : bool{

View File

@ -53,7 +53,7 @@ class Door extends Transparent{
//copy door properties from other half //copy door properties from other half
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
if($other instanceof Door && $other->isSameType($this)){ if($other instanceof Door && $other->hasSameTypeId($this)){
if($this->top){ if($this->top){
$this->facing = $other->facing; $this->facing = $other->facing;
$this->open = $other->open; $this->open = $other->open;
@ -126,7 +126,7 @@ class Door extends Transparent{
$next = $this->getSide(Facing::rotateY($this->facing, false)); $next = $this->getSide(Facing::rotateY($this->facing, false));
$next2 = $this->getSide(Facing::rotateY($this->facing, true)); $next2 = $this->getSide(Facing::rotateY($this->facing, true));
if($next->isSameType($this) || (!$next2->isTransparent() && $next->isTransparent())){ //Door hinge if($next->hasSameTypeId($this) || (!$next2->isTransparent() && $next->isTransparent())){ //Door hinge
$this->hingeRight = true; $this->hingeRight = true;
} }
@ -145,7 +145,7 @@ class Door extends Transparent{
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
$world = $this->position->getWorld(); $world = $this->position->getWorld();
if($other instanceof Door && $other->isSameType($this)){ if($other instanceof Door && $other->hasSameTypeId($this)){
$other->open = $this->open; $other->open = $this->open;
$world->setBlock($other->position, $other); $world->setBlock($other->position, $other);
} }
@ -166,7 +166,7 @@ class Door extends Transparent{
public function getAffectedBlocks() : array{ public function getAffectedBlocks() : array{
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); $other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
if($other->isSameType($this)){ if($other->hasSameTypeId($this)){
return [$this, $other]; return [$this, $other];
} }
return parent::getAffectedBlocks(); return parent::getAffectedBlocks();

View File

@ -65,7 +65,7 @@ class DoublePlant extends Flowable{
return ( return (
$other instanceof DoublePlant && $other instanceof DoublePlant &&
$other->isSameType($this) && $other->hasSameTypeId($this) &&
$other->top !== $this->top $other->top !== $this->top
); );
} }

View File

@ -144,7 +144,7 @@ abstract class Liquid extends Transparent{
} }
protected function getEffectiveFlowDecay(Block $block) : int{ protected function getEffectiveFlowDecay(Block $block) : int{
if(!($block instanceof Liquid) || !$block->isSameType($this)){ if(!($block instanceof Liquid) || !$block->hasSameTypeId($this)){
return -1; return -1;
} }
@ -282,7 +282,7 @@ abstract class Liquid extends Transparent{
$minAdjacentSources = $this->getMinAdjacentSourcesToFormSource(); $minAdjacentSources = $this->getMinAdjacentSourcesToFormSource();
if($minAdjacentSources !== null && $this->adjacentSources >= $minAdjacentSources){ if($minAdjacentSources !== null && $this->adjacentSources >= $minAdjacentSources){
$bottomBlock = $world->getBlockAt($this->position->x, $this->position->y - 1, $this->position->z); $bottomBlock = $world->getBlockAt($this->position->x, $this->position->y - 1, $this->position->z);
if($bottomBlock->isSolid() || ($bottomBlock instanceof Liquid && $bottomBlock->isSameType($this) && $bottomBlock->isSource())){ if($bottomBlock->isSolid() || ($bottomBlock instanceof Liquid && $bottomBlock->hasSameTypeId($this) && $bottomBlock->isSource())){
$newDecay = 0; $newDecay = 0;
$falling = false; $falling = false;
} }
@ -343,7 +343,7 @@ abstract class Liquid extends Transparent{
/** @phpstan-impure */ /** @phpstan-impure */
private function getSmallestFlowDecay(Block $block, int $decay) : int{ private function getSmallestFlowDecay(Block $block, int $decay) : int{
if(!($block instanceof Liquid) || !$block->isSameType($this)){ if(!($block instanceof Liquid) || !$block->hasSameTypeId($this)){
return $decay; return $decay;
} }

View File

@ -87,7 +87,7 @@ class NetherVines extends Flowable{
} }
private function canBeSupportedBy(Block $block) : bool{ private function canBeSupportedBy(Block $block) : bool{
return $block->getSupportType($this->getSupportFace())->hasCenterSupport() || $block->isSameType($this); return $block->getSupportType($this->getSupportFace())->hasCenterSupport() || $block->hasSameTypeId($this);
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
@ -101,7 +101,7 @@ class NetherVines extends Flowable{
*/ */
private function seekToTip() : NetherVines{ private function seekToTip() : NetherVines{
$top = $this; $top = $this;
while(($next = $top->getSide($this->growthFace)) instanceof NetherVines && $next->isSameType($this)){ while(($next = $top->getSide($this->growthFace)) instanceof NetherVines && $next->hasSameTypeId($this)){
$top = $next; $top = $next;
} }
return $top; return $top;

View File

@ -69,7 +69,7 @@ class Slab extends Transparent{
return true; return true;
} }
if($blockReplace instanceof Slab && !$blockReplace->slabType->equals(SlabType::DOUBLE()) && $blockReplace->isSameType($this)){ if($blockReplace instanceof Slab && !$blockReplace->slabType->equals(SlabType::DOUBLE()) && $blockReplace->hasSameTypeId($this)){
if($blockReplace->slabType->equals(SlabType::TOP())){ //Trying to combine with top slab if($blockReplace->slabType->equals(SlabType::TOP())){ //Trying to combine with top slab
return $clickVector->y <= 0.5 || (!$isClickedBlock && $face === Facing::UP); return $clickVector->y <= 0.5 || (!$isClickedBlock && $face === Facing::UP);
}else{ }else{
@ -81,7 +81,7 @@ class Slab extends Transparent{
} }
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($blockReplace instanceof Slab && !$blockReplace->slabType->equals(SlabType::DOUBLE()) && $blockReplace->isSameType($this) && ( if($blockReplace instanceof Slab && !$blockReplace->slabType->equals(SlabType::DOUBLE()) && $blockReplace->hasSameTypeId($this) && (
($blockReplace->slabType->equals(SlabType::TOP()) && ($clickVector->y <= 0.5 || $face === Facing::UP)) || ($blockReplace->slabType->equals(SlabType::TOP()) && ($clickVector->y <= 0.5 || $face === Facing::UP)) ||
($blockReplace->slabType->equals(SlabType::BOTTOM()) && ($clickVector->y >= 0.5 || $face === Facing::DOWN)) ($blockReplace->slabType->equals(SlabType::BOTTOM()) && ($clickVector->y >= 0.5 || $face === Facing::DOWN))
)){ )){

View File

@ -47,7 +47,7 @@ abstract class Stem extends Crops{
}else{ }else{
$grow = $this->getPlant(); $grow = $this->getPlant();
foreach(Facing::HORIZONTAL as $side){ foreach(Facing::HORIZONTAL as $side){
if($this->getSide($side)->isSameType($grow)){ if($this->getSide($side)->hasSameTypeId($grow)){
return; return;
} }
} }

View File

@ -45,7 +45,7 @@ class Sugarcane extends Flowable{
private function seekToBottom() : Position{ private function seekToBottom() : Position{
$world = $this->position->getWorld(); $world = $this->position->getWorld();
$bottom = $this->position; $bottom = $this->position;
while(($next = $world->getBlock($bottom->down()))->isSameType($this)){ while(($next = $world->getBlock($bottom->down()))->hasSameTypeId($this)){
$bottom = $next->position; $bottom = $next->position;
} }
return $bottom; return $bottom;
@ -67,7 +67,7 @@ class Sugarcane extends Flowable{
} }
$world->setBlock($b->position, $ev->getNewState()); $world->setBlock($b->position, $ev->getNewState());
$grew = true; $grew = true;
}elseif(!$b->isSameType($this)){ }elseif(!$b->hasSameTypeId($this)){
break; break;
} }
} }
@ -108,7 +108,7 @@ class Sugarcane extends Flowable{
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{
$down = $this->getSide(Facing::DOWN); $down = $this->getSide(Facing::DOWN);
if(!$down->isSameType($this) && !$this->canBeSupportedBy($down)){ if(!$down->hasSameTypeId($this) && !$this->canBeSupportedBy($down)){
$this->position->getWorld()->useBreakOn($this->position); $this->position->getWorld()->useBreakOn($this->position);
} }
} }
@ -118,7 +118,7 @@ class Sugarcane extends Flowable{
} }
public function onRandomTick() : void{ public function onRandomTick() : void{
if(!$this->getSide(Facing::DOWN)->isSameType($this)){ if(!$this->getSide(Facing::DOWN)->hasSameTypeId($this)){
if($this->age === self::MAX_AGE){ if($this->age === self::MAX_AGE){
$this->grow($this->position); $this->grow($this->position);
}else{ }else{
@ -130,7 +130,7 @@ class Sugarcane extends Flowable{
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN); $down = $this->getSide(Facing::DOWN);
if($down->isSameType($this)){ if($down->hasSameTypeId($this)){
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}elseif($this->canBeSupportedBy($down)){ }elseif($this->canBeSupportedBy($down)){
foreach(Facing::HORIZONTAL as $side){ foreach(Facing::HORIZONTAL as $side){

View File

@ -1922,7 +1922,7 @@ class World implements ChunkManager{
$itemParser = LegacyStringToItemParser::getInstance(); $itemParser = LegacyStringToItemParser::getInstance();
foreach($item->getCanDestroy() as $v){ foreach($item->getCanDestroy() as $v){
$entry = $itemParser->parse($v); $entry = $itemParser->parse($v);
if($entry->getBlock()->isSameType($target)){ if($entry->getBlock()->hasSameTypeId($target)){
$canBreak = true; $canBreak = true;
break; break;
} }
@ -2077,7 +2077,7 @@ class World implements ChunkManager{
$itemParser = LegacyStringToItemParser::getInstance(); $itemParser = LegacyStringToItemParser::getInstance();
foreach($item->getCanPlaceOn() as $v){ foreach($item->getCanPlaceOn() as $v){
$entry = $itemParser->parse($v); $entry = $itemParser->parse($v);
if($entry->getBlock()->isSameType($blockClicked)){ if($entry->getBlock()->hasSameTypeId($blockClicked)){
$canPlace = true; $canPlace = true;
break; break;
} }

View File

@ -40,7 +40,7 @@ class Ore{
} }
public function canPlaceObject(ChunkManager $world, int $x, int $y, int $z) : bool{ public function canPlaceObject(ChunkManager $world, int $x, int $y, int $z) : bool{
return $world->getBlockAt($x, $y, $z)->isSameType($this->type->replaces); return $world->getBlockAt($x, $y, $z)->hasSameTypeId($this->type->replaces);
} }
public function placeObject(ChunkManager $world, int $x, int $y, int $z) : void{ public function placeObject(ChunkManager $world, int $x, int $y, int $z) : void{
@ -80,7 +80,7 @@ class Ore{
$sizeZ = ($zz + 0.5 - $seedZ) / $size; $sizeZ = ($zz + 0.5 - $seedZ) / $size;
$sizeZ *= $sizeZ; $sizeZ *= $sizeZ;
if(($sizeX + $sizeY + $sizeZ) < 1 && $world->getBlockAt($xx, $yy, $zz)->isSameType($this->type->replaces)){ if(($sizeX + $sizeY + $sizeZ) < 1 && $world->getBlockAt($xx, $yy, $zz)->hasSameTypeId($this->type->replaces)){
$world->setBlockAt($xx, $yy, $zz, $this->type->material); $world->setBlockAt($xx, $yy, $zz, $this->type->material);
} }
} }