Skip to content

Commit

Permalink
fix(scavenging): fix totals not displaying and add coins
Browse files Browse the repository at this point in the history
  • Loading branch information
AsoDesu committed Jan 6, 2025
1 parent ea738ed commit e7da9be
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private void init(ResourceLocation file, int i, int j, int[][] chars, CallbackIn
case "_fonts/body/scavenging.png" -> Scavenging.setTitleCharacter(character);
case "_fonts/material_dust.png" -> Scavenging.setDustCharacter(character);
case "_fonts/silver.png" -> Scavenging.setSilverCharacter(character);
case "_fonts/coin_small.png" -> Scavenging.setCoinCharacter(character);

case "_fonts/tooltips/hat.png" -> CosmeticState.HAT_COMP = comp;
case "_fonts/tooltips/accessory.png" -> CosmeticState.ACCESSORY_COMP = comp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ public class Scavenging {
// the width of the menu body
private static final int GUI_BODY_WIDTH = 164;
// the offset between the end of the scavenging icons and the right-side of the body
private static final int SCAVENGING_ICON_INNER_OFFSET = 22;
private static final int SCAVENGING_ICON_INNER_OFFSET = 24;

private static Component titleComponent;
private static ScavengingItemHandler dustHandler;
private static ScavengingItemHandler silverHandler;
private static ScavengingItemHandler coinHandler;

public static boolean isScavengingMenuOrDisabled(AbstractContainerScreen<?> screen) {
if (!IslandOptions.getMisc().isSilverPreview()) return false;
Expand All @@ -40,7 +41,7 @@ public static void renderSilverTotal(ScavengingTotalList silverTotal, GuiGraphic
if (!(minecraft.screen instanceof ContainerScreen screen)) return;

int bgX = (screen.width - GUI_TOTAL_WIDTH) / 2;
int x = bgX + (GUI_BODY_WIDTH - SCAVENGING_ICON_INNER_OFFSET);
int x = bgX + (GUI_TOTAL_WIDTH - SCAVENGING_ICON_INNER_OFFSET);

Collection<ScavengingTotal> totals = silverTotal.totals.values();
for (ScavengingTotal total : totals) {
Expand All @@ -55,8 +56,8 @@ public static ScavengingTotalList getSilverTotal(ChestMenu menu) {
ScavengingTotalList list = new ScavengingTotalList();

Container container = menu.getContainer();
applyItemRow(list, container, 20, 24);
applyItemRow(list, container, 29, 33);
applyItemRow(list, container, 11, 15);
applyItemRow(list, container, 20, 25);
return list;
}
private static void applyItemRow(ScavengingTotalList list, Container container, int min, int max) {
Expand All @@ -69,11 +70,12 @@ private static void applyItemRow(ScavengingTotalList list, Container container,

public static void applyItems(ItemStack item, ScavengingTotalList list) {
List<Component> lores = Utils.getLores(item);
if (lores == null || silverHandler == null || dustHandler == null) return;
if (lores == null) return;

for (Component line : lores) {
list.apply(silverHandler.checkLine(line));
list.apply(dustHandler.checkLine(line));
if (silverHandler != null) list.apply(silverHandler.checkLine(line));
if (dustHandler != null) list.apply(dustHandler.checkLine(line));
if (coinHandler != null) list.apply(coinHandler.checkLine(line));
}
}

Expand All @@ -83,6 +85,9 @@ public static void setDustCharacter(String dustCharacter) {
public static void setSilverCharacter(String silverCharacter) {
silverHandler = new ScavengingItemHandler("silver", silverCharacter);
}
public static void setCoinCharacter(String coinCharacter) {
coinHandler = new ScavengingItemHandler("coin", coinCharacter);
}

public static void setTitleCharacter(String titleCharacter) {
Scavenging.titleComponent = Component.literal(titleCharacter).withStyle(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package net.asodev.islandutils.modules.scavenging;

import net.asodev.islandutils.mixins.accessors.ContainerScreenAccessor;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.gui.screens.inventory.ContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.world.inventory.ChestMenu;

import java.util.Objects;
import java.util.regex.Matcher;
Expand All @@ -16,7 +19,7 @@

public class ScavengingItemHandler {
private static final int MENU_WIDTH = 176;
private static final int MENU_HEIGHT = 166;
private static final int CHEST_MENU_HEIGHT = 222;

private final String character;
private final Pattern pattern;
Expand Down Expand Up @@ -44,8 +47,13 @@ public int renderTotal(GuiGraphics guiGraphics, Long total, int x) {
int width = font.width(silverComponent);

x -= width;
int bgY = (screen.height - MENU_HEIGHT) / 2;
int y = bgY + 89 - 4;

// 25 = y offset between label y & top of menu
int topPos = ((screen.height - CHEST_MENU_HEIGHT) / 2) - 25;
// 152 = y pos of top of footer
// 20 = y pos from top of footer to top of button
// 5 = bottom padding
int y = topPos + 152 + 20 - 5;

guiGraphics.pose().pushPose();
guiGraphics.pose().translate(0, 0, 105); // z-index: 105
Expand Down

0 comments on commit e7da9be

Please sign in to comment.