Skip to content

Commit

Permalink
Merge pull request #675 from viciscat/fixes-and-things
Browse files Browse the repository at this point in the history
Fixes and things
  • Loading branch information
kevinthegreat1 authored Apr 28, 2024
2 parents 115078d + 76d03af commit 75547cb
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 36 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(slot, 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 @@ -34,15 +34,13 @@ public interface HandledScreenProviderMixin<T extends ScreenHandler> {

switch (screenHandler) {
// Better party finder
case GenericContainerScreenHandler ignored when SkyblockerConfigManager.get().general.betterPartyFinder && nameLowercase.contains("select tier") -> PartyFinderScreen.isInKuudraPartyFinder = true;
case GenericContainerScreenHandler ignored when SkyblockerConfigManager.get().general.betterPartyFinder && nameLowercase.contains("catacombs") -> PartyFinderScreen.isInKuudraPartyFinder = false;

case GenericContainerScreenHandler containerScreenHandler when SkyblockerConfigManager.get().general.betterPartyFinder && PartyFinderScreen.possibleInventoryNames.contains(nameLowercase) -> {
if (client.currentScreen != null) {
String lowerCase = client.currentScreen.getTitle().getString().toLowerCase();
if (lowerCase.contains("group builder")) return;
if (lowerCase.contains("select tier")) {
PartyFinderScreen.isInKuudraPartyFinder = true;
} else if (lowerCase.contains("catacombs")) {
PartyFinderScreen.isInKuudraPartyFinder = false;
}
}

if (PartyFinderScreen.isInKuudraPartyFinder) return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package de.hysky.skyblocker.skyblock.garden;

import com.mojang.authlib.properties.Property;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.NEURepoManager;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import io.github.moulberry.repo.data.NEUItem;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectObjectImmutablePair;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
Expand All @@ -33,7 +37,8 @@
public class VisitorHelper {
private static final Logger LOGGER = LoggerFactory.getLogger("Skyblocker Visitor Helper");

private static final Map<String, Object2IntMap<String>> itemMap = new HashMap<>();
// The pair contains the name of the visitor and the texture if the icon is a player head
private static final Map<Pair<String, String>, Object2IntMap<String>> itemMap = new HashMap<>();
private static final Map<String, ItemStack> itemCache = new HashMap<>();
private static final int TEXT_START_X = 4;
private static final int TEXT_START_Y = 4;
Expand All @@ -57,7 +62,7 @@ public static void renderScreen(String title, DrawContext context, TextRenderer
public static void onMouseClicked(double mouseX, double mouseY, int mouseButton, TextRenderer textRenderer) {
int yPosition = TEXT_START_Y;

for (Map.Entry<String, Object2IntMap<String>> visitorEntry : itemMap.entrySet()) {
for (Map.Entry<Pair<String, String>, Object2IntMap<String>> visitorEntry : itemMap.entrySet()) {
int textWidth;
int textHeight = textRenderer.fontHeight;

Expand All @@ -76,9 +81,9 @@ public static void onMouseClicked(double mouseX, double mouseY, int mouseButton,
}
}

public static void onSlotClick(Slot slot, 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(title);
itemMap.remove(new ObjectObjectImmutablePair<>(title, getTextureOrNull(visitorHeadStack)));
}
}

Expand All @@ -87,43 +92,52 @@ private static void processVisitorItem(String visitorName, ScreenHandler handler
if (visitorItem == null || !visitorItem.contains(DataComponentTypes.LORE) || ItemUtils.getLoreLineIf(visitorItem, t -> t.contains("Times Visited")) == null) return;
ItemStack acceptButton = handler.getSlot(29).getStack();
if (acceptButton == null) return;
processLore(visitorName, ItemUtils.getLore(acceptButton));
processLore(visitorName, getTextureOrNull(visitorItem), ItemUtils.getLore(acceptButton));
}

private static void processLore(String visitorName, List<Text> loreList) {
private static @Nullable String getTextureOrNull(ItemStack stack) {
if (!stack.isOf(Items.PLAYER_HEAD) || stack.get(DataComponentTypes.PROFILE) == null) return null;
return stack.get(DataComponentTypes.PROFILE).properties().get("textures").stream()
.map(Property::value)
.findFirst()
.orElse(null);
}

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, loreList.get(i));
updateItemMap(visitorName, visitorTexture, text);
}
}

private static void updateItemMap(String visitorName, Text lore) {
private static void updateItemMap(String visitorName, @Nullable String visitorTexture, Text lore) {
String[] splitItemText = lore.getString().split(" x");
String itemName = splitItemText[0].trim();
if (itemName.isEmpty()) return;
try {
int amount = splitItemText.length == 2 ? NumberFormat.getInstance(Locale.US).parse(splitItemText[1].trim()).intValue() : 1;
Object2IntMap<String> visitorMap = itemMap.getOrDefault(visitorName, new Object2IntOpenHashMap<>());
Pair<String, String> key = Pair.of(visitorName, visitorTexture);
Object2IntMap<String> visitorMap = itemMap.getOrDefault(key, new Object2IntOpenHashMap<>());
visitorMap.putIfAbsent(itemName, amount);
itemMap.putIfAbsent(visitorName, visitorMap);
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);
}
}

private static void drawScreenItems(DrawContext context, TextRenderer textRenderer, int mouseX, int mouseY) {
context.getMatrices().push();
context.getMatrices().translate(0, 0, 200);
int index = 0;
for (Map.Entry<String, Object2IntMap<String>> visitorEntry : itemMap.entrySet()) {
String visitorName = visitorEntry.getKey();
drawTextWithOptionalUnderline(context, textRenderer, Text.literal(visitorName), TEXT_START_X, TEXT_START_Y + index * (LINE_SPACING + textRenderer.fontHeight), mouseX, mouseY);
for (Map.Entry<Pair<String, String>, Object2IntMap<String>> visitorEntry : itemMap.entrySet()) {
Pair<String, String> visitorName = visitorEntry.getKey();
drawTextWithOptionalUnderline(context, textRenderer, Text.literal(visitorName.left()), TEXT_START_X, TEXT_START_Y + index * (LINE_SPACING + textRenderer.fontHeight), mouseX, mouseY);
index++;

for (Object2IntMap.Entry<String> itemEntry : visitorEntry.getValue().object2IntEntrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.OrderedText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

Expand Down Expand Up @@ -56,11 +57,13 @@ protected void init() {
button.setPosition(this.x + 5, this.height / 2 - 49);
if (moreCraftsButton != null) moreCraftsButton.setPosition(this.x + 174, this.y + 62);
}));
moreCraftsButton = new TexturedButtonWidget(this.x + 174, y + 62, 16, 16, MORE_CRAFTS_TEXTURES,
button -> this.onMouseClick(handler.slots.get(26), handler.slots.get(26).id, 0, SlotActionType.PICKUP));
moreCraftsButton.setTooltipDelay(Duration.ofMillis(250L));
moreCraftsButton.setTooltip(Tooltip.of(Text.literal("More Crafts")));
this.addDrawableChild(moreCraftsButton);
if (!handler.mirrorverse) {
moreCraftsButton = new TexturedButtonWidget(this.x + 174, y + 62, 16, 16, MORE_CRAFTS_TEXTURES,
button -> this.onMouseClick(handler.slots.get(26), handler.slots.get(26).id, 0, SlotActionType.PICKUP));
moreCraftsButton.setTooltipDelay(Duration.ofMillis(250L));
moreCraftsButton.setTooltip(Tooltip.of(Text.literal("More Crafts")));
this.addDrawableChild(moreCraftsButton);
}
assert (client != null ? client.player : null) != null;
client.player.currentScreenHandler = handler; // recipe book replaces it with the Dummy one fucking DUMBASS
this.addSelectableChild(this.recipeBook);
Expand Down Expand Up @@ -103,7 +106,7 @@ protected void drawBackground(DrawContext context, float delta, int mouseX, int
int i = this.x;
int j = (this.height - this.backgroundHeight) / 2;
context.drawTexture(TEXTURE, i, j, 0, 0, this.backgroundWidth, this.backgroundHeight);
context.drawGuiTexture(QUICK_CRAFT, i + 173, j, 0, 25, 84);
if (!handler.mirrorverse) context.drawGuiTexture(QUICK_CRAFT, i + 173, j, 0, 25, 84);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.hysky.skyblocker.skyblock.item;

import de.hysky.skyblocker.utils.Utils;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.Inventory;
import net.minecraft.screen.GenericContainerScreenHandler;
Expand All @@ -16,11 +17,22 @@ public class SkyblockCraftingTableScreenHandler extends GenericContainerScreenHa
28, 29, 30, 34
};

private static final int[] riftNormalSlots = new int[]{
11, 12, 13,
20, 21, 22, 24,
29, 30, 31
};

public final boolean mirrorverse;

public SkyblockCraftingTableScreenHandler(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory, Inventory inventory, int rows) {
super(type, syncId, playerInventory, inventory, rows);
mirrorverse = Utils.getIslandArea().toLowerCase().contains("mirrorverse");
int[] activeSlots = mirrorverse ? riftNormalSlots: normalSlots;

for (int i = 0; i < rows * 9; i++) {
Slot originalSlot = slots.get(i);
if (Arrays.binarySearch(normalSlots, i) >= 0) {
if (Arrays.binarySearch(activeSlots, i) >= 0) {
int[] coords = getCoords(i);
Slot slot = new Slot(originalSlot.inventory, originalSlot.getIndex(), coords[0], coords[1]);
slot.id = i;
Expand All @@ -45,14 +57,21 @@ public SkyblockCraftingTableScreenHandler(GenericContainerScreenHandler handler,
}

private int[] getCoords(int slot) {
if (slot == 23) return new int[]{124, 35};
if (slot == 16 || slot == 25 || slot == 34) {
int y = (slot / 9 - 1) * 18 + 8;
return new int[]{174, y};
if (mirrorverse) {
if (slot == 24) return new int[]{124, 35};
int gridX = slot % 9 - 2;
int gridY = slot / 9 - 1;
return new int[]{30 + gridX * 18, 17 + gridY * 18};
} else {
if (slot == 23) return new int[]{124, 35};
if (slot == 16 || slot == 25 || slot == 34) {
int y = (slot / 9 - 1) * 18 + 8;
return new int[]{174, y};
}
int gridX = slot % 9 - 1;
int gridY = slot / 9 - 1;
return new int[]{30 + gridX * 18, 17 + gridY * 18};
}
int gridX = slot % 9 - 1;
int gridY = slot / 9 - 1;
return new int[]{30 + gridX * 18, 17 + gridY * 18};
}

public static class DisabledSlot extends Slot {
Expand Down

0 comments on commit 75547cb

Please sign in to comment.