diff --git a/dependencies.gradle b/dependencies.gradle index 1da637d..d259867 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -62,8 +62,9 @@ dependencies { compileOnly("com.github.GTNewHorizons:NotEnoughItems:2.7.22-GTNH:dev") compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.51.79:dev") compileOnly("com.github.GTNewHorizons:Botania:1.12.5-GTNH:dev") - devOnlyNonPublishable("com.github.GTNewHorizons:StorageDrawers:2.1.0-GTNH:dev") - + compileOnly("com.github.GTNewHorizons:StorageDrawers:2.1.0-GTNH:dev") + compileOnly("com.github.GTNewHorizons:Backhand:1.5.16:dev") + runtimeOnlyNonPublishable("com.github.GTNewHorizons:waila:1.8.2:dev") compileOnly rfg.deobf('curse.maven:projecte-226410:2340786') diff --git a/src/main/java/com/cleanroommc/bogosorter/client/usageticker/UsageTicker.java b/src/main/java/com/cleanroommc/bogosorter/client/usageticker/UsageTicker.java index 750ac72..b67fc45 100644 --- a/src/main/java/com/cleanroommc/bogosorter/client/usageticker/UsageTicker.java +++ b/src/main/java/com/cleanroommc/bogosorter/client/usageticker/UsageTicker.java @@ -16,17 +16,21 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; +import com.cleanroommc.bogosorter.common.ReadableNumberConverter; +import com.cleanroommc.bogosorter.compat.loader.Mods; import com.gtnewhorizon.gtnhlib.eventbus.EventBusSubscriber; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import cpw.mods.fml.relauncher.Side; +import xonin.backhand.api.core.BackhandUtils; // todo: backhand compat @EventBusSubscriber(side = { Side.CLIENT }) public class UsageTicker { public static boolean enableMainHand = true; + public static boolean enableOffHand = true; public static boolean enableArmor = true; public static boolean enableModule = true; @@ -40,12 +44,18 @@ public static void reloadElements() { if (enableMainHand) { elements.add(new Element(EquipmentSlotType.MAINHAND)); } + + if (Mods.Backhand.isLoaded() && enableOffHand) { + elements.add(new Element(EquipmentSlotType.OFFHAND)); + } + if (enableArmor) { elements.add(new Element(EquipmentSlotType.HEAD)); elements.add(new Element(EquipmentSlotType.CHEST)); elements.add(new Element(EquipmentSlotType.LEGS)); elements.add(new Element(EquipmentSlotType.FEET)); } + } @EventBusSubscriber.Condition @@ -97,31 +107,36 @@ public void render(ScaledResolution resolution, EntityClientPlayerMP player, flo float anim = -animProgress * (animProgress - 2) * 19F; - float x = resolution.getScaledWidth() / 2f; + float x = resolution.getScaledWidth() / 2f - (Mods.Backhand.isLoaded() ? 30 : 0); float y = resolution.getScaledHeight() - anim; int barWidth = 190; - boolean armor = slot != EquipmentSlotType.MAINHAND; + boolean armor = !(slot == EquipmentSlotType.MAINHAND || slot == EquipmentSlotType.OFFHAND); - int slots = armor ? 4 : 1; + int slots = armor ? 4 : (Mods.Backhand.isLoaded() && enableOffHand) ? 2 : 1; int index = slots - slot.ordinal() - 1; Minecraft mc = Minecraft.getMinecraft(); - x -= (barWidth / 2f) - index * 20; + x -= (barWidth / 2f) - index * 22; x -= slots * 20; ItemStack stack = getRenderedStack(player); if (stack == null) return; RenderItem renderer = new RenderItem(); - GL11.glPushMatrix(); GL11.glTranslatef(x, y, 0); GL11.glEnable(GL12.GL_RESCALE_NORMAL); RenderHelper.enableGUIStandardItemLighting(); renderer.renderItemAndEffectIntoGUI(mc.fontRenderer, mc.renderEngine, stack, 0, 0); - renderer.renderItemOverlayIntoGUI(mc.fontRenderer, mc.renderEngine, stack, 0, 0); + renderer.renderItemOverlayIntoGUI( + mc.fontRenderer, + mc.renderEngine, + stack, + 0, + 0, + stack.stackSize > 1 ? ReadableNumberConverter.INSTANCE.toSlimReadableForm(stack.stackSize) : null); RenderHelper.disableStandardItemLighting(); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); @@ -166,7 +181,11 @@ public ItemStack getStack(EntityClientPlayerMP player) { return player.inventory.getCurrentItem(); } - return player.inventory.armorItemInSlot(slot.ordinal() - 1); + if (slot == EquipmentSlotType.OFFHAND) { + return BackhandUtils.getOffhandItem(player); + } + + return player.inventory.armorItemInSlot(slot.ordinal() - 2); } public ItemStack getRenderedStack(EntityClientPlayerMP player) { @@ -189,6 +208,7 @@ public ItemStack getRenderedStack(EntityClientPlayerMP player) { public ItemStack getDisplayedStack(ItemStack stack, int count) { if (stack == null) return null; if (slot == EquipmentSlotType.MAINHAND && !stack.isStackable()) return null; + if (slot == EquipmentSlotType.OFFHAND && !stack.isStackable()) return null; if (count == stack.stackSize) return null; return stack; @@ -214,10 +234,11 @@ private int getStackCount(EntityClientPlayerMP player, ItemStack stack) { public enum EquipmentSlotType { MAINHAND, + OFFHAND, HEAD, CHEST, LEGS, - FEET + FEET, } } diff --git a/src/main/java/com/cleanroommc/bogosorter/common/ReadableNumberConverter.java b/src/main/java/com/cleanroommc/bogosorter/common/ReadableNumberConverter.java new file mode 100644 index 0000000..94a8ef2 --- /dev/null +++ b/src/main/java/com/cleanroommc/bogosorter/common/ReadableNumberConverter.java @@ -0,0 +1,97 @@ +package com.cleanroommc.bogosorter.common; + +import java.math.RoundingMode; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.text.Format; + +/** + * copy from nei copy from ae2 Converter class to convert a large number into a SI system. + * + * @author thatsIch + * @version rv2 + * @since rv2 + */ +public enum ReadableNumberConverter { + + INSTANCE; + + /** + * Defines the base for a division, non-si standard could be 1024 for kilobytes + */ + private static final int DIVISION_BASE = 1000; + + /** + * String representation of the sorted postfixes + */ + private static final char[] ENCODED_POSTFIXES = "KMGTPE".toCharArray(); + + private final Format format; + + /** + * Initializes the specific decimal format with special format for negative and positive numbers + */ + ReadableNumberConverter() { + final DecimalFormatSymbols symbols = new DecimalFormatSymbols(); + symbols.setDecimalSeparator('.'); + symbols.setGroupingSeparator(','); + final DecimalFormat format = new DecimalFormat(".#;0.#"); + format.setDecimalFormatSymbols(symbols); + format.setRoundingMode(RoundingMode.DOWN); + + this.format = format; + } + + public String toSlimReadableForm(final long number) { + return this.toReadableFormRestrictedByWidth(number, 3); + } + + /** + * restricts a string representation of a number to a specific width + * + * @param number to be formatted number + * @param width width limitation of the resulting number + * @return formatted number restricted by the width limitation + */ + private String toReadableFormRestrictedByWidth(final long number, final int width) { + assert number >= 0; + + // handles low numbers more efficiently since no format is needed + final String numberString = Long.toString(number); + int numberSize = numberString.length(); + if (numberSize <= width) { + return numberString; + } + + long base = number; + double last = base * 1000; + int exponent = -1; + String postFix = ""; + + while (numberSize > width) { + last = base; + base /= DIVISION_BASE; + + exponent++; + + // adds +1 due to the postfix + numberSize = Long.toString(base) + .length() + 1; + postFix = String.valueOf(ENCODED_POSTFIXES[exponent]); + } + + final String withPrecision = this.format.format(last / DIVISION_BASE) + postFix; + final String withoutPrecision = Long.toString(base) + postFix; + + final String slimResult = (withPrecision.length() <= width) ? withPrecision : withoutPrecision; + + // post condition + assert slimResult.length() <= width; + + return slimResult; + } + + public String toWideReadableForm(final long number) { + return this.toReadableFormRestrictedByWidth(number, 4); + } +} diff --git a/src/main/java/com/cleanroommc/bogosorter/common/config/BogoSorterConfig.java b/src/main/java/com/cleanroommc/bogosorter/common/config/BogoSorterConfig.java index f8b65a8..554e2e6 100644 --- a/src/main/java/com/cleanroommc/bogosorter/common/config/BogoSorterConfig.java +++ b/src/main/java/com/cleanroommc/bogosorter/common/config/BogoSorterConfig.java @@ -85,6 +85,7 @@ public static void save(JsonObject json) { JsonObject usageTicker = new JsonObject(); usageTicker.addProperty("enableModule", UsageTicker.enableModule); usageTicker.addProperty("enableMainHand", UsageTicker.enableMainHand); + usageTicker.addProperty("enableOffHand", UsageTicker.enableOffHand); usageTicker.addProperty("enableArmor", UsageTicker.enableArmor); json.add("UsageTicker", usageTicker); } @@ -162,6 +163,7 @@ public static void load(JsonObject json) { JsonObject ticker = json.getAsJsonObject("UsageTicker"); UsageTicker.enableModule = JsonHelper.getBoolean(ticker, true, "enableModule"); UsageTicker.enableMainHand = JsonHelper.getBoolean(ticker, true, "enableMainHand"); + UsageTicker.enableOffHand = JsonHelper.getBoolean(ticker, true, "enableOffHand"); UsageTicker.enableArmor = JsonHelper.getBoolean(ticker, true, "enableArmor"); } } diff --git a/src/main/java/com/cleanroommc/bogosorter/common/config/ConfigGui.java b/src/main/java/com/cleanroommc/bogosorter/common/config/ConfigGui.java index ce1c1df..2993ede 100644 --- a/src/main/java/com/cleanroommc/bogosorter/common/config/ConfigGui.java +++ b/src/main/java/com/cleanroommc/bogosorter/common/config/ConfigGui.java @@ -353,6 +353,25 @@ public IWidget createGeneralConfigUI(GuiContext context) { .height(14) .marginLeft(10) .expanded())) + .child( + new Row().widthRel(1f) + .height(14) + .margin(0, 2) + .child(new CycleButtonWidget().value(new BoolValue.Dynamic(() -> UsageTicker.enableOffHand, val -> { + UsageTicker.enableOffHand = val; + UsageTicker.reloadElements(); + })) + .stateOverlay(TOGGLE_BUTTON) + .disableHoverBackground() + .size(14, 14) + .margin(8, 0) + .background(IDrawable.EMPTY)) + .child( + IKey.lang("bogosort.gui.usageticker_offhand") + .asWidget() + .height(14) + .marginLeft(10) + .expanded())) .child( new Row().widthRel(1f) .height(14) diff --git a/src/main/java/com/cleanroommc/bogosorter/compat/loader/Mods.java b/src/main/java/com/cleanroommc/bogosorter/compat/loader/Mods.java index 87cd87f..82aec20 100644 --- a/src/main/java/com/cleanroommc/bogosorter/compat/loader/Mods.java +++ b/src/main/java/com/cleanroommc/bogosorter/compat/loader/Mods.java @@ -9,6 +9,7 @@ public enum Mods { AdventureBackpack2("adventurebackpack"), Ae2("appliedenergistics2"), AvaritiaAddons("avaritiaddons"), + Backhand("backhand"), Backpack("Backpack"), Bibliocraft("BiblioCraft"), CookingForBlockheads("cookingforblockheads"), diff --git a/src/main/resources/assets/bogosorter/lang/en_US.lang b/src/main/resources/assets/bogosorter/lang/en_US.lang index fde14c4..540a39c 100644 --- a/src/main/resources/assets/bogosorter/lang/en_US.lang +++ b/src/main/resources/assets/bogosorter/lang/en_US.lang @@ -26,6 +26,7 @@ bogosort.gui.dropoff_render=Show Dropoff Targets bogosort.gui.dropoff_chatmessage=Show Dropoff Chat Message bogosort.gui.usageticker_enable=Enable Usage Ticker bogosort.gui.usageticker_mainhand=Enable Usage Ticker Mainhand +bogosort.gui.usageticker_offhand=Enable Usage Ticker Offhand bogosort.gui.usageticker_armor=Enable Usage Ticker Armor