-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wind Charge Implementation #6427
base: minor-next
Are you sure you want to change the base?
Changes from all commits
f828749
4f3fc20
54caeb4
d1e5f8c
0002323
3b16dd7
4a2c6cc
10ac730
7117617
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
|
||
use pocketmine\block\utils\AnyFacingTrait; | ||
use pocketmine\data\runtime\RuntimeDataDescriber; | ||
use pocketmine\entity\projectile\Projectile; | ||
use pocketmine\entity\projectile\WindCharge; | ||
use pocketmine\item\Item; | ||
use pocketmine\math\Facing; | ||
use pocketmine\math\Vector3; | ||
|
@@ -63,11 +65,7 @@ abstract protected function getActivationTime() : int; | |
|
||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ | ||
if(!$this->pressed){ | ||
$this->pressed = true; | ||
$world = $this->position->getWorld(); | ||
$world->setBlock($this->position, $this); | ||
$world->scheduleDelayedBlockUpdate($this->position, $this->getActivationTime()); | ||
$world->addSound($this->position->add(0.5, 0.5, 0.5), new RedstonePowerOnSound()); | ||
$this->press(); | ||
} | ||
|
||
return true; | ||
|
@@ -91,4 +89,19 @@ public function onNearbyBlockChange() : void{ | |
private function canBeSupportedAt(Block $block, int $face) : bool{ | ||
return $block->getAdjacentSupportType(Facing::opposite($face))->hasCenterSupport(); | ||
} | ||
|
||
public function onProjectileInteraction(Projectile $projectile) : void{ | ||
if($projectile instanceof WindCharge) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to check if its not pressed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $this->pressed(); in this context, thereby extending the pushed duration if already down, I do not see a need to change this, thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by checking that it is not activated, you will avoid extra sound. |
||
$this->press(); | ||
} | ||
} | ||
|
||
public function press() : void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
$this->pressed = true; | ||
|
||
$world = $this->position->getWorld(); | ||
$world->setBlock($this->position, $this); | ||
$world->scheduleDelayedBlockUpdate($this->position, $this->getActivationTime()); | ||
$world->addSound($this->position->add(0.5, 0.5, 0.5), new RedstonePowerOnSound()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
use pocketmine\block\utils\HorizontalFacingTrait; | ||
use pocketmine\block\utils\SupportType; | ||
use pocketmine\data\runtime\RuntimeDataDescriber; | ||
use pocketmine\entity\projectile\Projectile; | ||
use pocketmine\entity\projectile\WindCharge; | ||
use pocketmine\item\Item; | ||
use pocketmine\math\AxisAlignedBB; | ||
use pocketmine\math\Facing; | ||
|
@@ -142,17 +144,7 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo | |
} | ||
|
||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ | ||
$this->open = !$this->open; | ||
|
||
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); | ||
$world = $this->position->getWorld(); | ||
if($other instanceof Door && $other->hasSameTypeId($this)){ | ||
$other->open = $this->open; | ||
$world->setBlock($other->position, $other); | ||
} | ||
|
||
$world->setBlock($this->position, $this); | ||
$world->addSound($this->position, new DoorSound()); | ||
$this->toggle(); | ||
|
||
return true; | ||
} | ||
|
@@ -176,4 +168,34 @@ public function getAffectedBlocks() : array{ | |
private function canBeSupportedAt(Block $block) : bool{ | ||
return $block->getAdjacentSupportType(Facing::DOWN)->hasEdgeSupport(); | ||
} | ||
|
||
public function onProjectileInteraction(Projectile $projectile) : void{ | ||
if($projectile instanceof WindCharge) { | ||
if($this->getTypeId() === BlockTypeIds::IRON_DOOR) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not liking this check, same as before with trapdoors |
||
return; | ||
} | ||
|
||
// This is to avoid calling Door::onProjectileInteraction() twice due to two tiles. | ||
if($this->top) { | ||
Comment on lines
+178
to
+179
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, if the projectile hit the upper one, no toggle will be happened ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is my best attempt at handling this issue, if it hits both blocks the door hits, (open, close) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be useful before toggling to check the other state. If its not the same as ours when projectile hits, we can ignore ? Just a theory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. feels a little hacky to be honest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe hacky but can avoid to have unexpected side effect if only the top block is hitten by the effect area. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, only checking the one half will cause bugs. It's the same as if a player were clicking the top or bottom half, so the logic should be basically the same. |
||
return; | ||
} | ||
|
||
$this->toggle(); | ||
} | ||
} | ||
|
||
public function toggle() : void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
$this->open = !$this->open; | ||
|
||
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP); | ||
$world = $this->position->getWorld(); | ||
|
||
if($other instanceof Door && $other->hasSameTypeId($this)){ | ||
$other->open = $this->open; | ||
$world->setBlock($other->position, $other); | ||
} | ||
|
||
$world->setBlock($this->position, $this); | ||
$world->addSound($this->position, new DoorSound()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ | |
|
||
use pocketmine\block\utils\LeverFacing; | ||
use pocketmine\data\runtime\RuntimeDataDescriber; | ||
use pocketmine\entity\projectile\Projectile; | ||
use pocketmine\entity\projectile\WindCharge; | ||
use pocketmine\item\Item; | ||
use pocketmine\math\Axis; | ||
use pocketmine\math\Facing; | ||
|
@@ -91,14 +93,25 @@ public function onNearbyBlockChange() : void{ | |
} | ||
|
||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ | ||
$this->toggle(); | ||
|
||
return true; | ||
} | ||
|
||
public function onProjectileInteraction(Projectile $projectile) : void{ | ||
if($projectile instanceof WindCharge) { | ||
$this->toggle(); | ||
} | ||
} | ||
|
||
public function toggle() : void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
$this->activated = !$this->activated; | ||
$world = $this->position->getWorld(); | ||
$world->setBlock($this->position, $this); | ||
$world->addSound( | ||
$this->position->add(0.5, 0.5, 0.5), | ||
$this->activated ? new RedstonePowerOnSound() : new RedstonePowerOffSound() | ||
); | ||
return true; | ||
} | ||
|
||
private function canBeSupportedAt(Block $block, int $face) : bool{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
use pocketmine\block\utils\HorizontalFacingTrait; | ||
use pocketmine\block\utils\SupportType; | ||
use pocketmine\data\runtime\RuntimeDataDescriber; | ||
use pocketmine\entity\projectile\Projectile; | ||
use pocketmine\entity\projectile\WindCharge; | ||
use pocketmine\item\Item; | ||
use pocketmine\math\AxisAlignedBB; | ||
use pocketmine\math\Facing; | ||
|
@@ -85,10 +87,22 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo | |
} | ||
|
||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ | ||
$this->toggle(); | ||
|
||
return true; | ||
} | ||
|
||
public function onProjectileInteraction(Projectile $projectile) : void{ | ||
if($projectile instanceof WindCharge && $this->getTypeId() !== BlockTypeIds::IRON_TRAPDOOR){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not liking the iron trapdoor check hardcoded in here. |
||
$this->toggle(); | ||
} | ||
} | ||
|
||
public function toggle() : void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
$this->open = !$this->open; | ||
|
||
$world = $this->position->getWorld(); | ||
$world->setBlock($this->position, $this); | ||
$world->addSound($this->position, new DoorSound()); | ||
return true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence doesn't mean anything to me. It doesn't tell me why an update was triggered, nor what kind of state alterations should take place.
The function is trying to look and sound generic, but it's not.
"interaction" is also too vague.