summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-26 16:37:41 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-26 16:37:41 +0100
commit39826c759c26776f655cb8237b57f25343e8a77b (patch)
tree4b65714e5ba3a3def16cd41b45c2e89f84e81e4f /src/main/java/at/hannibal2/skyhanni/features
parentefe26c67aad6143cde820a8836495631a8128d0f (diff)
downloadskyhanni-39826c759c26776f655cb8237b57f25343e8a77b.tar.gz
skyhanni-39826c759c26776f655cb8237b57f25343e8a77b.tar.bz2
skyhanni-39826c759c26776f655cb8237b57f25343e8a77b.zip
Added GardenPlotAPI, support for detecting the current slot of the player
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt
new file mode 100644
index 000000000..6ab6775e9
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt
@@ -0,0 +1,68 @@
+package at.hannibal2.skyhanni.features.garden
+
+import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LocationUtils
+import at.hannibal2.skyhanni.utils.LocationUtils.isInside
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import net.minecraft.util.AxisAlignedBB
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+object GardenPlotAPI {
+
+ private val pestNamePattern = "§aPlot §7- §b(?<name>.*)".toPattern()
+
+ var plots = listOf<Plot>()
+
+ fun getCurrentPlot(): Plot? {
+ val location = LocationUtils.playerLocation()
+ return plots.firstOrNull { it.box.isInside(location) }
+ }
+
+ class Plot(val id: Int, var inventorySlot: Int, val box: AxisAlignedBB)
+
+ val Plot.name get() = GardenAPI.storage?.plotNames?.get(id) ?: "$id"
+
+ fun Plot.isBarn() = id == -1
+
+ init {
+ val plotMap = listOf(
+ listOf(21, 13, 9, 14, 22),
+ listOf(15, 5, 1, 6, 16),
+ listOf(10, 2, -1, 3, 11),
+ listOf(17, 7, 4, 8, 18),
+ listOf(23, 19, 12, 20, 24),
+ )
+ val list = mutableListOf<Plot>()
+ var slot = 2
+ for ((y, rows) in plotMap.withIndex()) {
+ for ((x, id) in rows.withIndex()) {
+ val minX = ((x - 2) * 96 - 48).toDouble()
+ val minY = ((y - 2) * 96 - 48).toDouble()
+ val maxX = ((x - 2) * 96 + 48).toDouble()
+ val maxY = ((y - 2) * 96 + 48).toDouble()
+ val box = AxisAlignedBB(minX, 0.0, minY, maxX, 256.0, maxY)
+ list.add(
+ Plot(id, slot, box)
+ )
+ slot++
+ }
+ slot += 4
+ }
+ plots = list
+ }
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
+ if (!GardenAPI.inGarden()) return
+ if (event.inventoryName != "Configure Plots") return
+
+ val names = GardenAPI.storage?.plotNames ?: return
+ for (plot in plots) {
+ val itemName = event.inventoryItems[plot.inventorySlot]?.name ?: continue
+ pestNamePattern.matchMatcher(itemName) {
+ names[plot.id] = group("name")
+ }
+ }
+ }
+}