aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorHiZe <superhize@hotmail.com>2024-01-22 19:28:55 +0100
committerGitHub <noreply@github.com>2024-01-22 19:28:55 +0100
commit9653e0d13514ed528df486741828267a8b5227f8 (patch)
tree50905d84b51e88368736cf14a89e005111ae7410 /src/main/java/at/hannibal2/skyhanni/features
parent09045cb73ba548ca156224d1f5b3bf076f184bc0 (diff)
downloadskyhanni-9653e0d13514ed528df486741828267a8b5227f8.tar.gz
skyhanni-9653e0d13514ed528df486741828267a8b5227f8.tar.bz2
skyhanni-9653e0d13514ed528df486741828267a8b5227f8.zip
Add: Draw box around Sulphur Block (#810)
Added Sulphur Skitter Box in Crimson Isle #810
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/nether/SulphurSkitterBox.kt114
2 files changed, 115 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt
index 6edc1be10..abcf3a234 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingAPI.kt
@@ -28,7 +28,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
object FishingAPI {
- private val lavaBlocks = listOf(Blocks.lava, Blocks.flowing_lava)
+ val lavaBlocks = listOf(Blocks.lava, Blocks.flowing_lava)
private val waterBlocks = listOf(Blocks.water, Blocks.flowing_water)
var lastCastTime = SimpleTimeMark.farPast()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/SulphurSkitterBox.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/SulphurSkitterBox.kt
new file mode 100644
index 000000000..3d4beaae2
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/nether/SulphurSkitterBox.kt
@@ -0,0 +1,114 @@
+package at.hannibal2.skyhanni.features.nether
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.config.features.crimsonisle.SulphurSkitterBoxConfig
+import at.hannibal2.skyhanni.data.IslandType
+import at.hannibal2.skyhanni.data.jsonobjects.repo.ItemsJson
+import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
+import at.hannibal2.skyhanni.events.LorenzTickEvent
+import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.events.RepositoryReloadEvent
+import at.hannibal2.skyhanni.features.fishing.FishingAPI
+import at.hannibal2.skyhanni.utils.BlockUtils.getBlockAt
+import at.hannibal2.skyhanni.utils.InventoryUtils
+import at.hannibal2.skyhanni.utils.LocationUtils
+import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
+import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
+import at.hannibal2.skyhanni.utils.NEUInternalName
+import at.hannibal2.skyhanni.utils.RenderUtils
+import at.hannibal2.skyhanni.utils.RenderUtils.expandBlock
+import at.hannibal2.skyhanni.utils.SpecialColour
+import at.hannibal2.skyhanni.utils.toLorenzVec
+import net.minecraft.init.Blocks
+import net.minecraft.util.AxisAlignedBB
+import net.minecraft.util.BlockPos
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.awt.Color
+
+class SulphurSkitterBox {
+
+ private val config get() = SkyHanniMod.feature.crimsonIsle.sulphurSkitterBoxConfig
+ private var rods = listOf<NEUInternalName>()
+ private var spongeBlocks = listOf<BlockPos>()
+ private var closestBlock: BlockPos? = null
+ private val radius = 8
+
+ @SubscribeEvent
+ fun onTick(event: LorenzTickEvent) {
+ if (!isEnabled()) return
+ if (event.isMod(5)) {
+ closestBlock = getClosestBlockToPlayer()
+ }
+ if (event.repeatSeconds(1)) {
+ val location = LocationUtils.playerLocation()
+ val from = location.add(-20, -20, -20).toBlockPos()
+ val to = location.add(20, 20, 20).toBlockPos()
+
+ spongeBlocks = BlockPos.getAllInBox(from, to).filter {
+ val b = it.toLorenzVec().getBlockAt()
+ b == Blocks.sponge && it.toLorenzVec().distanceToPlayer() <= 15
+ }.filter {
+ val pos1 = it.add(-radius, -radius, -radius)
+ val pos2 = it.add(radius, radius, radius)
+ BlockPos.getAllInBox(pos1, pos2).any { pos ->
+ pos.toLorenzVec().getBlockAt() in FishingAPI.lavaBlocks
+ }
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onWorldChange(event: LorenzWorldChangeEvent) {
+ spongeBlocks = emptyList()
+ }
+
+ @SubscribeEvent
+ fun onRenderWorld(event: LorenzRenderWorldEvent) {
+ if (!isEnabled()) return
+ closestBlock?.let {
+ if (it.toLorenzVec().distanceToPlayer() >= 50) return
+ val pos1 = it.add(-radius, -radius, -radius)
+ val pos2 = it.add(radius, radius, radius)
+ val axis = AxisAlignedBB(pos1, pos2).expandBlock()
+
+ drawBox(axis, event.partialTicks)
+ }
+ }
+
+ private fun getClosestBlockToPlayer(): BlockPos? {
+ return spongeBlocks.minByOrNull { it.toLorenzVec().distanceToPlayer() }
+ }
+
+ private fun drawBox(axis: AxisAlignedBB, partialTicks: Float) {
+ val color = Color(SpecialColour.specialToChromaRGB(config.boxColor), true)
+ when (config.boxType) {
+ SulphurSkitterBoxConfig.BoxType.FULL -> {
+ RenderUtils.drawFilledBoundingBox_nea(axis,
+ color,
+ partialTicks = partialTicks,
+ renderRelativeToCamera = false)
+ }
+
+ SulphurSkitterBoxConfig.BoxType.WIREFRAME -> {
+ RenderUtils.drawWireframeBoundingBox_nea(axis, color, partialTicks)
+ }
+
+ else -> {
+ RenderUtils.drawWireframeBoundingBox_nea(axis, color, partialTicks)
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onRepoReload(event: RepositoryReloadEvent) {
+ val data = event.getConstant<ItemsJson>("Items")
+ rods = data.lava_fishing_rods ?: emptyList()
+
+ if (rods.isEmpty()) {
+ error("§cConstants Items is missing data, please use /shupdaterepo")
+ }
+ }
+
+ fun isEnabled() =
+ IslandType.CRIMSON_ISLE.isInIsland() && config.enabled && (!config.onlyWithRods || InventoryUtils.itemInHandId in rods)
+}