Skip to content

Commit

Permalink
feat: block clicks on alignment task solver
Browse files Browse the repository at this point in the history
  • Loading branch information
My-Name-Is-Jeff committed Jan 17, 2024
1 parent 95ebab6 commit 3c818ee
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/main/kotlin/gg/skytils/skytilsmod/core/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,13 @@ object Config : Vigilant(
)
var alignmentTerminalSolver = false

@Property(
type = PropertyType.SWITCH, name = "Predict Clicks for Alignment Solver",
description = "Predict the amount of clicks needed on the device in Floor 7.",
category = "Dungeons", subcategory = "Terminal Solvers"
)
var predictAlignmentClicks = false

@Property(
type = PropertyType.SWITCH, name = "Shoot the Target Solver",
description = "Shows all the shot blocks on the device in Floor 7.",
Expand Down Expand Up @@ -2983,6 +2990,7 @@ object Config : Vigilant(
addDependency("clickInOrderThird", "clickInOrderTerminalSolver")
addDependency("changeToSameColorMode", "changeAllSameColorTerminalSolver")
addDependency("lividFinderType", "findCorrectLivid")
addDependency("predictAlignmentClicks", "alignmentTaskSolver")

listOf(
"emptyBurrowColor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,26 @@ import gg.essential.universal.UMatrixStack
import gg.skytils.skytilsmod.Skytils
import gg.skytils.skytilsmod.Skytils.Companion.mc
import gg.skytils.skytilsmod.core.tickTimer
import gg.skytils.skytilsmod.events.impl.PacketEvent
import gg.skytils.skytilsmod.features.impl.dungeons.DungeonFeatures
import gg.skytils.skytilsmod.features.impl.dungeons.DungeonTimer
import gg.skytils.skytilsmod.utils.*
import gg.skytils.skytilsmod.utils.RenderUtil
import gg.skytils.skytilsmod.utils.SuperSecretSettings
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.middleVec
import net.minecraft.entity.item.EntityItemFrame
import net.minecraft.init.Blocks
import net.minecraft.init.Items
import net.minecraft.item.Item
import net.minecraft.network.play.client.C02PacketUseEntity
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumFacing
import net.minecraft.util.Vec3
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.awt.Color
import java.awt.Point
import java.util.*
import kotlin.math.floor
import kotlin.random.Random

object AlignmentTaskSolver {
Expand All @@ -55,8 +58,8 @@ object AlignmentTaskSolver {
}

private val grid = LinkedHashSet<MazeSpace>()

private val directionSet = HashMap<Point, Int>()
private val clicks = HashMap<BlockPos, Int>()

init {
tickTimer(20, repeats = true) {
Expand Down Expand Up @@ -106,22 +109,46 @@ object AlignmentTaskSolver {
}
}
}
tickTimer(5, repeats = true) {
for (space in grid) {
if (space.type != SpaceType.PATH || space.framePos == null) continue
val frame =
(mc.theWorld.loadedEntityList.find { it is EntityItemFrame && it.hangingPosition == space.framePos }
?: continue) as EntityItemFrame
val neededClicks = if (!SuperSecretSettings.bennettArthur) (directionSet.getOrElse(space.coords) { 0 } - frame.rotation + 8) % 8 else Random.nextInt(8)
clicks[space.framePos] = neededClicks
}
}
}

@SubscribeEvent
fun onPacket(event: PacketEvent) {
if (directionSet.isNotEmpty() && Skytils.config.alignmentTerminalSolver && Skytils.config.blockIncorrectTerminalClicks) {
if (event.packet is C02PacketUseEntity && event.packet.action == C02PacketUseEntity.Action.INTERACT) {
val entity = event.packet.getEntityFromWorld(mc.theWorld) ?: return
if (entity !is EntityItemFrame) return
val needed = clicks[entity.hangingPosition] ?: return
if (needed == 0) event.isCanceled = true
else {
val blockBehind = mc.theWorld.getBlockState(entity.hangingPosition.offset(entity.facingDirection.opposite))
if (blockBehind.block == Blocks.sea_lantern) event.isCanceled = true
}

if (!event.isCanceled && Skytils.config.predictAlignmentClicks) {
clicks[entity.hangingPosition] = (needed - 1 + 8) % 8
}
}
}
}

@SubscribeEvent
fun onRenderWorld(event: RenderWorldLastEvent) {
val matrixStack = UMatrixStack()
for (space in grid) {
if (space.type != SpaceType.PATH || space.framePos == null) continue
val frame =
(mc.theWorld.loadedEntityList.find { it is EntityItemFrame && it.hangingPosition == space.framePos }
?: continue) as EntityItemFrame
var neededClicks =
if (!SuperSecretSettings.bennettArthur) directionSet.getOrElse(space.coords) { 0 } - frame.rotation else Random.nextInt(
8
)
val neededClicks = clicks[space.framePos] ?: continue
if (neededClicks == 0) continue
if (neededClicks < 0) neededClicks += 8

RenderUtil.drawLabel(
space.framePos.middleVec(),
neededClicks.toString(),
Expand Down

0 comments on commit 3c818ee

Please sign in to comment.