PocketMine-MP 5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
RedstoneComparator.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
28use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
29use pocketmine\block\utils\FacesOppositePlacingPlayerTrait;
32use pocketmine\block\utils\PoweredByRedstoneTrait;
33use pocketmine\block\utils\StaticSupportTrait;
34use pocketmine\block\utils\SupportType;
41use function assert;
42
44 use FacesOppositePlacingPlayerTrait;
45 use AnalogRedstoneSignalEmitterTrait;
46 use PoweredByRedstoneTrait;
47 use StaticSupportTrait;
48
49 protected bool $isSubtractMode = false;
50
51 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
52 $w->enum($this->facing);
53 $w->bool($this->isSubtractMode);
54 $w->bool($this->powered);
55 }
56
57 public function readStateFromWorld() : Block{
58 parent::readStateFromWorld();
59 $tile = $this->position->getWorld()->getTile($this->position);
60 if($tile instanceof Comparator){
61 $this->signalStrength = $tile->getSignalStrength();
62 }
63
64 return $this;
65 }
66
67 public function writeStateToWorld() : void{
68 parent::writeStateToWorld();
69 $tile = $this->position->getWorld()->getTile($this->position);
70 assert($tile instanceof Comparator);
71 $tile->setSignalStrength($this->signalStrength);
72 }
73
74 public function isSubtractMode() : bool{
75 return $this->isSubtractMode;
76 }
77
79 public function setSubtractMode(bool $isSubtractMode) : self{
80 $this->isSubtractMode = $isSubtractMode;
81 return $this;
82 }
83
84 protected function recalculateCollisionBoxes() : array{
85 return [AxisAlignedBB::one()->trimmedCopy(Facing::UP, 7 / 8)];
86 }
87
88 public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
89 $this->isSubtractMode = !$this->isSubtractMode;
90 $this->position->getWorld()->setBlock($this->position, $this);
91 return true;
92 }
93
94 private function canBeSupportedAt(Block $block) : bool{
95 return $block->getAdjacentSupportType(Facing::DOWN) !== SupportType::NONE;
96 }
97
98 //TODO: redstone functionality
99}
describeBlockOnlyState(RuntimeDataDescriber $w)
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])