From 0f8a1757ebdc7fa2f581135b6da571bd5bf579ac Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 4 Apr 2023 10:03:51 +0200 Subject: [PATCH] Add Wing --- .../lobby/otherparticle/WingDesign.java | 41 +++++++++++++++++++ .../lobby/otherparticle/elements/Wing.java | 36 ++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/de/steamwar/lobby/otherparticle/WingDesign.java create mode 100644 src/de/steamwar/lobby/otherparticle/elements/Wing.java diff --git a/src/de/steamwar/lobby/otherparticle/WingDesign.java b/src/de/steamwar/lobby/otherparticle/WingDesign.java new file mode 100644 index 0000000..a0a9379 --- /dev/null +++ b/src/de/steamwar/lobby/otherparticle/WingDesign.java @@ -0,0 +1,41 @@ +package de.steamwar.lobby.otherparticle; + +import de.steamwar.lobby.particle.decorator.WingParticle; +import lombok.SneakyThrows; +import org.bukkit.util.Vector; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.List; + +public interface WingDesign { + + @SneakyThrows + static Vector[] create(String resource) { + List vectors = new ArrayList<>(); + BufferedImage bufferedImage = ImageIO.read(WingParticle.class.getResourceAsStream(resource)); + for (int x = 0; x < bufferedImage.getWidth(); x++) { + for (int y = 0; y < bufferedImage.getHeight(); y++) { + int rgb = bufferedImage.getRGB(x, y); + if (Color.WHITE.getRGB() != rgb) { + vectors.add(new Vector(x - bufferedImage.getWidth() / 2.0, bufferedImage.getHeight() - y - 1.0, 0)); + } + } + } + return vectors.toArray(new Vector[0]); + } + + Vector[] getVectors(); + + WingDesign SIMPLE = () -> create("/de/steamwar/lobby/particle/decorator/WingSimple4.png"); + WingDesign COMPLEX = () -> create("/de/steamwar/lobby/particle/decorator/WingSimple2.png"); + WingDesign SWORD = () -> create("/de/steamwar/lobby/particle/decorator/WingSword.png"); + WingDesign SW = () -> create("/de/steamwar/lobby/particle/decorator/WingSW.png"); + WingDesign WGS = () -> create("/de/steamwar/lobby/particle/decorator/WingWGS.png"); + WingDesign SWORD_CROSSED = () -> create("/de/steamwar/lobby/particle/decorator/WingSwordCrossed.png"); + WingDesign MWGL = () -> create("/de/steamwar/lobby/particle/decorator/MWGL.png"); + + WingDesign ECLIPSE = () -> create("/de/steamwar/lobby/particle/decorator/ECLIPSE-Logo.png"); +} diff --git a/src/de/steamwar/lobby/otherparticle/elements/Wing.java b/src/de/steamwar/lobby/otherparticle/elements/Wing.java new file mode 100644 index 0000000..46b91d0 --- /dev/null +++ b/src/de/steamwar/lobby/otherparticle/elements/Wing.java @@ -0,0 +1,36 @@ +package de.steamwar.lobby.otherparticle.elements; + +import de.steamwar.lobby.otherparticle.ParticleElement; +import de.steamwar.lobby.otherparticle.ParticleTickData; +import de.steamwar.lobby.otherparticle.WingDesign; +import org.bukkit.Location; +import org.bukkit.util.Vector; + +public class Wing extends DelegatingParticleElement { + + private double size; + private WingDesign wingDesign; + + public Wing(ParticleElement particleElement, double size, WingDesign wingDesign) { + super(particleElement); + this.wingDesign = wingDesign; + } + + @Override + public String attribute() { + return "PARTICLE_ATTRIBUTE_WING"; + } + + @Override + public void tick(ParticleTickData particleTickData) { + for (Vector dVector : wingDesign.getVectors()) { + Vector vector = new Vector(dVector.getX() * size, 0.6 + dVector.getY() * size - (particleTickData.getPlayer().isSneaking() ? 0.5 : 0) , 0.5); + vector.rotateAroundY(Math.toRadians(particleTickData.getPlayer().getLocation().getYaw() * -1)); + vector.setX(-vector.getX()); + vector.setZ(-vector.getZ()); + Location location = particleTickData.getPlayer().getLocation().clone().add(vector); + ParticleTickData current = particleTickData.withLocation(location); + particleElement.tick(current); + } + } +}