Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backhand support #53

Merged
merged 2 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

import com.cleanroommc.bogosorter.common.McUtils;
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;

Expand All @@ -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
Expand Down Expand Up @@ -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 ? McUtils.format(stack.stackSize) : null);
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
GL11.glPopMatrix();
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -214,10 +234,11 @@ private int getStackCount(EntityClientPlayerMP player, ItemStack stack) {

public enum EquipmentSlotType {
MAINHAND,
OFFHAND,
HEAD,
CHEST,
LEGS,
FEET
FEET,
}

}
29 changes: 29 additions & 0 deletions src/main/java/com/cleanroommc/bogosorter/common/McUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.cleanroommc.bogosorter.common;

import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -104,4 +107,30 @@ public static void playSound(String sound) {

soundHandler.playSound(record);
}

// credit https://stackoverflow.com/a/30661479
private static final NavigableMap<Long, String> suffixes = new TreeMap<>();
static {
suffixes.put(1_000L, "k");
suffixes.put(1_000_000L, "M");
suffixes.put(1_000_000_000L, "G");
suffixes.put(1_000_000_000_000L, "T");
suffixes.put(1_000_000_000_000_000L, "P");
suffixes.put(1_000_000_000_000_000_000L, "E");
}

public static String format(long value) {
// Long.MIN_VALUE == -Long.MIN_VALUE so we need an adjustment here
if (value == Long.MIN_VALUE) return format(Long.MIN_VALUE + 1);
if (value < 0) return "-" + format(-value);
if (value < 1000) return Long.toString(value); // deal with easy case

Map.Entry<Long, String> e = suffixes.floorEntry(value);
Long divideBy = e.getKey();
String suffix = e.getValue();

long truncated = value / (divideBy / 10); // the number part of the output times 10
boolean hasDecimal = truncated < 100 && (truncated / 10d) != (truncated / 10);
return hasDecimal ? (truncated / 10d) + suffix : (truncated / 10) + suffix;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum Mods {
AdventureBackpack2("adventurebackpack"),
Ae2("appliedenergistics2"),
AvaritiaAddons("avaritiaddons"),
Backhand("backhand"),
Backpack("Backpack"),
Bibliocraft("BiblioCraft"),
CookingForBlockheads("cookingforblockheads"),
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/bogosorter/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down