diff --git a/src/block/BaseBanner.php b/src/block/BaseBanner.php index dcdc36c60..e83ac1636 100644 --- a/src/block/BaseBanner.php +++ b/src/block/BaseBanner.php @@ -62,12 +62,7 @@ abstract class BaseBanner extends Transparent implements Colored{ return $this; } - /** - * TODO: make this abstract in PM6 (BC break) - */ - protected function getOminousVersion() : Block{ - return VanillaBlocks::AIR(); - } + abstract protected function getOminousVersion() : Block; public function writeStateToWorld() : void{ parent::writeStateToWorld(); diff --git a/src/block/BaseSign.php b/src/block/BaseSign.php index f5d96fa74..4739210d2 100644 --- a/src/block/BaseSign.php +++ b/src/block/BaseSign.php @@ -53,7 +53,7 @@ use function strlen; abstract class BaseSign extends Transparent implements WoodMaterial{ use WoodTypeTrait; - protected SignText $text; //TODO: rename this (BC break) + protected SignText $frontText; protected SignText $backText; private bool $waxed = false; @@ -68,7 +68,7 @@ abstract class BaseSign extends Transparent implements WoodMaterial{ public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, WoodType $woodType, \Closure $asItemCallback){ $this->woodType = $woodType; parent::__construct($idInfo, $name, $typeInfo); - $this->text = new SignText(); + $this->frontText = new SignText(); $this->backText = new SignText(); $this->asItemCallback = $asItemCallback; } @@ -77,7 +77,7 @@ abstract class BaseSign extends Transparent implements WoodMaterial{ parent::readStateFromWorld(); $tile = $this->position->getWorld()->getTile($this->position); if($tile instanceof TileSign){ - $this->text = $tile->getText(); + $this->frontText = $tile->getFrontText(); $this->backText = $tile->getBackText(); $this->waxed = $tile->isWaxed(); $this->editorEntityRuntimeId = $tile->getEditorEntityRuntimeId(); @@ -90,7 +90,7 @@ abstract class BaseSign extends Transparent implements WoodMaterial{ parent::writeStateToWorld(); $tile = $this->position->getWorld()->getTile($this->position); assert($tile instanceof TileSign); - $tile->setText($this->text); + $tile->setFrontText($this->frontText); $tile->setBackText($this->backText); $tile->setWaxed($this->waxed); $tile->setEditorEntityRuntimeId($this->editorEntityRuntimeId); @@ -228,39 +228,15 @@ abstract class BaseSign extends Transparent implements WoodMaterial{ return $this->position->add(0.5, 0.5, 0.5); } - /** - * TODO: make this abstract (BC break) - */ - protected function getFacingDegrees() : float{ - return 0; - } - - /** - * Returns an object containing information about the sign text. - * @deprecated - * @see self::getFaceText() - */ - public function getText() : SignText{ - return $this->text; - } - - /** - * @deprecated - * @see self::setFaceText() - * @return $this - */ - public function setText(SignText $text) : self{ - $this->text = $text; - return $this; - } + abstract protected function getFacingDegrees() : float; public function getFaceText(bool $frontFace) : SignText{ - return $frontFace ? $this->text : $this->backText; + return $frontFace ? $this->frontText : $this->backText; } /** @return $this */ public function setFaceText(bool $frontFace, SignText $text) : self{ - $frontFace ? $this->text = $text : $this->backText = $text; + $frontFace ? $this->frontText = $text : $this->backText = $text; return $this; } @@ -288,14 +264,6 @@ abstract class BaseSign extends Transparent implements WoodMaterial{ return $this; } - /** - * @deprecated - * @see self::updateFaceText() - */ - public function updateText(Player $author, SignText $text) : bool{ - return $this->updateFaceText($author, true, $text); - } - /** * Called by the player controller (network session) to update the sign text, firing events as appropriate. * diff --git a/src/block/PressurePlate.php b/src/block/PressurePlate.php index b96154a15..fb8c8b8f2 100644 --- a/src/block/PressurePlate.php +++ b/src/block/PressurePlate.php @@ -43,7 +43,7 @@ abstract class PressurePlate extends Transparent{ BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, - int $deactivationDelayTicks = 20 //TODO: make this mandatory in PM6 + int $deactivationDelayTicks ){ parent::__construct($idInfo, $name, $typeInfo); $this->deactivationDelayTicks = $deactivationDelayTicks; @@ -89,24 +89,15 @@ abstract class PressurePlate extends Transparent{ ->offsetCopy($this->position->x, $this->position->y, $this->position->z); } - /** - * TODO: make this abstract in PM6 - */ - protected function hasOutputSignal() : bool{ - return false; - } + abstract protected function hasOutputSignal() : bool; /** - * TODO: make this abstract in PM6 - * * @param Entity[] $entities * * @return mixed[] * @phpstan-return array{Block, ?bool} */ - protected function calculatePlateState(array $entities) : array{ - return [$this, null]; - } + abstract protected function calculatePlateState(array $entities) : array; /** * Filters entities which don't affect the pressure plate state from the given list. diff --git a/src/block/VanillaBlocks.php b/src/block/VanillaBlocks.php index 569efe0d3..8343bd5cf 100644 --- a/src/block/VanillaBlocks.php +++ b/src/block/VanillaBlocks.php @@ -1182,7 +1182,7 @@ final class VanillaBlocks{ self::register("mossy_stone_brick_stairs", fn(BID $id) => new Stair($id, "Mossy Stone Brick Stairs", $stoneBreakInfo)); self::register("stone_button", fn(BID $id) => new StoneButton($id, "Stone Button", new Info(BreakInfo::pickaxe(0.5)))); self::register("stonecutter", fn(BID $id) => new Stonecutter($id, "Stonecutter", new Info(BreakInfo::pickaxe(3.5)))); - self::register("stone_pressure_plate", fn(BID $id) => new StonePressurePlate($id, "Stone Pressure Plate", new Info(BreakInfo::pickaxe(0.5)))); + self::register("stone_pressure_plate", fn(BID $id) => new StonePressurePlate($id, "Stone Pressure Plate", new Info(BreakInfo::pickaxe(0.5)), deactivationDelayTicks: 20)); $stoneSlabBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD, 30.0)); diff --git a/src/block/WoodenPressurePlate.php b/src/block/WoodenPressurePlate.php index 6d638788b..caab7bdc0 100644 --- a/src/block/WoodenPressurePlate.php +++ b/src/block/WoodenPressurePlate.php @@ -35,7 +35,7 @@ class WoodenPressurePlate extends SimplePressurePlate implements WoodMaterial{ string $name, BlockTypeInfo $typeInfo, WoodType $woodType, - int $deactivationDelayTicks = 20 //TODO: make this mandatory in PM6 + int $deactivationDelayTicks ){ $this->woodType = $woodType; parent::__construct($idInfo, $name, $typeInfo, $deactivationDelayTicks); diff --git a/src/block/tile/Sign.php b/src/block/tile/Sign.php index aef646e8e..0f642e623 100644 --- a/src/block/tile/Sign.php +++ b/src/block/tile/Sign.php @@ -58,14 +58,14 @@ class Sign extends Spawnable{ public const TAG_WAXED = "IsWaxed"; //TAG_Byte public const TAG_LOCKED_FOR_EDITING_BY = "LockedForEditingBy"; //TAG_Long - protected SignText $text; + protected SignText $frontText; protected SignText $backText; private bool $waxed = false; protected ?int $editorEntityRuntimeId = null; public function __construct(World $world, Vector3 $pos){ - $this->text = new SignText(); + $this->frontText = new SignText(); $this->backText = new SignText(); parent::__construct($world, $pos); } @@ -95,13 +95,13 @@ class Sign extends Spawnable{ public function readSaveData(CompoundTag $nbt) : void{ $frontTextTag = $nbt->getTag(self::TAG_FRONT_TEXT); if($frontTextTag instanceof CompoundTag){ - $this->text = $this->readTextTag($frontTextTag, true); + $this->frontText = $this->readTextTag($frontTextTag, true); }elseif($nbt->getTag(self::TAG_TEXT_BLOB) instanceof StringTag){ //MCPE 1.2 save format $lightingBugResolved = false; if(($lightingBugResolvedTag = $nbt->getTag(self::TAG_LEGACY_BUG_RESOLVE)) instanceof ByteTag){ $lightingBugResolved = $lightingBugResolvedTag->getValue() !== 0; } - $this->text = $this->readTextTag($nbt, $lightingBugResolved); + $this->frontText = $this->readTextTag($nbt, $lightingBugResolved); }else{ $text = []; for($i = 0; $i < SignText::LINE_COUNT; ++$i){ @@ -110,7 +110,7 @@ class Sign extends Spawnable{ $text[$i] = mb_scrub($lineTag->getValue(), 'UTF-8'); } } - $this->text = new SignText($text); + $this->frontText = new SignText($text); } $backTextTag = $nbt->getTag(self::TAG_BACK_TEXT); $this->backText = $backTextTag instanceof CompoundTag ? $this->readTextTag($backTextTag, true) : new SignText(); @@ -118,18 +118,18 @@ class Sign extends Spawnable{ } protected function writeSaveData(CompoundTag $nbt) : void{ - $nbt->setTag(self::TAG_FRONT_TEXT, $this->writeTextTag($this->text)); + $nbt->setTag(self::TAG_FRONT_TEXT, $this->writeTextTag($this->frontText)); $nbt->setTag(self::TAG_BACK_TEXT, $this->writeTextTag($this->backText)); $nbt->setByte(self::TAG_WAXED, $this->waxed ? 1 : 0); } - public function getText() : SignText{ - return $this->text; + public function getFrontText() : SignText{ + return $this->frontText; } - public function setText(SignText $text) : void{ - $this->text = $text; + public function setFrontText(SignText $frontText) : void{ + $this->frontText = $frontText; } public function getBackText() : SignText{ return $this->backText; } @@ -157,7 +157,7 @@ class Sign extends Spawnable{ } protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ - $nbt->setTag(self::TAG_FRONT_TEXT, $this->writeTextTag($this->text)); + $nbt->setTag(self::TAG_FRONT_TEXT, $this->writeTextTag($this->frontText)); $nbt->setTag(self::TAG_BACK_TEXT, $this->writeTextTag($this->backText)); $nbt->setByte(self::TAG_WAXED, $this->waxed ? 1 : 0); $nbt->setLong(self::TAG_LOCKED_FOR_EDITING_BY, $this->editorEntityRuntimeId ?? -1); diff --git a/src/inventory/BaseInventory.php b/src/inventory/BaseInventory.php index 26c13dec5..9aa20d7f7 100644 --- a/src/inventory/BaseInventory.php +++ b/src/inventory/BaseInventory.php @@ -155,14 +155,6 @@ abstract class BaseInventory implements Inventory, SlotValidatedInventory{ return -1; } - /** - * TODO: make this abstract and force implementations to implement it properly (BC break) - * This default implementation works, but is slow. - */ - public function isSlotEmpty(int $index) : bool{ - return $this->getItem($index)->isNull(); - } - public function canAddItem(Item $item) : bool{ return $this->getAddableItemQuantity($item) === $item->getCount(); } diff --git a/src/inventory/transaction/SlotChangeActionBuilder.php b/src/inventory/transaction/SlotChangeActionBuilder.php index 02d089029..ce14c6e7d 100644 --- a/src/inventory/transaction/SlotChangeActionBuilder.php +++ b/src/inventory/transaction/SlotChangeActionBuilder.php @@ -101,6 +101,11 @@ final class SlotChangeActionBuilder extends BaseInventory{ return $this->inventoryWindow->getInventory()->getMatchingItemCount($slot, $test, $checkTags); } + public function isSlotEmpty(int $index) : bool{ + $slotItem = $this->changedSlots[$index] ?? null; + return $slotItem !== null ? $slotItem->isNull() : $this->inventoryWindow->getInventory()->isSlotEmpty($index); + } + /** * @return SlotChangeAction[] */ diff --git a/src/world/World.php b/src/world/World.php index f72e3fbdd..2929f9d97 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -281,7 +281,6 @@ class World implements ChunkManager{ private float $sunAnglePercentage = 0.0; private int $skyLightReduction = 0; - private string $folderName; private string $displayName; /** @@ -482,11 +481,10 @@ class World implements ChunkManager{ */ public function __construct( private Server $server, - string $name, //TODO: this should be folderName (named arguments BC break) + private string $folderName, private WritableWorldProvider $provider, private AsyncPool $workerPool ){ - $this->folderName = $name; $this->worldId = self::$worldIdCounter++; $this->displayName = $this->provider->getWorldData()->getName(); @@ -1487,29 +1485,18 @@ class World implements ChunkManager{ } /** - * Identical to {@link World::notifyNeighbourBlockUpdate()}, but without the Vector3 requirement. We don't want or - * need Vector3 in the places where this is called. + * Notify the blocks at and around the position that the block at the position may have changed. + * This will cause onNearbyBlockChange() to be called for these blocks. * - * TODO: make this the primary method in PM6 + * @see Block::onNearbyBlockChange() */ - private function internalNotifyNeighbourBlockUpdate(int $x, int $y, int $z) : void{ + public function notifyNeighbourBlockUpdate(int $x, int $y, int $z) : void{ $this->tryAddToNeighbourUpdateQueue($x, $y, $z); foreach(Facing::OFFSET as [$dx, $dy, $dz]){ $this->tryAddToNeighbourUpdateQueue($x + $dx, $y + $dy, $z + $dz); } } - /** - * Notify the blocks at and around the position that the block at the position may have changed. - * This will cause onNearbyBlockChange() to be called for these blocks. - * TODO: Accept plain integers in PM6 - the Vector3 requirement is an unnecessary inconvenience - * - * @see Block::onNearbyBlockChange() - */ - public function notifyNeighbourBlockUpdate(Vector3 $pos) : void{ - $this->internalNotifyNeighbourBlockUpdate($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ()); - } - /** * @return Block[] * @phpstan-return list @@ -2065,7 +2052,7 @@ class World implements ChunkManager{ if($update){ $this->updateAllLight($x, $y, $z); - $this->internalNotifyNeighbourBlockUpdate($x, $y, $z); + $this->notifyNeighbourBlockUpdate($x, $y, $z); } $this->timings->setBlock->stopTiming();