aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorHiZe_ <superhize@hotmail.com>2023-12-01 02:05:31 +0100
committerGitHub <noreply@github.com>2023-12-01 02:05:31 +0100
commitaef7ba127c67950a685fead8a79c3daf7fa23e4b (patch)
tree0320ea2e5b9badb305a43270c476375d68262eab /src/main
parent25fb97e316095ae922fb9bcb23fc2026b3a85d37 (diff)
downloadskyhanni-aef7ba127c67950a685fead8a79c3daf7fa23e4b.tar.gz
skyhanni-aef7ba127c67950a685fead8a79c3daf7fa23e4b.tar.bz2
skyhanni-aef7ba127c67950a685fead8a79c3daf7fa23e4b.zip
Add: Draw Plot border when holding Sprayonator (#747)
Draw plots border when holding the Sprayonator. #747
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java8
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt86
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotBorders.kt88
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayFeatures.kt15
5 files changed, 113 insertions, 90 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java
index a1026bd6c..da715712f 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/pests/SprayConfig.java
@@ -11,12 +11,18 @@ public class SprayConfig {
@Expose
@ConfigOption(
name = "Pest Spray Selector",
- desc = "Show the pests that are attracted when changing the selected material of the §aSprayanator§7."
+ desc = "Show the pests that are attracted when changing the selected material of the §aSprayonator§7."
)
@ConfigEditorBoolean
@FeatureToggle
public boolean pestWhenSelector = true;
@Expose
+ @ConfigOption(name = "Draw Plot Border", desc = "Draw plots border when holding the Sprayonator.")
+ @ConfigEditorBoolean
+ @FeatureToggle
+ public boolean drawPlotsBorderWhenInHands = true;
+
+ @Expose
public Position position = new Position(315, -200, 2.3f);
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt
index 0fd984346..4131ad60f 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotAPI.kt
@@ -1,15 +1,19 @@
package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.features.misc.LockMouseLook
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LocationUtils.isPlayerInside
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzVec
+import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import com.google.gson.annotations.Expose
import net.minecraft.util.AxisAlignedBB
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.awt.Color
+import kotlin.math.floor
object GardenPlotAPI {
@@ -99,4 +103,86 @@ object GardenPlotAPI {
}
fun getPlotByName(plotName: String) = plots.firstOrNull { it.name == plotName }
+
+ fun LorenzRenderWorldEvent.renderPlot(plot: GardenPlotAPI.Plot, lineColor: Color, cornerColor: Color) {
+
+ // These don't refer to Minecraft chunks but rather garden plots, but I use
+ // the word chunk as the logic closely represents how chunk borders are rendered in latter mc versions
+ val plotSize = 96
+ val chunkX = floor((plot.middle.x + 48) / plotSize).toInt()
+ val chunkZ = floor((plot.middle.z + 48) / plotSize).toInt()
+ val chunkMinX = (chunkX * plotSize) - 48
+ val chunkMinZ = (chunkZ * plotSize) - 48
+
+ // Lowest point in the garden
+ val minHeight = 66
+ val maxHeight = 256
+
+ // Render 4 vertical corners
+ for (i in 0..plotSize step plotSize) {
+ for (j in 0..plotSize step plotSize) {
+ val start = LorenzVec(chunkMinX + i, minHeight, chunkMinZ + j)
+ val end = LorenzVec(chunkMinX + i, maxHeight, chunkMinZ + j)
+ tryDraw3DLine(start, end, cornerColor, 2, true)
+ }
+ }
+
+ // Render vertical on X-Axis
+ for (x in 4..<plotSize step 4) {
+ val start = LorenzVec(chunkMinX + x, minHeight, chunkMinZ)
+ val end = LorenzVec(chunkMinX + x, maxHeight, chunkMinZ)
+ // Front lines
+ tryDraw3DLine(start, end, lineColor, 1, true)
+ // Back lines
+ tryDraw3DLine(start.addZ(plotSize), end.addZ(plotSize), lineColor, 1, true)
+ }
+
+ // Render vertical on Z-Axis
+ for (z in 4..<plotSize step 4) {
+ val start = LorenzVec(chunkMinX, minHeight, chunkMinZ + z)
+ val end = LorenzVec(chunkMinX, maxHeight, chunkMinZ + z)
+ // Left lines
+ tryDraw3DLine(start, end, lineColor, 1, true)
+ // Right lines
+ tryDraw3DLine(start.addX(plotSize), end.addX(plotSize), lineColor, 1, true)
+ }
+
+ // Render horizontal
+ for (y in minHeight..maxHeight step 4) {
+ val start = LorenzVec(chunkMinX, y, chunkMinZ)
+ // (minX, minZ) -> (minX, minZ + 96)
+ tryDraw3DLine(start, start.addZ(plotSize), lineColor, 1, true)
+ // (minX, minZ + 96) -> (minX + 96, minZ + 96)
+ tryDraw3DLine(start.addZ(plotSize), start.addXZ(plotSize, plotSize), lineColor, 1, true)
+ // (minX + 96, minZ + 96) -> (minX + 96, minZ)
+ tryDraw3DLine(start.addXZ(plotSize, plotSize), start.addX(plotSize), lineColor, 1, true)
+ // (minX + 96, minZ) -> (minX, minZ)
+ tryDraw3DLine(start.addX(plotSize), start, lineColor, 1, true)
+ }
+ }
+
+ private fun LorenzRenderWorldEvent.tryDraw3DLine(
+ p1: LorenzVec,
+ p2: LorenzVec,
+ color: Color,
+ lineWidth: Int,
+ depth: Boolean
+ ) {
+ if (isOutOfBorders(p1)) return
+ if (isOutOfBorders(p2)) return
+ draw3DLine(p1, p2, color, lineWidth, depth)
+ }
+
+ private fun isOutOfBorders(location: LorenzVec) = when {
+ location.x > 240 -> true
+ location.x < -240 -> true
+ location.z > 240 -> true
+ location.z < -240 -> true
+
+ else -> false
+ }
+
+ private fun LorenzVec.addX(x: Int) = add(x, 0, 0)
+ private fun LorenzVec.addZ(z: Int) = add(0, 0, z)
+ private fun LorenzVec.addXZ(x: Int, z: Int) = add(x, 0, z)
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotBorders.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotBorders.kt
index 7ab485aa8..893e31cbf 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotBorders.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenPlotBorders.kt
@@ -2,14 +2,11 @@ package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.events.LorenzKeyPressEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
+import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.renderPlot
import at.hannibal2.skyhanni.utils.LorenzColor
-import at.hannibal2.skyhanni.utils.LorenzVec
-import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.input.Keyboard
-import java.awt.Color
-import kotlin.math.floor
import kotlin.time.Duration.Companion.milliseconds
object GardenPlotBorders {
@@ -18,10 +15,6 @@ object GardenPlotBorders {
private var timeLastSaved = SimpleTimeMark.farPast()
private var showBorders = false
- private fun LorenzVec.addX(x: Int) = add(x, 0, 0)
- private fun LorenzVec.addZ(z: Int) = add(0, 0, z)
- private fun LorenzVec.addXZ(x: Int, z: Int) = add(x, 0, z)
-
@SubscribeEvent
fun onKeyClick(event: LorenzKeyPressEvent) {
if (!isEnabled()) return
@@ -42,86 +35,9 @@ object GardenPlotBorders {
if (!isEnabled()) return
if (!showBorders) return
val plot = GardenPlotAPI.getCurrentPlot() ?: return
- event.render(plot, LorenzColor.YELLOW.toColor(), LorenzColor.DARK_BLUE.toColor())
+ event.renderPlot(plot, LorenzColor.YELLOW.toColor(), LorenzColor.DARK_BLUE.toColor())
}
- fun LorenzRenderWorldEvent.render(plot: GardenPlotAPI.Plot, lineColor: Color, cornerColor: Color) {
-
- // These don't refer to Minecraft chunks but rather garden plots, but I use
- // the word chunk as the logic closely represents how chunk borders are rendered in latter mc versions
- val plotSize = 96
- val chunkX = floor((plot.middle.x + 48) / plotSize).toInt()
- val chunkZ = floor((plot.middle.z + 48) / plotSize).toInt()
- val chunkMinX = (chunkX * plotSize) - 48
- val chunkMinZ = (chunkZ * plotSize) - 48
-
- // Lowest point in the garden
- val minHeight = 66
- val maxHeight = 256
-
- // Render 4 vertical corners
- for (i in 0..plotSize step plotSize) {
- for (j in 0..plotSize step plotSize) {
- val start = LorenzVec(chunkMinX + i, minHeight, chunkMinZ + j)
- val end = LorenzVec(chunkMinX + i, maxHeight, chunkMinZ + j)
- tryDraw3DLine(start, end, cornerColor, 2, true)
- }
- }
-
- // Render vertical on X-Axis
- for (x in 4..<plotSize step 4) {
- val start = LorenzVec(chunkMinX + x, minHeight, chunkMinZ)
- val end = LorenzVec(chunkMinX + x, maxHeight, chunkMinZ)
- // Front lines
- tryDraw3DLine(start, end, lineColor, 1, true)
- // Back lines
- tryDraw3DLine(start.addZ(plotSize), end.addZ(plotSize), lineColor, 1, true)
- }
-
- // Render vertical on Z-Axis
- for (z in 4..<plotSize step 4) {
- val start = LorenzVec(chunkMinX, minHeight, chunkMinZ + z)
- val end = LorenzVec(chunkMinX, maxHeight, chunkMinZ + z)
- // Left lines
- tryDraw3DLine(start, end, lineColor, 1, true)
- // Right lines
- tryDraw3DLine(start.addX(plotSize), end.addX(plotSize), lineColor, 1, true)
- }
-
- // Render horizontal
- for (y in minHeight..maxHeight step 4) {
- val start = LorenzVec(chunkMinX, y, chunkMinZ)
- // (minX, minZ) -> (minX, minZ + 96)
- tryDraw3DLine(start, start.addZ(plotSize), lineColor, 1, true)
- // (minX, minZ + 96) -> (minX + 96, minZ + 96)
- tryDraw3DLine(start.addZ(plotSize), start.addXZ(plotSize, plotSize), lineColor, 1, true)
- // (minX + 96, minZ + 96) -> (minX + 96, minZ)
- tryDraw3DLine(start.addXZ(plotSize, plotSize), start.addX(plotSize), lineColor, 1, true)
- // (minX + 96, minZ) -> (minX, minZ)
- tryDraw3DLine(start.addX(plotSize), start, lineColor, 1, true)
- }
- }
-
- private fun LorenzRenderWorldEvent.tryDraw3DLine(
- p1: LorenzVec,
- p2: LorenzVec,
- color: Color,
- lineWidth: Int,
- depth: Boolean
- ) {
- if (isOutOfBorders(p1)) return
- if (isOutOfBorders(p2)) return
- draw3DLine(p1, p2, color, lineWidth, depth)
- }
-
- private fun isOutOfBorders(location: LorenzVec) = when {
- location.x > 240 -> true
- location.x < -240 -> true
- location.z > 240 -> true
- location.z < -240 -> true
-
- else -> false
- }
fun isEnabled() = GardenAPI.inGarden() && config
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt
index 19b794757..dfe34c56c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/PestFinder.kt
@@ -13,8 +13,8 @@ import at.hannibal2.skyhanni.features.garden.GardenPlotAPI
import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.isPlayerInside
import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.name
import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.pests
+import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.renderPlot
import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.sendTeleportTo
-import at.hannibal2.skyhanni.features.garden.GardenPlotBorders.render
import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LocationUtils.distanceSqToPlayer
@@ -182,10 +182,10 @@ class PestFinder {
val playerLocation = event.exactPlayerEyeLocation()
for (plot in getPlotsWithPests()) {
if (plot.isPlayerInside()) {
- event.render(plot, LorenzColor.RED.toColor(), LorenzColor.DARK_RED.toColor())
+ event.renderPlot(plot, LorenzColor.RED.toColor(), LorenzColor.DARK_RED.toColor())
continue
}
- event.render(plot, LorenzColor.GOLD.toColor(), LorenzColor.RED.toColor())
+ event.renderPlot(plot, LorenzColor.GOLD.toColor(), LorenzColor.RED.toColor())
val pestsName = StringUtils.optionalPlural(plot.pests, "pest", "pests")
val plotName = plot.name
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayFeatures.kt
index 8f9fd866f..04501d1f4 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/pests/SprayFeatures.kt
@@ -2,9 +2,16 @@ package at.hannibal2.skyhanni.features.garden.pests
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
+import at.hannibal2.skyhanni.features.garden.GardenPlotAPI
+import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.renderPlot
import at.hannibal2.skyhanni.features.garden.pests.PestAPI.getPests
import at.hannibal2.skyhanni.test.command.ErrorManager
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
+import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
@@ -57,5 +64,13 @@ class SprayFeatures {
config.position.renderString(display, posLabel = "Pest Spray Selector")
}
+ @SubscribeEvent
+ fun onWorldRender(event: LorenzRenderWorldEvent) {
+ if (!config.drawPlotsBorderWhenInHands) return
+ if (!InventoryUtils.itemInHandId.equals("SPRAYONATOR")) return
+ val plot = GardenPlotAPI.getCurrentPlot() ?: return
+ event.renderPlot(plot, LorenzColor.YELLOW.toColor(), LorenzColor.DARK_BLUE.toColor())
+ }
+
fun isEnabled() = LorenzUtils.inSkyBlock && config.pestWhenSelector
}