diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-08-20 03:20:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-20 11:20:08 +1000 |
commit | 46e99cbaac7e999048c18ee8f310b1b1b5d333af (patch) | |
tree | 338338f5719e1f9c7ea5f50ba19d1ced36aa9fe5 | |
parent | 5908643f22674f68ad5f48edae01133b61e593a7 (diff) | |
download | NotEnoughUpdates-46e99cbaac7e999048c18ee8f310b1b1b5d333af.tar.gz NotEnoughUpdates-46e99cbaac7e999048c18ee8f310b1b1b5d333af.tar.bz2 NotEnoughUpdates-46e99cbaac7e999048c18ee8f310b1b1b5d333af.zip |
more friendly drop chance format (#231)
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java index 0d891071..7702f365 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/MobLootRecipe.java @@ -26,6 +26,7 @@ import com.google.gson.JsonPrimitive; import io.github.moulberry.notenoughupdates.NEUManager; import io.github.moulberry.notenoughupdates.miscfeatures.entityviewer.EntityViewer; import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; +import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; import io.github.moulberry.notenoughupdates.profileviewer.Panorama; import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.JsonUtils; @@ -64,11 +65,28 @@ public class MobLootRecipe implements NeuRecipe { if (itemStack == null) { itemStack = drop.getItemStack().copy(); List<String> arrayList = new ArrayList<>(extra); - arrayList.add("§r§e§lDrop Chance: §6" + chance); + arrayList.add("§r§e§lDrop Chance: §6" + formatDropChance()); ItemUtils.appendLore(itemStack, arrayList); } return itemStack; } + + private String formatDropChance() { + if (!chance.endsWith("%")) { + return chance + " §cInvalid repo data!"; + } + + String chanceText = chance.substring(0, chance.length() - 1); + int chanceIn; + try { + chanceIn = (int) (100.0 / Double.parseDouble(chanceText)); + } catch (NumberFormatException e) { + return chance + " §cInvalid repo data!"; + } + + String format = GuiProfileViewer.numberFormat.format(chanceIn); + return "1/" + format + " (" + chance + ")"; + } } public static ResourceLocation BACKGROUND = new ResourceLocation( |