Skip to content

Commit

Permalink
Improvement: Line to goblin (#2717)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <[email protected]>
  • Loading branch information
Thunderblade73 and hannibal002 authored Oct 13, 2024
1 parent c31bef7 commit 6609f21
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public class MiningConfig {
public boolean highlightYourGoldenGoblin = true;

@Expose
@ConfigOption(name = "Line to your Golden Goblin", desc = "Also makes a line to your goblin. §eNeeds the option above to work.")
@ConfigEditorBoolean
public boolean lineToYourGoldenGoblin = false;

@ConfigOption(name = "Precision Mining Helper", desc = "Draws a box over the Precision Mining particles.")
@ConfigEditorBoolean
@FeatureToggle
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/data/mob/LineToMobHandler.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package at.hannibal2.skyhanni.data.mob

import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.events.MobEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color

@SkyHanniModule
object LineToMobHandler {

data class LineSettings(
val color: Color,
val width: Int,
val depth: Boolean,
)

private val lines = mutableMapOf<Mob, LineSettings>()

fun register(mob: Mob, color: Color, width: Int, depth: Boolean) = register(mob, LineSettings(color, width, depth))

fun register(mob: Mob, settings: LineSettings) {
lines[mob] = settings
}

@SubscribeEvent
fun onMobDeSpawn(event: MobEvent.DeSpawn) {
lines.remove(event.mob)
}

@SubscribeEvent
fun onLorenzRenderWorld(event: LorenzRenderWorldEvent) {
if (!LorenzUtils.inSkyBlock) return
if (lines.isEmpty()) return
RenderUtils.LineDrawer.draw3D(event.partialTicks) {
for ((mob, settings) in lines) {
if (!mob.canBeSeen()) continue
draw3DLineFromPlayer(mob.centerCords, settings.color, settings.width, settings.depth)
}
}
}
}
7 changes: 5 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/data/mob/Mob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.toSingletonListOrEmpty
import at.hannibal2.skyhanni.utils.ColorUtils.addAlpha
import at.hannibal2.skyhanni.utils.EntityUtils.canBeSeen
import at.hannibal2.skyhanni.utils.EntityUtils.cleanName
import at.hannibal2.skyhanni.utils.EntityUtils.getArmorInventory
import at.hannibal2.skyhanni.utils.EntityUtils.isCorrupted
import at.hannibal2.skyhanni.utils.EntityUtils.isRunic
import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LocationUtils.getCenter
import at.hannibal2.skyhanni.utils.LocationUtils.union
import at.hannibal2.skyhanni.utils.MobUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.entity.monster.EntityZombie
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.util.AxisAlignedBB
import java.awt.Color
import java.util.UUID
Expand Down Expand Up @@ -228,6 +227,8 @@ class Mob(
internalHighlight()
}

val centerCords get() = boundingBox.getCenter()

override fun hashCode() = id.hashCode()

override fun toString(): String = "$name - ${baseEntity.entityId}"
Expand All @@ -238,4 +239,6 @@ class Mob(

return id == other.id
}

fun lineToPlayer(color: Color, lineWidth: Int = 2, depth: Boolean = true) = LineToMobHandler.register(this, color, lineWidth, depth)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import kotlin.time.Duration.Companion.seconds
@SkyHanniModule
object GoldenGoblinHighlight {

private val config get() = SkyHanniMod.feature.mining.highlightYourGoldenGoblin
private val config get() = SkyHanniMod.feature.mining

private val goblinPattern by RepoPattern.pattern("mining.mob.golden.goblin", "Golden Goblin|Diamond Goblin")

private fun isEnabled() = LorenzUtils.inMiningIsland() && config
private fun isEnabled() = LorenzUtils.inMiningIsland() && config.highlightYourGoldenGoblin

private val timeOut = 10.seconds

Expand Down Expand Up @@ -48,10 +48,16 @@ object GoldenGoblinHighlight {
}

private fun handle() {
// TODO merge the two time objects into one
if (lastChatMessage.passedSince() > timeOut || lastGoblinSpawn.passedSince() > timeOut) return
lastChatMessage = SimpleTimeMark.farPast()
lastGoblinSpawn = SimpleTimeMark.farPast()
lastGoblin?.highlight(LorenzColor.GREEN.toColor())

val goblin = lastGoblin ?: return
goblin.highlight(LorenzColor.GREEN.toColor())
if (config.lineToYourGoldenGoblin) {
goblin.lineToPlayer(LorenzColor.GREEN.toColor())
}
lastGoblin = null
}

Expand Down
15 changes: 10 additions & 5 deletions src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,10 @@ object RenderUtils {
}
}

class LineDrawer @PublishedApi internal constructor(val tessellator: Tessellator) {
class LineDrawer @PublishedApi internal constructor(val tessellator: Tessellator, val inverseView: LorenzVec) {

val worldRenderer = tessellator.worldRenderer

fun drawPath(path: List<LorenzVec>, color: Color, lineWidth: Int, depth: Boolean, bezierPoint: Double = 1.0) {
if (bezierPoint < 0) {
path.zipWithNext().forEach {
Expand Down Expand Up @@ -1380,6 +1382,9 @@ object RenderUtils {
}
}

fun draw3DLineFromPlayer(lorenzVec: LorenzVec, color: Color, lineWidth: Int, depth: Boolean) =
draw3DLine(inverseView.add(y = Minecraft.getMinecraft().thePlayer.eyeHeight.toDouble()), lorenzVec, color, lineWidth, depth)

fun drawBezier2(
p1: LorenzVec,
p2: LorenzVec,
Expand Down Expand Up @@ -1426,7 +1431,7 @@ object RenderUtils {
companion object {
inline fun draw3D(
partialTicks: Float = 0F,
crossinline quads: LineDrawer.() -> Unit,
crossinline draws: LineDrawer.() -> Unit,
) {

GlStateManager.enableBlend()
Expand All @@ -1439,10 +1444,10 @@ object RenderUtils {
val tessellator = Tessellator.getInstance()

GlStateManager.pushMatrix()
RenderUtils.translate(getViewerPos(partialTicks).negated())
getViewerPos(partialTicks)
val inverseView = getViewerPos(partialTicks)
RenderUtils.translate(inverseView.negated())

quads.invoke(LineDrawer(Tessellator.getInstance()))
draws.invoke(LineDrawer(Tessellator.getInstance(), inverseView))

GlStateManager.popMatrix()

Expand Down

0 comments on commit 6609f21

Please sign in to comment.