Changing Redstone color.

Discussion in 'Plugin Development' started by 360_, Dec 14, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    360_

    So I've been trying to find a way to make the color of a Redstone particle change (Sorta like a rainbow) but it found no luck in attempting to do this. This the current code I'm using.
    Code (open)
    Code:
    public void lava(Player p) {
            f.remove(p);
            fw.remove(p);
            wa.remove(p);
            la.add(p);
            new BukkitRunnable() {
                double phi = 0;
    
                @Override
                public void run() {
                    if (la.contains(p)) {
                        //if (phi > PI * 2) {
                        //this.cancel();
                        //return;//}
    
                        phi += PI * 2 / 20;
                        World world = p.getWorld();
                        Location center = p.getLocation().add(0, 2, 0);
    
    
                        double x = Math.sin(phi) * 0.6;
                        double z = Math.cos(phi) * 0.6;
                        Location particleLoc = center.add(x, 0, z);
    
    
    
                        R = Integer.parseInt(String.valueOf(R/ 255));
                        G = Integer.parseInt(String.valueOf(G/ 255));
                        B = Integer.parseInt(String.valueOf(B/ 255));
    
                        PacketPlayOutWorldParticles _packet =
                                new PacketPlayOutWorldParticles(EnumParticle.REDSTONE,
                                        true,
                                        (float) particleLoc.getX(),
                                        (float) particleLoc.getY(),
                                        (float) particleLoc.getZ(),
                                        R ,
                                        G ,
                                        B ,
                                        1, 0);
                        for(Player _online : Bukkit.getOnlinePlayers()) {
                            ((CraftPlayer)_online).getHandle().playerConnection.sendPacket(_packet);
                        }
                        if (R > 255){
                            R = (int) 0.0000000000001;
                        }else{
                            R = R+1;
                        }
                        if (G > 255){
                            G = (int) 0.0000000000001;
    
                        }else{
                            G = G+1;
                        }
                        if (B > 255){
                            B = (int) 0.0000000000001;
                        }else{
                            B = B+1;
                        }
                    } else {
                        this.cancel();
                    }
                }
    
            }.runTaskTimer(this, 0, 2);
        }
    
        public static int R, G, B = 0;

    What could I fix to make the Rainbow particle or what should I try instead of this?
    Thanks in advanced.
     
  2. Offline

    MightyOne

    It would be interesting would you code produces so far.
    Anyway, I think I can already see the which parts of the code might not function right.

    Code:
    R = Integer.parseInt(String.valueOf(R/ 255));
    This is the weirdest thing I've ever seen.
    If you devide an int by another int the result will also be an int
    Code:
    R /= 255;
    Second thing is, that at this point variable R can only be 0 or 1. Deviding it by will always return 0 again. Over and over.

    Code:
    R = (int) 0.0000000000001
    After this line variable R would also just be 0 btw.
     
Thread Status:
Not open for further replies.

Share This Page