position === self::BOTTOM){ $rotationMeta = Facing::axis($this->facing) === Facing::AXIS_Z ? 7 : 0; }elseif($this->position === self::TOP){ $rotationMeta = Facing::axis($this->facing) === Facing::AXIS_Z ? 5 : 6; }else{ $rotationMeta = 6 - $this->facing; } return $rotationMeta | ($this->powered ? 0x08 : 0); } public function readStateFromData(int $id, int $stateMeta) : void{ $rotationMeta = $stateMeta & 0x07; if($rotationMeta === 5 or $rotationMeta === 6){ $this->position = self::TOP; $this->facing = $rotationMeta === 5 ? Facing::SOUTH : Facing::EAST; }elseif($rotationMeta === 7 or $rotationMeta === 0){ $this->position = self::BOTTOM; $this->facing = $rotationMeta === 7 ? Facing::SOUTH : Facing::EAST; }else{ $this->position = self::SIDE; $this->facing = BlockDataValidator::readHorizontalFacing(6 - $rotationMeta); } $this->powered = ($stateMeta & 0x08) !== 0; } public function getStateBitmask() : int{ return 0b1111; } public function getHardness() : float{ return 0.5; } public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if(!$blockClicked->isSolid()){ return false; } if(Facing::axis($face) === Facing::AXIS_Y){ if($player !== null){ $this->facing = Facing::opposite($player->getHorizontalFacing()); } $this->position = $face === Facing::DOWN ? self::BOTTOM : self::TOP; }else{ $this->facing = $face; $this->position = self::SIDE; } return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player); } public function onNearbyBlockChange() : void{ if($this->position === self::BOTTOM){ $face = Facing::UP; }elseif($this->position === self::TOP){ $face = Facing::DOWN; }else{ $face = Facing::opposite($this->facing); } if(!$this->getSide($face)->isSolid()){ $this->level->useBreakOn($this); } } public function onActivate(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->powered = !$this->powered; $this->level->setBlock($this, $this); $this->level->broadcastLevelSoundEvent( $this->add(0.5, 0.5, 0.5), $this->powered ? LevelSoundEventPacket::SOUND_POWER_ON : LevelSoundEventPacket::SOUND_POWER_OFF ); return true; } //TODO }