Skip to content

EnumCycler#allowedOrdinals() has inverted implementation logic #332

Description

@TheDeathlyCow

Using 3.9.2+26.1-fabric, the logic for the implementation of EnumCycler#allowedOrdinals appears to be inverted from how it is described in the documentation. The documentation says:

The allowed ordinals of the enum class. If empty, all ordinals are allowed.
This is only used if the enum does not implement {@link CyclableEnum}.

However, the logic here uses noneMatch, which will mean that the filter will only allow any ordinal which is not included in the allowedOrdinals array. It should instead use anyMatch.

.filter(ordinal -> annotation.allowedOrdinals().length == 0 || Arrays.stream(annotation.allowedOrdinals()).noneMatch(allowed -> allowed == ordinal))

Example

In my mod using this enum:

public enum DifficultySetting implements StringRepresentable {
    AUTOMATIC("automatic"),
    PEACEFUL("peaceful"),
    EASY("easy"),
    NORMAL("normal"),
    HARD("hard");

    private final String name;

    DifficultySetting(String name) {
        this.name = name;
    }

    @Override
    public String getSerializedName() {
        return this.name;
    }
}

This setting will only allow the setting PEACEFUL to be selected, and not any of the others:

@AutoGen(category = "main")
@SerialEntry
@EnumCycler(allowedOrdinals = {0, 2, 3, 4})
DifficultySetting frostBiteAmplifierDifficulty = DifficultySetting.AUTOMATIC;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions