mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Optimise the experience groups a little
This commit is contained in:
parent
31612a92a3
commit
4404b4108d
1 changed files with 39 additions and 31 deletions
|
@ -1,43 +1,51 @@
|
||||||
package com.minelittlepony.unicopia.entity.player;
|
package com.minelittlepony.unicopia.entity.player;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
public interface ExperienceGroup {
|
public interface ExperienceGroup {
|
||||||
LinearSelector<String> EXPERIENCES = new LinearSelector<>(new String[] {
|
String[] EXPERIENCES = {
|
||||||
"MAGICAL_KINDERGARTENER",
|
"magical_kindergartner",
|
||||||
"FRIENDSHIP_STUDENT",
|
"friendship_student",
|
||||||
"SENIOR_FRIENDSHIP_STUDENT",
|
"senior_friendship_student",
|
||||||
"JUNIOR_MAGE",
|
"junior_mage",
|
||||||
"MAGE",
|
"mage",
|
||||||
"ARCHMAGE",
|
"archmage",
|
||||||
"ARCHMAGUS",
|
"archmagus",
|
||||||
"SENIOR_ARCHMAGUS",
|
"senior_archmagus",
|
||||||
"ASCENDED_SENIOR_ARCHMAGUS",
|
"ascended_senior_archmagus",
|
||||||
"DEMI_GOD",
|
"demi_god",
|
||||||
"ARCH_DEMI_GOD",
|
"arch_demi_god",
|
||||||
"ALICORN_PRINCESS",
|
"alicorn_princess",
|
||||||
"POLYCORN_PRINCESS",
|
"polycorn_princess",
|
||||||
"FAUSTIAN_LEGEND"
|
"faustian_legend"
|
||||||
}, 2);
|
};
|
||||||
LinearSelector<String> CORRUPTIONS = new LinearSelector<>(new String[] {
|
String[] CORRUPTIONS = {
|
||||||
"PURE",
|
"pure",
|
||||||
"IMPURE",
|
"impure",
|
||||||
"TAINTED",
|
"tainted",
|
||||||
"TWISTED",
|
"twisted",
|
||||||
"CORRUPT",
|
"corrupt",
|
||||||
"MONSTROUS"
|
"monstrous"
|
||||||
}, 1F/8F);
|
};
|
||||||
|
Int2ObjectArrayMap<WeakReference<Text>> CACHE = new Int2ObjectArrayMap<>();
|
||||||
|
|
||||||
static Text forLevel(float level, float corruption) {
|
static Text forLevel(float level, float corruption) {
|
||||||
return Text.translatable(
|
int c = get(CORRUPTIONS, corruption);
|
||||||
"experience.unicopia." + CORRUPTIONS.get(corruption).toLowerCase() + "." + EXPERIENCES.get(level).toLowerCase()
|
int x = get(EXPERIENCES, level);
|
||||||
);
|
int i = x * c;
|
||||||
|
|
||||||
|
Text value;
|
||||||
|
if (!CACHE.containsKey(i) || (value = CACHE.get(i).get()) == null) {
|
||||||
|
CACHE.put(i, new WeakReference<>(value = Text.translatable("experience.unicopia." + CORRUPTIONS[c] + "." + EXPERIENCES[x])));
|
||||||
|
}
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public record LinearSelector<T> (T[] values, float ratio) {
|
private static int get(String[] values, float level) {
|
||||||
public T get(float level) {
|
return MathHelper.clamp(MathHelper.floor(level * values.length), 0, values.length - 1);
|
||||||
return values()[MathHelper.clamp(MathHelper.floor(level * values().length), 0, values().length - 1)];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue