Search code examples
javaminecraftbukkitpackets

Redstone particles don't change their color


I'm trying to send colored redstone particles to player via packets using ProtocolLib. I Googled that to make them colored, I need use the offset parameters as the RGB system. However, it didn't work as intended; particles are still red or have random color (see below), and offset still is used as randomizer of each particle from the given location. My code:

PacketContainer packet = new PacketContainer(PacketType.Play.Server.WORLD_PARTICLES);
packet.getModifier().writeDefaults();
packet.getParticles().write(0, Particle.REDSTONE);
float x = (float) loc.getX();
float y = (float) loc.getY() + 3;
float z = (float) loc.getZ();
float red = 0;
float green = 0;
float blue = 1;
packet.getFloat().write(0, x).write(1, y).write(2, z); // Location
packet.getFloat().write(3, red).write(4, green).write(5, blue); // Offset
packet.getFloat().write(6, 0F); // Particle data ?
packet.getIntegers().write(0, 1); // Amount

ProtocolManager manager = ProtocolLibrary.getProtocolManager();
try {
    for (Player player : getters) manager.sendServerPacket(player, packet);
} catch (Exception ex) {ex.printStackTrace();}

I tried to change amount and particle data. If particle data is 0, then particles are red, in other cases up to 1 particles are random colored.
I'm using ProtocolLib 4.3.0 and Spigot 1.12.2


Solution

  • I solved my problem, to spawn colored true redstone particle there must be 3 things:

    1. Amount must be 0
    2. Data must be 1
    3. Red component (x offset) must be x - 1 (because this component automatically increased by 1 before pushing into the packet)