aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorappable <enzospiacitelli@gmail.com>2024-05-28 23:47:36 -0700
committerGitHub <noreply@github.com>2024-05-29 08:47:36 +0200
commitf6a31d6a3f6caf1ad3476f9019b8bd278d7e1c3d (patch)
treefdbba96ae6f3a67caa45bf88cabf826f910d4f82 /src/main
parentc8043a2c0b4dbd0733a316f2ed9b4f8c8d605056 (diff)
downloadskyhanni-f6a31d6a3f6caf1ad3476f9019b8bd278d7e1c3d.tar.gz
skyhanni-f6a31d6a3f6caf1ad3476f9019b8bd278d7e1c3d.tar.bz2
skyhanni-f6a31d6a3f6caf1ad3476f9019b8bd278d7e1c3d.zip
Feature: Last farmed location waypoint (#1335)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/CropStartLocationConfig.java26
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenStartLocation.kt45
3 files changed, 69 insertions, 5 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/CropStartLocationConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/CropStartLocationConfig.java
index dc81a0063..048ae4f89 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/CropStartLocationConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/CropStartLocationConfig.java
@@ -3,14 +3,38 @@ package at.hannibal2.skyhanni.config.features.garden;
import at.hannibal2.skyhanni.config.FeatureToggle;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
+import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
public class CropStartLocationConfig {
@Expose
- @ConfigOption(name = "Enable", desc = "Show the start waypoint for the farm of your current tool in hand. Do §e/shcropstartlocation §7to change the waypoint again.")
+ @ConfigOption(name = "Enable", desc = "Show waypoints for the farm of your current tool in hand. ")
@ConfigEditorBoolean
@FeatureToggle
public boolean enabled = false;
+ @Expose
+ @ConfigOption(name = "Crop Location Mode", desc = "Whether to show waypoint at start location (set with §e/shcropstartlocation §7) or last farmed location.")
+ @ConfigEditorDropdown
+ public CropLocationMode mode = CropLocationMode.START;
+
+ public enum CropLocationMode {
+ START("Start Only"),
+ LAST_FARMED("Last Farmed Only"),
+ BOTH("Both"),
+ ;
+
+ private final String str;
+
+ CropLocationMode(String str) {
+ this.str = str;
+ }
+
+ @Override
+ public String toString() {
+ return str;
+ }
+ }
+
}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java
index 91484305e..e5127faf5 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java
@@ -318,6 +318,9 @@ public class ProfileSpecificStorage {
public Map<CropType, LorenzVec> cropStartLocations = new HashMap<>();
@Expose
+ public Map<CropType, LorenzVec> cropLastFarmedLocations = new HashMap<>();
+
+ @Expose
public Map<CropType, FarmingLane> farmingLanes = new HashMap<>();
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenStartLocation.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenStartLocation.kt
index b746e03ea..9188b66eb 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenStartLocation.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/GardenStartLocation.kt
@@ -1,18 +1,23 @@
package at.hannibal2.skyhanni.features.garden.farming
+import at.hannibal2.skyhanni.config.features.garden.CropStartLocationConfig.CropLocationMode
+import at.hannibal2.skyhanni.data.ClickType
import at.hannibal2.skyhanni.events.CropClickEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LocationUtils
+import at.hannibal2.skyhanni.utils.LocationUtils.distanceSqToPlayer
import at.hannibal2.skyhanni.utils.LorenzColor
+import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
object GardenStartLocation {
private val config get() = GardenAPI.config.cropStartLocation
+ private var shouldShowLastFarmedWaypoint = false
fun setLocationCommand() {
if (!GardenAPI.inGarden()) {
@@ -46,7 +51,9 @@ object GardenStartLocation {
@SubscribeEvent
fun onCropClick(event: CropClickEvent) {
if (!isEnabled()) return
+ if (event.clickType != ClickType.LEFT_CLICK || !GardenAPI.hasFarmingToolInHand()) return
val startLocations = GardenAPI.storage?.cropStartLocations ?: return
+ val lastFarmedLocations = GardenAPI.storage?.cropLastFarmedLocations ?: return
val crop = GardenAPI.getCurrentlyFarmedCrop() ?: return
if (crop != GardenCropSpeed.lastBrokenCrop) return
@@ -54,18 +61,48 @@ object GardenStartLocation {
startLocations[crop] = LocationUtils.playerLocation()
ChatUtils.chat("Auto updated your Crop Start Location for ${crop.cropName}")
}
+
+ lastFarmedLocations[crop] = LorenzVec.getBlockBelowPlayer().add(0.0, 1.0, 0.0)
+ shouldShowLastFarmedWaypoint = false
}
@SubscribeEvent
fun onRenderWorld(event: LorenzRenderWorldEvent) {
if (!isEnabled()) return
- val startLocations = GardenAPI.storage?.cropStartLocations ?: return
val crop = GardenAPI.cropInHand ?: return
- val location = startLocations[crop]?.add(-0.5, 0.5, -0.5) ?: return
- event.drawWaypointFilled(location, LorenzColor.WHITE.toColor())
- event.drawDynamicText(location, crop.cropName, 1.5)
+ if (showStartWaypoint()) {
+ GardenAPI.storage?.cropStartLocations?.get(crop)
+ ?.roundLocationToBlock()
+ ?.also {
+ event.drawWaypointFilled(it, LorenzColor.WHITE.toColor())
+ event.drawDynamicText(it, "§b${crop.cropName}", 1.5)
+ if (shouldShowBoth()) {
+ event.drawDynamicText(it, "§aStart Location", 1.1, yOff = 12f)
+ }
+ }
+ }
+
+ if (showLastFarmedWaypoint()) {
+ val location = GardenAPI.storage?.cropLastFarmedLocations?.get(crop)
+ if (location != null) {
+ if (location.distanceSqToPlayer() >= 100.0) {
+ shouldShowLastFarmedWaypoint = true
+ }
+ if (shouldShowLastFarmedWaypoint) {
+ event.drawWaypointFilled(location, LorenzColor.LIGHT_PURPLE.toColor(), seeThroughBlocks = true, beacon = true)
+ event.drawDynamicText(location, "§b${crop.cropName}", 1.5)
+ if (shouldShowBoth()) {
+ event.drawDynamicText(location, "§eLast Farmed", 1.1, yOff = 12f)
+ }
+ }
+ }
+ }
}
+ private fun shouldShowBoth() = config.mode == CropLocationMode.BOTH
+ private fun showStartWaypoint() = config.mode != CropLocationMode.LAST_FARMED
+ private fun showLastFarmedWaypoint() = config.mode != CropLocationMode.START
+
fun isEnabled() = GardenAPI.inGarden() && config.enabled
}