ItemTypeIds: added fromBlockTypeId() and toBlockTypeId()

this allows checking the type of a blockitem without being required to create a block to do it.
This commit is contained in:
Dylan K. Taylor
2023-03-02 15:28:50 +00:00
parent 77fe0a69ba
commit 33140482bb
4 changed files with 21 additions and 10 deletions

View File

@ -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);
}