diff options
author | Linnea Gräf <nea@nea.moe> | 2024-03-08 16:21:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-08 16:21:23 +0100 |
commit | 4fc87fe42d9668c94c2e9208a15abd39dbb0c3ff (patch) | |
tree | bdad3c60b3cac2dc24d3f02fa4c2bf0d9a9481e7 | |
parent | a1f9ab2fb2052c2362caaf0a97dada95b1e9fcab (diff) | |
download | NotEnoughUpdates-4fc87fe42d9668c94c2e9208a15abd39dbb0c3ff.tar.gz NotEnoughUpdates-4fc87fe42d9668c94c2e9208a15abd39dbb0c3ff.tar.bz2 NotEnoughUpdates-4fc87fe42d9668c94c2e9208a15abd39dbb0c3ff.zip |
Tooltips (#1035)
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java | 30 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java | 70 |
2 files changed, 74 insertions, 26 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java index 3c2358cf..594facc2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java @@ -174,32 +174,38 @@ public class DungeonNpcProfitOverlay { } dungeonChest.name = stack.getDisplayName(); List<SkyblockItem> items = new ArrayList<>(); + boolean isInCost = false; for (String s : lore) { - if ("§7Contents".equals(s) || "".equals(s) || "§7Cost".equals(s) || "§cCan't open another chest!".equals(s) || + if ("§7Contents".equals(s) || "".equals(s) || "§cCan't open another chest!".equals(s) || "§aAlready opened!".equals(s) || "§eClick to open!".equals(s)) continue; + if ("§7Cost".equals(s)) { + isInCost = true; + continue; + } //check if this line is showing the cost of opening the Chest - if (s.endsWith(" Coins")) { - String coinString = StringUtils.cleanColour(s); - int whitespace = coinString.indexOf(' '); - if (whitespace != -1) { - String amountString = coinString.substring(0, whitespace).replace(",", ""); - dungeonChest.costToOpen = Integer.parseInt(amountString); - continue; + if (isInCost) { + if (s.endsWith(" Coins")) { + String coinString = StringUtils.cleanColour(s); + int whitespace = coinString.indexOf(' '); + if (whitespace != -1) { + String amountString = coinString.substring(0, whitespace).replace(",", ""); + dungeonChest.costToOpen = Integer.parseInt(amountString); + } + } else if (s.equals("§aFREE")) { + dungeonChest.costToOpen = 0; } - } else if (s.equals("§aFREE")) { - dungeonChest.costToOpen = 0; continue; } - //check if the line can be converted to a SkyblockItem SkyblockItem skyblockItem = SkyblockItem.createFromLoreEntry(s); if (skyblockItem != null) { items.add(skyblockItem); - } else + } else { System.out.println("Unexpected line " + s + " while analyzing croesus lore"); + } } dungeonChest.items = items; if (dungeonChest.costToOpen != -1) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java index 72aeaa23..f3757243 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java @@ -31,6 +31,8 @@ import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.SBInfo; +import io.github.moulberry.notenoughupdates.util.Utils; +import lombok.var; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.ISound; import net.minecraft.client.audio.PositionedSound; @@ -45,6 +47,7 @@ import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; +import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; @@ -57,6 +60,7 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.util.vector.Vector2f; import java.io.File; +import java.util.Arrays; import java.util.HashMap; @NEUAutoSubscribe @@ -190,6 +194,15 @@ public class SlotLocking { return slot; } + private Slot getFocusedSlot(GuiContainer container) { + final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + final int scaledWidth = scaledresolution.getScaledWidth(); + final int scaledHeight = scaledresolution.getScaledHeight(); + int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; + int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; + return ((AccessorGuiContainer) container).doGetSlotAtPosition(mouseX, mouseY); + } + @SubscribeEvent(priority = EventPriority.LOW) public void keyboardInput(GuiScreenEvent.KeyboardInputEvent.Pre event) { if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard() || @@ -203,13 +216,7 @@ public class SlotLocking { int key = NotEnoughUpdates.INSTANCE.config.slotLocking.slotLockKey; if (!lockKeyHeld && KeybindHelper.isKeyPressed(key) && !Keyboard.isRepeatEvent()) { - final ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - final int scaledWidth = scaledresolution.getScaledWidth(); - final int scaledHeight = scaledresolution.getScaledHeight(); - int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; - int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; - - Slot slot = ((AccessorGuiContainer) container).doGetSlotAtPosition(mouseX, mouseY); + Slot slot = getFocusedSlot(container); if (slot != null && slot.getSlotIndex() != 8 && slot.inventory == Minecraft.getMinecraft().thePlayer.inventory) { int slotNum = slot.getSlotIndex(); if (slotNum >= 0 && slotNum <= 39) { @@ -719,15 +726,50 @@ public class SlotLocking { boolean setTopHalfBarrier = false; + private boolean shouldShowBarrier(int slotNumber, IInventory inventory) { + if (!(inventory instanceof InventoryPlayer)) + return false; + if (slotNumber < 9) + return false; + if (pairingSlot != null && (slotNumber == pairingSlot.slotNumber || isArmourSlot( + slotNumber, + pairingSlot.slotNumber + ))) + return false; + if (!setTopHalfBarrier) + return false; + return true; + } + + @SubscribeEvent(priority = EventPriority.LOW) + public void afterRenderInventory(GuiScreenEvent.DrawScreenEvent.Post event) { + if (!(event.gui instanceof GuiContainer)) return; + var gui = (GuiContainer) event.gui; + var slot = getFocusedSlot(gui); + if (slot == null || !shouldShowBarrier(slot.getSlotIndex(), slot.inventory)) + return; + final var scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); + final int scaledWidth = scaledresolution.getScaledWidth(); + final int scaledHeight = scaledresolution.getScaledHeight(); + int mouseX = Mouse.getX() * scaledWidth / Minecraft.getMinecraft().displayWidth; + int mouseY = scaledHeight - Mouse.getY() * scaledHeight / Minecraft.getMinecraft().displayHeight - 1; + Utils.drawHoveringText( + Arrays.asList( + "§cYou cannot bind slots to anything except the hotbar.", + "§cBinding to a normal inventory slot would require cheats.", + "§cAnd you are not a cheater, are you?", + "§cWe certainly hope you are not."), + mouseX, + mouseY, + scaledWidth, + scaledHeight, + -1 + ); + } + @SubscribeEvent public void barrierInventory(ReplaceItemEvent event) { - if (event.getSlotNumber() < 9 || - (pairingSlot != null && (event.getSlotNumber() == pairingSlot.slotNumber || isArmourSlot( - event.getSlotNumber(), - pairingSlot.slotNumber - ))) || - !setTopHalfBarrier || - !(event.getInventory() instanceof InventoryPlayer)) return; + if (!shouldShowBarrier(event.getSlotNumber(), event.getInventory())) return; ItemStack stack = new ItemStack(Blocks.barrier); ItemUtils.getOrCreateTag(stack).setBoolean( "NEUHIDETOOLIP", |