From ab4fd7796d173615595cd09de091c6e2da58d1d9 Mon Sep 17 00:00:00 2001 From: Conutik <60240193+Conutik@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:26:25 +0300 Subject: [PATCH 1/8] Progress till now --- .../garden/visitor/GardenVisitorFeatures.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index e051520f29fe..d53aff39d2f1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -41,7 +41,9 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.LorenzUtils.runDelayed import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.NEUItems.getPrice @@ -62,11 +64,13 @@ import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiEditSign import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand +import net.minecraft.init.Items import net.minecraft.item.ItemStack import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.math.round +import kotlin.time.Duration.Companion.parse import kotlin.time.Duration.Companion.seconds private val config get() = VisitorAPI.config @@ -129,6 +133,35 @@ class GardenVisitorFeatures { val (itemName, amount) = pair val internalName = NEUInternalName.fromItemName(itemName) visitor.shoppingList[internalName] = amount +// +// GET SUPERCRAFT FOR SACKS CODE +// + val item = + NEUItems.getRecipes(internalName).first { !it.ingredients.first().internalItemId.contains("PEST") } + val ingredients = item.ingredients + val ingredientReqs = mutableMapOf() + for(ingredient in ingredients) { + val ing = ingredient.serialize().split(":") + ingredientReqs[ing[0]] = ingredientReqs.getOrDefault(ing[0], 0) + ing[1].toDouble().toInt() + } + println(ingredientReqs) + var hasIngredients = false; + for((key, value) in ingredientReqs) { + val sackItem = SackAPI.fetchSackItem(key.asInternalName()) + if(sackItem.amount >= value*amount) { +// runDelayed(parse("10ms")) { +// print(InventoryUtils.getItemsInOpenChest()) +// } + hasIngredients = true; +// InventoryUtils.getItemsInOpenChest()[31].putStack(ItemStack(Items.golden_pickaxe)) + } else { + hasIngredients = false; + break; + } + } + if(hasIngredients) runDelayed(parse("10ms")) { + InventoryUtils.getItemsInOpenChest()[31].putStack(ItemStack(Items.golden_pickaxe)) + } } readToolTip(visitor, offerItem) From a924297bd6b36c10920add3a564233d156ffeab5 Mon Sep 17 00:00:00 2001 From: Conutik <60240193+Conutik@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:16:47 +0300 Subject: [PATCH 2/8] Implemented Super Craft into Visitors --- .../garden/visitor/GardenVisitorFeatures.kt | 63 +++++++++++++++---- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index d53aff39d2f1..969dd2585272 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.data.SackAPI import at.hannibal2.skyhanni.data.SackStatus import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent @@ -50,8 +51,10 @@ import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatInt +import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeUtils @@ -60,10 +63,14 @@ import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import com.google.gson.JsonArray import com.google.gson.JsonPrimitive +import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent +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.GuiEditSign import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand +import net.minecraft.entity.player.InventoryPlayer import net.minecraft.init.Items import net.minecraft.item.ItemStack import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent @@ -103,6 +110,19 @@ class GardenVisitorFeatures { private val logger = LorenzLogger("garden/visitors") private var lastFullPrice = 0.0 + private var hasIngredients = false; + private var lastClick = SimpleTimeMark.farPast() + private var lastSuperCraftMaterial = "" + + private val superCraftItem by lazy { + val neuItem = "GOLD_PICKAXE".asInternalName().getItemStack() + Utils.createItemStack( + neuItem.item, + "§bSuper Craft", + "§7You have the items to craft", + "§7Click me to open the super crafter!" + ) + } @SubscribeEvent fun onProfileJoin(event: ProfileJoinEvent) { @@ -144,24 +164,15 @@ class GardenVisitorFeatures { val ing = ingredient.serialize().split(":") ingredientReqs[ing[0]] = ingredientReqs.getOrDefault(ing[0], 0) + ing[1].toDouble().toInt() } - println(ingredientReqs) - var hasIngredients = false; + hasIngredients = true; for((key, value) in ingredientReqs) { val sackItem = SackAPI.fetchSackItem(key.asInternalName()) - if(sackItem.amount >= value*amount) { -// runDelayed(parse("10ms")) { -// print(InventoryUtils.getItemsInOpenChest()) -// } - hasIngredients = true; -// InventoryUtils.getItemsInOpenChest()[31].putStack(ItemStack(Items.golden_pickaxe)) - } else { + lastSuperCraftMaterial = internalName.itemName + if(sackItem.amount < value*amount) { hasIngredients = false; break; } } - if(hasIngredients) runDelayed(parse("10ms")) { - InventoryUtils.getItemsInOpenChest()[31].putStack(ItemStack(Items.golden_pickaxe)) - } } readToolTip(visitor, offerItem) @@ -295,6 +306,34 @@ class GardenVisitorFeatures { } } + @SubscribeEvent + fun replaceItem(event: ReplaceItemEvent) { + if (!hasIngredients) return + if (event.inventory is InventoryPlayer) return + + if (event.slotNumber == 31) { + event.replaceWith(superCraftItem) + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onStackClick(event: SlotClickEvent) { + if (!hasIngredients) return + + if (event.slotId == 31) { + event.isCanceled = true + if (lastClick.passedSince() > 0.3.seconds) { + ChatUtils.sendCommandToServer("recipe $lastSuperCraftMaterial") + lastClick = SimpleTimeMark.now() + } + } + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + if(hasIngredients) { hasIngredients = false } + } + @SubscribeEvent fun onOwnInventoryItemUpdate(event: OwnInventoryItemUpdateEvent) { if (GardenAPI.onBarnPlot) { From d743e86af137e6dae24428bd58088e5b833fbbc7 Mon Sep 17 00:00:00 2001 From: Conutik <60240193+Conutik@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:23:17 +0300 Subject: [PATCH 3/8] Added config and reformatted code --- .../garden/visitor/ShoppingListConfig.java | 6 ++++ .../garden/visitor/GardenVisitorFeatures.kt | 28 +++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java index 3b5d4da6b99d..cc9fd384e9a8 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java @@ -46,6 +46,12 @@ public class ShoppingListConfig { @ConfigEditorBoolean public boolean showSackCount = true; + @Expose + @ConfigOption(name = "Show Super Craft", desc = "Show super craft button if there are enough materials to make in the sack.") + @ConfigEditorBoolean + @FeatureToggle + public boolean showSuperCraft = true; + @Expose @ConfigOption(name = "Item Preview", desc = "Show the base type for the required items next to new visitors. §cNote that some visitors may require any crop.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index 969dd2585272..2888ea112753 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -156,21 +156,23 @@ class GardenVisitorFeatures { // // GET SUPERCRAFT FOR SACKS CODE // - val item = - NEUItems.getRecipes(internalName).first { !it.ingredients.first().internalItemId.contains("PEST") } - val ingredients = item.ingredients + if (config.shoppingList.showSuperCraft) { + val item = + NEUItems.getRecipes(internalName).first { !it.ingredients.first().internalItemId.contains("PEST") } + val ingredients = item.ingredients val ingredientReqs = mutableMapOf() - for(ingredient in ingredients) { + for (ingredient in ingredients) { val ing = ingredient.serialize().split(":") ingredientReqs[ing[0]] = ingredientReqs.getOrDefault(ing[0], 0) + ing[1].toDouble().toInt() } - hasIngredients = true; - for((key, value) in ingredientReqs) { - val sackItem = SackAPI.fetchSackItem(key.asInternalName()) - lastSuperCraftMaterial = internalName.itemName - if(sackItem.amount < value*amount) { - hasIngredients = false; - break; + hasIngredients = true; + for ((key, value) in ingredientReqs) { + val sackItem = SackAPI.fetchSackItem(key.asInternalName()) + lastSuperCraftMaterial = internalName.itemName + if (sackItem.amount < value * amount) { + hasIngredients = false; + break; + } } } } @@ -331,7 +333,9 @@ class GardenVisitorFeatures { @SubscribeEvent fun onInventoryClose(event: InventoryCloseEvent) { - if(hasIngredients) { hasIngredients = false } + if (hasIngredients) { + hasIngredients = false + } } @SubscribeEvent From c338182e214bd77030905bd43611a4b86b1f1f3c Mon Sep 17 00:00:00 2001 From: Conutik <60240193+Conutik@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:09:41 +0300 Subject: [PATCH 4/8] Added changes --- .../java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 + .../garden/visitor/GardenVisitorFeatures.kt | 76 ----------- .../garden/visitor/GardenVisitorSupercraft.kt | 119 ++++++++++++++++++ 3 files changed, 121 insertions(+), 76 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index e6e27dc97b79..b96c9c59c76b 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -205,6 +205,7 @@ import at.hannibal2.skyhanni.features.garden.pests.SprayFeatures import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorColorNames import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorDropStatistics import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorFeatures +import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorSupercraft import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorTimer import at.hannibal2.skyhanni.features.garden.visitor.HighlightVisitorsOutsideOfGarden import at.hannibal2.skyhanni.features.garden.visitor.NPCVisitorFix @@ -615,6 +616,7 @@ class SkyHanniMod { loadModule(MiscFeatures()) loadModule(SkyMartCopperPrice()) loadModule(GardenVisitorFeatures()) + loadModule(GardenVisitorSupercraft()) loadModule(NPCVisitorFix) loadModule(GardenInventoryNumbers()) loadModule(GardenVisitorTimer()) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index 2888ea112753..e051520f29fe 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -7,7 +7,6 @@ import at.hannibal2.skyhanni.data.SackAPI import at.hannibal2.skyhanni.data.SackStatus import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent @@ -42,19 +41,15 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland -import at.hannibal2.skyhanni.utils.LorenzUtils.runDelayed import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatInt -import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RenderUtils.drawString import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems -import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeUtils @@ -63,21 +58,15 @@ import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import com.google.gson.JsonArray import com.google.gson.JsonPrimitive -import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent -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.GuiEditSign import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.item.EntityArmorStand -import net.minecraft.entity.player.InventoryPlayer -import net.minecraft.init.Items import net.minecraft.item.ItemStack import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.math.round -import kotlin.time.Duration.Companion.parse import kotlin.time.Duration.Companion.seconds private val config get() = VisitorAPI.config @@ -110,19 +99,6 @@ class GardenVisitorFeatures { private val logger = LorenzLogger("garden/visitors") private var lastFullPrice = 0.0 - private var hasIngredients = false; - private var lastClick = SimpleTimeMark.farPast() - private var lastSuperCraftMaterial = "" - - private val superCraftItem by lazy { - val neuItem = "GOLD_PICKAXE".asInternalName().getItemStack() - Utils.createItemStack( - neuItem.item, - "§bSuper Craft", - "§7You have the items to craft", - "§7Click me to open the super crafter!" - ) - } @SubscribeEvent fun onProfileJoin(event: ProfileJoinEvent) { @@ -153,28 +129,6 @@ class GardenVisitorFeatures { val (itemName, amount) = pair val internalName = NEUInternalName.fromItemName(itemName) visitor.shoppingList[internalName] = amount -// -// GET SUPERCRAFT FOR SACKS CODE -// - if (config.shoppingList.showSuperCraft) { - val item = - NEUItems.getRecipes(internalName).first { !it.ingredients.first().internalItemId.contains("PEST") } - val ingredients = item.ingredients - val ingredientReqs = mutableMapOf() - for (ingredient in ingredients) { - val ing = ingredient.serialize().split(":") - ingredientReqs[ing[0]] = ingredientReqs.getOrDefault(ing[0], 0) + ing[1].toDouble().toInt() - } - hasIngredients = true; - for ((key, value) in ingredientReqs) { - val sackItem = SackAPI.fetchSackItem(key.asInternalName()) - lastSuperCraftMaterial = internalName.itemName - if (sackItem.amount < value * amount) { - hasIngredients = false; - break; - } - } - } } readToolTip(visitor, offerItem) @@ -308,36 +262,6 @@ class GardenVisitorFeatures { } } - @SubscribeEvent - fun replaceItem(event: ReplaceItemEvent) { - if (!hasIngredients) return - if (event.inventory is InventoryPlayer) return - - if (event.slotNumber == 31) { - event.replaceWith(superCraftItem) - } - } - - @SubscribeEvent(priority = EventPriority.HIGH) - fun onStackClick(event: SlotClickEvent) { - if (!hasIngredients) return - - if (event.slotId == 31) { - event.isCanceled = true - if (lastClick.passedSince() > 0.3.seconds) { - ChatUtils.sendCommandToServer("recipe $lastSuperCraftMaterial") - lastClick = SimpleTimeMark.now() - } - } - } - - @SubscribeEvent - fun onInventoryClose(event: InventoryCloseEvent) { - if (hasIngredients) { - hasIngredients = false - } - } - @SubscribeEvent fun onOwnInventoryItemUpdate(event: OwnInventoryItemUpdateEvent) { if (GardenAPI.onBarnPlot) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt new file mode 100644 index 000000000000..936461a9c523 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt @@ -0,0 +1,119 @@ +package at.hannibal2.skyhanni.features.garden.visitor + +import at.hannibal2.skyhanni.data.SackAPI +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.garden.visitor.VisitorOpenEvent +import at.hannibal2.skyhanni.test.command.ErrorManager +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.ItemUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.itemName +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent +import io.github.moulberry.notenoughupdates.events.SlotClickEvent +import io.github.moulberry.notenoughupdates.util.Utils +import net.minecraft.entity.player.InventoryPlayer +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +class GardenVisitorSupercraft { + + private val isSupercraftEnabled get() = VisitorAPI.config.shoppingList.showSuperCraft + + private var hasIngredients = false; + private var lastClick = SimpleTimeMark.farPast() + private var lastSuperCraftMaterial = "" + + private val superCraftItem by lazy { + val neuItem = "GOLD_PICKAXE".asInternalName().getItemStack() + Utils.createItemStack( + neuItem.item, + "§bSuper Craft", + "§7You have the items to craft", + "§7Click me to open the super crafter!" + ) + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + if (hasIngredients) { + hasIngredients = false + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onVisitorOpen(event: VisitorOpenEvent) { + val visitor = event.visitor + val offerItem = visitor.offer!!.offerItem + + val lore = offerItem.getLore() + for (line in lore) { + if (line == "§7Items Required:") continue + if (line.isEmpty()) break + + val pair = ItemUtils.readItemAmount(line) + if (pair == null) { + ErrorManager.logErrorStateWithData( + "Could not read Shopping List in Visitor Inventory", "ItemUtils.readItemAmount returns null", + "line" to line, + "offerItem" to offerItem, + "lore" to lore, + "visitor" to visitor + ) + continue + } + val (itemName, amount) = pair + val internalName = NEUInternalName.fromItemName(itemName) +// +// GET SUPERCRAFT FOR SACKS CODE +// + if (isSupercraftEnabled) { + val item = + NEUItems.getRecipes(internalName).first { !it.ingredients.first().internalItemId.contains("PEST") } + val ingredients = item.ingredients + val ingredientReqs = mutableMapOf() + for (ingredient in ingredients) { + val ing = ingredient.serialize().split(":") + ingredientReqs[ing[0]] = ingredientReqs.getOrDefault(ing[0], 0) + ing[1].toDouble().toInt() + } + hasIngredients = true; + for ((key, value) in ingredientReqs) { + val sackItem = SackAPI.fetchSackItem(key.asInternalName()) + lastSuperCraftMaterial = internalName.itemName + if (sackItem.amount < value * amount) { + hasIngredients = false; + break; + } + } + } + } + } + + @SubscribeEvent + fun replaceItem(event: ReplaceItemEvent) { + if (!hasIngredients) return + if (event.inventory is InventoryPlayer) return + + if (event.slotNumber == 31) { + event.replaceWith(superCraftItem) + } + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onStackClick(event: SlotClickEvent) { + if (!hasIngredients) return + + if (event.slotId == 31) { + event.isCanceled = true + if (lastClick.passedSince() > 0.3.seconds) { + ChatUtils.sendCommandToServer("recipe $lastSuperCraftMaterial") + lastClick = SimpleTimeMark.now() + } + } + } +} From ad5e2643db3d700faf7d41358c46a78291da29af Mon Sep 17 00:00:00 2001 From: Conutik <60240193+Conutik@users.noreply.github.com> Date: Wed, 27 Mar 2024 23:52:50 +0300 Subject: [PATCH 5/8] Update src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com> --- .../skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt index 936461a9c523..be4a795ab8d5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt @@ -49,7 +49,7 @@ class GardenVisitorSupercraft { @SubscribeEvent(priority = EventPriority.HIGH) fun onVisitorOpen(event: VisitorOpenEvent) { val visitor = event.visitor - val offerItem = visitor.offer!!.offerItem + val offerItem = visitor.offer?.offerItem ?: return val lore = offerItem.getLore() for (line in lore) { From 3d206b8b33f916e7c2111f90bb76de4f625ad4bb Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 30 Mar 2024 09:57:00 +0100 Subject: [PATCH 6/8] fix Illegal import io.github.moulberry.notenoughupdates.events.SlotClickEvent --- .../features/garden/visitor/GardenVisitorSupercraft.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt index be4a795ab8d5..e26f36d45a23 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.garden.visitor import at.hannibal2.skyhanni.data.SackAPI +import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorOpenEvent import at.hannibal2.skyhanni.test.command.ErrorManager @@ -14,7 +15,6 @@ import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.SimpleTimeMark import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent -import io.github.moulberry.notenoughupdates.events.SlotClickEvent import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.entity.player.InventoryPlayer import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -105,7 +105,7 @@ class GardenVisitorSupercraft { } @SubscribeEvent(priority = EventPriority.HIGH) - fun onStackClick(event: SlotClickEvent) { + fun onStackClick(event: GuiContainerEvent.SlotClickEvent) { if (!hasIngredients) return if (event.slotId == 31) { From 5b7d6f4fb8e3a6eeda74de078df171b027f7cddd Mon Sep 17 00:00:00 2001 From: Conutik <60240193+Conutik@users.noreply.github.com> Date: Sat, 30 Mar 2024 16:46:32 +0300 Subject: [PATCH 7/8] Added changes --- .../garden/visitor/ShoppingListConfig.java | 2 +- .../garden/visitor/GardenVisitorSupercraft.kt | 44 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java index cc9fd384e9a8..d50ec07cbf0d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java @@ -50,7 +50,7 @@ public class ShoppingListConfig { @ConfigOption(name = "Show Super Craft", desc = "Show super craft button if there are enough materials to make in the sack.") @ConfigEditorBoolean @FeatureToggle - public boolean showSuperCraft = true; + public boolean showSuperCraft = false; @Expose @ConfigOption(name = "Item Preview", desc = "Show the base type for the required items next to new visitors. §cNote that some visitors may require any crop.") diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt index e26f36d45a23..51ad9fcd9fb2 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.garden.visitor import at.hannibal2.skyhanni.data.SackAPI +import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorOpenEvent @@ -14,6 +15,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.StringUtils.removeColor import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent import io.github.moulberry.notenoughupdates.util.Utils import net.minecraft.entity.player.InventoryPlayer @@ -25,7 +27,7 @@ class GardenVisitorSupercraft { private val isSupercraftEnabled get() = VisitorAPI.config.shoppingList.showSuperCraft - private var hasIngredients = false; + private var hasIngredients = false private var lastClick = SimpleTimeMark.farPast() private var lastSuperCraftMaterial = "" @@ -46,7 +48,7 @@ class GardenVisitorSupercraft { } } - @SubscribeEvent(priority = EventPriority.HIGH) + @SubscribeEvent(priority = EventPriority.NORMAL) fun onVisitorOpen(event: VisitorOpenEvent) { val visitor = event.visitor val offerItem = visitor.offer?.offerItem ?: return @@ -69,27 +71,23 @@ class GardenVisitorSupercraft { } val (itemName, amount) = pair val internalName = NEUInternalName.fromItemName(itemName) -// -// GET SUPERCRAFT FOR SACKS CODE -// - if (isSupercraftEnabled) { - val item = - NEUItems.getRecipes(internalName).first { !it.ingredients.first().internalItemId.contains("PEST") } - val ingredients = item.ingredients - val ingredientReqs = mutableMapOf() - for (ingredient in ingredients) { - val ing = ingredient.serialize().split(":") - ingredientReqs[ing[0]] = ingredientReqs.getOrDefault(ing[0], 0) + ing[1].toDouble().toInt() - } - hasIngredients = true; - for ((key, value) in ingredientReqs) { - val sackItem = SackAPI.fetchSackItem(key.asInternalName()) - lastSuperCraftMaterial = internalName.itemName - if (sackItem.amount < value * amount) { - hasIngredients = false; - break; - } - } + if (isSupercraftEnabled) getSupercraftForSacks(internalName, amount) + } + } + + fun getSupercraftForSacks(internalName: NEUInternalName, amount: Int) { + val ingredients = NEUItems.getRecipes(internalName).first { !it.ingredients.first().internalItemId.contains("PEST") }.ingredients + val ingredientReqs = mutableMapOf() + for (ingredient in ingredients) { + ingredientReqs[ingredient.internalItemId] = ingredientReqs.getOrDefault(ingredient.internalItemId, 0) + ingredient.count.toInt() + } + hasIngredients = true + for ((key, value) in ingredientReqs) { + val sackItem = key.asInternalName().getAmountInSacks() + lastSuperCraftMaterial = internalName.itemName.removeColor() + if (sackItem < value * amount) { + hasIngredients = false + break } } } From 3b6c0ff1f2cc889d0d1299270af6c1b5fe280a2d Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 17 Apr 2024 17:35:56 +0200 Subject: [PATCH 8/8] code cleanup --- .../garden/visitor/GardenVisitorSupercraft.kt | 29 +++---------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt index 51ad9fcd9fb2..a3afd06ab8b0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt @@ -1,14 +1,10 @@ package at.hannibal2.skyhanni.features.garden.visitor -import at.hannibal2.skyhanni.data.SackAPI import at.hannibal2.skyhanni.data.SackAPI.getAmountInSacks import at.hannibal2.skyhanni.events.GuiContainerEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.garden.visitor.VisitorOpenEvent -import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.ChatUtils -import at.hannibal2.skyhanni.utils.ItemUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName @@ -48,29 +44,12 @@ class GardenVisitorSupercraft { } } - @SubscribeEvent(priority = EventPriority.NORMAL) + // needs to run later than onVisitorOpen at GardenVisitorFeatures + @SubscribeEvent(priority = EventPriority.LOW) fun onVisitorOpen(event: VisitorOpenEvent) { val visitor = event.visitor - val offerItem = visitor.offer?.offerItem ?: return - - val lore = offerItem.getLore() - for (line in lore) { - if (line == "§7Items Required:") continue - if (line.isEmpty()) break - - val pair = ItemUtils.readItemAmount(line) - if (pair == null) { - ErrorManager.logErrorStateWithData( - "Could not read Shopping List in Visitor Inventory", "ItemUtils.readItemAmount returns null", - "line" to line, - "offerItem" to offerItem, - "lore" to lore, - "visitor" to visitor - ) - continue - } - val (itemName, amount) = pair - val internalName = NEUInternalName.fromItemName(itemName) + visitor.offer?.offerItem ?: return + for ((internalName, amount) in visitor.shoppingList) { if (isSupercraftEnabled) getSupercraftForSacks(internalName, amount) } }