Skip to content

Commit

Permalink
Add chance decimal place setting
Browse files Browse the repository at this point in the history
  • Loading branch information
fzzyhmstrs committed Sep 26, 2024
1 parent 2e5e310 commit de341a1
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 10 deletions.
8 changes: 7 additions & 1 deletion xplat/src/main/java/fzzyhmstrs/emi_loot/EMILoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import me.fzzyhmstrs.fzzy_config.validation.misc.ValidatedAny;
import me.fzzyhmstrs.fzzy_config.validation.misc.ValidatedChoice;
import me.fzzyhmstrs.fzzy_config.validation.misc.ValidatedString;
import me.fzzyhmstrs.fzzy_config.validation.number.ValidatedInt;
import me.fzzyhmstrs.fzzy_config.validation.number.ValidatedNumber;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentTarget;
import net.minecraft.entity.EquipmentSlot;
Expand Down Expand Up @@ -132,7 +134,10 @@ public static class EmiLootConfig extends Config {
@NonSync
public boolean mobLootIncludeDirectDrops = true;

@NonSync
@NonSync
public ValidatedInt chanceDecimalPlaces = new ValidatedInt(1, 10, 0, ValidatedNumber.WidgetType.SLIDER);

@NonSync
@SuppressWarnings("FieldMayBeFinal")
private ValidatedChoice<String> conditionStyle = EMILootAgnos.isModLoaded("symbols_n_stuff")
?
Expand All @@ -159,6 +164,7 @@ public boolean isDebug(Type type) {
public boolean isLogI18n(Type type) {
return type.logUntranslatedTablesSupplier.getAsBoolean();
}

}

@IgnoreVisibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void addWidgets(WidgetHolder widgets) {
int row = (int) Math.ceil(index.get() / columns) - 1;
int column= (index.get() - 1) % (int) columns;
index.getAndDecrement();
String fTrim = trimFloatString(weight);
String fTrim = trimFloatString(weight, EMILoot.config.chanceDecimalPlaces.get());
SlotWidget slotWidget = new SlotWidget(stack, column * 18, titleSpace + row * finalRowHeight).recipeContext(this);
widgets.add(slotWidget.appendTooltip(LText.translatable("emi_loot.percentage", fTrim)));
}
Expand All @@ -165,7 +165,7 @@ public void addWidgets(WidgetHolder widgets) {
int column = (int)((index.get() - 1) % columns);
index.getAndDecrement();
EmiIngredient ingredient = EmiIngredient.of(items.stream().toList());
String fTrim = trimFloatString(Math.max(weight / 100f, 0.01f), 2);
String fTrim = trimFloatString(Math.max(weight / 100f, 0.01f), Math.max(EMILoot.config.chanceDecimalPlaces.get() + 1, 2));
SlotWidget slotWidget = new SlotWidget(ingredient, column * 18, titleSpace + row * finalRowHeight).recipeContext(this);
widgets.add(slotWidget.appendTooltip(LText.translatable("emi_loot.rolls", fTrim).formatted(Formatting.ITALIC, Formatting.GOLD)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void addWidgets(WidgetHolder widgets) {
int j = 0;
for (ConditionalStack stack: stacks) {
SlotWidget widget = widgets.addSlot(stack.getIngredient(), i * 18, 18 * j);
String rounded = FloatTrimmer.trimFloatString(stack.weight());
String rounded = FloatTrimmer.trimFloatString(stack.weight(), EMILoot.config.chanceDecimalPlaces.get());
widget.appendTooltip(FcText.INSTANCE.translatable("emi_loot.percent_chance", rounded));
if (EMILoot.config.isNotPlain()) {
for (Pair<Integer, Text> pair : stack.conditions()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void addWidgets(WidgetHolder widgets) {
int row = (int) Math.ceil(index.get() / columns) - 1;
int column = (index.get() - 1) % (int) columns;
index.getAndDecrement();
String fTrim = trimFloatString(weight);
String fTrim = trimFloatString(weight, EMILoot.config.chanceDecimalPlaces.get());
SlotWidget slotWidget = new SlotWidget(stack, column * 18, titleSpace + row * finalRowHeight).recipeContext(this);
widgets.add(slotWidget.appendTooltip(LText.translatable("emi_loot.percentage", fTrim)));
}
Expand All @@ -168,7 +168,7 @@ public void addWidgets(WidgetHolder widgets) {
int column = (int)((index.get() - 1) % columns);
index.getAndDecrement();
EmiIngredient ingredient = EmiIngredient.of(items.stream().toList());
String fTrim = trimFloatString(Math.max(weight/100f, 0.01f), 2);
String fTrim = trimFloatString(Math.max(weight/100f, 0.01f), Math.max(EMILoot.config.chanceDecimalPlaces.get() + 1, 2));
SlotWidget slotWidget = new SlotWidget(ingredient, column * 18, titleSpace + row * finalRowHeight).recipeContext(this);
widgets.add(slotWidget.appendTooltip(LText.translatable("emi_loot.rolls", fTrim).formatted(Formatting.ITALIC, Formatting.GOLD)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public void addWidgets(WidgetHolder widgets) {
int j = 0;
for (ConditionalStack stack: stacks) {
SlotWidget widget = widgets.addSlot(stack.getIngredient(), i * 18, 11 + (18 * j));
String rounded = FloatTrimmer.trimFloatString(stack.weight());
String rounded = FloatTrimmer.trimFloatString(stack.weight(), EMILoot.config.chanceDecimalPlaces.get());
widget.appendTooltip(FcText.INSTANCE.translatable("emi_loot.percent_chance", rounded));
if (EMILoot.config.isNotPlain()) {
for (Pair<Integer, Text> pair : stack.conditions()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void addWidgets(WidgetHolder widgets) {
int j = 0;
for (ConditionalStack stack: stacks) {
SlotWidget widget = widgets.addSlot(stack.getIngredient(), i * 18, 11 + (18 * j));
String rounded = FloatTrimmer.trimFloatString(stack.weight());
String rounded = FloatTrimmer.trimFloatString(stack.weight(), EMILoot.config.chanceDecimalPlaces.get());
widget.appendTooltip(FcText.INSTANCE.translatable("emi_loot.percent_chance", rounded));
if (EMILoot.config.isNotPlain()) {
for (Pair<Integer, Text> pair : stack.conditions()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ public static String trimFloatString(float weight, int places) {
int fDot = f.indexOf(".");
String fTrim;
if (fDot > 0) {
fTrim = f.substring(0, Math.min(f.length(), fDot + 1 + places));
if (places > 0) {
fTrim = f.substring(0, Math.min(f.length(), fDot + 1 + places));
} else {
fTrim = f.substring(0, fDot);
}
} else {
if (weight < 10f) {
fTrim = f + ".0";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.emi.emi.api.widget.Bounds;
import dev.emi.emi.api.widget.SlotWidget;
import dev.emi.emi.api.widget.Widget;
import fzzyhmstrs.emi_loot.EMILoot;
import fzzyhmstrs.emi_loot.EMILootClientAgnos;
import fzzyhmstrs.emi_loot.client.ClientBuiltPool;
import net.minecraft.client.gui.DrawContext;
Expand Down Expand Up @@ -40,7 +41,7 @@ public IconGroupEmiWidget(int x, int y, ClientBuiltPool pool) {
List<SlotWidget> list2 = new LinkedList<>();
int itemXOffset = iconsWidth + 2;
for(ConditionalStack entry: pool.stacks()) {
String rounded = FloatTrimmer.trimFloatString(entry.weight());
String rounded = FloatTrimmer.trimFloatString(entry.weight(), EMILoot.config.chanceDecimalPlaces.get());
SlotWidget widget = new SlotWidget(entry.getIngredient(), itemXOffset + x, y + 3).appendTooltip(LText.translatable("emi_loot.percent_chance", rounded));
itemXOffset +=20;
list2.add(widget);
Expand Down
2 changes: 2 additions & 0 deletions xplat/src/main/resources/assets/emi_loot/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"emi_loot.emi_loot_config.chestLootAlwaysStackSame.desc": "If true, chest and archaeology pages will always condense stacks that are equivalent in drop chance. If false, stacks will be spread out if there are fewer than 48 of them.",
"emi_loot.emi_loot_config.mobLootIncludeDirectDrops": "Include Direct Drops",
"emi_loot.emi_loot_config.mobLootIncludeDirectDrops.desc": "Whether mob loot tables include manually added 'direct drops', such as equipment drops",
"emi_loot.emi_loot_config.chanceDecimalPlaces": "Chance Decimal Places",
"emi_loot.emi_loot_config.chanceDecimalPlaces.desc": "How many decimal places show on chances or weights (5.123%, 5.1%, 5%, etc.)",
"emi_loot.emi_loot_config.conditionStyle": "Condition Style",
"emi_loot.emi_loot_config.conditionStyle.desc": "How loot conditions are visually presented in the recipe viewer",
"emi_loot.emi_loot_config.conditionStyle.default": "Default",
Expand Down

0 comments on commit de341a1

Please sign in to comment.