Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hanging signs #6013

Draft
wants to merge 4 commits into
base: minor-next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/block/BlockTypeIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,28 @@ private function __construct(){
public const PITCHER_PLANT = 10715;
public const PITCHER_CROP = 10716;
public const DOUBLE_PITCHER_CROP = 10717;
public const ACACIA_CEILING_HANGING_SIGN = 10718;
public const ACACIA_WALL_HANGING_SIGN = 10719;
public const BIRCH_CEILING_HANGING_SIGN = 10720;
public const BIRCH_WALL_HANGING_SIGN = 10721;
public const CRIMSON_CEILING_HANGING_SIGN = 10722;
public const CRIMSON_WALL_HANGING_SIGN = 10723;
public const DARK_OAK_CEILING_HANGING_SIGN = 10724;
public const DARK_OAK_WALL_HANGING_SIGN = 10725;
public const JUNGLE_CEILING_HANGING_SIGN = 10726;
public const JUNGLE_WALL_HANGING_SIGN = 10727;
public const OAK_CEILING_HANGING_SIGN = 10728;
public const OAK_WALL_HANGING_SIGN = 10729;
public const SPRUCE_CEILING_HANGING_SIGN = 10730;
public const SPRUCE_WALL_HANGING_SIGN = 10731;
public const WARPED_CEILING_HANGING_SIGN = 10732;
public const WARPED_WALL_HANGING_SIGN = 10733;
public const MANGROVE_CEILING_HANGING_SIGN = 10734;
public const MANGROVE_WALL_HANGING_SIGN = 10735;
public const CHERRY_CEILING_HANGING_SIGN = 10736;
public const CHERRY_WALL_HANGING_SIGN = 10737;

public const FIRST_UNUSED_BLOCK_ID = 10718;
public const FIRST_UNUSED_BLOCK_ID = 10738;

private static int $nextDynamicId = self::FIRST_UNUSED_BLOCK_ID;

Expand Down
81 changes: 81 additions & 0 deletions src/block/CeilingHangingSign.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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\SignLikeRotationTrait;
use pocketmine\block\utils\SupportType;
use pocketmine\data\runtime\RuntimeDataDescriber;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use function var_dump;

final class CeilingHangingSign extends BaseSign{
use SignLikeRotationTrait {
describeBlockOnlyState as describeSignRotation;
}

private bool $centerAttached = false;

protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
parent::describeBlockOnlyState($w);
$this->describeSignRotation($w);
$w->bool($this->centerAttached);
}

protected function getSupportingFace() : int{
return Facing::UP;
}

public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($face !== Facing::DOWN){
return false;
}

$supportType = $blockReplace->getAdjacentSupportType(Facing::UP);
if($supportType->equals(SupportType::CENTER)){
$this->centerAttached = true;
}
if($player !== null){
$this->rotation = self::getRotationFromYaw($player->getLocation()->getYaw());
var_dump($this->rotation);
}
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}

/**
* Returns whether the sign is attached to a single point on the block above.
* If false, the sign has two chains attached to different points on the block above.
*/
public function isCenterAttached() : bool{ return $this->centerAttached; }

public function setCenterAttached(bool $centerAttached) : self{
$this->centerAttached = $centerAttached;
return $this;
}

//TODO: these may have a solid collision box
}
24 changes: 24 additions & 0 deletions src/block/VanillaBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
* @generate-registry-docblock
*
* @method static WoodenButton ACACIA_BUTTON()
* @method static CeilingHangingSign ACACIA_CEILING_HANGING_SIGN()
* @method static WoodenDoor ACACIA_DOOR()
* @method static WoodenFence ACACIA_FENCE()
* @method static FenceGate ACACIA_FENCE_GATE()
Expand All @@ -87,6 +88,7 @@
* @method static WoodenSlab ACACIA_SLAB()
* @method static WoodenStairs ACACIA_STAIRS()
* @method static WoodenTrapdoor ACACIA_TRAPDOOR()
* @method static WallHangingSign ACACIA_WALL_HANGING_SIGN()
* @method static WallSign ACACIA_WALL_SIGN()
* @method static Wood ACACIA_WOOD()
* @method static ActivatorRail ACTIVATOR_RAIL()
Expand Down Expand Up @@ -117,6 +119,7 @@
* @method static BigDripleafHead BIG_DRIPLEAF_HEAD()
* @method static BigDripleafStem BIG_DRIPLEAF_STEM()
* @method static WoodenButton BIRCH_BUTTON()
* @method static CeilingHangingSign BIRCH_CEILING_HANGING_SIGN()
* @method static WoodenDoor BIRCH_DOOR()
* @method static WoodenFence BIRCH_FENCE()
* @method static FenceGate BIRCH_FENCE_GATE()
Expand All @@ -129,6 +132,7 @@
* @method static WoodenSlab BIRCH_SLAB()
* @method static WoodenStairs BIRCH_STAIRS()
* @method static WoodenTrapdoor BIRCH_TRAPDOOR()
* @method static WallHangingSign BIRCH_WALL_HANGING_SIGN()
* @method static WallSign BIRCH_WALL_SIGN()
* @method static Wood BIRCH_WOOD()
* @method static Opaque BLACKSTONE()
Expand Down Expand Up @@ -164,6 +168,7 @@
* @method static Chain CHAIN()
* @method static ChemicalHeat CHEMICAL_HEAT()
* @method static WoodenButton CHERRY_BUTTON()
* @method static CeilingHangingSign CHERRY_CEILING_HANGING_SIGN()
* @method static WoodenDoor CHERRY_DOOR()
* @method static WoodenFence CHERRY_FENCE()
* @method static FenceGate CHERRY_FENCE_GATE()
Expand All @@ -175,6 +180,7 @@
* @method static WoodenSlab CHERRY_SLAB()
* @method static WoodenStairs CHERRY_STAIRS()
* @method static WoodenTrapdoor CHERRY_TRAPDOOR()
* @method static WallHangingSign CHERRY_WALL_HANGING_SIGN()
* @method static WallSign CHERRY_WALL_SIGN()
* @method static Wood CHERRY_WOOD()
* @method static Chest CHEST()
Expand Down Expand Up @@ -217,6 +223,7 @@
* @method static Opaque CRACKED_STONE_BRICKS()
* @method static CraftingTable CRAFTING_TABLE()
* @method static WoodenButton CRIMSON_BUTTON()
* @method static CeilingHangingSign CRIMSON_CEILING_HANGING_SIGN()
* @method static WoodenDoor CRIMSON_DOOR()
* @method static WoodenFence CRIMSON_FENCE()
* @method static FenceGate CRIMSON_FENCE_GATE()
Expand All @@ -229,6 +236,7 @@
* @method static WoodenStairs CRIMSON_STAIRS()
* @method static Wood CRIMSON_STEM()
* @method static WoodenTrapdoor CRIMSON_TRAPDOOR()
* @method static WallHangingSign CRIMSON_WALL_HANGING_SIGN()
* @method static WallSign CRIMSON_WALL_SIGN()
* @method static Opaque CRYING_OBSIDIAN()
* @method static Copper CUT_COPPER()
Expand All @@ -240,6 +248,7 @@
* @method static Slab CUT_SANDSTONE_SLAB()
* @method static Flower DANDELION()
* @method static WoodenButton DARK_OAK_BUTTON()
* @method static CeilingHangingSign DARK_OAK_CEILING_HANGING_SIGN()
* @method static WoodenDoor DARK_OAK_DOOR()
* @method static WoodenFence DARK_OAK_FENCE()
* @method static FenceGate DARK_OAK_FENCE_GATE()
Expand All @@ -252,6 +261,7 @@
* @method static WoodenSlab DARK_OAK_SLAB()
* @method static WoodenStairs DARK_OAK_STAIRS()
* @method static WoodenTrapdoor DARK_OAK_TRAPDOOR()
* @method static WallHangingSign DARK_OAK_WALL_HANGING_SIGN()
* @method static WallSign DARK_OAK_WALL_SIGN()
* @method static Wood DARK_OAK_WOOD()
* @method static Opaque DARK_PRISMARINE()
Expand Down Expand Up @@ -474,6 +484,7 @@
* @method static ItemFrame ITEM_FRAME()
* @method static Jukebox JUKEBOX()
* @method static WoodenButton JUNGLE_BUTTON()
* @method static CeilingHangingSign JUNGLE_CEILING_HANGING_SIGN()
* @method static WoodenDoor JUNGLE_DOOR()
* @method static WoodenFence JUNGLE_FENCE()
* @method static FenceGate JUNGLE_FENCE_GATE()
Expand All @@ -486,6 +497,7 @@
* @method static WoodenSlab JUNGLE_SLAB()
* @method static WoodenStairs JUNGLE_STAIRS()
* @method static WoodenTrapdoor JUNGLE_TRAPDOOR()
* @method static WallHangingSign JUNGLE_WALL_HANGING_SIGN()
* @method static WallSign JUNGLE_WALL_SIGN()
* @method static Wood JUNGLE_WOOD()
* @method static ChemistryTable LAB_TABLE()
Expand All @@ -508,6 +520,7 @@
* @method static Loom LOOM()
* @method static Magma MAGMA()
* @method static WoodenButton MANGROVE_BUTTON()
* @method static CeilingHangingSign MANGROVE_CEILING_HANGING_SIGN()
* @method static WoodenDoor MANGROVE_DOOR()
* @method static WoodenFence MANGROVE_FENCE()
* @method static FenceGate MANGROVE_FENCE_GATE()
Expand All @@ -520,6 +533,7 @@
* @method static WoodenSlab MANGROVE_SLAB()
* @method static WoodenStairs MANGROVE_STAIRS()
* @method static WoodenTrapdoor MANGROVE_TRAPDOOR()
* @method static WallHangingSign MANGROVE_WALL_HANGING_SIGN()
* @method static WallSign MANGROVE_WALL_SIGN()
* @method static Wood MANGROVE_WOOD()
* @method static ChemistryTable MATERIAL_REDUCER()
Expand Down Expand Up @@ -558,6 +572,7 @@
* @method static Opaque NETHER_WART_BLOCK()
* @method static Note NOTE_BLOCK()
* @method static WoodenButton OAK_BUTTON()
* @method static CeilingHangingSign OAK_CEILING_HANGING_SIGN()
* @method static WoodenDoor OAK_DOOR()
* @method static WoodenFence OAK_FENCE()
* @method static FenceGate OAK_FENCE_GATE()
Expand All @@ -570,6 +585,7 @@
* @method static WoodenSlab OAK_SLAB()
* @method static WoodenStairs OAK_STAIRS()
* @method static WoodenTrapdoor OAK_TRAPDOOR()
* @method static WallHangingSign OAK_WALL_HANGING_SIGN()
* @method static WallSign OAK_WALL_SIGN()
* @method static Wood OAK_WOOD()
* @method static Opaque OBSIDIAN()
Expand Down Expand Up @@ -693,6 +709,7 @@
* @method static Sponge SPONGE()
* @method static SporeBlossom SPORE_BLOSSOM()
* @method static WoodenButton SPRUCE_BUTTON()
* @method static CeilingHangingSign SPRUCE_CEILING_HANGING_SIGN()
* @method static WoodenDoor SPRUCE_DOOR()
* @method static WoodenFence SPRUCE_FENCE()
* @method static FenceGate SPRUCE_FENCE_GATE()
Expand All @@ -705,6 +722,7 @@
* @method static WoodenSlab SPRUCE_SLAB()
* @method static WoodenStairs SPRUCE_STAIRS()
* @method static WoodenTrapdoor SPRUCE_TRAPDOOR()
* @method static WallHangingSign SPRUCE_WALL_HANGING_SIGN()
* @method static WallSign SPRUCE_WALL_SIGN()
* @method static Wood SPRUCE_WOOD()
* @method static StainedHardenedClay STAINED_CLAY()
Expand Down Expand Up @@ -741,6 +759,7 @@
* @method static WallBanner WALL_BANNER()
* @method static WallCoralFan WALL_CORAL_FAN()
* @method static WoodenButton WARPED_BUTTON()
* @method static CeilingHangingSign WARPED_CEILING_HANGING_SIGN()
* @method static WoodenDoor WARPED_DOOR()
* @method static WoodenFence WARPED_FENCE()
* @method static FenceGate WARPED_FENCE_GATE()
Expand All @@ -753,6 +772,7 @@
* @method static WoodenStairs WARPED_STAIRS()
* @method static Wood WARPED_STEM()
* @method static WoodenTrapdoor WARPED_TRAPDOOR()
* @method static WallHangingSign WARPED_WALL_HANGING_SIGN()
* @method static WallSign WARPED_WALL_SIGN()
* @method static Opaque WARPED_WART_BLOCK()
* @method static Water WATER()
Expand Down Expand Up @@ -1299,6 +1319,10 @@ private static function registerWoodenBlocks() : void{
[$floorSignId, $wallSignId, $signAsItem] = WoodLikeBlockIdHelper::getSignInfo($woodType);
self::register($idName("sign"), new FloorSign($floorSignId, $name . " Sign", $signBreakInfo, $woodType, $signAsItem));
self::register($idName("wall_sign"), new WallSign($wallSignId, $name . " Wall Sign", $signBreakInfo, $woodType, $signAsItem));

[$ceilingHangingSignId, $wallHangingSignId, $hangingSignAsItem] = WoodLikeBlockIdHelper::getHangingSignInfo($woodType);
self::register($idName("ceiling_hanging_sign"), new CeilingHangingSign($ceilingHangingSignId, $name . " Ceiling Hanging Sign", $signBreakInfo, $woodType, $hangingSignAsItem));
self::register($idName("wall_hanging_sign"), new WallHangingSign($wallHangingSignId, $name . " Wall Hanging Sign", $signBreakInfo, $woodType, $hangingSignAsItem));
}
}

