From 9653e0d13514ed528df486741828267a8b5227f8 Mon Sep 17 00:00:00 2001 From: HiZe Date: Mon, 22 Jan 2024 19:28:55 +0100 Subject: Add: Draw box around Sulphur Block (#810) Added Sulphur Skitter Box in Crimson Isle #810 --- .../skyhanni/features/fishing/FishingAPI.kt | 2 +- .../skyhanni/features/nether/SulphurSkitterBox.kt | 114 +++++++++++++++++++++ 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/nether/SulphurSkitterBox.kt (limited to 'src/main/java/at/hannibal2/skyhanni/features') 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() + private var spongeBlocks = listOf() + 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("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) +} -- cgit