Skip to content

Commit

Permalink
Refactor VisitorHelper and head detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 committed Apr 28, 2024
1 parent 0c6bae0 commit 76d03af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ protected HandledScreenMixin(Text title) {
return;
}
if (this.handler instanceof GenericContainerScreenHandler genericContainerScreenHandler && genericContainerScreenHandler.getRows() == 6) {
VisitorHelper.onSlotClick(genericContainerScreenHandler.getSlot(13), slotId, title);
VisitorHelper.onSlotClick(slot, slotId, title, genericContainerScreenHandler.getSlot(13).getStack());

// Prevent selling to NPC shops
ItemStack sellStack = this.handler.slots.get(49).getStack();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public static void onMouseClicked(double mouseX, double mouseY, int mouseButton,
}
}

public static void onSlotClick(Slot visitorSlot, int slotId, String title) {
public static void onSlotClick(Slot slot, int slotId, String title, ItemStack visitorHeadStack) {
if (slotId == 29 || slotId == 13 || slotId == 33) {
itemMap.remove(new ObjectObjectImmutablePair<>(title, getTextureOrNull(visitorSlot.getStack())));
itemMap.remove(new ObjectObjectImmutablePair<>(title, getTextureOrNull(visitorHeadStack)));
}
}

Expand All @@ -105,14 +105,14 @@ private static void processVisitorItem(String visitorName, ScreenHandler handler

private static void processLore(String visitorName, @Nullable String visitorTexture, List<Text> loreList) {
boolean saveRequiredItems = false;
for (int i = 0; i < loreList.size(); i++) {
String lore = loreList.get(i).getString();
for (Text text : loreList) {
String lore = text.getString();
if (lore.contains("Items Required"))
saveRequiredItems = true;
else if (lore.contains("Rewards"))
break;
else if (saveRequiredItems)
updateItemMap(visitorName, visitorTexture, loreList.get(i));
updateItemMap(visitorName, visitorTexture, text);
}
}

Expand All @@ -122,12 +122,12 @@ private static void updateItemMap(String visitorName, @Nullable String visitorTe
if (itemName.isEmpty()) return;
try {
int amount = splitItemText.length == 2 ? NumberFormat.getInstance(Locale.US).parse(splitItemText[1].trim()).intValue() : 1;
ObjectObjectImmutablePair<String, String> key = new ObjectObjectImmutablePair<>(visitorName, visitorTexture);
Pair<String, String> key = Pair.of(visitorName, visitorTexture);
Object2IntMap<String> visitorMap = itemMap.getOrDefault(key, new Object2IntOpenHashMap<>());
visitorMap.putIfAbsent(itemName, amount);
itemMap.putIfAbsent(key, visitorMap);
} catch (Exception e) {
LOGGER.error("[Skyblocker Visitor Helper] Failed to parse item: " + lore.getString(), e);
LOGGER.error("[Skyblocker Visitor Helper] Failed to parse item: {}", lore.getString(), e);
}
}

Expand Down

0 comments on commit 76d03af

Please sign in to comment.