aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock
diff options
context:
space:
mode:
authorKevin <92656833+kevinthegreat1@users.noreply.github.com>2024-04-28 14:46:28 -0400
committerGitHub <noreply@github.com>2024-04-28 14:46:28 -0400
commit75547cb59396252f8e5bde41181b9f27c655ccf2 (patch)
tree9e24bb51bed5c65758c6b762a05c2ea9bb761ff1 /src/main/java/de/hysky/skyblocker/skyblock
parent115078d8ce5584fa1bae256d4a44696c6ac79b44 (diff)
parent76d03afae9e757510fae0ae5ac701c26d19f6327 (diff)
downloadSkyblocker-75547cb59396252f8e5bde41181b9f27c655ccf2.tar.gz
Skyblocker-75547cb59396252f8e5bde41181b9f27c655ccf2.tar.bz2
Skyblocker-75547cb59396252f8e5bde41181b9f27c655ccf2.zip
Merge pull request #675 from viciscat/fixes-and-things
Fixes and things
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java46
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreen.java15
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreenHandler.java35
3 files changed, 66 insertions, 30 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java
index 2805cb0e..ff6086d3 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/VisitorHelper.java
@@ -1,5 +1,6 @@
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;
@@ -7,14 +8,17 @@ 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;
@@ -33,7 +37,8 @@ import java.util.Map;
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;
@@ -57,7 +62,7 @@ public class VisitorHelper {
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;
@@ -76,9 +81,9 @@ public class VisitorHelper {
}
}
- 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)));
}
}
@@ -87,33 +92,42 @@ public class VisitorHelper {
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);
}
}
@@ -121,9 +135,9 @@ public class VisitorHelper {
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()) {
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreen.java
index ad4f8b30..a09b260a 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreen.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreen.java
@@ -23,6 +23,7 @@ import net.minecraft.screen.AbstractRecipeScreenHandler;
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;
@@ -56,11 +57,13 @@ public class SkyblockCraftingTableScreen extends HandledScreen<SkyblockCraftingT
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);
@@ -103,7 +106,7 @@ public class SkyblockCraftingTableScreen extends HandledScreen<SkyblockCraftingT
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
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreenHandler.java b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreenHandler.java
index 04974ade..c3704d8c 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreenHandler.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/item/SkyblockCraftingTableScreenHandler.java
@@ -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;
@@ -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;
@@ -45,14 +57,21 @@ public class SkyblockCraftingTableScreenHandler extends GenericContainerScreenHa
}
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 {