Skip to content

Commit e48efb6

Browse files
committed
Fix repeater behavior
1 parent 5100adb commit e48efb6

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/tedo0627/redstonecircuit/block/transmission/BlockRedstoneRepeater.php

+25-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,24 @@ public function onNearbyBlockChange(): void {
4444
}
4545

4646
public function onScheduledUpdate(): void {
47-
$this->setPowered(!$this->isPowered());
48-
$this->getPosition()->getWorld()->setBlock($this->getPosition(), $this);
49-
BlockUpdateHelper::updateDiodeRedstone($this, Facing::opposite($this->getFacing()));
47+
if ($this->isLocked()) return;
48+
49+
$powered = $this->isPowered();
50+
$side = BlockPowerHelper::isSidePowered($this, $this->getFacing());
51+
if ($powered && !$side) {
52+
$this->setPowered(false);
53+
$this->getPosition()->getWorld()->setBlock($this->getPosition(), $this);
54+
BlockUpdateHelper::updateDiodeRedstone($this, Facing::opposite($this->getFacing()));
55+
return;
56+
}
57+
58+
if (!$powered) {
59+
$this->setPowered(true);
60+
$this->getPosition()->getWorld()->setBlock($this->getPosition(), $this);
61+
BlockUpdateHelper::updateDiodeRedstone($this, Facing::opposite($this->getFacing()));
62+
63+
if (!$side) $this->getPosition()->getWorld()->scheduleDelayedBlockUpdate($this->getPosition(), $this->getDelay() * 2);
64+
}
5065
}
5166

5267
public function isLocked(): bool {
@@ -73,8 +88,14 @@ public function isPowerSource(): bool {
7388

7489
public function onRedstoneUpdate(): void {
7590
if ($this->isLocked()) return;
76-
if (BlockPowerHelper::isSidePowered($this, $this->getFacing()) === $this->isPowered()) return;
7791

92+
$side = BlockPowerHelper::isSidePowered($this, $this->getFacing());
93+
if ($side && !$this->isPowered()) {
94+
$this->getPosition()->getWorld()->scheduleDelayedBlockUpdate($this->getPosition(), $this->getDelay() * 2);
95+
return;
96+
}
97+
98+
if ($side || !$this->isPowered()) return;
7899
$this->getPosition()->getWorld()->scheduleDelayedBlockUpdate($this->getPosition(), $this->getDelay() * 2);
79100
}
80101

0 commit comments

Comments
 (0)