22declare(strict_types=1);
26use pocketmine\block\utils\StaticSupportTrait;
27use pocketmine\block\utils\SupportType;
38 use StaticSupportTrait;
40 private readonly
int $deactivationDelayTicks;
42 public function __construct(
46 int $deactivationDelayTicks = 20
48 parent::__construct($idInfo, $name, $typeInfo);
49 $this->deactivationDelayTicks = $deactivationDelayTicks;
61 return SupportType::NONE;
64 private function canBeSupportedAt(
Block $block) : bool{
65 return $block->getAdjacentSupportType(
Facing::DOWN) !== SupportType::NONE;
73 if(!$this->hasOutputSignal()){
74 $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, 0);
86 ->squash(
Axis::X, 1 / 8)
87 ->squash(
Axis::Z, 1 / 8)
89 ->offset($this->position->x, $this->position->y, $this->position->z);
108 return [$this, null];
122 $world = $this->position->getWorld();
124 $intersectionAABB = $this->getActivationBox();
125 $activatingEntities = $this->filterIrrelevantEntities($world->getNearbyEntities($intersectionAABB));
130 if(count($activatingEntities) > 0 || $this->hasOutputSignal()){
131 [$newState, $pressedChange] = $this->calculatePlateState($activatingEntities);
134 if(PressurePlateUpdateEvent::hasHandlers()){
137 $newState = $ev->isCancelled() ? null : $ev->getNewState();
139 if($newState !==
null){
140 $world->setBlock($this->position, $newState);
141 if($pressedChange !==
null){
142 $world->addSound($this->position, $pressedChange ?
148 if($pressedChange ?? $this->hasOutputSignal()){
149 $world->scheduleDelayedBlockUpdate($this->position, $this->deactivationDelayTicks);
filterIrrelevantEntities(array $entities)
onEntityInside(Entity $entity)
calculatePlateState(array $entities)
getSupportType(int $facing)
recalculateCollisionBoxes()