Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: ShiftClickNPCSell #907

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ import at.hannibal2.skyhanni.features.inventory.QuickCraftFeatures
import at.hannibal2.skyhanni.features.inventory.RngMeterInventory
import at.hannibal2.skyhanni.features.inventory.SackDisplay
import at.hannibal2.skyhanni.features.inventory.ShiftClickEquipment
import at.hannibal2.skyhanni.features.inventory.ShiftClickNPCSell
import at.hannibal2.skyhanni.features.inventory.SkyBlockLevelGuideHelper
import at.hannibal2.skyhanni.features.inventory.StatsTuning
import at.hannibal2.skyhanni.features.inventory.tiarelay.TiaRelayHelper
Expand All @@ -235,6 +236,7 @@ import at.hannibal2.skyhanni.features.misc.FixNEUHeavyPearls
import at.hannibal2.skyhanni.features.misc.HideArmor
import at.hannibal2.skyhanni.features.misc.InGameDateDisplay
import at.hannibal2.skyhanni.features.misc.JoinCrystalHollows
import at.hannibal2.skyhanni.features.misc.LesserOrbHider
import at.hannibal2.skyhanni.features.misc.LimboTimeTracker
import at.hannibal2.skyhanni.features.misc.LockMouseLook
import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager
Expand All @@ -255,7 +257,6 @@ import at.hannibal2.skyhanni.features.misc.SkyBlockKickDuration
import at.hannibal2.skyhanni.features.misc.SuperpairsClicksAlert
import at.hannibal2.skyhanni.features.misc.TimeFeatures
import at.hannibal2.skyhanni.features.misc.TpsCounter
import at.hannibal2.skyhanni.features.misc.LesserOrbHider
import at.hannibal2.skyhanni.features.misc.compacttablist.AdvancedPlayerList
import at.hannibal2.skyhanni.features.misc.compacttablist.TabListReader
import at.hannibal2.skyhanni.features.misc.compacttablist.TabListRenderer
Expand Down Expand Up @@ -517,6 +518,7 @@ class SkyHanniMod {
loadModule(SoopyGuessBurrow())
loadModule(DianaProfitTracker)
loadModule(MythologicalCreatureTracker)
loadModule(ShiftClickNPCSell)
loadModule(HighlightJerries())
loadModule(TheGreatSpook())
loadModule(GriffinBurrowHelper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean;
import io.github.moulberry.moulconfig.annotations.ConfigEditorDraggableList;
import io.github.moulberry.moulconfig.annotations.ConfigOption;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -184,9 +183,15 @@ public String toString() {
public boolean copyUnderbidPrice = false;

@Expose
@ConfigOption(name = "Shift Click Equipment", desc = "Makes normal clicks to shift clicks in equipment inventory")
@ConfigOption(name = "Shift Click Equipment", desc = "Makes normal clicks to shift clicks in equipment inventory.")
@ConfigEditorBoolean
@FeatureToggle
public boolean shiftClickForEquipment = false;

@Expose
@ConfigOption(name = "Shift Click NPC sell", desc = "Makes normal clicks to shift clicks in npc inventory for selling.")
@ConfigEditorBoolean
@FeatureToggle
public boolean shiftClickNPCSell = false;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background
import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.borderLine
import at.hannibal2.skyhanni.data.jsonobjects.repo.HideNotClickableItemsJson
import at.hannibal2.skyhanni.data.jsonobjects.repo.HideNotClickableItemsJson.SalvageFilter
import at.hannibal2.skyhanni.data.jsonobjects.repo.MultiFilterJson
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.features.bazaar.BazaarApi
Expand Down Expand Up @@ -49,16 +48,12 @@ class HideNotClickableItems {

private val hideNpcSellFilter = MultiFilter()
private val hideInStorageFilter = MultiFilter()
private val tradeNpcFilter = MultiFilter()
private val itemsToSalvage = mutableListOf<String>()
private val hidePlayerTradeFilter = MultiFilter()
private val notAuctionableFilter = MultiFilter()

@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<MultiFilterJson>("TradeNpcs")
tradeNpcFilter.load(data)

val hideNotClickable = event.getConstant<HideNotClickableItemsJson>("HideNotClickableItems")
hideNpcSellFilter.load(hideNotClickable.hide_npc_sell)
hideInStorageFilter.load(hideNotClickable.hide_in_storage)
Expand Down Expand Up @@ -175,7 +170,7 @@ class HideNotClickableItems {
reverseColor = false

return when {
hideNpcSell(chestName, stack) -> true
hideNpcSell(stack) -> true
hideInStorage(chestName, stack) -> true
hideSalvage(chestName, stack) -> true
hidePlayerTrade(chestName, stack) -> true
Expand Down Expand Up @@ -260,7 +255,7 @@ class HideNotClickableItems {
"BRACELET"
)
for (type in list) {
if (stack.getLore().any { it.contains("§l") && it.contains(type) }) {//todo use item api
if (stack.getLore().any { it.contains("§l") && it.contains(type) }) {// todo use item api
reverseColor = true
return false
}
Expand Down Expand Up @@ -289,7 +284,7 @@ class HideNotClickableItems {
private fun hidePrivateIslandChest(chestName: String, stack: ItemStack): Boolean {
if (chestName != "Chest" && chestName != "Large Chest") return false

//TODO make check if player is on private island
// TODO make check if player is on private island

if (!ItemUtils.isSoulBound(stack)) return false

Expand Down Expand Up @@ -378,8 +373,8 @@ class HideNotClickableItems {
return result
}

private fun hideNpcSell(chestName: String, stack: ItemStack): Boolean {
if (!tradeNpcFilter.match(chestName)) return false
private fun hideNpcSell(stack: ItemStack): Boolean {
if (!ShiftClickNPCSell.inInventory) return false
if (VisitorAPI.inInventory) return false
reverseColor = true

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package at.hannibal2.skyhanni.features.inventory

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object ShiftClickNPCSell {

private val config get() = SkyHanniMod.feature.inventory.shiftClickNPCSell

private val sellSlot = 49
private val lastLoreLineOfSellPattern by RepoPattern.pattern(
"inventory.npc.sell.lore",
"§7them to this Shop!|§eClick to buyback!"
)

var inInventory = false
private set

fun isEnabled() = LorenzUtils.inSkyBlock && config

@SubscribeEvent
fun onOpen(event: InventoryFullyOpenedEvent) {
if (!LorenzUtils.inSkyBlock) return
inInventory = lastLoreLineOfSellPattern.matches(event.inventoryItems[sellSlot]?.getLore()?.lastOrNull() ?: "")
}

@SubscribeEvent
fun onClose(event: InventoryCloseEvent) {
inInventory = false
}

@SubscribeEvent
fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) {
if (!isEnabled()) return
if (!inInventory) return

val slot = event.slot ?: return

if (slot.slotNumber == slot.slotIndex) return

event.isCanceled = true
Minecraft.getMinecraft().playerController.windowClick(
event.container.windowId, event.slot.slotNumber, event.clickedButton, 1, Minecraft.getMinecraft().thePlayer
)
}
}
Loading