mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Flatten wall_banner and wall_sign into single blocks (#2798)
This comes with some problems, but the problems are more bearable than the previous code.
This commit is contained in:
parent
bb718faa2e
commit
8f1bc5d497
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
||||
|
||||
use Ds\Deque;
|
||||
use pocketmine\block\utils\BannerPattern;
|
||||
use pocketmine\block\utils\BlockDataValidator;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\item\Banner as ItemBanner;
|
||||
use pocketmine\item\Item;
|
||||
@ -37,18 +38,25 @@ use pocketmine\tile\Banner as TileBanner;
|
||||
use function assert;
|
||||
use function floor;
|
||||
|
||||
class StandingBanner extends Transparent{
|
||||
class Banner extends Transparent{
|
||||
/** @var BlockIdentifierFlattened */
|
||||
protected $idInfo;
|
||||
|
||||
//TODO: conditionally useless properties, find a way to fix
|
||||
|
||||
/** @var int */
|
||||
protected $rotation = 0;
|
||||
|
||||
/** @var int */
|
||||
protected $facing = Facing::UP;
|
||||
|
||||
/** @var DyeColor */
|
||||
protected $baseColor;
|
||||
|
||||
/** @var Deque|BannerPattern[] */
|
||||
protected $patterns;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name){
|
||||
public function __construct(BlockIdentifierFlattened $idInfo, string $name){
|
||||
parent::__construct($idInfo, $name);
|
||||
$this->baseColor = DyeColor::BLACK();
|
||||
$this->patterns = new Deque();
|
||||
@ -58,12 +66,24 @@ class StandingBanner extends Transparent{
|
||||
$this->patterns = $this->patterns->map(function(BannerPattern $pattern) : BannerPattern{ return clone $pattern; });
|
||||
}
|
||||
|
||||
public function getId() : int{
|
||||
return $this->facing === Facing::UP ? parent::getId() : $this->idInfo->getSecondId();
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->rotation;
|
||||
if($this->facing === Facing::UP){
|
||||
return $this->rotation;
|
||||
}
|
||||
return $this->facing;
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->rotation = $stateMeta;
|
||||
if($id === $this->idInfo->getSecondId()){
|
||||
$this->facing = BlockDataValidator::readHorizontalFacing($stateMeta);
|
||||
}else{
|
||||
$this->facing = Facing::UP;
|
||||
$this->rotation = $stateMeta;
|
||||
}
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
@ -131,24 +151,19 @@ class StandingBanner extends Transparent{
|
||||
$this->setPatterns($item->getPatterns());
|
||||
}
|
||||
if($face !== Facing::DOWN){
|
||||
if($face === Facing::UP and $player !== null){
|
||||
$this->rotation = ((int) floor((($player->yaw + 180) * 16 / 360) + 0.5)) & 0x0f;
|
||||
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
$this->facing = $face;
|
||||
if($face === Facing::UP){
|
||||
$this->rotation = $player !== null ? ((int) floor((($player->yaw + 180) * 16 / 360) + 0.5)) & 0x0f : 0;
|
||||
}
|
||||
|
||||
//TODO: awful hack :(
|
||||
$wallBanner = BlockFactory::get(Block::WALL_BANNER, $face);
|
||||
assert($wallBanner instanceof WallBanner);
|
||||
$wallBanner->baseColor = $this->baseColor;
|
||||
$wallBanner->setPatterns($this->patterns);
|
||||
return $this->getLevel()->setBlock($blockReplace, $wallBanner);
|
||||
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
if($this->getSide(Facing::DOWN)->getId() === self::AIR){
|
||||
if($this->getSide(Facing::opposite($this->facing))->getId() === self::AIR){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
}
|
||||
}
|
@ -78,6 +78,7 @@ class BlockFactory{
|
||||
self::register(new Anvil(new BID(Block::ANVIL, Anvil::TYPE_NORMAL), "Anvil"));
|
||||
self::register(new Anvil(new BID(Block::ANVIL, Anvil::TYPE_SLIGHTLY_DAMAGED), "Slightly Damaged Anvil"));
|
||||
self::register(new Anvil(new BID(Block::ANVIL, Anvil::TYPE_VERY_DAMAGED), "Very Damaged Anvil"));
|
||||
self::register(new Banner(new BlockIdentifierFlattened(Block::STANDING_BANNER, Block::WALL_BANNER, 0, ItemIds::BANNER, \pocketmine\tile\Banner::class), "Banner"));
|
||||
self::register(new Bed(new BID(Block::BED_BLOCK, 0, ItemIds::BED, \pocketmine\tile\Bed::class), "Bed Block"));
|
||||
self::register(new Bedrock(new BID(Block::BEDROCK), "Bedrock"));
|
||||
self::register(new Beetroot(new BID(Block::BEETROOT_BLOCK), "Beetroot Block"));
|
||||
@ -224,14 +225,13 @@ class BlockFactory{
|
||||
self::register(new SandstoneStairs(new BID(Block::RED_SANDSTONE_STAIRS), "Red Sandstone Stairs"));
|
||||
self::register(new SandstoneStairs(new BID(Block::SANDSTONE_STAIRS), "Sandstone Stairs"));
|
||||
self::register(new SeaLantern(new BID(Block::SEALANTERN), "Sea Lantern"));
|
||||
self::register(new SignPost(new BID(Block::SIGN_POST, 0, ItemIds::SIGN, \pocketmine\tile\Sign::class), "Sign Post"));
|
||||
self::register(new Sign(new BlockIdentifierFlattened(Block::STANDING_SIGN, Block::WALL_SIGN, 0, ItemIds::SIGN, \pocketmine\tile\Sign::class), "Sign"));
|
||||
self::register(new Skull(new BID(Block::MOB_HEAD_BLOCK, 0, null, \pocketmine\tile\Skull::class), "Mob Head"));
|
||||
self::register(new SmoothStone(new BID(Block::STONE, Stone::NORMAL), "Stone"));
|
||||
self::register(new Snow(new BID(Block::SNOW), "Snow Block"));
|
||||
self::register(new SnowLayer(new BID(Block::SNOW_LAYER), "Snow Layer"));
|
||||
self::register(new SoulSand(new BID(Block::SOUL_SAND), "Soul Sand"));
|
||||
self::register(new Sponge(new BID(Block::SPONGE), "Sponge"));
|
||||
self::register(new StandingBanner(new BID(Block::STANDING_BANNER, 0, ItemIds::BANNER, \pocketmine\tile\Banner::class), "Standing Banner"));
|
||||
self::register(new Stone(new BID(Block::STONE, Stone::ANDESITE), "Andesite"));
|
||||
self::register(new Stone(new BID(Block::STONE, Stone::DIORITE), "Diorite"));
|
||||
self::register(new Stone(new BID(Block::STONE, Stone::GRANITE), "Granite"));
|
||||
@ -279,8 +279,6 @@ class BlockFactory{
|
||||
self::register(new TripwireHook(new BID(Block::TRIPWIRE_HOOK), "Tripwire Hook"));
|
||||
self::register(new UnderwaterTorch(new BID(Block::UNDERWATER_TORCH), "Underwater Torch"));
|
||||
self::register(new Vine(new BID(Block::VINE), "Vines"));
|
||||
self::register(new WallBanner(new BID(Block::WALL_BANNER, 0, ItemIds::BANNER, \pocketmine\tile\Banner::class), "Wall Banner"));
|
||||
self::register(new WallSign(new BID(Block::WALL_SIGN, 0, ItemIds::SIGN, \pocketmine\tile\Sign::class), "Wall Sign"));
|
||||
self::register(new Water(new BlockIdentifierFlattened(Block::FLOWING_WATER, Block::STILL_WATER), "Water"));
|
||||
self::register(new WaterLily(new BID(Block::LILY_PAD), "Lily Pad"));
|
||||
self::register(new WeightedPressurePlateHeavy(new BID(Block::HEAVY_WEIGHTED_PRESSURE_PLATE), "Weighted Pressure Plate Heavy"));
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\BlockDataValidator;
|
||||
use pocketmine\block\utils\SignText;
|
||||
use pocketmine\event\block\SignChangeEvent;
|
||||
use pocketmine\item\Item;
|
||||
@ -36,15 +37,22 @@ use function array_map;
|
||||
use function assert;
|
||||
use function floor;
|
||||
|
||||
class SignPost extends Transparent{
|
||||
class Sign extends Transparent{
|
||||
/** @var BlockIdentifierFlattened */
|
||||
protected $idInfo;
|
||||
|
||||
//TODO: conditionally useless properties, find a way to fix
|
||||
|
||||
/** @var int */
|
||||
protected $rotation = 0;
|
||||
|
||||
/** @var int */
|
||||
protected $facing = Facing::UP;
|
||||
|
||||
/** @var SignText */
|
||||
protected $text;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name){
|
||||
public function __construct(BlockIdentifierFlattened $idInfo, string $name){
|
||||
parent::__construct($idInfo, $name);
|
||||
$this->text = new SignText();
|
||||
}
|
||||
@ -53,12 +61,24 @@ class SignPost extends Transparent{
|
||||
$this->text = clone $this->text;
|
||||
}
|
||||
|
||||
public function getId() : int{
|
||||
return $this->facing === Facing::UP ? parent::getId() : $this->idInfo->getSecondId();
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->rotation;
|
||||
if($this->facing === Facing::UP){
|
||||
return $this->rotation;
|
||||
}
|
||||
return $this->facing;
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->rotation = $stateMeta;
|
||||
if($id === $this->idInfo->getSecondId()){
|
||||
$this->facing = BlockDataValidator::readHorizontalFacing($stateMeta);
|
||||
}else{
|
||||
$this->facing = Facing::UP;
|
||||
$this->rotation = $stateMeta;
|
||||
}
|
||||
}
|
||||
|
||||
public function readStateFromWorld() : void{
|
||||
@ -94,20 +114,19 @@ class SignPost extends Transparent{
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||
if($face !== Facing::DOWN){
|
||||
|
||||
$this->facing = $face;
|
||||
if($face === Facing::UP){
|
||||
$this->rotation = $player !== null ? ((int) floor((($player->yaw + 180) * 16 / 360) + 0.5)) & 0x0f : 0;
|
||||
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
return $this->getLevel()->setBlock($blockReplace, BlockFactory::get(Block::WALL_SIGN, $face));
|
||||
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
if($this->getSide(Facing::DOWN)->getId() === self::AIR){
|
||||
if($this->getSide(Facing::opposite($this->facing))->getId() === self::AIR){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\BlockDataValidator;
|
||||
use pocketmine\math\Facing;
|
||||
|
||||
class WallBanner extends StandingBanner{
|
||||
|
||||
/** @var int */
|
||||
protected $facing = Facing::NORTH;
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->facing;
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->facing = BlockDataValidator::readHorizontalFacing($stateMeta);
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b111;
|
||||
}
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
if($this->getSide(Facing::opposite($this->facing))->getId() === self::AIR){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\BlockDataValidator;
|
||||
use pocketmine\math\Facing;
|
||||
|
||||
class WallSign extends SignPost{
|
||||
|
||||
/** @var int */
|
||||
protected $facing = Facing::NORTH;
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->facing;
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->facing = BlockDataValidator::readHorizontalFacing($stateMeta);
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b111;
|
||||
}
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
if($this->getSide(Facing::opposite($this->facing))->getId() === self::AIR){
|
||||
$this->getLevel()->useBreakOn($this);
|
||||
}
|
||||
}
|
||||
}
|
@ -23,11 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\utils;
|
||||
|
||||
use pocketmine\block\StandingBanner;
|
||||
use pocketmine\block\Banner;
|
||||
|
||||
/**
|
||||
* Contains information about a pattern layer on a banner.
|
||||
* @see StandingBanner
|
||||
* @see Banner
|
||||
*/
|
||||
class BannerPattern{
|
||||
public const BORDER = "bo";
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\event\block;
|
||||
|
||||
use pocketmine\block\SignPost;
|
||||
use pocketmine\block\Sign;
|
||||
use pocketmine\block\utils\SignText;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\event\CancellableTrait;
|
||||
@ -35,7 +35,7 @@ use pocketmine\Player;
|
||||
class SignChangeEvent extends BlockEvent implements Cancellable{
|
||||
use CancellableTrait;
|
||||
|
||||
/** @var SignPost */
|
||||
/** @var Sign */
|
||||
private $sign;
|
||||
|
||||
/** @var Player */
|
||||
@ -45,11 +45,11 @@ class SignChangeEvent extends BlockEvent implements Cancellable{
|
||||
private $text;
|
||||
|
||||
/**
|
||||
* @param SignPost $sign
|
||||
* @param Sign $sign
|
||||
* @param Player $player
|
||||
* @param SignText $text
|
||||
*/
|
||||
public function __construct(SignPost $sign, Player $player, SignText $text){
|
||||
public function __construct(Sign $sign, Player $player, SignText $text){
|
||||
parent::__construct($sign);
|
||||
$this->sign = $sign;
|
||||
$this->player = $player;
|
||||
@ -57,9 +57,9 @@ class SignChangeEvent extends BlockEvent implements Cancellable{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SignPost
|
||||
* @return Sign
|
||||
*/
|
||||
public function getSign() : SignPost{
|
||||
public function getSign() : Sign{
|
||||
return $this->sign;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\network\mcpe\handler;
|
||||
|
||||
use pocketmine\block\ItemFrame;
|
||||
use pocketmine\block\SignPost;
|
||||
use pocketmine\block\Sign;
|
||||
use pocketmine\block\utils\SignText;
|
||||
use pocketmine\inventory\transaction\action\InventoryAction;
|
||||
use pocketmine\inventory\transaction\CraftingTransaction;
|
||||
@ -403,7 +403,7 @@ class SimpleSessionHandler extends SessionHandler{
|
||||
throw new BadPacketException($e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
if($block instanceof SignPost){
|
||||
if($block instanceof Sign){
|
||||
if($nbt->hasTag("Text", StringTag::class)){
|
||||
try{
|
||||
$text = SignText::fromBlob($nbt->getString("Text"));
|
||||
|
@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
namespace pocketmine\tile;
|
||||
|
||||
use Ds\Deque;
|
||||
use pocketmine\block\StandingBanner;
|
||||
use pocketmine\block\utils\BannerPattern;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\level\Level;
|
||||
@ -36,7 +35,7 @@ use pocketmine\nbt\tag\StringTag;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see StandingBanner
|
||||
* @see \pocketmine\block\Banner
|
||||
*/
|
||||
class Banner extends Spawnable{
|
||||
|
||||
|
@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\tile;
|
||||
|
||||
use pocketmine\block\SignPost;
|
||||
use pocketmine\block\utils\SignText;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\math\Vector3;
|
||||
@ -38,7 +37,7 @@ use function sprintf;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @see SignPost
|
||||
* @see \pocketmine\block\Sign
|
||||
*/
|
||||
class Sign extends Spawnable{
|
||||
public const TAG_TEXT_BLOB = "Text";
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user