Skip to content
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

Open
wants to merge 9 commits into
base: minor-next
Choose a base branch
from
7 changes: 7 additions & 0 deletions src/block/Bell.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -134,6 +135,12 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player
return false;
}

public function onProjectileInteraction(Projectile $projectile) : void{
if($projectile instanceof WindCharge) {
$this->ring($this->facing);
}
}

public function onProjectileHit(Projectile $projectile, RayTraceResult $hitResult) : void{
$faceHit = Facing::opposite($projectile->getHorizontalFacing());
if($this->isValidFaceToRing($faceHit)){
Expand Down
9 changes: 9 additions & 0 deletions src/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,15 @@ public function onScheduledUpdate() : void{

}

/**
* Called when this block is updated by a state altering projectile in the world.
*
* @param Projectile $projectile The projectile affecting the block
*/
public function onProjectileInteraction(Projectile $projectile) : void {

}

/**
* Do actions when interacted by Item. Returns if it has done anything
*
Expand Down
23 changes: 18 additions & 5 deletions src/block/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check if its not pressed

Copy link
Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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 {
$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());
}
}
15 changes: 15 additions & 0 deletions src/block/CakeWithCandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@

use pocketmine\block\utils\CandleTrait;
use pocketmine\entity\Living;
use pocketmine\entity\projectile\Projectile;
use pocketmine\entity\projectile\WindCharge;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\sound\FlintSteelSound;

class CakeWithCandle extends BaseCake{
use CandleTrait {
Expand Down Expand Up @@ -59,6 +62,18 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player
return parent::onInteract($item, $face, $clickVector, $player, $returnedItems);
}

public function onProjectileInteraction(Projectile $projectile) : void{
if($projectile instanceof WindCharge) {
if(!$this->lit) {
return;
}
CJMustard1452 marked this conversation as resolved.
Show resolved Hide resolved

$world = $this->position->getWorld();
$world->setBlock($this->position, $this->setLit(false));
$world->addSound($this->position, new FlintSteelSound());
}
}

public function getDropsForCompatibleTool(Item $item) : array{
return [$this->getCandle()->asItem()];
}
Expand Down
13 changes: 13 additions & 0 deletions src/block/Candle.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use pocketmine\block\utils\CandleTrait;
use pocketmine\block\utils\SupportType;
use pocketmine\data\runtime\RuntimeDataDescriber;
use pocketmine\entity\projectile\Projectile;
use pocketmine\item\Item;
use pocketmine\math\Axis;
use pocketmine\math\AxisAlignedBB;
Expand All @@ -34,6 +35,7 @@
use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\world\BlockTransaction;
use pocketmine\world\sound\FlintSteelSound;

class Candle extends Transparent{
use CandleTrait {
Expand Down Expand Up @@ -98,6 +100,17 @@ protected function getCandleIfCompatibleType(Block $block) : ?Candle{
return $block instanceof Candle && $block->hasSameTypeId($this) ? $block : null;
}

public function onProjectileInteraction(Projectile $projectile) : void{
if(!$this->lit) {
return;
}

$newCandle = $this->setLit(false);
CJMustard1452 marked this conversation as resolved.
Show resolved Hide resolved
$world = $this->position->getWorld();
$world->setBlock($this->position, $newCandle);
$world->addSound($this->position, new FlintSteelSound());
}

public function canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock) : bool{
$candle = $this->getCandleIfCompatibleType($blockReplace);
return $candle !== null ? $candle->count < self::MAX_COUNT : parent::canBePlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
Expand Down
7 changes: 7 additions & 0 deletions src/block/ChorusFlower.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use pocketmine\block\utils\AgeableTrait;
use pocketmine\block\utils\StaticSupportTrait;
use pocketmine\entity\projectile\Projectile;
use pocketmine\entity\projectile\WindCharge;
use pocketmine\event\block\StructureGrowEvent;
use pocketmine\math\Axis;
use pocketmine\math\AxisAlignedBB;
Expand Down Expand Up @@ -118,6 +119,12 @@ private function allHorizontalBlocksEmpty(World $world, Vector3 $position, ?int
return true;
}

public function onProjectileInteraction(Projectile $projectile) : void{
if($projectile instanceof WindCharge) {
$this->position->getWorld()->useBreakOn($this->position);
CJMustard1452 marked this conversation as resolved.
Show resolved Hide resolved
}
}

private function canGrowUpwards(int $stemHeight, bool $endStoneBelow) : bool{
$world = $this->position->getWorld();

Expand Down
39 changes: 28 additions & 11 deletions src/block/Door.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -176,4 +168,29 @@ 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) {
return;
}

$this->toggle();
}
}

public function toggle() : void {
$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());
}
}
15 changes: 14 additions & 1 deletion src/block/Lever.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
$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{
Expand Down
20 changes: 19 additions & 1 deletion src/block/Trapdoor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,10 +87,26 @@ 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){
if($this->getTypeId() === BlockTypeIds::IRON_TRAPDOOR) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better to moove it into the condition above?


$this->toggle();
}
}

public function toggle() : void {
$this->open = !$this->open;

$world = $this->position->getWorld();
$world->setBlock($this->position, $this);
$world->addSound($this->position, new DoorSound());
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ private function register1to1ItemMappings() : void{
$this->map1to1Item(Ids::WHEAT, Items::WHEAT());
$this->map1to1Item(Ids::WHEAT_SEEDS, Items::WHEAT_SEEDS());
$this->map1to1Item(Ids::WILD_ARMOR_TRIM_SMITHING_TEMPLATE, Items::WILD_ARMOR_TRIM_SMITHING_TEMPLATE());
$this->map1to1Item(Ids::WIND_CHARGE, Items::WIND_CHARGE());
$this->map1to1Item(Ids::WOODEN_AXE, Items::WOODEN_AXE());
$this->map1to1Item(Ids::WOODEN_HOE, Items::WOODEN_HOE());
$this->map1to1Item(Ids::WOODEN_PICKAXE, Items::WOODEN_PICKAXE());
Expand Down
5 changes: 5 additions & 0 deletions src/entity/EntityFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use pocketmine\entity\projectile\ExperienceBottle;
use pocketmine\entity\projectile\Snowball;
use pocketmine\entity\projectile\SplashPotion;
use pocketmine\entity\projectile\WindCharge;
use pocketmine\item\Item;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
Expand Down Expand Up @@ -169,6 +170,10 @@ public function __construct(){
return new Villager(Helper::parseLocation($nbt, $world), $nbt);
}, ['Villager', 'minecraft:villager']);

$this->register(WindCharge::class, function(World $world, CompoundTag $nbt) : WindCharge {
return new WindCharge(Helper::parseLocation($nbt, $world), null, $nbt);
}, ['Wind Charge', 'minecraft:wind_charge']);

$this->register(Zombie::class, function(World $world, CompoundTag $nbt) : Zombie{
return new Zombie(Helper::parseLocation($nbt, $world), $nbt);
}, ['Zombie', 'minecraft:zombie']);
Expand Down
Loading