mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 10:49:10 +00:00
Added on/off handling for buttons and levers
This commit is contained in:
parent
ebf5ccea8a
commit
f2c960cfd8
@ -26,6 +26,7 @@ namespace pocketmine\block;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||
use pocketmine\Player;
|
||||
|
||||
abstract class Button extends Flowable{
|
||||
@ -59,8 +60,24 @@ abstract class Button extends Flowable{
|
||||
return parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
abstract protected function getActivationTime() : int;
|
||||
|
||||
public function onActivate(Item $item, Player $player = null) : bool{
|
||||
//TODO
|
||||
if(!$this->powered){
|
||||
$this->powered = true;
|
||||
$this->level->setBlock($this, $this);
|
||||
$this->level->scheduleDelayedBlockUpdate($this, $this->getActivationTime());
|
||||
$this->level->broadcastLevelSoundEvent($this->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_POWER_ON);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onScheduledUpdate() : void{
|
||||
if($this->powered){
|
||||
$this->powered = false;
|
||||
$this->level->setBlock($this, $this);
|
||||
$this->level->broadcastLevelSoundEvent($this->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_POWER_OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ use pocketmine\item\Item;
|
||||
use pocketmine\math\Bearing;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Lever extends Flowable{
|
||||
@ -118,5 +119,15 @@ class Lever extends Flowable{
|
||||
}
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player = null) : bool{
|
||||
$this->powered = !$this->powered;
|
||||
$this->level->setBlock($this, $this);
|
||||
$this->level->broadcastLevelSoundEvent(
|
||||
$this->add(0.5, 0.5, 0.5),
|
||||
$this->powered ? LevelSoundEventPacket::SOUND_POWER_ON : LevelSoundEventPacket::SOUND_POWER_OFF
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
@ -38,4 +38,8 @@ class StoneButton extends Button{
|
||||
public function getToolType() : int{
|
||||
return BlockToolType::TYPE_PICKAXE;
|
||||
}
|
||||
|
||||
protected function getActivationTime() : int{
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
|
@ -38,4 +38,12 @@ class WoodenButton extends Button{
|
||||
public function getToolType() : int{
|
||||
return BlockToolType::TYPE_AXE;
|
||||
}
|
||||
|
||||
protected function getActivationTime() : int{
|
||||
return 30;
|
||||
}
|
||||
|
||||
public function hasEntityCollision() : bool{
|
||||
return false; //TODO: arrows activate wooden buttons
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user