diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-26 16:37:41 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-26 16:37:41 +0100 |
commit | 39826c759c26776f655cb8237b57f25343e8a77b (patch) | |
tree | 4b65714e5ba3a3def16cd41b45c2e89f84e81e4f /src/main | |
parent | efe26c67aad6143cde820a8836495631a8128d0f (diff) | |
download | skyhanni-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')
4 files changed, 75 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 8dd3640b6..76e6a44e8 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -137,6 +137,7 @@ import at.hannibal2.skyhanni.features.garden.GardenCropMilestoneFix import at.hannibal2.skyhanni.features.garden.GardenLevelDisplay import at.hannibal2.skyhanni.features.garden.GardenNextJacobContest import at.hannibal2.skyhanni.features.garden.GardenOptimalSpeed +import at.hannibal2.skyhanni.features.garden.GardenPlotAPI import at.hannibal2.skyhanni.features.garden.GardenPlotBorders import at.hannibal2.skyhanni.features.garden.GardenWarpCommands import at.hannibal2.skyhanni.features.garden.GardenYawAndPitch @@ -398,6 +399,7 @@ class SkyHanniMod { // APIs loadModule(BazaarApi()) loadModule(GardenAPI) + loadModule(GardenPlotAPI) loadModule(CollectionAPI()) loadModule(FarmingContestAPI) loadModule(FriendAPI) diff --git a/src/main/java/at/hannibal2/skyhanni/config/Storage.java b/src/main/java/at/hannibal2/skyhanni/config/Storage.java index d85b02651..e2d8750b0 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Storage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Storage.java @@ -227,6 +227,9 @@ public class Storage { } @Expose + public Map<Integer, String> plotNames = new HashMap<>(); + + @Expose public Map<CropType, LorenzVec> cropStartLocations = new HashMap<>(); @Expose 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") + } + } + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt index e6929d737..580075543 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LocationUtils.kt @@ -27,9 +27,9 @@ object LocationUtils { return vec.add(0.0, 0.0 + player.getEyeHeight(), 0.0) } - fun AxisAlignedBB.isVecInside(vec: LorenzVec) = isVecInside(vec.toVec3()) + fun AxisAlignedBB.isInside(vec: LorenzVec) = isVecInside(vec.toVec3()) - fun AxisAlignedBB.isPlayerInside() = isVecInside(playerLocation()) + fun AxisAlignedBB.isPlayerInside() = isInside(playerLocation()) fun LorenzVec.canBeSeen(radius: Double = 150.0): Boolean { val a = playerEyeLocation() |