mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 00:39:45 +00:00
ItemBlock no longer depends on legacy ID/metadata
This commit is contained in:
parent
7ef794d725
commit
c42a6d7552
@ -31,25 +31,15 @@ use pocketmine\block\BlockFactory;
|
||||
*/
|
||||
class ItemBlock extends Item{
|
||||
/** @var int */
|
||||
protected $blockId;
|
||||
/** @var int */
|
||||
protected $blockMeta;
|
||||
private $blockFullId;
|
||||
|
||||
/**
|
||||
* @param int $blockMeta usually 0-15 (placed blocks may only have meta values 0-15)
|
||||
*/
|
||||
public function __construct(int $blockId, int $blockMeta, ItemIdentifier $identifier){
|
||||
if($blockMeta < 0 || $blockMeta > 15){
|
||||
throw new \InvalidArgumentException("Block meta value may only be between 0 and 15");
|
||||
}
|
||||
$this->blockId = $blockId;
|
||||
$this->blockMeta = $blockMeta;
|
||||
|
||||
parent::__construct($identifier, $this->getBlock()->getName());
|
||||
public function __construct(ItemIdentifier $identifier, Block $block){
|
||||
parent::__construct($identifier, $block->getName());
|
||||
$this->blockFullId = $block->getFullId();
|
||||
}
|
||||
|
||||
public function getBlock(?int $clickedFace = null) : Block{
|
||||
return BlockFactory::getInstance()->get($this->blockId, $this->blockMeta);
|
||||
return BlockFactory::getInstance()->fromFullBlock($this->blockFullId);
|
||||
}
|
||||
|
||||
public function getFuelTime() : int{
|
||||
|
@ -25,7 +25,6 @@ namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\BlockLegacyIds;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\block\utils\RecordType;
|
||||
use pocketmine\block\utils\SkullType;
|
||||
@ -178,23 +177,22 @@ class ItemFactory{
|
||||
$this->register(new Item(new ItemIdentifier(ItemIds::SUGAR, 0), "Sugar"));
|
||||
$this->register(new Item(new ItemIdentifier(ItemIds::TURTLE_SHELL_PIECE, 0), "Scute"));
|
||||
$this->register(new Item(new ItemIdentifier(ItemIds::WHEAT, 0), "Wheat"));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::ACACIA_DOOR_BLOCK, 0, new ItemIdentifier(ItemIds::ACACIA_DOOR, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::BIRCH_DOOR_BLOCK, 0, new ItemIdentifier(ItemIds::BIRCH_DOOR, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::BREWING_STAND_BLOCK, 0, new ItemIdentifier(ItemIds::BREWING_STAND, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::CAKE_BLOCK, 0, new ItemIdentifier(ItemIds::CAKE, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::CAULDRON_BLOCK, 0, new ItemIdentifier(ItemIds::CAULDRON, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::COMPARATOR_BLOCK, 0, new ItemIdentifier(ItemIds::COMPARATOR, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::DARK_OAK_DOOR_BLOCK, 0, new ItemIdentifier(ItemIds::DARK_OAK_DOOR, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::FLOWER_POT_BLOCK, 0, new ItemIdentifier(ItemIds::FLOWER_POT, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::HOPPER_BLOCK, 0, new ItemIdentifier(ItemIds::HOPPER, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::IRON_DOOR_BLOCK, 0, new ItemIdentifier(ItemIds::IRON_DOOR, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::ITEM_FRAME_BLOCK, 0, new ItemIdentifier(ItemIds::ITEM_FRAME, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::JUNGLE_DOOR_BLOCK, 0, new ItemIdentifier(ItemIds::JUNGLE_DOOR, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::NETHER_WART_PLANT, 0, new ItemIdentifier(ItemIds::NETHER_WART, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::OAK_DOOR_BLOCK, 0, new ItemIdentifier(ItemIds::OAK_DOOR, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::REPEATER_BLOCK, 0, new ItemIdentifier(ItemIds::REPEATER, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::SPRUCE_DOOR_BLOCK, 0, new ItemIdentifier(ItemIds::SPRUCE_DOOR, 0)));
|
||||
$this->register(new ItemBlock(BlockLegacyIds::SUGARCANE_BLOCK, 0, new ItemIdentifier(ItemIds::SUGARCANE, 0)));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::ACACIA_DOOR, 0), VanillaBlocks::ACACIA_DOOR()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::BIRCH_DOOR, 0), VanillaBlocks::BIRCH_DOOR()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::BREWING_STAND, 0), VanillaBlocks::BREWING_STAND()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::CAKE, 0), VanillaBlocks::CAKE()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::COMPARATOR, 0), VanillaBlocks::REDSTONE_COMPARATOR()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::DARK_OAK_DOOR, 0), VanillaBlocks::DARK_OAK_DOOR()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::FLOWER_POT, 0), VanillaBlocks::FLOWER_POT()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::HOPPER, 0), VanillaBlocks::HOPPER()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::IRON_DOOR, 0), VanillaBlocks::IRON_DOOR()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::ITEM_FRAME, 0), VanillaBlocks::ITEM_FRAME()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::JUNGLE_DOOR, 0), VanillaBlocks::JUNGLE_DOOR()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::NETHER_WART, 0), VanillaBlocks::NETHER_WART()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::OAK_DOOR, 0), VanillaBlocks::OAK_DOOR()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::REPEATER, 0), VanillaBlocks::REDSTONE_REPEATER()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::SPRUCE_DOOR, 0), VanillaBlocks::SPRUCE_DOOR()));
|
||||
$this->register(new ItemBlock(new ItemIdentifier(ItemIds::SUGARCANE, 0), VanillaBlocks::SUGARCANE()));
|
||||
//TODO: fix metadata for buckets with still liquid in them
|
||||
//the meta values are intentionally hardcoded because block IDs will change in the future
|
||||
$this->register(new LiquidBucket(new ItemIdentifier(ItemIds::BUCKET, 8), "Water Bucket", VanillaBlocks::WATER()));
|
||||
@ -433,7 +431,7 @@ class ItemFactory{
|
||||
}
|
||||
}elseif($id < 256){ //intentionally includes negatives, for extended block IDs
|
||||
//TODO: do not assume that item IDs and block IDs are the same or related
|
||||
$item = new ItemBlock($id < 0 ? 255 - $id : $id, $meta, new ItemIdentifier($id, $meta));
|
||||
$item = new ItemBlock(new ItemIdentifier($id, $meta), BlockFactory::getInstance()->get($id < 0 ? 255 - $id : $id, $meta & 0xf));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user