aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Storage.java9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Garden.java25
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenPlotIcon.kt155
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt2
5 files changed, 188 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index ef8ba9814..8cf8f782e 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -282,6 +282,7 @@ class SkyHanniMod {
loadModule(PetCandyUsedDisplay())
loadModule(ServerRestartTitle())
loadModule(CityProjectFeatures())
+ loadModule(GardenPlotIcon)
init()
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
index 8f9aba6bf..1807e2e22 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java
@@ -153,6 +153,13 @@ public class Storage {
}
@Expose
+ public PlotIcon plotIcon = new PlotIcon();
+ public static class PlotIcon {
+ @Expose
+ public Map<Integer, String> plotList = new HashMap<>();
+ }
+
+ @Expose
public Map<CropType, LorenzVec> cropStartLocations = new HashMap<>();
@Expose
@@ -180,4 +187,4 @@ public class Storage {
}
}
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
index b4ebe1ff0..2ae4f95fb 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
@@ -2,6 +2,9 @@ package at.hannibal2.skyhanni.config.features;
import at.hannibal2.skyhanni.config.commands.Commands;
import at.hannibal2.skyhanni.config.core.config.Position;
+import at.hannibal2.skyhanni.data.GuiEditManager;
+import at.hannibal2.skyhanni.features.garden.inventory.GardenPlotIcon;
+import at.hannibal2.skyhanni.utils.LorenzUtils;
import com.google.gson.annotations.Expose;
import io.github.moulberry.moulconfig.annotations.*;
import io.github.moulberry.moulconfig.observer.Property;
@@ -175,7 +178,6 @@ public class Garden {
@ConfigAccordionId(id = 1)
public boolean visitorHideChat = true;
-
@Expose
@ConfigOption(name = "Visitor Drops Statistics Counter", desc = "")
@Accordion
@@ -1142,6 +1144,25 @@ public class Garden {
}
@Expose
+ @ConfigOption(name = "Garden Plot Icon", desc = "")
+ @Accordion
+ public PlotIcon plotIcon = new PlotIcon();
+
+ public static class PlotIcon {
+ @Expose
+ @ConfigOption(name = "Enable", desc = "Enable icon replacement in the Configure Plots menu.")
+ @ConfigEditorBoolean
+ public boolean enabled = true;
+
+ @ConfigOption(name = "Hard Reset", desc = "Reset every slot to it's original item.")
+ @ConfigEditorButton
+ public Runnable hardReset = () -> {
+ GardenPlotIcon.INSTANCE.setHardReset(true);
+ LorenzUtils.INSTANCE.sendCommandToServer("desk");
+ };
+ }
+
+ @Expose
@ConfigOption(name = "Plot Price", desc = "Show the price of the plot in coins when inside the Configure Plots inventory.")
@ConfigEditorBoolean
public boolean plotPrice = true;
@@ -1204,4 +1225,4 @@ public class Garden {
@Expose
public Position cropSpeedMeterPos = new Position(278, -236, false, true);
-}
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenPlotIcon.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenPlotIcon.kt
new file mode 100644
index 000000000..e5df053fd
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/GardenPlotIcon.kt
@@ -0,0 +1,155 @@
+package at.hannibal2.skyhanni.features.garden.inventory
+
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.InventoryCloseEvent
+import at.hannibal2.skyhanni.events.InventoryOpenEvent
+import at.hannibal2.skyhanni.events.LorenzToolTipEvent
+import at.hannibal2.skyhanni.features.garden.GardenAPI
+import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
+import at.hannibal2.skyhanni.utils.ItemUtils.getLore
+import at.hannibal2.skyhanni.utils.LorenzUtils.chat
+import at.hannibal2.skyhanni.utils.NEUItems
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+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.player.inventory.ContainerLocalMenu
+import net.minecraft.init.Items
+import net.minecraft.item.ItemStack
+import net.minecraftforge.fml.common.eventhandler.EventPriority
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object GardenPlotIcon {
+
+ private val config get() = SkyHanniMod.feature.garden.plotIcon
+ private val plotList get() = GardenAPI.config?.plotIcon?.plotList
+ private var inInventory = false
+ private var copyStack: ItemStack? = null
+ private var editMode = 0 // 0 = off, 1 = on, 2 = reset
+ private var lastClickedSlotId = -1
+ private var originalStack = mutableMapOf<Int, ItemStack>()
+ private var cachedStack = mutableMapOf<Int, ItemStack>()
+ private val editStack = ItemStack(Items.wooden_axe)
+
+ var hardReset = false
+
+ fun isEnabled() = GardenAPI.inGarden() && config.enabled && inInventory
+
+ @SubscribeEvent(priority = EventPriority.HIGHEST)
+ fun onInventoryOpen(event: InventoryOpenEvent) {
+ inInventory = event.inventoryName == "Configure Plots"
+ if (!isEnabled()) return
+
+ for ((index, stack) in event.inventoryItems) {
+ originalStack[index] = stack
+ }
+ val plotList = plotList ?: return
+ for ((index, internalName) in plotList) {
+ val old = originalStack[index]!!
+ val new = NEUItems.getItemStack(internalName)
+ cachedStack[index] = Utils.editItemStackInfo(new, old.displayName, true, *old.getLore().toTypedArray())
+ }
+ }
+
+ @SubscribeEvent
+ fun onInventoryClose(event: InventoryCloseEvent) {
+ inInventory = false
+ editMode = 0
+ }
+
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun replaceItem(event: ReplaceItemEvent) {
+ if (!isEnabled()) return
+ val plotList = plotList ?: return
+ if (hardReset) {
+ plotList.clear()
+ hardReset = false
+ return
+ }
+
+ if (event.inventory is ContainerLocalMenu) {
+ if (event.slotNumber == 53) {
+ event.replaceWith(editStack)
+ }
+ if (plotList.isNotEmpty() && plotList.contains(event.slotNumber)) {
+ if (lastClickedSlotId == event.slotNumber) {
+ lastClickedSlotId = -1
+ return
+ }
+ event.replaceWith(cachedStack[event.slotNumber])
+ }
+ }
+ }
+
+ @SubscribeEvent(priority = EventPriority.HIGH)
+ fun onStackClick(event: SlotClickEvent) {
+ if (!isEnabled()) return
+ lastClickedSlotId = event.slotId
+ if (event.slotId == 53) {
+ event.isCanceled = true
+ if (event.clickedButton == 0) {
+ if (editMode == 2)
+ editMode = 0
+ else
+ editMode++
+ } else if (event.clickedButton == 1) {
+ if (editMode == 0)
+ editMode = 2
+ else
+ editMode--
+ }
+ return
+ }
+ if (editMode != 0) {
+ if (event.slotId in 54..89) {
+ event.isCanceled = true
+ if (event.slot.stack == null) return
+ copyStack = event.slot.stack
+ chat("§6§lClick an item in the desk menu to replace it with that item!")
+ return
+ }
+ if (event.slotId != 53) {
+ val plotList = plotList ?: return
+ if (!event.slot.stack.displayName.removeColor().startsWith("Plot")) return
+ event.isCanceled = true
+ if (editMode == 2) {
+ plotList.remove(event.slotId)
+ return
+ }
+ val copyStack = copyStack ?: return
+ plotList[event.slotId] = copyStack.getInternalName()
+ cachedStack[event.slotId] = copyStack
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onTooltip(event: LorenzToolTipEvent) {
+ if (!isEnabled()) return
+ val plotList = plotList ?: return
+ val list = event.toolTip
+ val index = event.slot.slotNumber
+ if (index == 53) {
+ list.clear()
+ list.add("§6Edit Mode")
+ list.add("")
+ list.add("${if (editMode == 0) "§6► " else ""}§cOFF§7: §bNothing change, behave like normal.")
+ list.add("${if (editMode == 1) "§6► " else ""}§aON§7: §bClick an item in your inventory then click again")
+ list.add("${if (editMode == 1) "§6► " else ""}§bin the plot menu to change it to that item.")
+ list.add("${if (editMode == 2) "§6► " else ""}§9RESET§7: §bClick an item in the menu to reset it to default.")
+ list.add("")
+ list.add("§eClick to switch Edit Mode !")
+ list.add("")
+ }
+ if (plotList.contains(index)) {
+ val stack = originalStack[index] ?: return
+ val lore = stack.getLore()
+ list.clear()
+ list.add(0, stack.displayName)
+ for (i in lore.indices) {
+ list.add(i + 1, stack.getLore()[i])
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
index 8ae1fe288..fc043e26b 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
@@ -93,4 +93,4 @@ object StringUtils {
fun encodeBase64(input: String) = Base64.getEncoder().encodeToString(input.toByteArray())
fun decodeBase64(input: String) = Base64.getDecoder().decode(input).decodeToString()
-}
+} \ No newline at end of file