Revert back to floor/wall banner variants

this code largely duplicates the same code in FloorSign/WallSign and needs to be de-duplicated.
This commit is contained in:
Dylan K. Taylor 2020-10-04 19:05:43 +01:00
parent 505d4e402f
commit 7f9c4355f0
10 changed files with 155 additions and 92 deletions

View File

@ -41,18 +41,7 @@ use pocketmine\world\BlockTransaction;
use function assert;
use function floor;
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;
abstract class BaseBanner extends Transparent{
/** @var DyeColor */
protected $baseColor;
@ -62,7 +51,7 @@ class Banner extends Transparent{
*/
protected $patterns;
public function __construct(BlockIdentifierFlattened $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.0, BlockToolType::AXE));
$this->baseColor = DyeColor::BLACK();
$this->patterns = new Deque();
@ -74,30 +63,6 @@ class Banner extends Transparent{
$this->patterns = $this->patterns->copy();
}
public function getId() : int{
return $this->facing === Facing::UP ? parent::getId() : $this->idInfo->getSecondId();
}
protected function writeStateToMeta() : int{
if($this->facing === Facing::UP){
return $this->rotation;
}
return BlockDataSerializer::writeHorizontalFacing($this->facing);
}
public function readStateFromData(int $id, int $stateMeta) : void{
if($id === $this->idInfo->getSecondId()){
$this->facing = BlockDataSerializer::readHorizontalFacing($stateMeta);
}else{
$this->facing = Facing::UP;
$this->rotation = $stateMeta;
}
}
public function getStateBitmask() : int{
return 0b1111;
}
public function readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->pos->getWorld()->getTile($this->pos);
@ -160,20 +125,14 @@ class Banner extends Transparent{
$this->baseColor = $item->getColor();
$this->setPatterns($item->getPatterns());
}
if($face !== Facing::DOWN){
$this->facing = $face;
if($face === Facing::UP){
$this->rotation = $player !== null ? ((int) floor((($player->getLocation()->getYaw() + 180) * 16 / 360) + 0.5)) & 0x0f : 0;
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
abstract protected function getSupportingFace() : int;
public function onNearbyBlockChange() : void{
if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){
if($this->getSide($this->getSupportingFace())->getId() === BlockLegacyIds::AIR){
$this->pos->getWorld()->useBreakOn($this->pos);
}
}

View File

@ -104,7 +104,8 @@ class BlockFactory{
$this->register(new Anvil(new BID(Ids::ANVIL), "Anvil"));
$this->register(new Bamboo(new BID(Ids::BAMBOO), "Bamboo", new BlockBreakInfo(2.0 /* 1.0 in PC */, BlockToolType::AXE)));
$this->register(new BambooSapling(new BID(Ids::BAMBOO_SAPLING), "Bamboo Sapling", BlockBreakInfo::instant()));
$this->register(new Banner(new BIDFlattened(Ids::STANDING_BANNER, Ids::WALL_BANNER, 0, ItemIds::BANNER, TileBanner::class), "Banner"));
$this->register(new FloorBanner(new BID(Ids::STANDING_BANNER, 0, ItemIds::BANNER, TileBanner::class), "Banner"));
$this->register(new WallBanner(new BID(Ids::WALL_BANNER, 0, ItemIds::BANNER, TileBanner::class), "Wall Banner"));
$this->register(new Transparent(new BID(Ids::BARRIER), "Barrier", BlockBreakInfo::indestructible()));
$this->register(new Beacon(new BID(Ids::BEACON, 0, null, TileBeacon::class), "Beacon", new BlockBreakInfo(3.0)));
$this->register(new Bed(new BID(Ids::BED_BLOCK, 0, ItemIds::BED, TileBed::class), "Bed Block"));

62
src/block/FloorBanner.php Normal file
View File

@ -0,0 +1,62 @@
<?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\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
final class FloorBanner extends BaseBanner{
/** @var int */
protected $rotation = 0;
public function readStateFromData(int $id, int $stateMeta) : void{
$this->rotation = $stateMeta;
}
protected function writeStateToMeta() : int{
return $this->rotation;
}
public function getStateBitmask() : int{
return 0b1111;
}
protected function getSupportingFace() : int{
return Facing::DOWN;
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face !== Facing::UP){
return false;
}
if($player !== null){
$this->rotation = ((int) floor((($player->getLocation()->getYaw() + 180) * 16 / 360) + 0.5)) & 0x0f;
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
}

View File

@ -57,7 +57,7 @@ use function assert;
* @method static Flower AZURE_BLUET()
* @method static Bamboo BAMBOO()
* @method static BambooSapling BAMBOO_SAPLING()
* @method static Banner BANNER()
* @method static FloorBanner BANNER()
* @method static Transparent BARRIER()
* @method static Beacon BEACON()
* @method static Bed BED()
@ -654,6 +654,7 @@ use function assert;
* @method static TripwireHook TRIPWIRE_HOOK()
* @method static UnderwaterTorch UNDERWATER_TORCH()
* @method static Vine VINES()
* @method static WallBanner WALL_BANNER()
* @method static Water WATER()
* @method static WeightedPressurePlateHeavy WEIGHTED_PRESSURE_PLATE_HEAVY()
* @method static WeightedPressurePlateLight WEIGHTED_PRESSURE_PLATE_LIGHT()
@ -1328,6 +1329,7 @@ final class VanillaBlocks{
self::register("tripwire_hook", $factory->get(131));
self::register("underwater_torch", $factory->get(239, 5));
self::register("vines", $factory->get(106));
self::register("wall_banner", $factory->get(177, 2));
self::register("water", $factory->get(8));
self::register("weighted_pressure_plate_heavy", $factory->get(148));
self::register("weighted_pressure_plate_light", $factory->get(147));

61
src/block/WallBanner.php Normal file
View File

@ -0,0 +1,61 @@
<?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\BlockDataSerializer;
use pocketmine\block\utils\HorizontalFacingTrait;
use pocketmine\item\Item;
use pocketmine\math\Axis;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
final class WallBanner extends BaseBanner{
use HorizontalFacingTrait;
protected function writeStateToMeta() : int{
return BlockDataSerializer::writeHorizontalFacing($this->facing);
}
public function readStateFromData(int $id, int $stateMeta) : void{
$this->facing = BlockDataSerializer::readHorizontalFacing($stateMeta);
}
public function getStateBitmask() : int{
return 0b111;
}
protected function getSupportingFace() : int{
return Facing::opposite($this->facing);
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if(Facing::axis($face) === Axis::Y){
return false;
}
$this->facing = $face;
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
}

View File

@ -35,7 +35,7 @@ use pocketmine\world\World;
/**
* @deprecated
* @see \pocketmine\block\Banner
* @see \pocketmine\block\BaseBanner
*/
class Banner extends Spawnable{

View File

@ -23,11 +23,11 @@ declare(strict_types=1);
namespace pocketmine\block\utils;
use pocketmine\block\Banner;
use pocketmine\block\BaseBanner;
/**
* Contains information about a pattern layer on a banner.
* @see Banner
* @see BaseBanner
*/
class BannerPattern{
public const BORDER = "bo";

View File

@ -33,7 +33,7 @@ use pocketmine\data\bedrock\DyeColorIdMap;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag;
class Banner extends Item{
class Banner extends ItemBlockWallOrFloor{
public const TAG_PATTERNS = TileBanner::TAG_PATTERNS;
public const TAG_PATTERN_COLOR = TileBanner::TAG_PATTERN_COLOR;
public const TAG_PATTERN_NAME = TileBanner::TAG_PATTERN_NAME;
@ -47,9 +47,9 @@ class Banner extends Item{
*/
private $patterns;
public function __construct(ItemIdentifier $identifier, string $name, DyeColor $color){
parent::__construct($identifier, $name);
$this->color = $color;
public function __construct(ItemIdentifier $identifier, Block $floorVariant, Block $wallVariant){
parent::__construct($identifier, $floorVariant, $wallVariant);
$this->color = DyeColor::BLACK();
$this->patterns = new Deque();
}
@ -58,8 +58,14 @@ class Banner extends Item{
return $this->color;
}
public function getBlock(?int $clickedFace = null) : Block{
return VanillaBlocks::BANNER();
/** @return $this */
public function setColor(DyeColor $color) : self{
$this->color = $color;
return $this;
}
public function getMeta() : int{
return DyeColorIdMap::getInstance()->toInvertedId($this->color);
}
public function getMaxStackSize() : int{

View File

@ -260,7 +260,11 @@ class ItemFactory{
//TODO: add interface to dye-colour objects
$this->register(new Dye(new ItemIdentifier(ItemIds::DYE, $dyeMap[$color->id()] ?? $colorIdMap->toInvertedId($color)), $color->getDisplayName() . " Dye", $color));
$this->register(new Bed(new ItemIdentifier(ItemIds::BED, $colorIdMap->toId($color)), $color->getDisplayName() . " Bed", $color));
$this->register(new Banner(new ItemIdentifier(ItemIds::BANNER, $colorIdMap->toInvertedId($color)), $color->getDisplayName() . " Banner", $color));
$this->register((new Banner(
new ItemIdentifier(ItemIds::BANNER, 0),
VanillaBlocks::BANNER(),
VanillaBlocks::WALL_BANNER()
))->setColor($color));
}
foreach(Potion::ALL as $type){

View File

@ -30,7 +30,7 @@ use function assert;
/**
* This doc-block is generated automatically, do not modify it manually.
* This must be regenerated whenever registry members are added, removed or changed.
* @see RegistryTrait::_generateMethodAnnotations()
* @see \pocketmine\utils\RegistryUtils::_generateMethodAnnotations()
*
* @method static Boat ACACIA_BOAT()
* @method static Apple APPLE()
@ -40,13 +40,11 @@ use function assert;
* @method static BeetrootSeeds BEETROOT_SEEDS()
* @method static BeetrootSoup BEETROOT_SOUP()
* @method static Boat BIRCH_BOAT()
* @method static Banner BLACK_BANNER()
* @method static Bed BLACK_BED()
* @method static Dye BLACK_DYE()
* @method static Item BLAZE_POWDER()
* @method static BlazeRod BLAZE_ROD()
* @method static Item BLEACH()
* @method static Banner BLUE_BANNER()
* @method static Bed BLUE_BED()
* @method static Dye BLUE_DYE()
* @method static Item BONE()
@ -56,7 +54,6 @@ use function assert;
* @method static Bowl BOWL()
* @method static Bread BREAD()
* @method static Item BRICK()
* @method static Banner BROWN_BANNER()
* @method static Bed BROWN_BED()
* @method static Dye BROWN_DYE()
* @method static Bucket BUCKET()
@ -120,7 +117,6 @@ use function assert;
* @method static CookedSalmon COOKED_SALMON()
* @method static Cookie COOKIE()
* @method static Skull CREEPER_HEAD()
* @method static Banner CYAN_BANNER()
* @method static Bed CYAN_BED()
* @method static Dye CYAN_DYE()
* @method static Boat DARK_OAK_BOAT()
@ -164,10 +160,8 @@ use function assert;
* @method static Pickaxe GOLDEN_PICKAXE()
* @method static Shovel GOLDEN_SHOVEL()
* @method static Sword GOLDEN_SWORD()
* @method static Banner GRAY_BANNER()
* @method static Bed GRAY_BED()
* @method static Dye GRAY_DYE()
* @method static Banner GREEN_BANNER()
* @method static Bed GREEN_BED()
* @method static Dye GREEN_DYE()
* @method static Item GUNPOWDER()
@ -192,16 +186,12 @@ use function assert;
* @method static Armor LEATHER_CAP()
* @method static Armor LEATHER_PANTS()
* @method static Armor LEATHER_TUNIC()
* @method static Banner LIGHT_BLUE_BANNER()
* @method static Bed LIGHT_BLUE_BED()
* @method static Dye LIGHT_BLUE_DYE()
* @method static Banner LIGHT_GRAY_BANNER()
* @method static Bed LIGHT_GRAY_BED()
* @method static Dye LIGHT_GRAY_DYE()
* @method static Banner LIME_BANNER()
* @method static Bed LIME_BED()
* @method static Dye LIME_DYE()
* @method static Banner MAGENTA_BANNER()
* @method static Bed MAGENTA_BED()
* @method static Dye MAGENTA_DYE()
* @method static Item MAGMA_CREAM()
@ -216,12 +206,10 @@ use function assert;
* @method static Item NETHER_STAR()
* @method static ItemBlock NETHER_WART()
* @method static Boat OAK_BOAT()
* @method static Banner ORANGE_BANNER()
* @method static Bed ORANGE_BED()
* @method static Dye ORANGE_DYE()
* @method static PaintingItem PAINTING()
* @method static Item PAPER()
* @method static Banner PINK_BANNER()
* @method static Bed PINK_BED()
* @method static Dye PINK_DYE()
* @method static Skull PLAYER_HEAD()
@ -234,7 +222,6 @@ use function assert;
* @method static Pufferfish PUFFERFISH()
* @method static PumpkinPie PUMPKIN_PIE()
* @method static PumpkinSeeds PUMPKIN_SEEDS()
* @method static Banner PURPLE_BANNER()
* @method static Bed PURPLE_BED()
* @method static Dye PURPLE_DYE()
* @method static Item RABBIT_FOOT()
@ -259,7 +246,6 @@ use function assert;
* @method static Record RECORD_STRAD()
* @method static Record RECORD_WAIT()
* @method static Record RECORD_WARD()
* @method static Banner RED_BANNER()
* @method static Bed RED_BED()
* @method static Dye RED_DYE()
* @method static Redstone REDSTONE_DUST()
@ -287,7 +273,6 @@ use function assert;
* @method static LiquidBucket WATER_BUCKET()
* @method static Item WHEAT()
* @method static WheatSeeds WHEAT_SEEDS()
* @method static Banner WHITE_BANNER()
* @method static Bed WHITE_BED()
* @method static Dye WHITE_DYE()
* @method static Skull WITHER_SKELETON_SKULL()
@ -298,7 +283,6 @@ use function assert;
* @method static Sword WOODEN_SWORD()
* @method static WritableBook WRITABLE_BOOK()
* @method static WrittenBook WRITTEN_BOOK()
* @method static Banner YELLOW_BANNER()
* @method static Bed YELLOW_BED()
* @method static Dye YELLOW_DYE()
* @method static Skull ZOMBIE_HEAD()
@ -340,13 +324,11 @@ final class VanillaItems{
self::register("beetroot_seeds", $factory->get(458));
self::register("beetroot_soup", $factory->get(459));
self::register("birch_boat", $factory->get(333, 2));
self::register("black_banner", $factory->get(446));
self::register("black_bed", $factory->get(355, 15));
self::register("black_dye", $factory->get(351, 16));
self::register("blaze_powder", $factory->get(377));
self::register("blaze_rod", $factory->get(369));
self::register("bleach", $factory->get(451));
self::register("blue_banner", $factory->get(446, 4));
self::register("blue_bed", $factory->get(355, 11));
self::register("blue_dye", $factory->get(351, 18));
self::register("bone", $factory->get(352));
@ -356,7 +338,6 @@ final class VanillaItems{
self::register("bowl", $factory->get(281));
self::register("bread", $factory->get(297));
self::register("brick", $factory->get(336));
self::register("brown_banner", $factory->get(446, 3));
self::register("brown_bed", $factory->get(355, 12));
self::register("brown_dye", $factory->get(351, 17));
self::register("bucket", $factory->get(325));
@ -420,7 +401,6 @@ final class VanillaItems{
self::register("cooked_salmon", $factory->get(463));
self::register("cookie", $factory->get(357));
self::register("creeper_head", $factory->get(397, 4));
self::register("cyan_banner", $factory->get(446, 6));
self::register("cyan_bed", $factory->get(355, 9));
self::register("cyan_dye", $factory->get(351, 6));
self::register("dark_oak_boat", $factory->get(333, 5));
@ -464,10 +444,8 @@ final class VanillaItems{
self::register("golden_pickaxe", $factory->get(285));
self::register("golden_shovel", $factory->get(284));
self::register("golden_sword", $factory->get(283));
self::register("gray_banner", $factory->get(446, 8));
self::register("gray_bed", $factory->get(355, 7));
self::register("gray_dye", $factory->get(351, 8));
self::register("green_banner", $factory->get(446, 2));
self::register("green_bed", $factory->get(355, 13));
self::register("green_dye", $factory->get(351, 2));
self::register("gunpowder", $factory->get(289));
@ -492,16 +470,12 @@ final class VanillaItems{
self::register("leather_cap", $factory->get(298));
self::register("leather_pants", $factory->get(300));
self::register("leather_tunic", $factory->get(299));
self::register("light_blue_banner", $factory->get(446, 12));
self::register("light_blue_bed", $factory->get(355, 3));
self::register("light_blue_dye", $factory->get(351, 12));
self::register("light_gray_banner", $factory->get(446, 7));
self::register("light_gray_bed", $factory->get(355, 8));
self::register("light_gray_dye", $factory->get(351, 7));
self::register("lime_banner", $factory->get(446, 10));
self::register("lime_bed", $factory->get(355, 5));
self::register("lime_dye", $factory->get(351, 10));
self::register("magenta_banner", $factory->get(446, 13));
self::register("magenta_bed", $factory->get(355, 2));
self::register("magenta_dye", $factory->get(351, 13));
self::register("magma_cream", $factory->get(378));
@ -516,12 +490,10 @@ final class VanillaItems{
self::register("nether_star", $factory->get(399));
self::register("nether_wart", $factory->get(372));
self::register("oak_boat", $factory->get(333));
self::register("orange_banner", $factory->get(446, 14));
self::register("orange_bed", $factory->get(355, 1));
self::register("orange_dye", $factory->get(351, 14));
self::register("painting", $factory->get(321));
self::register("paper", $factory->get(339));
self::register("pink_banner", $factory->get(446, 9));
self::register("pink_bed", $factory->get(355, 6));
self::register("pink_dye", $factory->get(351, 9));
self::register("player_head", $factory->get(397, 3));
@ -534,7 +506,6 @@ final class VanillaItems{
self::register("pufferfish", $factory->get(462));
self::register("pumpkin_pie", $factory->get(400));
self::register("pumpkin_seeds", $factory->get(361));
self::register("purple_banner", $factory->get(446, 5));
self::register("purple_bed", $factory->get(355, 10));
self::register("purple_dye", $factory->get(351, 5));
self::register("rabbit_foot", $factory->get(414));
@ -559,7 +530,6 @@ final class VanillaItems{
self::register("record_strad", $factory->get(508));
self::register("record_wait", $factory->get(511));
self::register("record_ward", $factory->get(509));
self::register("red_banner", $factory->get(446, 1));
self::register("red_bed", $factory->get(355, 14));
self::register("red_dye", $factory->get(351, 1));
self::register("redstone_dust", $factory->get(331));
@ -587,7 +557,6 @@ final class VanillaItems{
self::register("water_bucket", $factory->get(325, 8));
self::register("wheat", $factory->get(296));
self::register("wheat_seeds", $factory->get(295));
self::register("white_banner", $factory->get(446, 15));
self::register("white_bed", $factory->get(355));
self::register("white_dye", $factory->get(351, 19));
self::register("wither_skeleton_skull", $factory->get(397, 1));
@ -598,7 +567,6 @@ final class VanillaItems{
self::register("wooden_sword", $factory->get(268));
self::register("writable_book", $factory->get(386));
self::register("written_book", $factory->get(387));
self::register("yellow_banner", $factory->get(446, 11));
self::register("yellow_bed", $factory->get(355, 4));
self::register("yellow_dye", $factory->get(351, 11));
self::register("zombie_head", $factory->get(397, 2));