aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2
diff options
context:
space:
mode:
authorConutik <60240193+Conutik@users.noreply.github.com>2024-04-17 18:38:53 +0300
committerGitHub <noreply@github.com>2024-04-17 17:38:53 +0200
commit5f6e3814d63df9bc29905d62ffc40d1615408928 (patch)
tree8cb31b0acf0d7b07fbee06128a425d443aa83f4b /src/main/java/at/hannibal2
parent5aae03a0e27f361ec4133ac1fda43a3d4e72061e (diff)
downloadskyhanni-5f6e3814d63df9bc29905d62ffc40d1615408928.tar.gz
skyhanni-5f6e3814d63df9bc29905d62ffc40d1615408928.tar.bz2
skyhanni-5f6e3814d63df9bc29905d62ffc40d1615408928.zip
Feature: Visitor Super Craft (#1173)
Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/ShoppingListConfig.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt96
3 files changed, 104 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 4ef7c0563..ed146902c 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -223,6 +223,7 @@ import at.hannibal2.skyhanni.features.garden.pests.StereoHarmonyDisplay
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
@@ -662,6 +663,7 @@ class SkyHanniMod {
loadModule(GardenPlotMenuHighlighting())
loadModule(SkyMartCopperPrice())
loadModule(GardenVisitorFeatures)
+ loadModule(GardenVisitorSupercraft())
loadModule(NPCVisitorFix)
loadModule(GardenInventoryNumbers())
loadModule(GardenVisitorTimer())
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 3155c5b0c..474b1a73b 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
@@ -49,6 +49,12 @@ public class ShoppingListConfig {
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 = 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.")
@ConfigEditorBoolean
@FeatureToggle
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 000000000..a3afd06ab
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorSupercraft.kt
@@ -0,0 +1,96 @@
+package at.hannibal2.skyhanni.features.garden.visitor
+
+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.utils.ChatUtils
+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 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
+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
+ }
+ }
+
+ // needs to run later than onVisitorOpen at GardenVisitorFeatures
+ @SubscribeEvent(priority = EventPriority.LOW)
+ fun onVisitorOpen(event: VisitorOpenEvent) {
+ val visitor = event.visitor
+ visitor.offer?.offerItem ?: return
+ for ((internalName, amount) in visitor.shoppingList) {
+ 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<String, Int>()
+ 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
+ }
+ }
+ }
+
+ @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: GuiContainerEvent.SlotClickEvent) {
+ if (!hasIngredients) return
+
+ if (event.slotId == 31) {
+ event.isCanceled = true
+ if (lastClick.passedSince() > 0.3.seconds) {
+ ChatUtils.sendCommandToServer("recipe $lastSuperCraftMaterial")
+ lastClick = SimpleTimeMark.now()
+ }
+ }
+ }
+}