22
33namespace jossc \volcano \task ;
44
5- use jossc \volcano \entity \FallingWool ;
5+ use jossc \volcano \entity \CustomFallingWoolBlock ;
66use jossc \volcano \utils \Utils ;
7- use pocketmine \block \BlockFactory ;
8- use pocketmine \block \BlockLegacyIds ;
9- use pocketmine \entity \EntityDataHelper ;
10- use pocketmine \entity \Location ;
11- use pocketmine \math \Vector3 ;
127use pocketmine \player \Player ;
138use pocketmine \scheduler \Task ;
149use pocketmine \world \World ;
@@ -17,10 +12,13 @@ class VolcanoTak extends Task {
1712
1813 /*** @var Player */
1914 private $ player ;
15+
2016 /*** @var World */
2117 private $ world ;
18+
2219 /*** @var array */
2320 private $ fallingBlocks = [];
21+
2422 /*** @var int */
2523 private $ amount = 100 ;
2624
@@ -34,69 +32,41 @@ public function __construct(Player $player, World $world) {
3432 $ this ->world = $ world ;
3533 }
3634
37- /*** @return bool */
38- private function isExecutable (): bool {
39- $ player = $ this ->player ;
40- $ amount = $ this ->amount ;
35+ public function onRun (): void {
36+ if ($ this ->isExecutable ()) {
4137
42- return ($ amount >= 1 ) &&
43- ($ player ->isOnline ()) &&
44- ($ player ->getWorld () === $ this ->world );
45- }
38+ $ location = $ this ->player ->getLocation ();
4639
47- public function onRun (): void {
48- if (!$ this ->isExecutable ()) {
49- $ this ->getHandler ()->cancel ();
40+ $ fallingWool = Utils::generateFallingWoolBlock ($ location );
41+ array_push ($ this ->fallingBlocks , $ fallingWool );
5042
51- foreach ($ this ->fallingBlocks as $ fallingBlock ) {
52- if (!$ fallingBlock instanceof FallingWool) {
53- continue ;
54- }
43+ Utils::playSound ("liquid.lavapop " , $ this ->player );
5544
56- if (!$ fallingBlock ->isFlaggedForDespawn ()) {
57- $ fallingBlock ->flagForDespawn ();
58- }
59- }
45+ $ this ->amount --;
6046
6147 return ;
6248 }
6349
64- $ player = $ this ->player ;
65- $ location = $ player ->getLocation ();
66- $ fallingWool = $ this ->generateFallingWool ($ location );
67- array_push ($ this ->fallingBlocks , $ fallingWool );
50+ $ this ->getHandler ()->cancel ();
6851
69- Utils::playSound ("liquid.lavapop " , $ player );
52+ foreach ($ this ->fallingBlocks as $ fallingBlock ) {
53+ if (!$ fallingBlock instanceof CustomFallingWoolBlock) {
54+ continue ;
55+ }
7056
71- $ this ->amount --;
57+ if (!$ fallingBlock ->isFlaggedForDespawn ()) {
58+ $ fallingBlock ->flagForDespawn ();
59+ }
60+ }
7261 }
7362
74- /**
75- * @param Location $location
76- * @return FallingWool
77- */
78- private function generateFallingWool (Location $ location ): FallingWool {
79- $ nbt = EntityDataHelper::createBaseNBT ($ location ->asVector3 ());
80-
81- $ meta = rand (0 , 15 );
82- $ fallingBlock = new FallingWool (
83- $ location ,
84- BlockFactory::getInstance ()->get (BlockLegacyIds::WOOL , $ meta ),
85- $ nbt
86- );
87-
88- $ fallingBlock ->setMotion (new Vector3 (
89- -sin (mt_rand (1 , 360 ) /60 * M_PI ),
90- 0.95 ,
91- cos (mt_rand (1 , 360 ) / 60 * M_PI ))
92- );
93-
94- $ fallingBlock ->setForceMovementUpdate (true );
95- $ fallingBlock ->setSilent (true );
96- $ fallingBlock ->setCanSaveWithChunk (false );
97-
98- $ fallingBlock ->spawnToAll ();
63+ /*** @return bool */
64+ private function isExecutable (): bool {
65+ $ player = $ this ->player ;
66+ $ amount = $ this ->amount ;
9967
100- return $ fallingBlock ;
68+ return ($ amount >= 1 ) &&
69+ ($ player ->isOnline ()) &&
70+ ($ player ->getWorld () === $ this ->world );
10171 }
10272}
0 commit comments