PocketMine-MP 5.33.2 git-919492bdcad8510eb6606439eb77e1c604f1d1ea
Loading...
Searching...
No Matches
RedstoneRepeater.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
26use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
29use pocketmine\block\utils\PoweredByRedstoneTrait;
30use pocketmine\block\utils\StaticSupportTrait;
31use pocketmine\block\utils\SupportType;
38
40 use FacesOppositePlacingPlayerTrait;
41 use PoweredByRedstoneTrait;
42 use StaticSupportTrait;
43
44 public const MIN_DELAY = 1;
45 public const MAX_DELAY = 4;
46
47 protected int $delay = self::MIN_DELAY;
48
49 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
50 $w->enum($this->facing);
51 $w->boundedIntAuto(self::MIN_DELAY, self::MAX_DELAY, $this->delay);
52 $w->bool($this->powered);
53 }
54
55 public function getDelay() : int{ return $this->delay; }
56
58 public function setDelay(int $delay) : self{
59 if($delay < self::MIN_DELAY || $delay > self::MAX_DELAY){
60 throw new \InvalidArgumentException("Delay must be in range " . self::MIN_DELAY . " ... " . self::MAX_DELAY);
61 }
62 $this->delay = $delay;
63 return $this;
64 }
65
66 protected function recalculateCollisionBoxes() : array{
67 return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 7 / 8)];
68 }
69
70 public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
71 if(++$this->delay > self::MAX_DELAY){
72 $this->delay = self::MIN_DELAY;
73 }
74 $this->position->getWorld()->setBlock($this->position, $this);
75 return true;
76 }
77
78 private function canBeSupportedAt(Block $block) : bool{
79 return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE;
80 }
81
82 //TODO: redstone functionality
83}
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
describeBlockOnlyState(RuntimeDataDescriber $w)
boundedIntAuto(int $min, int $max, int &$value)