Skip to content

Commit

Permalink
Add more particle and fix render particle
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuongaz committed Jun 22, 2021
1 parent 8d05b3b commit 14c750d
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 28 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# EasyWing
<img align="right" widht="auto" height="260" src="https://github.com/ZzKino/EasyWing/blob/master/icon.png?raw=true" alt="Logo">
Wing particle plugin for Pocketmine-MP

<a href="https://poggit.pmmp.io/p/EasyWing"><img src="https://poggit.pmmp.io/shield.state/EasyWing"></a>
Expand All @@ -18,8 +17,10 @@ shape: [
[1,1,1,1,0,0,0,1,1,0,0,0,1,1,1,1],
[1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1],
[1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1]]
scale: 0.3
Wing-Name: "Example Wing"
scale: 0.3 #scale of wing
Wing-Name: "Example Wing" #Name of wing
```

# List Particles
Expand All @@ -29,11 +30,21 @@ Wing-Name: "Example Wing"
4 : Red Dust
2: Green Dust
x: Redstone
f: Flame
F: Flame
b: Blue Flame
h: Villager Happy
p: Villager Angry
H: Heart
P: Portal
E: Entity Flame
W: Water
w: Water Drip
j: Enchant
J: Enchantment Table
D: Dragon Breath Lingering
```

# How to get a wing
+ Add permision to player `easywing.on.<wing name>`

<img align="left" widht="auto" height="260" src="https://github.com/ZzKino/EasyWing/blob/master/icon.png?raw=true" alt="Logo">
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: EasyWing
main: phuongaz\EasyWing\Loader
author: phuongaz
version: 1.0.4
version: 1.0.5
api: 3.0.0
68 changes: 46 additions & 22 deletions src/phuongaz/EasyWing/CustomWing.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace phuongaz\EasyWing;

use pocketmine\level\Level;
use pocketmine\level\Location;
use pocketmine\math\Vector3;
use pocketmine\Player;

use pocketmine\network\mcpe\protocol\SpawnParticleEffectPacket;
class CustomWing {

private Player $player;
Expand All @@ -17,17 +18,6 @@ public function __construct(Player $player, array $shape, float $scale){
$this->player = $player;
$this->shape = $shape;
$this->scale = $scale;
$l1 = count($this->shape);
for($y = 0; $y < $l1; $y++) {
$l2 = count($this->shape[$y]);
for($x = 0; $x < $l2; $x++) {
$flag = $shape[$y][$x];
if($flag == 0) continue;
$kx = $x - (int) ($l2 / 2);
$ky = ($y - (int) ($l1 / 2)) * (-1);
$this->vector3[] = [new Vector3($kx, $this->scale * $ky + 1.7), $flag];
}
}
}

public function getScale(): float{
Expand All @@ -38,17 +28,51 @@ public function getPlayer() :?Player{
return $this->player;
}

public function draw() :void{
public function draw(){
$player = $this->getPlayer();
$angle = $player->yaw;
$level = $player->getLevel();
$sin = sin(deg2rad($angle));
$cos = cos(deg2rad($angle));
foreach($this->vector3 as $data){
$r = $this->getScale() * $data[0]->x;
$px = $r * $cos;
$pz = $r * $sin;
$level->addParticle(Loader::getInstance()->parseWing($player->add($px, $data[0]->y, $pz), $data[1]));
$loc = clone $player->getLocation();
$space = $this->getScale();
$defX = $x = $loc->getX() - $space * count($this->shape[0]) / 2 + $space / 2;
$y = $loc->getY() + 2.8;
$angle = -(($loc->getYaw() + 180) / 60);
$angle += (($loc->getYaw() < -180) ? 3.25 : 2.985);
for($i = 0; $i < count($this->shape); ++$i){
for($j = 0; $j < count($this->shape[$i]); ++$j){
if($this->shape[$i][$j] != 0){
$target = clone $loc;
$target->x = $x;
$target->y = $y;
$v2 = $this->getBackVector($loc);
$v = $this->rotateAroundAxisY($target->subtract($loc->add(-0.5, 0, 0.35)), $angle);
$iT = $i / 18.0;
$v2->y = 0;
$newVec = $v->add($v2->multiply(-0.2 - $iT));
$newLoc = $newVec->add($loc);
for($k = 0; $k < 3; ++$k){
$particle = Loader::getInstance()->parseWing($newLoc, $this->shape[$i][$j]);
$player->getLevel()->addParticle($particle);
}
}
$x += $space;
}
$y -= $space;
$x = $defX;
}
}

public function getBackVector(Location $loc): Vector3{
$newZ = (float)($loc->getZ() + 0.75 * sin($loc->getYaw() * M_PI / 180));
$newX = (float)($loc->getX() + 0.75 * cos($loc->getYaw() * M_PI / 180));

return new Vector3($newX - $loc->getX(), $loc->getY(), $newZ - $loc->getZ());
}

public function rotateAroundAxisY(Vector3 $v, float $angle): Vector3{
$cos = cos($angle);
$sin = sin($angle);
$x = $v->getX() * $cos + $v->getZ() * $sin;
$z = $v->getX() * -$sin + $v->getZ() * $cos;

return $v->setComponents($x, $v->getY(), $z);
}
}
36 changes: 35 additions & 1 deletion src/phuongaz/EasyWing/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
DustParticle,
FlameParticle,
RedstoneParticle,
EntityFlameParticle,
EnchantParticle,
HeartParticle,
PortalParticle,
WaterParticle,
WaterDripParticle,
HappyVillagerParticle,
EnchantmentTableParticle,
Particle
};
use pocketmine\math\Vector3;
Expand All @@ -16,6 +24,8 @@
use phuongaz\EasyWing\task\WingTask;
use phuongaz\EasyWing\command\WingsCommand;
use phuongaz\EasyWing\utils\Particles;
use pocketmine\network\mcpe\protocol\SpawnParticleEffectPacket;

Class Loader extends PluginBase implements Listener{

private static array $equip_players = [];
Expand Down Expand Up @@ -79,9 +89,33 @@ public function parseWing(Vector3 $pos, $character) :Particle{
case "p":
$particle = new Particles(Particles::VILLAGER_ANGRY, $pos);
break;
case "f":
case "F":
$particle = new Particles(Particles::FLAME, $pos);
break;
case "H":
$particle = new HeartParticle($pos);
break;
case "P":
$particle = new PortalParticle($pos);
break;
case "E":
$particle = new EntityFlameParticle($pos);
break;
case "W":
$particle = new WaterDripParticle($pos);
break;
case "w":
$particle = new WaterParticle($pos);
break;
case "j":
$particle = new EnchantParticle($pos);
break;
case "J":
$particle = new EnchantmentTableParticle($pos);
break;
case "D":
$particle = new Particles(Particles::DRAGON_BREATH_LINGERING, $pos);
break;
default:
$particle = new RedstoneParticle($pos);
break;
Expand Down

0 comments on commit 14c750d

Please sign in to comment.