mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Avoid implicit ItemFactory reliance for blocks with special items
this hasn't yet been addressed for signs, since they are a bit of a pain in the ass.
This commit is contained in:
parent
db2b523762
commit
ba079bd9aa
@ -30,6 +30,7 @@ use pocketmine\event\block\StructureGrowEvent;
|
||||
use pocketmine\item\Bamboo as ItemBamboo;
|
||||
use pocketmine\item\Fertilizer;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
@ -243,4 +244,8 @@ class Bamboo extends Transparent{
|
||||
$world->setBlock($this->position, $this);
|
||||
}
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::BAMBOO();
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ use pocketmine\event\block\StructureGrowEvent;
|
||||
use pocketmine\item\Bamboo as ItemBamboo;
|
||||
use pocketmine\item\Fertilizer;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\BlockTransaction;
|
||||
@ -126,6 +127,6 @@ final class BambooSapling extends Flowable{
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return VanillaBlocks::BAMBOO()->asItem();
|
||||
return VanillaItems::BAMBOO();
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ use pocketmine\block\utils\BannerPatternLayer;
|
||||
use pocketmine\block\utils\ColoredTrait;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\block\utils\SupportType;
|
||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||
use pocketmine\item\Banner as ItemBanner;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\player\Player;
|
||||
@ -129,10 +129,6 @@ abstract class BaseBanner extends Transparent{
|
||||
}
|
||||
}
|
||||
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return DyeColorIdMap::getInstance()->toInvertedId($this->color);
|
||||
}
|
||||
|
||||
public function getDropsForCompatibleTool(Item $item) : array{
|
||||
$drop = $this->asItem();
|
||||
if($drop instanceof ItemBanner && count($this->patterns) > 0){
|
||||
@ -149,4 +145,8 @@ abstract class BaseBanner extends Transparent{
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::BANNER()->setColor($this->color);
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ use pocketmine\block\utils\SupportType;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\entity\Living;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
use pocketmine\lang\KnownTranslationFactory;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Facing;
|
||||
@ -218,4 +219,9 @@ class Bed extends Transparent{
|
||||
private function canBeSupportedBy(Block $block) : bool{
|
||||
return !$block->getSupportType(Facing::UP)->equals(SupportType::NONE());
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
//TODO: we might be able to get rid of this
|
||||
return VanillaItems::BED()->setColor($this->color);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class Beetroot extends Crops{
|
||||
];
|
||||
}
|
||||
|
||||
public function getPickedItem(bool $addUserData = false) : Item{
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::BEETROOT_SEEDS();
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class Carrot extends Crops{
|
||||
];
|
||||
}
|
||||
|
||||
public function getPickedItem(bool $addUserData = false) : Item{
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::CARROT();
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ class CocoaBlock extends Transparent{
|
||||
];
|
||||
}
|
||||
|
||||
public function getPickedItem(bool $addUserData = false) : Item{
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::COCOA_BEANS();
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,8 @@ namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\BlockDataReader;
|
||||
use pocketmine\block\utils\BlockDataWriter;
|
||||
use pocketmine\data\bedrock\CoralTypeIdMap;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemIds;
|
||||
use pocketmine\item\VanillaItems;
|
||||
use pocketmine\math\Axis;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
@ -39,14 +38,6 @@ use function rad2deg;
|
||||
final class FloorCoralFan extends BaseCoral{
|
||||
private int $axis = Axis::X;
|
||||
|
||||
public function getLegacyItemId() : int{
|
||||
return $this->dead ? ItemIds::CORAL_FAN_DEAD : ItemIds::CORAL_FAN;
|
||||
}
|
||||
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 1; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
@ -98,4 +89,8 @@ final class FloorCoralFan extends BaseCoral{
|
||||
private function canBeSupportedBy(Block $block) : bool{
|
||||
return $block->getSupportType(Facing::UP)->hasCenterSupport();
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::CORAL_FAN()->setCoralType($this->coralType)->setDead($this->dead);
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
|
||||
class MelonStem extends Stem{
|
||||
|
||||
protected function getPlant() : Block{
|
||||
return VanillaBlocks::MELON();
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::MELON_SEEDS();
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class Potato extends Crops{
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getPickedItem(bool $addUserData = false) : Item{
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::POTATO();
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
|
||||
class PumpkinStem extends Stem{
|
||||
|
||||
protected function getPlant() : Block{
|
||||
return VanillaBlocks::PUMPKIN();
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::PUMPKIN_SEEDS();
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\player\Player;
|
||||
@ -54,4 +55,8 @@ class RedstoneWire extends Flowable{
|
||||
private function canBeSupportedBy(Block $block) : bool{
|
||||
return $block->getSupportType(Facing::UP)->hasCenterSupport();
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::REDSTONE_DUST();
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ use pocketmine\block\utils\BlockDataWriterHelper;
|
||||
use pocketmine\block\utils\InvalidBlockStateException;
|
||||
use pocketmine\block\utils\SkullType;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\VanillaItems;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
@ -153,7 +154,8 @@ class Skull extends Flowable{
|
||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return $this->skullType->getMagicNumber();
|
||||
public function asItem() : Item{
|
||||
//TODO: we might be able to get rid of this
|
||||
return VanillaItems::MOB_HEAD()->setSkullType($this->skullType);
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,8 @@ namespace pocketmine\block;
|
||||
use pocketmine\block\utils\BlockDataReader;
|
||||
use pocketmine\block\utils\BlockDataWriter;
|
||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||
use pocketmine\data\bedrock\CoralTypeIdMap;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemIds;
|
||||
use pocketmine\item\VanillaItems;
|
||||
use pocketmine\math\Axis;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
@ -38,14 +37,6 @@ use pocketmine\world\BlockTransaction;
|
||||
final class WallCoralFan extends BaseCoral{
|
||||
use HorizontalFacingTrait;
|
||||
|
||||
public function getLegacyItemId() : int{
|
||||
return $this->dead ? ItemIds::CORAL_FAN_DEAD : ItemIds::CORAL_FAN;
|
||||
}
|
||||
|
||||
protected function writeStateToItemMeta() : int{
|
||||
return CoralTypeIdMap::getInstance()->toId($this->coralType);
|
||||
}
|
||||
|
||||
public function getRequiredStateDataBits() : int{ return parent::getRequiredStateDataBits() + 2; }
|
||||
|
||||
protected function decodeState(BlockDataReader $r) : void{
|
||||
@ -77,4 +68,8 @@ final class WallCoralFan extends BaseCoral{
|
||||
private function canBeSupportedBy(Block $block, int $face) : bool{
|
||||
return $block->getSupportType($face)->hasCenterSupport();
|
||||
}
|
||||
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::CORAL_FAN()->setCoralType($this->coralType)->setDead($this->dead);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class Wheat extends Crops{
|
||||
}
|
||||
}
|
||||
|
||||
public function getPickedItem(bool $addUserData = false) : Item{
|
||||
public function asItem() : Item{
|
||||
return VanillaItems::WHEAT_SEEDS();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user