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{
$world = $this->position->getWorld();
$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;
}
return $top;
@ -156,7 +156,7 @@ class Bamboo extends Transparent{
public function onNearbyBlockChange() : void{
$world = $this->position->getWorld();
$below = $world->getBlock($this->position->down());
if(!$this->canBeSupportedBy($below) && !$below->isSameType($this)){
if(!$this->canBeSupportedBy($below) && !$below->hasSameTypeId($this)){
$world->useBreakOn($this->position);
}
}
@ -168,7 +168,7 @@ class Bamboo extends Transparent{
}
$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){
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,
* 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();
}

View File

@ -79,7 +79,7 @@ class Cactus extends Transparent{
}
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{
@ -102,7 +102,7 @@ class Cactus extends Transparent{
}
public function onRandomTick() : void{
if(!$this->getSide(Facing::DOWN)->isSameType($this)){
if(!$this->getSide(Facing::DOWN)->hasSameTypeId($this)){
$world = $this->position->getWorld();
if($this->age === self::MAX_AGE){
for($y = 1; $y < 3; ++$y){

View File

@ -95,7 +95,7 @@ class Candle extends Transparent{
}
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{

View File

@ -57,13 +57,13 @@ class Chest extends Transparent{
foreach([false, true] as $clockwise){
$side = Facing::rotateY($this->facing, $clockwise);
$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);
if($pair instanceof TileChest && !$pair->isPaired()){
[$left, $right] = $clockwise ? [$c, $this] : [$this, $c];
$ev = new ChestPairEvent($left, $right);
$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);
$tile->pairWith($pair);
break;

View File

@ -40,7 +40,7 @@ final class ChorusPlant extends Flowable{
$bb = AxisAlignedBB::one();
foreach($this->getAllSides() as $facing => $block){
$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);
}
}
@ -49,7 +49,7 @@ final class ChorusPlant extends Flowable{
}
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{

View File

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

View File

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

View File

@ -144,7 +144,7 @@ abstract class Liquid extends Transparent{
}
protected function getEffectiveFlowDecay(Block $block) : int{
if(!($block instanceof Liquid) || !$block->isSameType($this)){
if(!($block instanceof Liquid) || !$block->hasSameTypeId($this)){
return -1;
}
@ -282,7 +282,7 @@ abstract class Liquid extends Transparent{
$minAdjacentSources = $this->getMinAdjacentSourcesToFormSource();
if($minAdjacentSources !== null && $this->adjacentSources >= $minAdjacentSources){
$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;
$falling = false;
}
@ -343,7 +343,7 @@ abstract class Liquid extends Transparent{
/** @phpstan-impure */
private function getSmallestFlowDecay(Block $block, int $decay) : int{
if(!($block instanceof Liquid) || !$block->isSameType($this)){
if(!($block instanceof Liquid) || !$block->hasSameTypeId($this)){
return $decay;
}

View File

@ -87,7 +87,7 @@ class NetherVines extends Flowable{
}
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{
@ -101,7 +101,7 @@ class NetherVines extends Flowable{
*/
private function seekToTip() : NetherVines{
$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;
}
return $top;

View File

@ -69,7 +69,7 @@ class Slab extends Transparent{
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
return $clickVector->y <= 0.5 || (!$isClickedBlock && $face === Facing::UP);
}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{
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::BOTTOM()) && ($clickVector->y >= 0.5 || $face === Facing::DOWN))
)){

View File

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

View File

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

View File

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

View File

@ -40,7 +40,7 @@ class Ore{
}
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{
@ -80,7 +80,7 @@ class Ore{
$sizeZ = ($zz + 0.5 - $seedZ) / $size;
$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);
}
}