mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 16:49:53 +00:00
Separated metadata handling from PillarRotationTrait
This commit is contained in:
parent
7469f28f24
commit
06efad94b6
@ -46,7 +46,7 @@ use pocketmine\block\tile\Note as TileNote;
|
||||
use pocketmine\block\tile\Skull as TileSkull;
|
||||
use pocketmine\block\utils\DyeColor;
|
||||
use pocketmine\block\utils\InvalidBlockStateException;
|
||||
use pocketmine\block\utils\PillarRotationTrait;
|
||||
use pocketmine\block\utils\PillarRotationInMetadataTrait;
|
||||
use pocketmine\block\utils\TreeType;
|
||||
use pocketmine\data\bedrock\DyeColorIdMap;
|
||||
use pocketmine\item\Item;
|
||||
@ -293,7 +293,7 @@ class BlockFactory{
|
||||
$purpurBreakInfo = new BlockBreakInfo(1.5, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel(), 30.0);
|
||||
$this->register(new Opaque(new BID(Ids::PURPUR_BLOCK, Meta::PURPUR_NORMAL), "Purpur Block", $purpurBreakInfo));
|
||||
$this->register(new class(new BID(Ids::PURPUR_BLOCK, Meta::PURPUR_PILLAR), "Purpur Pillar", $purpurBreakInfo) extends Opaque{
|
||||
use PillarRotationTrait;
|
||||
use PillarRotationInMetadataTrait;
|
||||
});
|
||||
$this->register(new Stair(new BID(Ids::PURPUR_STAIRS), "Purpur Stairs", $purpurBreakInfo));
|
||||
|
||||
@ -301,10 +301,10 @@ class BlockFactory{
|
||||
$this->register(new Opaque(new BID(Ids::QUARTZ_BLOCK, Meta::QUARTZ_NORMAL), "Quartz Block", $quartzBreakInfo));
|
||||
$this->register(new Stair(new BID(Ids::QUARTZ_STAIRS), "Quartz Stairs", $quartzBreakInfo));
|
||||
$this->register(new class(new BID(Ids::QUARTZ_BLOCK, Meta::QUARTZ_CHISELED), "Chiseled Quartz Block", $quartzBreakInfo) extends Opaque{
|
||||
use PillarRotationTrait;
|
||||
use PillarRotationInMetadataTrait;
|
||||
});
|
||||
$this->register(new class(new BID(Ids::QUARTZ_BLOCK, Meta::QUARTZ_PILLAR), "Quartz Pillar", $quartzBreakInfo) extends Opaque{
|
||||
use PillarRotationTrait;
|
||||
use PillarRotationInMetadataTrait;
|
||||
});
|
||||
$this->register(new Opaque(new BID(Ids::QUARTZ_BLOCK, Meta::QUARTZ_SMOOTH), "Smooth Quartz Block", $quartzBreakInfo)); //TODO: this has axis rotation in 1.9, unsure if a bug (https://bugs.mojang.com/browse/MCPE-39074)
|
||||
$this->register(new Stair(new BID(Ids::SMOOTH_QUARTZ_STAIRS), "Smooth Quartz Stairs", $quartzBreakInfo));
|
||||
|
@ -23,11 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\PillarRotationTrait;
|
||||
use pocketmine\block\utils\PillarRotationInMetadataTrait;
|
||||
use pocketmine\item\ToolTier;
|
||||
|
||||
class BoneBlock extends Opaque{
|
||||
use PillarRotationTrait;
|
||||
use PillarRotationInMetadataTrait;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(2.0, BlockToolType::PICKAXE, ToolTier::WOOD()->getHarvestLevel()));
|
||||
|
@ -23,10 +23,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\PillarRotationTrait;
|
||||
use pocketmine\block\utils\PillarRotationInMetadataTrait;
|
||||
|
||||
class HayBale extends Opaque{
|
||||
use PillarRotationTrait;
|
||||
use PillarRotationInMetadataTrait;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||
parent::__construct($idInfo, $name, $breakInfo ?? new BlockBreakInfo(0.5));
|
||||
|
@ -23,8 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\PillarRotationTrait;
|
||||
use pocketmine\block\utils\PillarRotationInMetadataTrait;
|
||||
|
||||
class Log extends Wood{
|
||||
use PillarRotationTrait;
|
||||
use PillarRotationInMetadataTrait;
|
||||
}
|
||||
|
76
src/block/utils/PillarRotationInMetadataTrait.php
Normal file
76
src/block/utils/PillarRotationInMetadataTrait.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?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;
|
||||
|
||||
use pocketmine\math\Axis;
|
||||
|
||||
trait PillarRotationInMetadataTrait{
|
||||
use PillarRotationTrait;
|
||||
|
||||
protected function getAxisMetaShift() : int{
|
||||
return 2; //default
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::writeStateToMeta()
|
||||
*/
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->writeAxisToMeta();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::readStateFromData()
|
||||
*/
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->readAxisFromMeta($stateMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::getStateBitmask()
|
||||
*/
|
||||
public function getStateBitmask() : int{
|
||||
return 0b11 << $this->getAxisMetaShift();
|
||||
}
|
||||
|
||||
protected function readAxisFromMeta(int $meta) : void{
|
||||
$axis = $meta >> $this->getAxisMetaShift();
|
||||
$mapped = [
|
||||
0 => Axis::Y,
|
||||
1 => Axis::X,
|
||||
2 => Axis::Z
|
||||
][$axis] ?? null;
|
||||
if($mapped === null){
|
||||
throw new InvalidBlockStateException("Invalid axis meta $axis");
|
||||
}
|
||||
$this->axis = $mapped;
|
||||
}
|
||||
|
||||
protected function writeAxisToMeta() : int{
|
||||
return [
|
||||
Axis::Y => 0,
|
||||
Axis::Z => 2,
|
||||
Axis::X => 1
|
||||
][$this->axis] << $this->getAxisMetaShift();
|
||||
}
|
||||
}
|
@ -36,52 +36,6 @@ trait PillarRotationTrait{
|
||||
/** @var int */
|
||||
protected $axis = Axis::Y;
|
||||
|
||||
protected function getAxisMetaShift() : int{
|
||||
return 2; //default
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::writeStateToMeta()
|
||||
*/
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->writeAxisToMeta();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::readStateFromData()
|
||||
*/
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->readAxisFromMeta($stateMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Block::getStateBitmask()
|
||||
*/
|
||||
public function getStateBitmask() : int{
|
||||
return 0b11 << $this->getAxisMetaShift();
|
||||
}
|
||||
|
||||
protected function readAxisFromMeta(int $meta) : void{
|
||||
$axis = $meta >> $this->getAxisMetaShift();
|
||||
$mapped = [
|
||||
0 => Axis::Y,
|
||||
1 => Axis::X,
|
||||
2 => Axis::Z
|
||||
][$axis] ?? null;
|
||||
if($mapped === null){
|
||||
throw new InvalidBlockStateException("Invalid axis meta $axis");
|
||||
}
|
||||
$this->axis = $mapped;
|
||||
}
|
||||
|
||||
protected function writeAxisToMeta() : int{
|
||||
return [
|
||||
Axis::Y => 0,
|
||||
Axis::Z => 2,
|
||||
Axis::X => 1
|
||||
][$this->axis] << $this->getAxisMetaShift();
|
||||
}
|
||||
|
||||
/** @see Axis */
|
||||
public function getAxis() : int{ return $this->axis; }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user