Revert back to separated floor/wall sign

the conditionally useless properties are problematic.
This commit is contained in:
Dylan K. Taylor
2020-10-04 17:52:23 +01:00
parent e6bf7278fc
commit d3a3a41d2b
29 changed files with 232 additions and 94 deletions

View File

@@ -39,46 +39,17 @@ use function assert;
use function floor;
use function strlen;
class Sign extends Transparent{
/** @var BlockIdentifierFlattened */
protected $idInfo;
abstract class BaseSign extends Transparent{
//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(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->text = new SignText();
}
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 readStateFromWorld() : void{
parent::readStateFromWorld();
$tile = $this->pos->getWorld()->getTile($this->pos);
@@ -94,10 +65,6 @@ class Sign extends Transparent{
$tile->setText($this->text);
}
public function getStateBitmask() : int{
return 0b1111;
}
public function isSolid() : bool{
return false;
}
@@ -109,21 +76,10 @@ class Sign extends Transparent{
return [];
}
public function place(BlockTransaction $tx, 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->getLocation()->getYaw() + 180) * 16 / 360) + 0.5)) & 0x0f : 0;
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}
return false;
}
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

@@ -443,7 +443,8 @@ class BlockFactory{
$this->register(new WoodenPressurePlate(BlockLegacyIdHelper::getWoodenPressurePlateIdentifier($treeType), $treeType->getDisplayName() . " Pressure Plate"));
$this->register(new WoodenTrapdoor(BlockLegacyIdHelper::getWoodenTrapdoorIdentifier($treeType), $treeType->getDisplayName() . " Trapdoor"));
$this->register(new Sign(BlockLegacyIdHelper::getWoodenSignIdentifier($treeType), $treeType->getDisplayName() . " Sign"));
$this->register(new FloorSign(BlockLegacyIdHelper::getWoodenFloorSignIdentifier($treeType), $treeType->getDisplayName() . " Sign"));
$this->register(new WallSign(BlockLegacyIdHelper::getWoodenWallSignIdentifier($treeType), $treeType->getDisplayName() . " Wall Sign"));
}
static $sandstoneTypes = [

View File

@@ -34,20 +34,38 @@ use pocketmine\utils\AssumptionFailedError;
final class BlockLegacyIdHelper{
public static function getWoodenSignIdentifier(TreeType $treeType) : BIDFlattened{
public static function getWoodenFloorSignIdentifier(TreeType $treeType) : BID{
switch($treeType->id()){
case TreeType::OAK()->id():
return new BIDFlattened(Ids::SIGN_POST, Ids::WALL_SIGN, 0, ItemIds::SIGN, TileSign::class);
return new BID(Ids::SIGN_POST, 0, ItemIds::SIGN, TileSign::class);
case TreeType::SPRUCE()->id():
return new BIDFlattened(Ids::SPRUCE_STANDING_SIGN, Ids::SPRUCE_WALL_SIGN, 0, ItemIds::SPRUCE_SIGN, TileSign::class);
return new BID(Ids::SPRUCE_STANDING_SIGN, 0, ItemIds::SPRUCE_SIGN, TileSign::class);
case TreeType::BIRCH()->id():
return new BIDFlattened(Ids::BIRCH_STANDING_SIGN, Ids::BIRCH_WALL_SIGN, 0, ItemIds::BIRCH_SIGN, TileSign::class);
return new BID(Ids::BIRCH_STANDING_SIGN, 0, ItemIds::BIRCH_SIGN, TileSign::class);
case TreeType::JUNGLE()->id():
return new BIDFlattened(Ids::JUNGLE_STANDING_SIGN, Ids::JUNGLE_WALL_SIGN, 0, ItemIds::JUNGLE_SIGN, TileSign::class);
return new BID(Ids::JUNGLE_STANDING_SIGN, 0, ItemIds::JUNGLE_SIGN, TileSign::class);
case TreeType::ACACIA()->id():
return new BIDFlattened(Ids::ACACIA_STANDING_SIGN, Ids::ACACIA_WALL_SIGN, 0, ItemIds::ACACIA_SIGN, TileSign::class);
return new BID(Ids::ACACIA_STANDING_SIGN,0, ItemIds::ACACIA_SIGN, TileSign::class);
case TreeType::DARK_OAK()->id():
return new BIDFlattened(Ids::DARKOAK_STANDING_SIGN, Ids::DARKOAK_WALL_SIGN, 0, ItemIds::DARKOAK_SIGN, TileSign::class);
return new BID(Ids::DARKOAK_STANDING_SIGN, 0, ItemIds::DARKOAK_SIGN, TileSign::class);
}
throw new AssumptionFailedError("Switch should cover all wood types");
}
public static function getWoodenWallSignIdentifier(TreeType $treeType) : BID{
switch($treeType->id()){
case TreeType::OAK()->id():
return new BID(Ids::WALL_SIGN, 0, ItemIds::SIGN, TileSign::class);
case TreeType::SPRUCE()->id():
return new BID(Ids::SPRUCE_WALL_SIGN, 0, ItemIds::SPRUCE_SIGN, TileSign::class);
case TreeType::BIRCH()->id():
return new BID(Ids::BIRCH_WALL_SIGN, 0, ItemIds::BIRCH_SIGN, TileSign::class);
case TreeType::JUNGLE()->id():
return new BID(Ids::JUNGLE_WALL_SIGN, 0, ItemIds::JUNGLE_SIGN, TileSign::class);
case TreeType::ACACIA()->id():
return new BID(Ids::ACACIA_WALL_SIGN, 0, ItemIds::ACACIA_SIGN, TileSign::class);
case TreeType::DARK_OAK()->id():
return new BID(Ids::DARKOAK_WALL_SIGN, 0, ItemIds::DARKOAK_SIGN, TileSign::class);
}
throw new AssumptionFailedError("Switch should cover all wood types");
}

63
src/block/FloorSign.php Normal file
View File

@@ -0,0 +1,63 @@
<?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;
use function floor;
final class FloorSign extends BaseSign{
/** @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

@@ -40,10 +40,11 @@ use function assert;
* @method static Planks ACACIA_PLANKS()
* @method static WoodenPressurePlate ACACIA_PRESSURE_PLATE()
* @method static Sapling ACACIA_SAPLING()
* @method static Sign ACACIA_SIGN()
* @method static FloorSign ACACIA_SIGN()
* @method static WoodenSlab ACACIA_SLAB()
* @method static WoodenStairs ACACIA_STAIRS()
* @method static WoodenTrapdoor ACACIA_TRAPDOOR()
* @method static WallSign ACACIA_WALL_SIGN()
* @method static Wood ACACIA_WOOD()
* @method static ActivatorRail ACTIVATOR_RAIL()
* @method static Air AIR()
@@ -71,10 +72,11 @@ use function assert;
* @method static Planks BIRCH_PLANKS()
* @method static WoodenPressurePlate BIRCH_PRESSURE_PLATE()
* @method static Sapling BIRCH_SAPLING()
* @method static Sign BIRCH_SIGN()
* @method static FloorSign BIRCH_SIGN()
* @method static WoodenSlab BIRCH_SLAB()
* @method static WoodenStairs BIRCH_STAIRS()
* @method static WoodenTrapdoor BIRCH_TRAPDOOR()
* @method static WallSign BIRCH_WALL_SIGN()
* @method static Wood BIRCH_WOOD()
* @method static Carpet BLACK_CARPET()
* @method static Concrete BLACK_CONCRETE()
@@ -158,10 +160,11 @@ use function assert;
* @method static Planks DARK_OAK_PLANKS()
* @method static WoodenPressurePlate DARK_OAK_PRESSURE_PLATE()
* @method static Sapling DARK_OAK_SAPLING()
* @method static Sign DARK_OAK_SIGN()
* @method static FloorSign DARK_OAK_SIGN()
* @method static WoodenSlab DARK_OAK_SLAB()
* @method static WoodenStairs DARK_OAK_STAIRS()
* @method static WoodenTrapdoor DARK_OAK_TRAPDOOR()
* @method static WallSign DARK_OAK_WALL_SIGN()
* @method static Wood DARK_OAK_WOOD()
* @method static Opaque DARK_PRISMARINE()
* @method static Slab DARK_PRISMARINE_SLAB()
@@ -410,10 +413,11 @@ use function assert;
* @method static Planks JUNGLE_PLANKS()
* @method static WoodenPressurePlate JUNGLE_PRESSURE_PLATE()
* @method static Sapling JUNGLE_SAPLING()
* @method static Sign JUNGLE_SIGN()
* @method static FloorSign JUNGLE_SIGN()
* @method static WoodenSlab JUNGLE_SLAB()
* @method static WoodenStairs JUNGLE_STAIRS()
* @method static WoodenTrapdoor JUNGLE_TRAPDOOR()
* @method static WallSign JUNGLE_WALL_SIGN()
* @method static Wood JUNGLE_WOOD()
* @method static ChemistryTable LAB_TABLE()
* @method static Ladder LADDER()
@@ -496,10 +500,11 @@ use function assert;
* @method static Planks OAK_PLANKS()
* @method static WoodenPressurePlate OAK_PRESSURE_PLATE()
* @method static Sapling OAK_SAPLING()
* @method static Sign OAK_SIGN()
* @method static FloorSign OAK_SIGN()
* @method static WoodenSlab OAK_SLAB()
* @method static WoodenStairs OAK_STAIRS()
* @method static WoodenTrapdoor OAK_TRAPDOOR()
* @method static WallSign OAK_WALL_SIGN()
* @method static Wood OAK_WOOD()
* @method static Opaque OBSIDIAN()
* @method static Carpet ORANGE_CARPET()
@@ -624,10 +629,11 @@ use function assert;
* @method static Planks SPRUCE_PLANKS()
* @method static WoodenPressurePlate SPRUCE_PRESSURE_PLATE()
* @method static Sapling SPRUCE_SAPLING()
* @method static Sign SPRUCE_SIGN()
* @method static FloorSign SPRUCE_SIGN()
* @method static WoodenSlab SPRUCE_SLAB()
* @method static WoodenStairs SPRUCE_STAIRS()
* @method static WoodenTrapdoor SPRUCE_TRAPDOOR()
* @method static WallSign SPRUCE_WALL_SIGN()
* @method static Wood SPRUCE_WOOD()
* @method static Opaque STONE()
* @method static Slab STONE_BRICK_SLAB()
@@ -712,6 +718,7 @@ final class VanillaBlocks{
self::register("acacia_slab", $factory->get(158, 4));
self::register("acacia_stairs", $factory->get(163));
self::register("acacia_trapdoor", $factory->get(400));
self::register("acacia_wall_sign", $factory->get(446, 2));
self::register("acacia_wood", $factory->get(467, 4));
self::register("activator_rail", $factory->get(126));
self::register("air", $factory->get(0));
@@ -743,6 +750,7 @@ final class VanillaBlocks{
self::register("birch_slab", $factory->get(158, 2));
self::register("birch_stairs", $factory->get(135));
self::register("birch_trapdoor", $factory->get(401));
self::register("birch_wall_sign", $factory->get(442, 2));
self::register("birch_wood", $factory->get(467, 2));
self::register("black_carpet", $factory->get(171, 15));
self::register("black_concrete", $factory->get(236, 15));
@@ -830,6 +838,7 @@ final class VanillaBlocks{
self::register("dark_oak_slab", $factory->get(158, 5));
self::register("dark_oak_stairs", $factory->get(164));
self::register("dark_oak_trapdoor", $factory->get(402));
self::register("dark_oak_wall_sign", $factory->get(448, 2));
self::register("dark_oak_wood", $factory->get(467, 5));
self::register("dark_prismarine", $factory->get(168, 1));
self::register("dark_prismarine_slab", $factory->get(182, 3));
@@ -1082,6 +1091,7 @@ final class VanillaBlocks{
self::register("jungle_slab", $factory->get(158, 3));
self::register("jungle_stairs", $factory->get(136));
self::register("jungle_trapdoor", $factory->get(403));
self::register("jungle_wall_sign", $factory->get(444, 2));
self::register("jungle_wood", $factory->get(467, 3));
self::register("lab_table", $factory->get(238, 12));
self::register("ladder", $factory->get(65, 2));
@@ -1168,6 +1178,7 @@ final class VanillaBlocks{
self::register("oak_slab", $factory->get(158));
self::register("oak_stairs", $factory->get(53));
self::register("oak_trapdoor", $factory->get(96));
self::register("oak_wall_sign", $factory->get(68, 2));
self::register("oak_wood", $factory->get(467));
self::register("obsidian", $factory->get(49));
self::register("orange_carpet", $factory->get(171, 1));
@@ -1296,6 +1307,7 @@ final class VanillaBlocks{
self::register("spruce_slab", $factory->get(158, 1));
self::register("spruce_stairs", $factory->get(134));
self::register("spruce_trapdoor", $factory->get(404));
self::register("spruce_wall_sign", $factory->get(437, 2));
self::register("spruce_wood", $factory->get(467, 1));
self::register("stone", $factory->get(1));
self::register("stone_brick_slab", $factory->get(44, 5));

61
src/block/WallSign.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 WallSign extends BaseSign{
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

@@ -37,7 +37,7 @@ use function sprintf;
/**
* @deprecated
* @see \pocketmine\block\Sign
* @see \pocketmine\block\BaseSign
*/
class Sign extends Spawnable{
public const TAG_TEXT_BLOB = "Text";