Skip to content

Commit

Permalink
Merge pull request #3 from NhanAZ/master
Browse files Browse the repository at this point in the history
Implemented particles
  • Loading branch information
ipad54 authored Jan 4, 2022
2 parents e270b48 + 1e21b86 commit e75e7f5
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/ipad54/composter/block/Composter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace ipad54\composter\block;


use pocketmine\network\mcpe\protocol\SpawnParticleEffectPacket;
use ipad54\composter\sound\ComposteEmptySound;
use ipad54\composter\sound\ComposteFillSound;
use ipad54\composter\sound\ComposteFillSuccessSound;
Expand Down Expand Up @@ -95,19 +96,30 @@ public function getStateBitmask(): int
return 0b1111;
}

private function spawnParticleEffect(Vector3 $position): void
{
$packet = new SpawnParticleEffectPacket();
$packet->position = $position;
$packet->particleName = "minecraft:crop_growth_emitter";
$recipients = $this->position->getWorld()->getViewersForPosition($this->position);
foreach($recipients as $player){
$player->getNetworkSession()->sendDataPacket($packet);
}
}

public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null): bool
{
if ($this->fill >= 8) {
$this->fill = 0;
$this->position->getWorld()->setBlock($this->position, $this);
$this->position->getWorld()->addSound($this->position, new ComposteEmptySound());
$this->position->getWorld()->dropItem($this->position, VanillaItems::BONE_MEAL());
$this->position->getWorld()->dropItem($this->position->add(0.5, 1.1, 0.5), VanillaItems::BONE_MEAL());
return true;
}
if (isset($this->ingridients[$item->getId()]) && $this->fill < 7) {
$item->pop();
$this->spawnParticleEffect($this->position->add(0.5, 0.5, 0.5));
if ($this->fill == 0) {

$this->incrimentFill(true);
return true;
}
Expand All @@ -121,7 +133,6 @@ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player
return true;
}


public function incrimentFill(bool $playsound = false): bool
{
if ($this->fill >= 7) {
Expand All @@ -146,4 +157,4 @@ public function onScheduledUpdate(): void
$this->position->getWorld()->addSound($this->position, new ComposteReadySound());
}
}
}
}

0 comments on commit e75e7f5

Please sign in to comment.