diff options
author | Roman / Linnea Gräf <roman.graef@gmail.com> | 2022-10-05 04:46:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-04 22:46:26 -0400 |
commit | 61513e20063d8997ba8a6d0cd7f34ef4ca29cdb6 (patch) | |
tree | f6a219b5a914b21722bb0c0eb26190db2e69256c | |
parent | 7b647deee3d37847f2ca2a6895d837748800c6b6 (diff) | |
download | NotEnoughUpdates-61513e20063d8997ba8a6d0cd7f34ef4ca29cdb6.tar.gz NotEnoughUpdates-61513e20063d8997ba8a6d0cd7f34ef4ca29cdb6.tar.bz2 NotEnoughUpdates-61513e20063d8997ba8a6d0cd7f34ef4ca29cdb6.zip |
EnchantingSolvers.java (#341)
* EnchantingSolvers.java
* remove println
* register bin overlay
Co-authored-by: nopo <nopotheemail@gmail.com>
11 files changed, 291 insertions, 271 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index efd45b3c..7175c7e8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -35,7 +35,11 @@ import io.github.moulberry.notenoughupdates.listener.ItemTooltipRngListener; import io.github.moulberry.notenoughupdates.listener.NEUEventListener; import io.github.moulberry.notenoughupdates.listener.OldAnimationChecker; import io.github.moulberry.notenoughupdates.listener.RenderListener; +import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; +import io.github.moulberry.notenoughupdates.miscfeatures.AntiCoopAdd; +import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionProfit; +import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalWishingCompassSolver; import io.github.moulberry.notenoughupdates.miscfeatures.CustomItemEffects; @@ -297,6 +301,10 @@ public class NotEnoughUpdates { MinecraftForge.EVENT_BUS.register(new SignCalculator()); MinecraftForge.EVENT_BUS.register(TrophyRewardOverlay.getInstance()); MinecraftForge.EVENT_BUS.register(PowerStoneStatsDisplay.getInstance()); + MinecraftForge.EVENT_BUS.register(new AntiCoopAdd()); + MinecraftForge.EVENT_BUS.register(AbiphoneWarning.getInstance()); + MinecraftForge.EVENT_BUS.register(new BetterContainers()); + MinecraftForge.EVENT_BUS.register(AuctionBINWarning.getInstance()); MinecraftForge.EVENT_BUS.register(navigation); if (Minecraft.getMinecraft().getResourceManager() instanceof IReloadableResourceManager) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/events/SlotClickEvent.java b/src/main/java/io/github/moulberry/notenoughupdates/events/SlotClickEvent.java new file mode 100644 index 00000000..13c31b54 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/events/SlotClickEvent.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.events; + +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Slot; +import net.minecraftforge.fml.common.eventhandler.Cancelable; + +@Cancelable +public class SlotClickEvent extends NEUEvent { + public final GuiContainer guiContainer; + public final Slot slot; + public final int slotId; + public int clickedButton; + public int clickType; + public boolean usePickblockInstead = false; + + public SlotClickEvent(GuiContainer guiContainer, Slot slot, int slotId, int clickedButton, int clickType) { + this.guiContainer = guiContainer; + this.slot = slot; + this.slotId = slotId; + this.clickedButton = clickedButton; + this.clickType = clickType; + } + + public void usePickblockInstead() { + usePickblockInstead = true; + } + + @Override + public void setCanceled(boolean cancel) { + super.setCanceled(cancel); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java index 254c891a..67ac4f4c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AbiphoneWarning.java @@ -23,6 +23,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.GuiElement; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; +import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.util.ItemUtils; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; @@ -33,6 +34,7 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -68,29 +70,28 @@ public class AbiphoneWarning extends GuiElement { return shouldPerformCheck() && showWarning; } - public boolean onMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { - if (!shouldPerformCheck()) return false; - if (!NotEnoughUpdates.INSTANCE.config.misc.abiphoneWarning) return false; - if (slotId == -999) return false; - if (clickedButton == 0) return false; + @SubscribeEvent + public void onMouseClick(SlotClickEvent event) { + if (!shouldPerformCheck()) return; + if (!NotEnoughUpdates.INSTANCE.config.misc.abiphoneWarning) return; + if (event.slotId == -999) return; + if (event.clickedButton == 0) return; GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; - ItemStack clickedContact = chest.inventorySlots.getSlot(slotId).getStack(); - if (clickedContact == null) return false; + ItemStack clickedContact = chest.inventorySlots.getSlot(event.slotId).getStack(); + if (clickedContact == null) return; List<String> list = ItemUtils.getLore(clickedContact); - if (list.isEmpty()) return false; + if (list.isEmpty()) return; String last = list.get(list.size() - 1); if (last.contains("Right-click to remove contact!")) { showWarning = true; contactName = clickedContact.getDisplayName(); - contactSlot = slotId; - return true; + contactSlot = event.slotId; + event.setCanceled(true); } - - return false; } public void overrideIsMouseOverSlot(Slot slot, int mouseX, int mouseY, CallbackInfoReturnable<Boolean> cir) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java index 25aaaa0a..70ac4489 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AntiCoopAdd.java @@ -20,43 +20,43 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.inventory.GuiChest; import net.minecraft.event.ClickEvent; import net.minecraft.event.HoverEvent; import net.minecraft.init.Items; -import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class AntiCoopAdd { - public static boolean onMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { - if (!NotEnoughUpdates.INSTANCE.config.misc.coopWarning) return false; - if (slotId == -999) return false; - if (!Utils.getOpenChestName().contains("Profile")) return false; + @SubscribeEvent + public void onMouseClick(SlotClickEvent event) { + if (!NotEnoughUpdates.INSTANCE.config.misc.coopWarning) return; + if (event.slotId == -999) return; + if (!Utils.getOpenChestName().contains("Profile")) return; - GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; - - ItemStack stack = chest.inventorySlots.getSlot(slotId).getStack(); - if (stack == null) return false; - if (stack.getItem() == Items.diamond && stack.getDisplayName() != null && stack.getDisplayName().contains("Co-op Request")) { + ItemStack stack = event.slot.getStack(); + if (stack == null) return; + if (stack.getItem() == Items.diamond && stack.getDisplayName() != null && stack.getDisplayName().contains( + "Co-op Request")) { String ign = Utils.getOpenChestName().split("'s Profile")[0]; ChatComponentText storageMessage = new ChatComponentText( EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.YELLOW + "You just clicked on the Co-op add button. If you want to coop add this person, click this chat message"); storageMessage.setChatStyle(Utils.createClickStyle(ClickEvent.Action.RUN_COMMAND, "/coopadd " + ign)); storageMessage.setChatStyle(storageMessage.getChatStyle().setChatHoverEvent( - new HoverEvent(HoverEvent.Action.SHOW_TEXT, - new ChatComponentText(EnumChatFormatting.YELLOW + "Click to add " + ign + " to your coop")))); + new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + new ChatComponentText(EnumChatFormatting.YELLOW + "Click to add " + ign + " to your coop") + ))); ChatComponentText storageChatMessage = new ChatComponentText(""); storageChatMessage.appendSibling(storageMessage); Minecraft.getMinecraft().thePlayer.addChatMessage(storageChatMessage); - return true; + event.setCanceled(true); } - - return false; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java index 3bd674dd..ad9df7af 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java @@ -24,6 +24,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.GuiElement; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.core.util.render.TextRenderUtils; +import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; @@ -33,6 +34,7 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -79,75 +81,73 @@ public class AuctionBINWarning extends GuiElement { return shouldPerformCheck() && showWarning; } - public boolean onMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType) { - if (!shouldPerformCheck()) return false; + @SubscribeEvent + public void onMouseClick(SlotClickEvent event) { + if (!shouldPerformCheck()) return; - if (slotId == 29) { - GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + if (event.slotId != 29) { + return; + } - sellingPrice = -1; + sellingPrice = -1; - ItemStack priceStack = chest.inventorySlots.getSlot(31).getStack(); - if (priceStack != null) { - String displayName = priceStack.getDisplayName(); - Matcher priceMatcher = ITEM_PRICE_REGEX.matcher(displayName); + ItemStack priceStack = event.guiContainer.inventorySlots.getSlot(31).getStack(); + if (priceStack != null) { + String displayName = priceStack.getDisplayName(); + Matcher priceMatcher = ITEM_PRICE_REGEX.matcher(displayName); - if (priceMatcher.matches()) { - try { - sellingPrice = Long.parseLong(priceMatcher.group(1).replace(",", "")); - } catch (NumberFormatException ignored) { - } + if (priceMatcher.matches()) { + try { + sellingPrice = Long.parseLong(priceMatcher.group(1).replace(",", "")); + } catch (NumberFormatException ignored) { } } + } - ItemStack sellStack = chest.inventorySlots.getSlot(13).getStack(); - String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(sellStack); - sellStackAmount = sellStack.stackSize; + ItemStack sellStack = event.guiContainer.inventorySlots.getSlot(13).getStack(); + String internalname = NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(sellStack); + sellStackAmount = sellStack.stackSize; - if (internalname == null) { - return false; - } + if (internalname == null) { + return; + } - JsonObject itemInfo = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(internalname); - if (itemInfo == null || !itemInfo.has("displayname")) { - sellingName = internalname; - } else { - sellingName = itemInfo.get("displayname").getAsString(); - } + JsonObject itemInfo = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(internalname); + if (itemInfo == null || !itemInfo.has("displayname")) { + sellingName = internalname; + } else { + sellingName = itemInfo.get("displayname").getAsString(); + } - sellingTooltip = sellStack.getTooltip( - Minecraft.getMinecraft().thePlayer, - Minecraft.getMinecraft().gameSettings.advancedItemTooltips - ); + sellingTooltip = sellStack.getTooltip( + Minecraft.getMinecraft().thePlayer, + Minecraft.getMinecraft().gameSettings.advancedItemTooltips + ); - lowestPrice = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname); - if (lowestPrice <= 0) { - lowestPrice = (int) NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalname); - } + lowestPrice = NotEnoughUpdates.INSTANCE.manager.auctionManager.getLowestBin(internalname); + if (lowestPrice <= 0) { + lowestPrice = (int) NotEnoughUpdates.INSTANCE.manager.auctionManager.getItemAvgBin(internalname); + } - float undercutFactor = 1 - NotEnoughUpdates.INSTANCE.config.ahTweaks.warningThreshold / 100; - if (undercutFactor < 0) undercutFactor = 0; - if (undercutFactor > 1) undercutFactor = 1; - float overcutFactor = 1 - NotEnoughUpdates.INSTANCE.config.ahTweaks.overcutWarningThreshold / 100; - if (overcutFactor < 0) overcutFactor = 0; - if (overcutFactor > 1) overcutFactor = 1; + float undercutFactor = 1 - NotEnoughUpdates.INSTANCE.config.ahTweaks.warningThreshold / 100; + if (undercutFactor < 0) undercutFactor = 0; + if (undercutFactor > 1) undercutFactor = 1; + float overcutFactor = 1 - NotEnoughUpdates.INSTANCE.config.ahTweaks.overcutWarningThreshold / 100; + if (overcutFactor < 0) overcutFactor = 0; + if (overcutFactor > 1) overcutFactor = 1; - if (lowestPrice == -1) { - return false; - } - if (NotEnoughUpdates.INSTANCE.config.ahTweaks.underCutWarning && - (sellingPrice > 0 && lowestPrice > 0 && sellingPrice < sellStackAmount * lowestPrice * undercutFactor)) { - showWarning = true; - return true; - } else if (NotEnoughUpdates.INSTANCE.config.ahTweaks.overCutWarning && - (sellingPrice > 0 && lowestPrice > 0 && sellingPrice > sellStackAmount * lowestPrice * (overcutFactor + 1))) { - showWarning = true; - return true; - } else { - return false; - } + if (lowestPrice == -1) { + return; + } + if (NotEnoughUpdates.INSTANCE.config.ahTweaks.underCutWarning && + (sellingPrice > 0 && lowestPrice > 0 && sellingPrice < sellStackAmount * lowestPrice * undercutFactor)) { + showWarning = true; + event.setCanceled(true); + } else if (NotEnoughUpdates.INSTANCE.config.ahTweaks.overCutWarning && + (sellingPrice > 0 && lowestPrice > 0 && sellingPrice > sellStackAmount * lowestPrice * (overcutFactor + 1))) { + showWarning = true; + event.setCanceled(true); } - return false; } public void overrideIsMouseOverSlot(Slot slot, int mouseX, int mouseY, CallbackInfoReturnable<Boolean> cir) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java index e51496e3..ad0b238a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java @@ -21,6 +21,7 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.listener.RenderListener; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiChest; @@ -37,6 +38,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import javax.imageio.ImageIO; import java.awt.*; @@ -563,4 +565,17 @@ public class BetterContainers { return 0; } } + + @SubscribeEvent + public void onMouseClick(SlotClickEvent event) { + if (!isOverriding()) return; + boolean isBlankStack = BetterContainers.isBlankStack(event.slot.slotNumber, event.slot.getStack()); + if (!(isBlankStack || + BetterContainers.isButtonStack(event.slot.slotNumber, event.slot.getStack()))) return; + clickSlot(event.slotId); + if (isBlankStack) { + event.usePickblockInstead(); + } + } + } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java index a1580d8e..d5cbfdde 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/EnchantingSolvers.java @@ -20,6 +20,7 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.inventory.GuiChest; @@ -308,98 +309,88 @@ public class EnchantingSolvers { return false; } - public static boolean onStackClick(ItemStack stack, int windowId, int slotId, int mouseButtonClicked, int mode) { - if (!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableEnchantingSolvers) { - return false; + @SubscribeEvent + public void onStackClick(SlotClickEvent event) { + if (!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.enableEnchantingSolvers + || !NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { + return; } - if (!NotEnoughUpdates.INSTANCE.hasSkyblockScoreboard()) { - return false; + ItemStack stack = event.slot.getStack(); + if (stack == null || stack.getDisplayName() == null) { + return; } + String displayName = stack.getDisplayName(); + if (!(Minecraft.getMinecraft().currentScreen instanceof GuiChest)) { + return; + } + GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; + ContainerChest container = (ContainerChest) chest.inventorySlots; + IInventory lower = container.getLowerChestInventory(); + + if (currentSolver == SolverType.CHRONOMATRON) { + ItemStack timerStack = lower.getStackInSlot(lower.getSizeInventory() - 5); + if (timerStack == null) { + return; + } - if (stack != null && stack.getDisplayName() != null) { - String displayName = stack.getDisplayName(); - if (Minecraft.getMinecraft().currentScreen instanceof GuiChest) { - GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; - ContainerChest container = (ContainerChest) chest.inventorySlots; - IInventory lower = container.getLowerChestInventory(); - - if (currentSolver == SolverType.CHRONOMATRON) { - ItemStack timerStack = lower.getStackInSlot(lower.getSizeInventory() - 5); - if (timerStack == null) { - return false; - } - - boolean yepClock = timerStack.getItem() == Items.clock; - if (timerStack.getItem() == Item.getItemFromBlock(Blocks.glowstone) || - (yepClock && (!addToChronomatron || chronomatronOrder.size() < lastChronomatronSize + 1))) { - return true; - } else if (yepClock) { - long currentTime = System.currentTimeMillis(); - if (currentTime - millisLastClick < 150) { - return true; - } + boolean yepClock = timerStack.getItem() == Items.clock; + if (timerStack.getItem() == Item.getItemFromBlock(Blocks.glowstone) || + (yepClock && (!addToChronomatron || chronomatronOrder.size() < lastChronomatronSize + 1))) { + event.setCanceled(true); + return; + } + if (yepClock) { + long currentTime = System.currentTimeMillis(); + if (currentTime - millisLastClick < 150) { + event.setCanceled(true); + return; + } - if (chronomatronReplayIndex < chronomatronOrder.size()) { - String chronomatronCurrent = chronomatronOrder.get(chronomatronReplayIndex); - if ((!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.preventMisclicks1 || - chronomatronCurrent.equals(displayName) || Keyboard.getEventKey() == Keyboard.KEY_LSHIFT) && - stack.getItem() != Item.getItemFromBlock(Blocks.stained_glass_pane) && slotId != 4 && slotId != 49) { - chronomatronReplayIndex++; - Minecraft.getMinecraft().playerController.windowClick(windowId, slotId, - 2, mode, Minecraft.getMinecraft().thePlayer - ); - millisLastClick = currentTime; - } - /*if (chronomatronCurrent.equals(displayName)) { - chronomatronReplayIndex++; - } - Minecraft.getMinecraft().playerController.windowClick(windowId, slotId, - 2, mode, Minecraft.getMinecraft().thePlayer); - millisLastClick = currentTime;*/ - } - return true; - } - } else if (currentSolver == SolverType.ULTRASEQUENCER) { - ItemStack timerStack = lower.getStackInSlot(lower.getSizeInventory() - 5); - if (timerStack == null) { - return false; + if (chronomatronReplayIndex < chronomatronOrder.size()) { + String chronomatronCurrent = chronomatronOrder.get(chronomatronReplayIndex); + if ((!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.preventMisclicks1 || + chronomatronCurrent.equals(displayName) || Keyboard.getEventKey() == Keyboard.KEY_LSHIFT) && + stack.getItem() != Item.getItemFromBlock(Blocks.stained_glass_pane) && event.slotId != 4 && + event.slotId != 49) { + chronomatronReplayIndex++; + millisLastClick = currentTime; + event.usePickblockInstead(); + return; } + } + event.setCanceled(true); + return; + } + } + if (currentSolver == SolverType.ULTRASEQUENCER) { + ItemStack timerStack = lower.getStackInSlot(lower.getSizeInventory() - 5); + if (timerStack == null) { + return; + } - boolean yepClock = timerStack.getItem() == Items.clock; - if (yepClock) { - UltrasequencerItem current = ultraSequencerOrder.get(ultrasequencerReplayIndex); - if (current == null) { - return true; - } - long currentTime = System.currentTimeMillis(); - if (currentTime - millisLastClick > 150 && - (!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.preventMisclicks1 || - current.containerIndex == slotId || Keyboard.getEventKey() == Keyboard.KEY_LSHIFT) && (slotId < 45 && slotId > 8)) { - ultrasequencerReplayIndex++; - Minecraft.getMinecraft().playerController.windowClick(windowId, slotId, - 2, mode, Minecraft.getMinecraft().thePlayer - ); - millisLastClick = currentTime; - } - /*if (currentTime - millisLastClick > 150) { - if (current.containerIndex == slotId) { - ultrasequencerReplayIndex++; - } - Minecraft.getMinecraft().playerController.windowClick(windowId, slotId, - 2, mode, Minecraft.getMinecraft().thePlayer); - millisLastClick = currentTime; - }*/ - return true; - } else { - return true; - } - } else if (currentSolver == SolverType.SUPERPAIRS) { - lastSlotClicked = slotId; + boolean yepClock = timerStack.getItem() == Items.clock; + if (yepClock) { + UltrasequencerItem current = ultraSequencerOrder.get(ultrasequencerReplayIndex); + long currentTime = System.currentTimeMillis(); + if (current == null) { + event.setCanceled(true); + return; + } + if (currentTime - millisLastClick > 150 && + (!NotEnoughUpdates.INSTANCE.config.enchantingSolvers.preventMisclicks1 || + current.containerIndex == event.slotId || Keyboard.getEventKey() == Keyboard.KEY_LSHIFT) && + (event.slotId < 45 && event.slotId > 8)) { + ultrasequencerReplayIndex++; + millisLastClick = currentTime; + event.usePickblockInstead(); + return; } } + event.setCanceled(true); + } else if (currentSolver == SolverType.SUPERPAIRS) { + lastSlotClicked = event.slotId; } - return false; } public static void processInventoryContents(boolean fromTick) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java index a14c98e7..f0902921 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -30,6 +30,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; +import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.overlays.TextOverlay; @@ -862,18 +863,19 @@ public class PetInfoOverlay extends TextOverlay { "alchemy" ); - public static void onStackClick(ItemStack stack, int windowId, int slotId, int mouseButtonClicked, int mode) { - if (mouseButtonClicked != 0 && mouseButtonClicked != 1 && mouseButtonClicked != 2) return; + @SubscribeEvent + public void onStackClick(SlotClickEvent event) { + if (event.clickedButton != 0 && event.clickedButton != 1 && event.clickedButton != 2) return; - int slotIdMod = (slotId - 10) % 9; - if (slotId >= 10 && slotId <= 43 && slotIdMod >= 0 && slotIdMod <= 6 && + int slotIdMod = (event.slotId - 10) % 9; + if (event.slotId >= 10 && event.slotId <= 43 && slotIdMod >= 0 && slotIdMod <= 6 && Minecraft.getMinecraft().currentScreen instanceof GuiChest) { GuiChest chest = (GuiChest) Minecraft.getMinecraft().currentScreen; ContainerChest container = (ContainerChest) chest.inventorySlots; IInventory lower = container.getLowerChestInventory(); String containerName = lower.getDisplayName().getUnformattedText(); - if (lower.getSizeInventory() >= 54 && windowId == container.windowId) { + if (lower.getSizeInventory() >= 54 && event.guiContainer.inventorySlots.windowId == container.windowId) { int page = 0; boolean isPets = false; @@ -895,7 +897,7 @@ public class PetInfoOverlay extends TextOverlay { boolean isRemoving = removingStack != null && removingStack.getItem() == Items.dye && removingStack.getItemDamage() == 10; - int newSelected = (slotId - 10) - (slotId - 10) / 9 * 2 + page * 28; + int newSelected = (event.slotId - 10) - (event.slotId - 10) / 9 * 2 + page * 28; lastPetSelect = System.currentTimeMillis(); @@ -908,7 +910,7 @@ public class PetInfoOverlay extends TextOverlay { } else { setCurrentPet(newSelected); - Pet pet = getPetFromStack(stack.getTagCompound()); + Pet pet = getPetFromStack(event.slot.getStack().getTagCompound()); if (pet != null) { config.petMap.put(config.selectedPet, pet); } 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 3955c363..24183f9a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/SlotLocking.java @@ -24,6 +24,7 @@ import com.google.gson.GsonBuilder; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.KeybindHelper; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer; import io.github.moulberry.notenoughupdates.util.SBInfo; import net.minecraft.client.Minecraft; @@ -43,7 +44,6 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.apache.commons.lang3.tuple.Triple; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; @@ -58,7 +58,6 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.util.HashMap; -import java.util.function.Consumer; public class SlotLocking { private static final SlotLocking INSTANCE = new SlotLocking(); @@ -455,22 +454,21 @@ public class SlotLocking { } } - public void onWindowClick( - Slot slotIn, - int slotId, - int clickedButton, - int clickType, - Consumer<Triple<Integer, Integer, Integer>> consumer - ) { - LockedSlot locked = getLockedSlot(slotIn); + @SubscribeEvent + public void onWindowClick(SlotClickEvent slotClickEvent) { + LockedSlot locked = getLockedSlot(slotClickEvent.slot); if (locked == null) { return; - } else if (locked.locked || (clickType == 2 && SlotLocking.getInstance().isSlotIndexLocked(clickedButton))) { - consumer.accept(null); - } else if (NotEnoughUpdates.INSTANCE.config.slotLocking.enableSlotBinding && clickType == 1 && + } + if (locked.locked || + (slotClickEvent.clickType == 2 && SlotLocking.getInstance().isSlotIndexLocked(slotClickEvent.clickedButton))) { + slotClickEvent.setCanceled(true); + return; + } + if (NotEnoughUpdates.INSTANCE.config.slotLocking.enableSlotBinding + && slotClickEvent.clickType == 1 && locked.boundTo != -1) { - GuiContainer container = (GuiContainer) Minecraft.getMinecraft().currentScreen; - Slot boundSlot = container.inventorySlots.getSlotFromInventory( + Slot boundSlot = slotClickEvent.guiContainer.inventorySlots.getSlotFromInventory( Minecraft.getMinecraft().thePlayer.inventory, locked.boundTo ); @@ -481,29 +479,37 @@ public class SlotLocking { LockedSlot boundLocked = getLockedSlot(boundSlot); - int id = slotIn.getSlotIndex(); - if (id >= 9 && locked.boundTo >= 0 && locked.boundTo < 8) { - if (!boundLocked.locked) { - consumer.accept(Triple.of(slotId, locked.boundTo, 2)); - if (boundLocked == DEFAULT_LOCKED_SLOT) { - LockedSlot[] lockedSlots = getDataForProfile(); - lockedSlots[locked.boundTo] = new LockedSlot(); - lockedSlots[locked.boundTo].boundTo = id; - } else { - boundLocked.boundTo = id; - } + int from, to; + int id = slotClickEvent.slot.getSlotIndex(); + if (id >= 9 && 0 <= locked.boundTo && locked.boundTo < 8 && !boundLocked.locked) { + from = id; + to = locked.boundTo; + if (boundLocked == DEFAULT_LOCKED_SLOT) { + LockedSlot[] lockedSlots = getDataForProfile(); + lockedSlots[locked.boundTo] = new LockedSlot(); + lockedSlots[locked.boundTo].boundTo = id; + } else { + boundLocked.boundTo = id; } - } else if (id >= 0 && id < 8 && locked.boundTo >= 9 && locked.boundTo <= 39) { + } else if (0 <= id && id < 8 && locked.boundTo >= 9 && locked.boundTo <= 39) { if (boundLocked.locked || boundLocked.boundTo != id) { locked.boundTo = -1; + return; } else { - int boundTo = boundSlot.slotNumber; - consumer.accept(Triple.of(boundTo, id, 2)); + from = boundSlot.slotNumber; + to = id; } + } else { + return; } + Minecraft.getMinecraft().playerController.windowClick( + slotClickEvent.guiContainer.inventorySlots.windowId, + from, to, 2, Minecraft.getMinecraft().thePlayer + ); + slotClickEvent.setCanceled(true); } else if (NotEnoughUpdates.INSTANCE.config.slotLocking.enableSlotBinding && locked.boundTo != -1 && NotEnoughUpdates.INSTANCE.config.slotLocking.bindingAlsoLocks) { - consumer.accept(null); + slotClickEvent.setCanceled(true); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiChest.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiChest.java index 1b6b5c61..94b1c704 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiChest.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiChest.java @@ -60,7 +60,7 @@ public class MixinGuiChest { private static final String TARGET_SBADRAWSTRING = "Lcodes/biscuit/skyblockaddons/asm/hooks/GuiChestHook;" + "drawString(Lnet/minecraft/client/gui/FontRenderer;Ljava/lang/String;III)I"; - @Redirect(method = "drawGuiContainerForegroundLayer", at = @At(value = "INVOKE", target = TARGET_SBADRAWSTRING, remap = false)) + @Redirect(method = "drawGuiContainerForegroundLayer", at = @At(value = "INVOKE", target = TARGET_SBADRAWSTRING, remap = false), expect = 0) public int drawGuiContainerForegroundLayer_SBA_drawString( FontRenderer fontRenderer, String text, diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java index a24f4c84..81918939 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -21,14 +21,13 @@ package io.github.moulberry.notenoughupdates.mixins; import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.events.SlotClickEvent; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.miscfeatures.AbiphoneWarning; -import io.github.moulberry.notenoughupdates.miscfeatures.AntiCoopAdd; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionBINWarning; import io.github.moulberry.notenoughupdates.miscfeatures.AuctionSortModeWarning; import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; -import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant; import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay; @@ -60,7 +59,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; @Mixin(GuiContainer.class) public abstract class MixinGuiContainer extends GuiScreen { @@ -98,7 +96,8 @@ public abstract class MixinGuiContainer extends GuiScreen { if (tag.hasKey("SkullOwner") && tag.getCompoundTag("SkullOwner").hasKey("Name")) { String tagName = tag.getCompoundTag("SkullOwner").getString("Name"); String displayName = Utils.cleanColour(cc.inventorySlots.get(22).getStack().getDisplayName()); - if (displayName.length() - tagName.length() >= 0 && tagName.equals(displayName.substring(displayName.length() - tagName.length()))) { + if (displayName.length() - tagName.length() >= 0 && tagName.equals(displayName.substring( + displayName.length() - tagName.length()))) { ci.cancel(); this.zLevel = 100.0F; @@ -127,7 +126,8 @@ public abstract class MixinGuiContainer extends GuiScreen { else if (!($this instanceof GuiChest)) BetterContainers.profileViewerStackIndex = -1; - if (slot.getStack() == null && NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && NotEnoughUpdates.INSTANCE.isOnSkyblock()) { + if (slot.getStack() == null && NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen && + NotEnoughUpdates.INSTANCE.isOnSkyblock()) { GlStateManager.pushMatrix(); GlStateManager.translate(0, 0, 100 + Minecraft.getMinecraft().getRenderItem().zLevel); GlStateManager.depthMask(false); @@ -303,74 +303,20 @@ public abstract class MixinGuiContainer extends GuiScreen { @Inject(method = "handleMouseClick", at = @At(value = "HEAD"), cancellable = true) public void handleMouseClick(Slot slotIn, int slotId, int clickedButton, int clickType, CallbackInfo ci) { + if (slotIn == null) return; GuiContainer $this = (GuiContainer) (Object) this; - - if (AuctionBINWarning.getInstance().onMouseClick(slotIn, slotId, clickedButton, clickType)) { - ci.cancel(); - return; - } - - if (AbiphoneWarning.getInstance().onMouseClick(slotIn, slotId, clickedButton, clickType)) { + SlotClickEvent event = new SlotClickEvent($this, slotIn, slotId, clickedButton, clickType); + event.post(); + if (event.isCanceled()) { ci.cancel(); return; } - - if (AntiCoopAdd.onMouseClick(slotIn, slotId, clickedButton, clickType)) { - ci.cancel(); - return; - } - - AtomicBoolean ret = new AtomicBoolean(false); - SlotLocking.getInstance().onWindowClick(slotIn, slotId, clickedButton, clickType, (tuple) -> { + if (event.usePickblockInstead) { + $this.mc.playerController.windowClick( + $this.inventorySlots.windowId, + slotId, 2, 3, $this.mc.thePlayer + ); ci.cancel(); - - if (tuple == null) { - ret.set(true); - } else { - int newSlotId = tuple.getLeft(); - int newClickedButton = tuple.getMiddle(); - int newClickedType = tuple.getRight(); - - ret.set(true); - $this.mc.playerController.windowClick( - $this.inventorySlots.windowId, - newSlotId, - newClickedButton, - newClickedType, - $this.mc.thePlayer - ); - } - }); - if (ret.get()) return; - - if (slotIn != null && slotIn.getStack() != null) { - if (EnchantingSolvers.onStackClick(slotIn.getStack(), $this.inventorySlots.windowId, - slotId, clickedButton, clickType - )) { - ci.cancel(); - } else { - PetInfoOverlay.onStackClick(slotIn.getStack(), $this.inventorySlots.windowId, - slotId, clickedButton, clickType - ); - } - } - if (slotIn != null && BetterContainers.isOverriding() && (BetterContainers.isBlankStack( - slotIn.slotNumber, - slotIn.getStack() - ) || - BetterContainers.isButtonStack(slotIn.slotNumber, slotIn.getStack()))) { - BetterContainers.clickSlot(slotIn.getSlotIndex()); - - if (BetterContainers.isBlankStack(slotIn.slotNumber, slotIn.getStack())) { - GuiContainer chest = ((GuiContainer) Minecraft.getMinecraft().currentScreen); - Minecraft.getMinecraft().playerController.windowClick( - chest.inventorySlots.windowId, - slotId, 2, 3, Minecraft.getMinecraft().thePlayer - ); - ci.cancel(); - } else { - Utils.playPressSound(); - } } } } |