mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-05 19:37:17 +00:00
added missing redstone power flag logic
This commit is contained in:
parent
1366c49f1f
commit
42d07c74d7
@ -142,6 +142,8 @@ final class BlockLegacyMetadata{
|
||||
public const LEAVES_FLAG_NO_DECAY = 0x04;
|
||||
public const LEAVES_FLAG_CHECK_DECAY = 0x08;
|
||||
|
||||
public const LECTERN_FLAG_POWERED = 0x04;
|
||||
|
||||
public const LEVER_FLAG_POWERED = 0x08;
|
||||
|
||||
public const LIQUID_FLAG_FALLING = 0x08;
|
||||
|
@ -40,13 +40,15 @@ class Lectern extends Transparent{
|
||||
|
||||
protected int $viewedPage = 0;
|
||||
protected ?WritableBookBase $book = null;
|
||||
protected bool $producingSignal = false;
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta);
|
||||
$this->facing = BlockDataSerializer::readLegacyHorizontalFacing($stateMeta & 0x03);
|
||||
$this->producingSignal = ($stateMeta & BlockLegacyMetadata::LECTERN_FLAG_POWERED) !== 0;
|
||||
}
|
||||
|
||||
public function writeStateToMeta() : int{
|
||||
return BlockDataSerializer::writeLegacyHorizontalFacing($this->facing);
|
||||
return BlockDataSerializer::writeLegacyHorizontalFacing($this->facing) | ($this->producingSignal ? BlockLegacyMetadata::LECTERN_FLAG_POWERED : 0);
|
||||
}
|
||||
|
||||
public function readStateFromWorld() : void{
|
||||
@ -68,7 +70,7 @@ class Lectern extends Transparent{
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
return 0b11;
|
||||
return 0b111;
|
||||
}
|
||||
|
||||
public function getFlammability() : int{
|
||||
@ -88,6 +90,14 @@ class Lectern extends Transparent{
|
||||
return [AxisAlignedBB::one()->trim(Facing::UP, 0.1)];
|
||||
}
|
||||
|
||||
public function isProducingSignal() : bool{ return $this->producingSignal; }
|
||||
|
||||
/** @return $this */
|
||||
public function setProducingSignal(bool $producingSignal) : self{
|
||||
$this->producingSignal = $producingSignal;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getViewedPage() : int{
|
||||
return $this->viewedPage;
|
||||
}
|
||||
@ -124,4 +134,30 @@ class Lectern extends Transparent{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function onPageTurn(int $newPage) : bool{
|
||||
if($newPage === $this->viewedPage){
|
||||
return true;
|
||||
}
|
||||
if($this->book === null || $newPage >= count($this->book->getPages()) || $newPage < 0){
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->viewedPage = $newPage;
|
||||
if(!$this->producingSignal){
|
||||
$this->producingSignal = true;
|
||||
$this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, 1);
|
||||
}
|
||||
|
||||
$this->position->getWorld()->setBlock($this->position, $this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onScheduledUpdate() : void{
|
||||
if($this->producingSignal){
|
||||
$this->producingSignal = false;
|
||||
$this->position->getWorld()->setBlock($this->position, $this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -945,14 +945,10 @@ class InGamePacketHandler extends PacketHandler{
|
||||
|
||||
$lectern = $world->getBlockAt($pos->getX(), $pos->getY(), $pos->getZ());
|
||||
if($lectern instanceof Lectern && $this->player->canInteract($lectern->getPosition(), 15)){
|
||||
if($lectern->getViewedPage() === $packet->page){
|
||||
return true;
|
||||
}
|
||||
$book = $lectern->getBook();
|
||||
if($book !== null && count($book->getPages()) === $packet->totalPages && $packet->page >= 0 && $packet->page < $packet->totalPages){
|
||||
$world->setBlock($lectern->getPosition(), $lectern->setViewedPage($packet->page));
|
||||
return true;
|
||||
if(!$lectern->onPageTurn($packet->page)){
|
||||
$this->onFailedBlockAction($lectern->getPosition(), null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user