Skip to content

Commit

Permalink
Refactor ghost nametag rendering and switch clicked secrets list to a…
Browse files Browse the repository at this point in the history
… concurrent queue
  • Loading branch information
odtheking committed Mar 6, 2025
1 parent c8de6d4 commit 7d75900
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public abstract class MixinNetworkPlayerInfo {

@Inject(method = "getLocationCape", at = @At("HEAD"), cancellable = true)
private void getDevCape(CallbackInfoReturnable<ResourceLocation> cir) {
this.locationCape = DevPlayers.INSTANCE.hookGetLocationCape(this.gameProfile);
if (this.locationCape != null) cir.setReturnValue(this.locationCape);
ResourceLocation devCape = DevPlayers.hookGetLocationCape(this.gameProfile);
if (devCape != null) cir.setReturnValue(devCape);
else cir.setReturnValue(this.locationCape);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public abstract class MixinNetworkPlayerInfo {

@Inject(method = "getLocationCape", at = @At("HEAD"), cancellable = true)
private void getDevCape(CallbackInfoReturnable<ResourceLocation> cir) {
this.locationCape = DevPlayers.INSTANCE.hookGetLocationCape(this.gameProfile);
if (this.locationCape != null) cir.setReturnValue(this.locationCape);
ResourceLocation devCape = DevPlayers.hookGetLocationCape(this.gameProfile);
if (devCape != null) cir.setReturnValue(devCape);
else cir.setReturnValue(this.locationCape);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object QueueTerms : Module(
) return
val click = queue.poll()?.takeIf { TerminalSolver.canClick(it.slot, it.button) } ?: return
clickedThisWindow = true
windowClick(slotId = click.slot, if (click.button == 1) ClickType.Right else ClickType.Middle)
windowClick(click.slot, if (click.button == 1) ClickType.Right else ClickType.Middle)
devMessage("Dispatched click on slot ${click.slot}")
lastClickTime = System.currentTimeMillis()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,21 @@ object Ghosts : Module(

@SubscribeEvent
fun onRenderWorldLast(event: RenderWorldLastEvent) {
if (!showGhostNametag) return
creeperList.forEach { entity ->
if (entity.isDead) return@forEach
if (showGhostNametag) drawGhostNameTag(entity)
val isRunic = entity.getSBMaxHealth() == 4000000f
val bracketsColor = if (isRunic) "&5" else "&8"
val lvlColor = if (isRunic) "&d" else "&7"
val nameColor = if (isRunic) "&5" else "&c"
val currentHealthColor = if (isRunic) "&d" else if (entity.health < entity.getSBMaxHealth() / 2) "&e" else "&a"
val maxHealthColor = if (isRunic) "&5" else "&a"
val name = "${bracketsColor}[${lvlColor}Lv250${bracketsColor}] ${nameColor + if (isRunic) "Runic " else ""}Ghost ${currentHealthColor + transformToSuffixedNumber(entity.health) + "&f"}/${maxHealthColor + transformToSuffixedNumber(entity.getSBMaxHealth()) + "&c" + ""}".replace("&", "§")

Renderer.drawStringInWorld(name, entity.renderVec.addVec(y = entity.height + 0.5), Color.WHITE, depth = false)
}
}

private fun drawGhostNameTag(creeper: EntityCreeper) {
val isRunic = creeper.getSBMaxHealth() == 4000000f
val bracketsColor = if (isRunic) "&5" else "&8"
val lvlColor = if (isRunic) "&d" else "&7"
val nameColor = if (isRunic) "&5" else "&c"
val currentHealthColor = if (isRunic) "&d" else if (creeper.health < creeper.getSBMaxHealth() / 2) "&e" else "&a"
val maxHealthColor = if (isRunic) "&5" else "&a"
val name = "${bracketsColor}[${lvlColor}Lv250${bracketsColor}] ${nameColor + if (isRunic) "Runic " else ""}Ghost ${currentHealthColor + transformToSuffixedNumber(creeper.health) + "&f"}/${maxHealthColor + transformToSuffixedNumber(creeper.getSBMaxHealth()) + "&c" + ""}".replace("&", "§")

Renderer.drawStringInWorld(name, creeper.renderVec.addVec(y = creeper.height + 0.5), Color.WHITE, depth = false)
}

private fun transformToSuffixedNumber(number: Float): String {
val result = if (number >= 1000000) {
val short = (number / 1000000).toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ object Triggerbot : Module(
}
}
}
val frameGridCorner = Vec3(-2.0, 120.0, 75.0)
private val frameGridCorner = Vec3(-2.0, 120.0, 75.0)

private fun arrowAlignTriggerbot() {
if ((sneakToDisableTriggerbot && mc.thePlayer.isSneaking) || clicksRemaining.isEmpty()) return
val targetFrame = mc.objectMouseOver?.entityHit as? EntityItemFrame ?: return

val targetFramePosition = targetFrame.positionVector.flooredVec()
val frameIndex = ((targetFramePosition.yCoord - frameGridCorner.yCoord) + (targetFramePosition.zCoord - frameGridCorner.zCoord) * 5).toInt()
if (targetFramePosition.xCoord != frameGridCorner.xCoord || currentFrameRotations?.get(frameIndex) == -1 || frameIndex !in 0..24) return
val (x, y, z) = targetFrame.positionVector.flooredVec()
val frameIndex = ((y - frameGridCorner.yCoord) + (z - frameGridCorner.zCoord) * 5).toInt()
if (x != frameGridCorner.xCoord || currentFrameRotations?.get(frameIndex) == -1 || frameIndex !in 0..24) return
clicksRemaining[frameIndex]?.let {
PlayerUtils.rightClick()
triggerBotClock.update()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object LeapMenu : Module(
val type by SelectorSetting("Sorting", "Odin Sorting", arrayListOf("Odin Sorting", "A-Z Class (BetterMap)", "A-Z Name", "Custom sorting", "No Sorting"), description = "How to sort the leap menu.")
private val onlyClass by BooleanSetting("Only Classes", false, description = "Renders classes instead of names.")
private val colorStyle by BooleanSetting("Color Style", false, description = "Which color style to use.")
private val backgroundColor by ColorSetting("Background Color", Color.DARK_GRAY.withAlpha(0.9f), allowAlpha = true, description = "Color of the background of the leap menu.")
private val backgroundColor by ColorSetting("Background Color", Color.DARK_GRAY.withAlpha(0.75f), allowAlpha = true, description = "Color of the background of the leap menu.").withDependency { !colorStyle }
private val roundedRect by BooleanSetting("Rounded Rect", true, description = "Toggles the rounded rect for the gui.")
private val useNumberKeys by BooleanSetting("Use Number Keys", false, description = "Use keyboard keys to leap to the player you want, going from left to right, top to bottom.")
private val topLeftKeybind by KeybindSetting("Top Left", Keyboard.KEY_1, "Used to click on the first person in the leap menu.").withDependency { useNumberKeys }
Expand Down
19 changes: 10 additions & 9 deletions src/main/kotlin/me/odinmain/features/impl/dungeon/SecretClicked.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import me.odinmain.utils.toBlockPos
import net.minecraft.util.BlockPos
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.concurrent.CopyOnWriteArrayList
import java.util.*
import java.util.concurrent.ConcurrentLinkedQueue

object SecretClicked : Module(
name = "Secret Clicked",
Expand Down Expand Up @@ -51,14 +52,14 @@ object SecretClicked : Module(
private val chimeInBoss by BooleanSetting("Chime In Boss", false, description = "Prevent playing the sound if in boss room.").withDependency { chimeDropdownSetting && chime }

private data class Secret(val pos: BlockPos, var locked: Boolean = false)
private val clickedSecretsList = CopyOnWriteArrayList<Secret>()
private val clickedSecretsQueue: Queue<Secret> = ConcurrentLinkedQueue()
private var lastPlayed = System.currentTimeMillis()

@SubscribeEvent
fun onRenderWorld(event: RenderWorldLastEvent) {
if (!boxes || !DungeonUtils.inDungeons || (DungeonUtils.inBoss && !boxInBoss) || clickedSecretsList.isEmpty()) return
if (!boxes || !DungeonUtils.inDungeons || (DungeonUtils.inBoss && !boxInBoss) || clickedSecretsQueue.isEmpty()) return

clickedSecretsList.forEach {
clickedSecretsQueue.forEach {
val currentColor = if (it.locked) lockedColor else color
if (useRealSize) Renderer.drawStyledBlock(it.pos, currentColor, style, lineWidth, depthCheck)
else Renderer.drawStyledBox(it.pos.toAABB(), currentColor, style, lineWidth, depthCheck)
Expand All @@ -82,14 +83,14 @@ object SecretClicked : Module(
}

private fun secretBox(pos: BlockPos) {
if (!boxes || (DungeonUtils.inBoss && !boxInBoss) || clickedSecretsList.any { it.pos == pos }) return
clickedSecretsList.add(Secret(pos))
runIn(timeToStay * 20) { clickedSecretsList.removeFirstOrNull() }
if (!boxes || (DungeonUtils.inBoss && !boxInBoss) || clickedSecretsQueue.any { it.pos == pos }) return
clickedSecretsQueue.add(Secret(pos))
runIn(timeToStay * 20) { clickedSecretsQueue.poll() }
}

init {
onWorldLoad { clickedSecretsList.clear() }
onWorldLoad { clickedSecretsQueue.clear() }

onMessage(Regex("That chest is locked!")) { clickedSecretsList.lastOrNull()?.locked = true }
onMessage(Regex("That chest is locked!")) { clickedSecretsQueue.peek()?.locked = true }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import me.odinmain.features.Category
import me.odinmain.features.Module
import me.odinmain.features.settings.Setting.Companion.withDependency
import me.odinmain.features.settings.impl.BooleanSetting
import me.odinmain.utils.addVec
import me.odinmain.utils.distanceSquaredTo
import me.odinmain.utils.flooredVec
import me.odinmain.utils.*
import me.odinmain.utils.render.Color
import me.odinmain.utils.render.Renderer
import me.odinmain.utils.skyblock.dungeon.DungeonUtils
Expand Down Expand Up @@ -66,9 +64,9 @@ object ArrowAlign : Module(
fun onPacket(event: PacketEvent.Send) {
val packet = event.packet as? C02PacketUseEntity ?: return
if (DungeonUtils.getF7Phase() != M7Phases.P3 || packet.action != C02PacketUseEntity.Action.INTERACT) return
val entityPosition = (packet.getEntityFromWorld(mc.theWorld) as? EntityItemFrame)?.takeIf { it.displayedItem?.item == Items.arrow }?.positionVector?.flooredVec() ?: return
val frameIndex = ((entityPosition.yCoord - frameGridCorner.yCoord) + (entityPosition.zCoord - frameGridCorner.zCoord) * 5).toInt()
if (entityPosition.xCoord != frameGridCorner.xCoord || currentFrameRotations?.get(frameIndex) == -1 || frameIndex !in 0..24) return
val (x, y, z) = (packet.getEntityFromWorld(mc.theWorld) as? EntityItemFrame)?.takeIf { it.displayedItem?.item == Items.arrow }?.positionVector?.flooredVec() ?: return
val frameIndex = ((y - frameGridCorner.yCoord) + (z - frameGridCorner.zCoord) * 5).toInt()
if (x != frameGridCorner.xCoord || currentFrameRotations?.get(frameIndex) == -1 || frameIndex !in 0..24) return

if (!clicksRemaining.containsKey(frameIndex) && mc.thePlayer.isSneaking == invertSneak && blockWrong) {
event.isCanceled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object RubixGui : TermGui() {
}
currentTerm.solution.toSet().forEach { pane ->
val needed = currentTerm.solution.count { it == pane }
val adjusted = if (pane == currentTerm.clickedSlot?.first && hideClicked) when (needed) {
val adjusted = if (hideClicked && pane == currentTerm.clickedSlot?.first) when (needed) {
3 -> 4
4 -> 0
else -> needed - 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object BlockOverlay : Module(

init {
HighlightRenderer.addEntityGetter({ HighlightRenderer.HighlightType.entries[entityMode]}) {
if (!entityToggle) emptyList()
if (!entityToggle || !enabled) emptyList()
else mc.objectMouseOver.entityHit?.takeIf { !it.isInvisible }?.let { listOf(HighlightRenderer.HighlightEntity(it, entityColor, thickness, true, entityStyle)) } ?: emptyList()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ object DevPlayers {
}

@OptIn(ExperimentalEncodingApi::class)
@JvmStatic
fun hookGetLocationCape(gameProfile: GameProfile): ResourceLocation? {
val name = gameProfile.name
val nameEncoded = Base64.encode(name.toByteArray())
Expand Down
7 changes: 3 additions & 4 deletions src/main/kotlin/me/odinmain/features/impl/render/Waypoints.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import me.odinmain.features.settings.impl.BooleanSetting
import me.odinmain.features.settings.impl.DropdownSetting
import me.odinmain.features.settings.impl.KeybindSetting
import me.odinmain.features.settings.impl.NumberSetting
import me.odinmain.utils.PositionLook
import me.odinmain.utils.addVec
import me.odinmain.utils.*
import me.odinmain.utils.render.RenderUtils.renderVec
import me.odinmain.utils.skyblock.EtherWarpHelper
import me.odinmain.utils.skyblock.sendCommand
Expand All @@ -27,8 +26,8 @@ object Waypoints : Module(
private val pingLocation by KeybindSetting("Ping Location Keybind", Keyboard.KEY_NONE, description = "Sends the location you are looking at as coords in chat for waypoints.").onPress {
if (!pingLocationToggle) return@onPress
EtherWarpHelper.getEtherPos(PositionLook(mc.thePlayer.renderVec, mc.thePlayer.rotationYaw, mc.thePlayer.rotationPitch), pingDistance).pos?.let { pos ->
val position = pos.addVec(0.5, 0.5, 0.5)
WaypointManager.addTempWaypoint(x = position.x, y = position.y, z = position.z, time = pingWaypointTime)
val (x, y, z) = pos.addVec(0.5, 0.5, 0.5)
WaypointManager.addTempWaypoint(x = x, y = y, z = z, time = pingWaypointTime)
if (sendPingedLocation) sendCommand("odinwaypoint share ${pos.x} ${pos.y} ${pos.z}", true)
}
}.withDependency { pingLocationToggle && pingLocationDropDown }
Expand Down
15 changes: 9 additions & 6 deletions src/main/kotlin/me/odinmain/utils/VecUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,17 @@ fun isFacingAABB(aabb: AxisAlignedBB, range: Float, yaw: Float = mc.thePlayer?.r
isInterceptable(aabb, range, yaw, pitch)


operator fun Vec3.component1(): Double =
xCoord
operator fun Vec3.component1(): Double = xCoord

operator fun Vec3.component2(): Double =
yCoord
operator fun Vec3.component2(): Double = yCoord

operator fun Vec3.component3(): Double =
zCoord
operator fun Vec3.component3(): Double = zCoord

operator fun Vec3i.component1(): Int = x

operator fun Vec3i.component2(): Int = y

operator fun Vec3i.component3(): Int = z

/**
* Returns true if the given position is being looked at by the player within the given range, ignoring the Y value.
Expand Down

0 comments on commit 7d75900

Please sign in to comment.