Item frames can now be placed on the up or down faces of blocks

This commit is contained in:
Dylan K. Taylor 2022-06-25 16:10:39 +01:00
parent db8bf672f0
commit 27d7672273
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 7 additions and 8 deletions

View File

@ -24,9 +24,9 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\block\tile\ItemFrame as TileItemFrame; use pocketmine\block\tile\ItemFrame as TileItemFrame;
use pocketmine\block\utils\AnyFacingTrait;
use pocketmine\block\utils\BlockDataReader; use pocketmine\block\utils\BlockDataReader;
use pocketmine\block\utils\BlockDataWriter; use pocketmine\block\utils\BlockDataWriter;
use pocketmine\block\utils\HorizontalFacingTrait;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\Facing; use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
@ -37,7 +37,7 @@ use function is_nan;
use function lcg_value; use function lcg_value;
class ItemFrame extends Flowable{ class ItemFrame extends Flowable{
use HorizontalFacingTrait; use AnyFacingTrait;
public const ROTATIONS = 8; public const ROTATIONS = 8;
@ -48,12 +48,12 @@ class ItemFrame extends Flowable{
protected float $itemDropChance = 1.0; protected float $itemDropChance = 1.0;
protected function decodeState(BlockDataReader $r) : void{ protected function decodeState(BlockDataReader $r) : void{
$this->facing = $r->readHorizontalFacing(); $this->facing = $r->readFacing();
$this->hasMap = $r->readBool(); $this->hasMap = $r->readBool();
} }
protected function encodeState(BlockDataWriter $w) : void{ protected function encodeState(BlockDataWriter $w) : void{
$w->writeHorizontalFacing($this->facing); $w->writeFacing($this->facing);
$w->writeBool($this->hasMap); $w->writeBool($this->hasMap);
} }
@ -164,7 +164,7 @@ class ItemFrame extends Flowable{
} }
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face === Facing::DOWN || $face === Facing::UP || !$blockClicked->isSolid()){ if(!$blockClicked->isSolid()){
return false; return false;
} }

View File

@ -694,7 +694,7 @@ final class BlockObjectToBlockStateSerializer implements BlockStateSerializer{
return Writer::create(Ids::FRAME) return Writer::create(Ids::FRAME)
->writeBool(StateNames::ITEM_FRAME_MAP_BIT, $block->hasMap()) ->writeBool(StateNames::ITEM_FRAME_MAP_BIT, $block->hasMap())
->writeBool(StateNames::ITEM_FRAME_PHOTO_BIT, false) ->writeBool(StateNames::ITEM_FRAME_PHOTO_BIT, false)
->writeHorizontalFacing($block->getFacing()); ->writeFacingDirection($block->getFacing());
}); });
$this->map(Blocks::JUKEBOX(), fn() => new Writer(Ids::JUKEBOX)); $this->map(Blocks::JUKEBOX(), fn() => new Writer(Ids::JUKEBOX));
$this->map(Blocks::JUNGLE_BUTTON(), fn(WoodenButton $block) => Helper::encodeButton($block, new Writer(Ids::JUNGLE_BUTTON))); $this->map(Blocks::JUNGLE_BUTTON(), fn(WoodenButton $block) => Helper::encodeButton($block, new Writer(Ids::JUNGLE_BUTTON)));

View File

@ -486,10 +486,9 @@ final class BlockStateToBlockObjectDeserializer implements BlockStateDeserialize
$this->map(Ids::FLOWING_LAVA, fn(Reader $in) => Helper::decodeFlowingLiquid(Blocks::LAVA(), $in)); $this->map(Ids::FLOWING_LAVA, fn(Reader $in) => Helper::decodeFlowingLiquid(Blocks::LAVA(), $in));
$this->map(Ids::FLOWING_WATER, fn(Reader $in) => Helper::decodeFlowingLiquid(Blocks::WATER(), $in)); $this->map(Ids::FLOWING_WATER, fn(Reader $in) => Helper::decodeFlowingLiquid(Blocks::WATER(), $in));
$this->map(Ids::FRAME, function(Reader $in) : Block{ $this->map(Ids::FRAME, function(Reader $in) : Block{
//TODO: in R13 this can be any side, not just horizontal
$in->todo(StateNames::ITEM_FRAME_PHOTO_BIT); //TODO: not sure what the point of this is $in->todo(StateNames::ITEM_FRAME_PHOTO_BIT); //TODO: not sure what the point of this is
return Blocks::ITEM_FRAME() return Blocks::ITEM_FRAME()
->setFacing($in->readHorizontalFacing()) ->setFacing($in->readFacingDirection())
->setHasMap($in->readBool(StateNames::ITEM_FRAME_MAP_BIT)); ->setHasMap($in->readBool(StateNames::ITEM_FRAME_MAP_BIT));
}); });
$this->map(Ids::FROSTED_ICE, function(Reader $in) : Block{ $this->map(Ids::FROSTED_ICE, function(Reader $in) : Block{