PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
9.37k stars 2.19k forks source link

Fix Color Particle API #10895

Open TreemanKing opened 2 weeks ago

TreemanKing commented 2 weeks ago

Checks particle datatype instead of particle type.

Fixes #10872

TreemanKing commented 2 weeks ago

To me, it doesn't make sense to allow calling color(Color,float) for non DustOptions types. The float size doesn't apply to stuff like ENTITY_EFFECT.

Currently, all colour methods lead to this as shown below, hence I didn't want to make changes to make big changes to the existing API as seen below.

public ParticleBuilder color(@Nullable Color color) {
    return color(color, 1);
}

@NotNull
public ParticleBuilder color(int r, int g, int b) {
    return color(Color.fromRGB(r, g, b));
}

@NotNull
public ParticleBuilder color(final int rgb) {
    return color(Color.fromRGB(rgb));
}

I'll go ahead and add that size doesn't apply to ENTITY_EFFECT unless you prefer for me to change up the first colour method to make that execute it for the datatype of COLOR.

EDIT: Something like this...

public ParticleBuilder color(@Nullable Color color) {
    if (datatype == DustOptions) {
        return color(color, 1)
    }

    if (datatype != Color) {
       throw "This particle cannot have a color"
    }

    if (color == null) {
       return data(null)
    }

    return data(color)
}