mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-10 15:59:39 +00:00
FenceGate: implement in-wall checks
This commit is contained in:
parent
6f7c63e2a8
commit
a95ecb3ff9
@ -37,18 +37,21 @@ class FenceGate extends Transparent{
|
|||||||
protected $open = false;
|
protected $open = false;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $facing = Facing::NORTH;
|
protected $facing = Facing::NORTH;
|
||||||
|
/** @var bool */
|
||||||
|
protected $inWall = false;
|
||||||
|
|
||||||
protected function writeStateToMeta() : int{
|
protected function writeStateToMeta() : int{
|
||||||
return Bearing::fromFacing($this->facing) | ($this->open ? 0x04 : 0);
|
return Bearing::fromFacing($this->facing) | ($this->open ? 0x04 : 0) | ($this->inWall ? 0x08 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function readStateFromMeta(int $meta) : void{
|
public function readStateFromMeta(int $meta) : void{
|
||||||
$this->facing = BlockDataValidator::readLegacyHorizontalFacing($meta & 0x03);
|
$this->facing = BlockDataValidator::readLegacyHorizontalFacing($meta & 0x03);
|
||||||
$this->open = ($meta & 0x04) !== 0;
|
$this->open = ($meta & 0x04) !== 0;
|
||||||
|
$this->inWall = ($meta & 0x08) !== 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getStateBitmask() : int{
|
public function getStateBitmask() : int{
|
||||||
return 0b111;
|
return 0b1111;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHardness() : float{
|
public function getHardness() : float{
|
||||||
@ -68,14 +71,31 @@ class FenceGate extends Transparent{
|
|||||||
return AxisAlignedBB::one()->extend(Facing::UP, 0.5)->squash(Facing::axis($this->facing), 6 / 16);
|
return AxisAlignedBB::one()->extend(Facing::UP, 0.5)->squash(Facing::axis($this->facing), 6 / 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function checkInWall() : bool{
|
||||||
|
return (
|
||||||
|
$this->getSide(Facing::rotateY($this->facing, false)) instanceof CobblestoneWall or
|
||||||
|
$this->getSide(Facing::rotateY($this->facing, true)) instanceof CobblestoneWall
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||||
if($player !== null){
|
if($player !== null){
|
||||||
$this->facing = $player->getHorizontalFacing();
|
$this->facing = $player->getHorizontalFacing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->inWall = $this->checkInWall();
|
||||||
|
|
||||||
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onNearbyBlockChange() : void{
|
||||||
|
$inWall = $this->checkInWall();
|
||||||
|
if($inWall !== $this->inWall){
|
||||||
|
$this->inWall = $inWall;
|
||||||
|
$this->level->setBlock($this, $this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
$this->open = !$this->open;
|
$this->open = !$this->open;
|
||||||
if($this->open and $player !== null){
|
if($this->open and $player !== null){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user