diff --git a/src/block/WaterCauldron.php b/src/block/WaterCauldron.php index 88327a010..fddccf43b 100644 --- a/src/block/WaterCauldron.php +++ b/src/block/WaterCauldron.php @@ -31,7 +31,6 @@ use pocketmine\item\Armor; use pocketmine\item\Banner; use pocketmine\item\Dye; use pocketmine\item\Item; -use pocketmine\item\ItemBlock; use pocketmine\item\ItemTypeIds; use pocketmine\item\Potion; use pocketmine\item\PotionType; @@ -155,7 +154,7 @@ final class WaterCauldron extends FillableCauldron{ $this->position->getWorld()->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::CLEAN_BANNER_USE_AMOUNT)); $this->position->getWorld()->addSound($this->position->add(0.5, 0.5, 0.5), new CauldronCleanItemSound()); } - }elseif($item instanceof ItemBlock && $item->getBlock()->getTypeId() === BlockTypeIds::DYED_SHULKER_BOX){ + }elseif(ItemTypeIds::toBlockTypeId($item->getTypeId()) === BlockTypeIds::DYED_SHULKER_BOX){ if($this->customWaterColor === null){ $newItem = VanillaBlocks::SHULKER_BOX()->asItem(); $newItem->setNamedTag($item->getNamedTag()); diff --git a/src/block/inventory/ShulkerBoxInventory.php b/src/block/inventory/ShulkerBoxInventory.php index 102e0b648..d915a9951 100644 --- a/src/block/inventory/ShulkerBoxInventory.php +++ b/src/block/inventory/ShulkerBoxInventory.php @@ -26,7 +26,7 @@ namespace pocketmine\block\inventory; use pocketmine\block\BlockTypeIds; use pocketmine\inventory\SimpleInventory; use pocketmine\item\Item; -use pocketmine\item\ItemBlock; +use pocketmine\item\ItemTypeIds; use pocketmine\network\mcpe\protocol\BlockEventPacket; use pocketmine\network\mcpe\protocol\types\BlockPosition; use pocketmine\world\Position; @@ -51,11 +51,9 @@ class ShulkerBoxInventory extends SimpleInventory implements BlockInventory{ } public function canAddItem(Item $item) : bool{ - if($item instanceof ItemBlock){ - $blockTypeId = $item->getBlock()->getTypeId(); - if($blockTypeId === BlockTypeIds::SHULKER_BOX || $blockTypeId === BlockTypeIds::DYED_SHULKER_BOX){ - return false; - } + $blockTypeId = ItemTypeIds::toBlockTypeId($item->getTypeId()); + if($blockTypeId === BlockTypeIds::SHULKER_BOX || $blockTypeId === BlockTypeIds::DYED_SHULKER_BOX){ + return false; } return parent::canAddItem($item); } diff --git a/src/item/ItemIdentifier.php b/src/item/ItemIdentifier.php index e0d0d28ba..8be4d7d56 100644 --- a/src/item/ItemIdentifier.php +++ b/src/item/ItemIdentifier.php @@ -31,9 +31,8 @@ class ItemIdentifier{ ){} public static function fromBlock(Block $block) : self{ - //negative item type IDs are treated as block IDs //TODO: maybe an ItemBlockIdentifier is in order? - return new self(-$block->getTypeId()); + return new self(ItemTypeIds::fromBlockTypeId($block->getTypeId())); } public function getTypeId() : int{ return $this->typeId; } diff --git a/src/item/ItemTypeIds.php b/src/item/ItemTypeIds.php index b7eea8055..180842555 100644 --- a/src/item/ItemTypeIds.php +++ b/src/item/ItemTypeIds.php @@ -311,4 +311,19 @@ final class ItemTypeIds{ public static function newId() : int{ return self::$nextDynamicId++; } + + public static function fromBlockTypeId(int $blockTypeId) : int{ + if($blockTypeId < 0){ + throw new \InvalidArgumentException("Block type IDs cannot be negative"); + } + //negative item type IDs are treated as block IDs + return -$blockTypeId; + } + + public static function toBlockTypeId(int $itemTypeId) : int{ + if($itemTypeId > 0){ + throw new \InvalidArgumentException("Item type ID $itemTypeId does not represent a block"); + } + return -$itemTypeId; + } }