top.hendrixshen.magiclib.api.malilib.config.option.EnumOptionEntry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magiclib-malilib-extra-1.19.2-fabric Show documentation
Show all versions of magiclib-malilib-extra-1.19.2-fabric Show documentation
Unleash Magic Enhancement Malilib.
/*
* This file is part of the TweakerMore project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2023 Fallen_Breath and contributors
*
* TweakerMore is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* TweakerMore is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with TweakerMore. If not, see .
*/
package top.hendrixshen.magiclib.api.malilib.config.option;
import fi.dy.masa.malilib.config.IConfigOptionListEntry;
import top.hendrixshen.magiclib.api.i18n.I18n;
import java.util.Arrays;
/**
* Reference to TweakerMore
*/
public interface EnumOptionEntry extends IConfigOptionListEntry {
String name();
int ordinal();
EnumOptionEntry[] getAllValues();
EnumOptionEntry getDefault();
String getTranslationPrefix();
@Override
default String getStringValue() {
return this.name().toLowerCase();
}
@Override
default String getDisplayName() {
return I18n.translateOrFallback(String.format("%s.value.%s", this.getTranslationPrefix(), this.name()),
this.name());
}
@Override
default IConfigOptionListEntry cycle(boolean forward) {
int index = this.ordinal();
EnumOptionEntry[] values = this.getAllValues();
index += forward ? 1 : -1;
index = (index + values.length) % values.length;
return values[index];
}
@Override
default IConfigOptionListEntry fromString(String value) {
return Arrays.stream(this.getAllValues())
.filter(o -> o.name().equalsIgnoreCase(value))
.findFirst()
.orElseGet(this::getDefault);
}
}