mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 06:25:32 +00:00
Make a trait for blocks which share the same horizontal facing metadata logic
This commit is contained in:
parent
11263909ab
commit
f204d6b3dd
@ -24,8 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\tile\Chest as TileChest;
|
use pocketmine\block\tile\Chest as TileChest;
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\NormalHorizontalFacingInMetadataTrait;
|
||||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -34,24 +33,12 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class Chest extends Transparent{
|
class Chest extends Transparent{
|
||||||
use HorizontalFacingTrait;
|
use NormalHorizontalFacingInMetadataTrait;
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.5, BlockToolType::AXE));
|
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.5, BlockToolType::AXE));
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return AxisAlignedBB[]
|
* @return AxisAlignedBB[]
|
||||||
*/
|
*/
|
||||||
|
@ -24,8 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\tile\EnderChest as TileEnderChest;
|
use pocketmine\block\tile\EnderChest as TileEnderChest;
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\NormalHorizontalFacingInMetadataTrait;
|
||||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ToolTier;
|
use pocketmine\item\ToolTier;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
@ -35,24 +34,12 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class EnderChest extends Transparent{
|
class EnderChest extends Transparent{
|
||||||
use HorizontalFacingTrait;
|
use NormalHorizontalFacingInMetadataTrait;
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(22.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 3000.0));
|
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(22.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 3000.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLightLevel() : int{
|
public function getLightLevel() : int{
|
||||||
return 7;
|
return 7;
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\tile\Furnace as TileFurnace;
|
use pocketmine\block\tile\Furnace as TileFurnace;
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\NormalHorizontalFacingInMetadataTrait;
|
||||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ToolTier;
|
use pocketmine\item\ToolTier;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -34,7 +33,9 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class Furnace extends Opaque{
|
class Furnace extends Opaque{
|
||||||
use HorizontalFacingTrait;
|
use NormalHorizontalFacingInMetadataTrait {
|
||||||
|
readStateFromData as readFacingStateFromData;
|
||||||
|
}
|
||||||
|
|
||||||
/** @var BlockIdentifierFlattened */
|
/** @var BlockIdentifierFlattened */
|
||||||
protected $idInfo;
|
protected $idInfo;
|
||||||
@ -50,19 +51,11 @@ class Furnace extends Opaque{
|
|||||||
return $this->lit ? $this->idInfo->getSecondId() : parent::getId();
|
return $this->lit ? $this->idInfo->getSecondId() : parent::getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function writeStateToMeta() : int{
|
|
||||||
return BlockDataSerializer::writeHorizontalFacing($this->facing);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||||
$this->facing = BlockDataSerializer::readHorizontalFacing($stateMeta);
|
$this->readFacingStateFromData($id, $stateMeta);
|
||||||
$this->lit = $id === $this->idInfo->getSecondId();
|
$this->lit = $id === $this->idInfo->getSecondId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStateBitmask() : int{
|
|
||||||
return 0b111;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLightLevel() : int{
|
public function getLightLevel() : int{
|
||||||
return $this->lit ? 13 : 0;
|
return $this->lit ? 13 : 0;
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\NormalHorizontalFacingInMetadataTrait;
|
||||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ToolTier;
|
use pocketmine\item\ToolTier;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -33,24 +32,12 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class GlazedTerracotta extends Opaque{
|
class GlazedTerracotta extends Opaque{
|
||||||
use HorizontalFacingTrait;
|
use NormalHorizontalFacingInMetadataTrait;
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.4, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
|
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(1.4, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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($player !== null){
|
if($player !== null){
|
||||||
$this->facing = Facing::opposite($player->getHorizontalFacing());
|
$this->facing = Facing::opposite($player->getHorizontalFacing());
|
||||||
|
@ -23,8 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\NormalHorizontalFacingInMetadataTrait;
|
||||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\entity\Living;
|
use pocketmine\entity\Living;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
@ -36,24 +35,12 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class Ladder extends Transparent{
|
class Ladder extends Transparent{
|
||||||
use HorizontalFacingTrait;
|
use NormalHorizontalFacingInMetadataTrait;
|
||||||
|
|
||||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.4, BlockToolType::AXE));
|
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.4, BlockToolType::AXE));
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function hasEntityCollision() : bool{
|
public function hasEntityCollision() : bool{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\NormalHorizontalFacingInMetadataTrait;
|
||||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Axis;
|
use pocketmine\math\Axis;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -33,19 +32,7 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
final class WallBanner extends BaseBanner{
|
final class WallBanner extends BaseBanner{
|
||||||
use HorizontalFacingTrait;
|
use NormalHorizontalFacingInMetadataTrait;
|
||||||
|
|
||||||
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{
|
protected function getSupportingFace() : int{
|
||||||
return Facing::opposite($this->facing);
|
return Facing::opposite($this->facing);
|
||||||
|
@ -23,8 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\NormalHorizontalFacingInMetadataTrait;
|
||||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Axis;
|
use pocketmine\math\Axis;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -33,19 +32,7 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
final class WallSign extends BaseSign{
|
final class WallSign extends BaseSign{
|
||||||
use HorizontalFacingTrait;
|
use NormalHorizontalFacingInMetadataTrait;
|
||||||
|
|
||||||
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{
|
protected function getSupportingFace() : int{
|
||||||
return Facing::opposite($this->facing);
|
return Facing::opposite($this->facing);
|
||||||
|
40
src/block/utils/NormalHorizontalFacingInMetadataTrait.php
Normal file
40
src/block/utils/NormalHorizontalFacingInMetadataTrait.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?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\utils;
|
||||||
|
|
||||||
|
trait NormalHorizontalFacingInMetadataTrait{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user