From ce4d3aef9e53ecf9dda38976f384ae66ee68fdfd Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 6 Dec 2024 15:34:32 +0000 Subject: [PATCH] Rename Container(Trait) -> ContainerTile(Trait) this allows introducing block variations of these without name conflicts --- src/block/tile/Barrel.php | 4 ++-- src/block/tile/BrewingStand.php | 4 ++-- src/block/tile/Campfire.php | 4 ++-- src/block/tile/Chest.php | 4 ++-- src/block/tile/ChiseledBookshelf.php | 12 ++++++------ .../tile/{Container.php => ContainerTile.php} | 2 +- .../{ContainerTrait.php => ContainerTileTrait.php} | 14 +++++++------- src/block/tile/Furnace.php | 4 ++-- src/block/tile/Hopper.php | 4 ++-- src/block/tile/ShulkerBox.php | 4 ++-- 10 files changed, 28 insertions(+), 28 deletions(-) rename src/block/tile/{Container.php => ContainerTile.php} (95%) rename src/block/tile/{ContainerTrait.php => ContainerTileTrait.php} (83%) diff --git a/src/block/tile/Barrel.php b/src/block/tile/Barrel.php index 9b64bbf32..d70f5a405 100644 --- a/src/block/tile/Barrel.php +++ b/src/block/tile/Barrel.php @@ -29,9 +29,9 @@ use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\world\World; -class Barrel extends Spawnable implements Container, Nameable{ +class Barrel extends Spawnable implements ContainerTile, Nameable{ use NameableTrait; - use ContainerTrait; + use ContainerTileTrait; protected Inventory $inventory; diff --git a/src/block/tile/BrewingStand.php b/src/block/tile/BrewingStand.php index 87b53eefb..30b94bc5f 100644 --- a/src/block/tile/BrewingStand.php +++ b/src/block/tile/BrewingStand.php @@ -41,11 +41,11 @@ use pocketmine\world\World; use function array_map; use function count; -class BrewingStand extends Spawnable implements Container, Nameable{ +class BrewingStand extends Spawnable implements ContainerTile, Nameable{ use NameableTrait { addAdditionalSpawnData as addNameSpawnData; } - use ContainerTrait; + use ContainerTileTrait; public const BREW_TIME_TICKS = 400; // Brew time in ticks diff --git a/src/block/tile/Campfire.php b/src/block/tile/Campfire.php index a9ad30351..44c7a9e6e 100644 --- a/src/block/tile/Campfire.php +++ b/src/block/tile/Campfire.php @@ -34,8 +34,8 @@ use pocketmine\nbt\tag\IntTag; use pocketmine\network\mcpe\convert\TypeConverter; use pocketmine\world\World; -class Campfire extends Spawnable implements Container{ - use ContainerTrait; +class Campfire extends Spawnable implements ContainerTile{ + use ContainerTileTrait; private const TAG_FIRST_INPUT_ITEM = "Item1"; //TAG_Compound private const TAG_SECOND_INPUT_ITEM = "Item2"; //TAG_Compound diff --git a/src/block/tile/Chest.php b/src/block/tile/Chest.php index 9bc3fdffb..8f5ee48fa 100644 --- a/src/block/tile/Chest.php +++ b/src/block/tile/Chest.php @@ -33,11 +33,11 @@ use pocketmine\world\format\Chunk; use pocketmine\world\World; use function abs; -class Chest extends Spawnable implements Container, Nameable{ +class Chest extends Spawnable implements ContainerTile, Nameable{ use NameableTrait { addAdditionalSpawnData as addNameSpawnData; } - use ContainerTrait { + use ContainerTileTrait { onBlockDestroyedHook as containerTraitBlockDestroyedHook; } diff --git a/src/block/tile/ChiseledBookshelf.php b/src/block/tile/ChiseledBookshelf.php index da7e42c0d..d18b606d7 100644 --- a/src/block/tile/ChiseledBookshelf.php +++ b/src/block/tile/ChiseledBookshelf.php @@ -37,8 +37,8 @@ use pocketmine\nbt\tag\StringTag; use pocketmine\world\World; use function count; -class ChiseledBookshelf extends Tile implements Container{ - use ContainerTrait; +class ChiseledBookshelf extends Tile implements ContainerTile{ + use ContainerTileTrait; private const TAG_LAST_INTERACTED_SLOT = "LastInteractedSlot"; //TAG_Int @@ -82,7 +82,7 @@ class ChiseledBookshelf extends Tile implements Container{ } protected function loadItems(CompoundTag $tag) : void{ - if(($inventoryTag = $tag->getTag(Container::TAG_ITEMS)) instanceof ListTag && $inventoryTag->getTagType() === NBT::TAG_Compound){ + if(($inventoryTag = $tag->getTag(ContainerTile::TAG_ITEMS)) instanceof ListTag && $inventoryTag->getTagType() === NBT::TAG_Compound){ $inventory = $this->inventory; $listeners = $inventory->getListeners()->toArray(); $inventory->getListeners()->remove(...$listeners); //prevent any events being fired by initialization @@ -107,7 +107,7 @@ class ChiseledBookshelf extends Tile implements Container{ $inventory->getListeners()->add(...$listeners); } - if(($lockTag = $tag->getTag(Container::TAG_LOCK)) instanceof StringTag){ + if(($lockTag = $tag->getTag(ContainerTile::TAG_LOCK)) instanceof StringTag){ $this->lock = $lockTag->getValue(); } } @@ -126,10 +126,10 @@ class ChiseledBookshelf extends Tile implements Container{ } } - $tag->setTag(Container::TAG_ITEMS, new ListTag($items, NBT::TAG_Compound)); + $tag->setTag(ContainerTile::TAG_ITEMS, new ListTag($items, NBT::TAG_Compound)); if($this->lock !== null){ - $tag->setString(Container::TAG_LOCK, $this->lock); + $tag->setString(ContainerTile::TAG_LOCK, $this->lock); } } } diff --git a/src/block/tile/Container.php b/src/block/tile/ContainerTile.php similarity index 95% rename from src/block/tile/Container.php rename to src/block/tile/ContainerTile.php index 1c4e37fec..51c7d3759 100644 --- a/src/block/tile/Container.php +++ b/src/block/tile/ContainerTile.php @@ -25,7 +25,7 @@ namespace pocketmine\block\tile; use pocketmine\inventory\InventoryHolder; -interface Container extends InventoryHolder{ +interface ContainerTile extends InventoryHolder{ public const TAG_ITEMS = "Items"; public const TAG_LOCK = "Lock"; diff --git a/src/block/tile/ContainerTrait.php b/src/block/tile/ContainerTileTrait.php similarity index 83% rename from src/block/tile/ContainerTrait.php rename to src/block/tile/ContainerTileTrait.php index cf69f37b5..f3e015ae4 100644 --- a/src/block/tile/ContainerTrait.php +++ b/src/block/tile/ContainerTileTrait.php @@ -33,14 +33,14 @@ use pocketmine\nbt\tag\StringTag; use pocketmine\world\Position; /** - * This trait implements most methods in the {@link Container} interface. It should only be used by Tiles. + * This trait implements most methods in the {@link ContainerTile} interface. It should only be used by Tiles. */ -trait ContainerTrait{ +trait ContainerTileTrait{ /** @var string|null */ private $lock = null; protected function loadItems(CompoundTag $tag) : void{ - if(($inventoryTag = $tag->getTag(Container::TAG_ITEMS)) instanceof ListTag && $inventoryTag->getTagType() === NBT::TAG_Compound){ + if(($inventoryTag = $tag->getTag(ContainerTile::TAG_ITEMS)) instanceof ListTag && $inventoryTag->getTagType() === NBT::TAG_Compound){ $inventory = $this->getInventory(); $listeners = $inventory->getListeners()->toArray(); $inventory->getListeners()->remove(...$listeners); //prevent any events being fired by initialization @@ -61,7 +61,7 @@ trait ContainerTrait{ $inventory->getListeners()->add(...$listeners); } - if(($lockTag = $tag->getTag(Container::TAG_LOCK)) instanceof StringTag){ + if(($lockTag = $tag->getTag(ContainerTile::TAG_LOCK)) instanceof StringTag){ $this->lock = $lockTag->getValue(); } } @@ -72,15 +72,15 @@ trait ContainerTrait{ $items[] = $item->nbtSerialize($slot); } - $tag->setTag(Container::TAG_ITEMS, new ListTag($items, NBT::TAG_Compound)); + $tag->setTag(ContainerTile::TAG_ITEMS, new ListTag($items, NBT::TAG_Compound)); if($this->lock !== null){ - $tag->setString(Container::TAG_LOCK, $this->lock); + $tag->setString(ContainerTile::TAG_LOCK, $this->lock); } } /** - * @see Container::canOpenWith() + * @see ContainerTile::canOpenWith() */ public function canOpenWith(string $key) : bool{ return $this->lock === null || $this->lock === $key; diff --git a/src/block/tile/Furnace.php b/src/block/tile/Furnace.php index e036a606e..b6d18b0ba 100644 --- a/src/block/tile/Furnace.php +++ b/src/block/tile/Furnace.php @@ -41,9 +41,9 @@ use pocketmine\world\World; use function array_map; use function max; -abstract class Furnace extends Spawnable implements Container, Nameable{ +abstract class Furnace extends Spawnable implements ContainerTile, Nameable{ use NameableTrait; - use ContainerTrait; + use ContainerTileTrait; public const TAG_BURN_TIME = "BurnTime"; public const TAG_COOK_TIME = "CookTime"; diff --git a/src/block/tile/Hopper.php b/src/block/tile/Hopper.php index 4a4273323..ed0c2c479 100644 --- a/src/block/tile/Hopper.php +++ b/src/block/tile/Hopper.php @@ -29,9 +29,9 @@ use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\world\World; -class Hopper extends Spawnable implements Container, Nameable{ +class Hopper extends Spawnable implements ContainerTile, Nameable{ - use ContainerTrait; + use ContainerTileTrait; use NameableTrait; private const TAG_TRANSFER_COOLDOWN = "TransferCooldown"; diff --git a/src/block/tile/ShulkerBox.php b/src/block/tile/ShulkerBox.php index 2e7565915..c30e1696e 100644 --- a/src/block/tile/ShulkerBox.php +++ b/src/block/tile/ShulkerBox.php @@ -35,11 +35,11 @@ use pocketmine\math\Vector3; use pocketmine\nbt\tag\CompoundTag; use pocketmine\world\World; -class ShulkerBox extends Spawnable implements Container, Nameable{ +class ShulkerBox extends Spawnable implements ContainerTile, Nameable{ use NameableTrait { addAdditionalSpawnData as addNameSpawnData; } - use ContainerTrait; + use ContainerTileTrait; public const TAG_FACING = "facing";