Expand Down
50 changes: 50 additions & 0 deletions src/block/WallHangingSign.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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\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 WallHangingSign extends BaseSign{
use HorizontalFacingTrait;

protected function getSupportingFace() : int{
return Facing::rotateY($this->facing, true);
}

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 = Facing::rotateY($face, true);
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
}

//TODO: these have a solid collision box
}
25 changes: 25 additions & 0 deletions src/block/WoodLikeBlockIdHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use pocketmine\block\BlockIdentifier as BID;
use pocketmine\block\BlockTypeIds as Ids;
use pocketmine\block\tile\HangingSign as TileHangingSign;
use pocketmine\block\tile\Sign as TileSign;
use pocketmine\block\utils\LeavesType;
use pocketmine\block\utils\SaplingType;
Expand Down Expand Up @@ -171,6 +172,30 @@ public static function getSignInfo(WoodType $treeType) : array{
};
}

/**
* @return BID[]|\Closure[]
* @phpstan-return array{BID, BID, \Closure() : \pocketmine\item\Item}
*/
public static function getHangingSignInfo(WoodType $woodType) : array{
$make = fn(int $ceilingId, int $wallId, \Closure $getItem) => [
new BID($ceilingId, TileHangingSign::class),
new BID($wallId, TileHangingSign::class),
$getItem
];
return match($woodType){
WoodType::OAK => $make(Ids::OAK_CEILING_HANGING_SIGN, Ids::OAK_WALL_HANGING_SIGN, fn() => VanillaItems::OAK_HANGING_SIGN()),
WoodType::SPRUCE => $make(Ids::SPRUCE_CEILING_HANGING_SIGN, Ids::SPRUCE_WALL_HANGING_SIGN, fn() => VanillaItems::SPRUCE_HANGING_SIGN()),
WoodType::BIRCH => $make(Ids::BIRCH_CEILING_HANGING_SIGN, Ids::BIRCH_WALL_HANGING_SIGN, fn() => VanillaItems::BIRCH_HANGING_SIGN()),
WoodType::JUNGLE => $make(Ids::JUNGLE_CEILING_HANGING_SIGN, Ids::JUNGLE_WALL_HANGING_SIGN, fn() => VanillaItems::JUNGLE_HANGING_SIGN()),
WoodType::ACACIA => $make(Ids::ACACIA_CEILING_HANGING_SIGN, Ids::ACACIA_WALL_HANGING_SIGN, fn() => VanillaItems::ACACIA_HANGING_SIGN()),
WoodType::DARK_OAK => $make(Ids::DARK_OAK_CEILING_HANGING_SIGN, Ids::DARK_OAK_WALL_HANGING_SIGN, fn() => VanillaItems::DARK_OAK_HANGING_SIGN()),
WoodType::MANGROVE => $make(Ids::MANGROVE_CEILING_HANGING_SIGN, Ids::MANGROVE_WALL_HANGING_SIGN, fn() => VanillaItems::MANGROVE_HANGING_SIGN()),
WoodType::CRIMSON => $make(Ids::CRIMSON_CEILING_HANGING_SIGN, Ids::CRIMSON_WALL_HANGING_SIGN, fn() => VanillaItems::CRIMSON_HANGING_SIGN()),
WoodType::WARPED => $make(Ids::WARPED_CEILING_HANGING_SIGN, Ids::WARPED_WALL_HANGING_SIGN, fn() => VanillaItems::WARPED_HANGING_SIGN()),
WoodType::CHERRY => $make(Ids::CHERRY_CEILING_HANGING_SIGN, Ids::CHERRY_WALL_HANGING_SIGN, fn() => VanillaItems::CHERRY_HANGING_SIGN()),
};
}

public static function getTrapdoorIdentifier(WoodType $treeType) : BID{
return new BID(match($treeType){
WoodType::OAK => Ids::OAK_TRAPDOOR,
Expand Down
Loading
Loading