feat(chestesp): add initial implementation, halfway done

Adds ChestESP features, only toggles on. There is no off toggle, and
once a block is highlighted it will remain highlighted
This commit is contained in:
illyum 2024-07-23 00:14:42 -06:00
parent f79942969a
commit 3f5e7acc0f
2 changed files with 69 additions and 15 deletions

View File

@ -12,6 +12,7 @@ import net.minecraft.client.settings.KeyBinding
import net.minecraft.command.CommandException import net.minecraft.command.CommandException
import net.minecraft.command.ICommandSender import net.minecraft.command.ICommandSender
import net.minecraft.entity.Entity import net.minecraft.entity.Entity
import net.minecraft.init.Blocks
import net.minecraft.util.AxisAlignedBB import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.BlockPos import net.minecraft.util.BlockPos
import net.minecraft.util.ChatComponentText import net.minecraft.util.ChatComponentText
@ -112,6 +113,7 @@ object STBKeyBinds {
lateinit var finishWaypoints: KeyBinding lateinit var finishWaypoints: KeyBinding
lateinit var clearWaypoints: KeyBinding lateinit var clearWaypoints: KeyBinding
lateinit var openRoutesGui: KeyBinding lateinit var openRoutesGui: KeyBinding
lateinit var xrayChests: KeyBinding
fun init() { fun init() {
addWaypoint = KeyBinding("key.addWaypoint", Keyboard.KEY_ADD, "key.categories.sbt") addWaypoint = KeyBinding("key.addWaypoint", Keyboard.KEY_ADD, "key.categories.sbt")
@ -125,6 +127,9 @@ object STBKeyBinds {
openRoutesGui = KeyBinding("key.openRoutesGui", Keyboard.KEY_O, "key.categories.sbt") openRoutesGui = KeyBinding("key.openRoutesGui", Keyboard.KEY_O, "key.categories.sbt")
ClientRegistry.registerKeyBinding(openRoutesGui) ClientRegistry.registerKeyBinding(openRoutesGui)
xrayChests = KeyBinding("key.xrayToggle", Keyboard.KEY_I, "key.categories.sbt")
ClientRegistry.registerKeyBinding(xrayChests)
} }
} }
@ -148,21 +153,61 @@ class KeyInputHandler {
mc.thePlayer.addChatMessage(ChatComponentText("Point ($x, $y, $z) is already in the route list")) mc.thePlayer.addChatMessage(ChatComponentText("Point ($x, $y, $z) is already in the route list"))
} }
} } else if (STBKeyBinds.finishWaypoints.isPressed) {
else if (STBKeyBinds.finishWaypoints.isPressed) {
mc.thePlayer.addChatMessage(ChatComponentText("Finished route! Copied route to clipboard")) mc.thePlayer.addChatMessage(ChatComponentText("Finished route! Copied route to clipboard"))
val jsonString = Gson().toJson(SkyBlockTweaks.routeList) val jsonString = Gson().toJson(SkyBlockTweaks.routeList)
setClipboard(jsonString) setClipboard(jsonString)
SkyBlockTweaks.routeList.clear() SkyBlockTweaks.routeList.clear()
} } else if (STBKeyBinds.clearWaypoints.isPressed) {
else if (STBKeyBinds.clearWaypoints.isPressed) {
SkyBlockTweaks.routeList.clear() SkyBlockTweaks.routeList.clear()
mc.thePlayer.addChatMessage(ChatComponentText("Reset current route")) mc.thePlayer.addChatMessage(ChatComponentText("Reset current route"))
} } else if (STBKeyBinds.openRoutesGui.isPressed) {
else if (STBKeyBinds.openRoutesGui.isPressed) {
mc.displayGuiScreen(RouteGui()) mc.displayGuiScreen(RouteGui())
} else if (STBKeyBinds.xrayChests.isPressed) {
highlightChests()
} }
} }
private fun highlightChests() {
val searchRadius = 8
val world = Minecraft.getMinecraft().thePlayer.worldObj
val posX = Minecraft.getMinecraft().thePlayer.posX
val posY = Minecraft.getMinecraft().thePlayer.posY
val posZ = Minecraft.getMinecraft().thePlayer.posZ
val boundXMax = posX + searchRadius
val boundXMin = posX - searchRadius
val boundYMax = posY + searchRadius
val boundYMin = posY - searchRadius
val boundZMax = posZ + searchRadius
val boundZMin = posZ - searchRadius
val maxMarker =
RouteMarker(boundXMax.toInt(), boundYMax.toInt(), boundZMax.toInt(), 1u, 0u, 0u, RouteOptions("Max Bounds"))
val minMarker =
RouteMarker(boundXMin.toInt(), boundYMin.toInt(), boundZMin.toInt(), 0u, 1u, 0u, RouteOptions("Min Bounds"))
Minecraft.getMinecraft().thePlayer.addChatMessage(ChatComponentText("Searching..."))
// Loop over each block in the defined bounds
for (x in boundXMin.toInt()..boundXMax.toInt()) {
for (y in boundYMin.toInt()..boundYMax.toInt()) {
for (z in boundZMin.toInt()..boundZMax.toInt()) {
// Get the block at the current coordinates
val block = world.getBlockState(BlockPos(x, y, z)).block
if (block == Blocks.chest || block == Blocks.trapped_chest || block == Blocks.ender_chest) {
val point = RouteMarker(x, y, z, 0u, 0u, 1u, RouteOptions("Located point"))
SkyBlockTweaks.routeList.add(point)
}
}
}
}
Minecraft.getMinecraft().thePlayer.addChatMessage(ChatComponentText("Done!"))
// SkyBlockTweaks.routeList.add(maxMarker)
// SkyBlockTweaks.routeList.add(minMarker)
}
} }
data class RouteMarker( data class RouteMarker(
@ -220,8 +265,10 @@ fun renderPoint(entity: Entity, blockPos: BlockPos, partialTicks: Float) {
// Create a default bounding box for blocks that don't have one // Create a default bounding box for blocks that don't have one
val boundingBox: AxisAlignedBB = block.getCollisionBoundingBox(world, blockPos, blockState) val boundingBox: AxisAlignedBB = block.getCollisionBoundingBox(world, blockPos, blockState)
?: AxisAlignedBB(blockPos.x.toDouble(), blockPos.y.toDouble(), blockPos.z.toDouble(), ?: AxisAlignedBB(
blockPos.x + 1.0, blockPos.y + 1.0, blockPos.z + 1.0).expand(padding, padding, padding) blockPos.x.toDouble(), blockPos.y.toDouble(), blockPos.z.toDouble(),
blockPos.x + 1.0, blockPos.y + 1.0, blockPos.z + 1.0
).expand(padding, padding, padding)
GL11.glPushMatrix() GL11.glPushMatrix()
GlStateManager.disableTexture2D() GlStateManager.disableTexture2D()
@ -287,13 +334,18 @@ class RouteGui : GuiScreen() {
buttonList.clear() buttonList.clear()
populateRouteList() populateRouteList()
buttonList.add(RouteMarkerButton(9000, width/2 + 20, height - 40, "Exit")) buttonList.add(RouteMarkerButton(9000, width / 2 + 20, height - 40, "Exit"))
} }
override fun actionPerformed(button: GuiButton?) { override fun actionPerformed(button: GuiButton?) {
if (button == null) { return } if (button == null) {
if (button.id < 1000) { buttonList.remove(button) } return
else if (button.id == 9000) { Minecraft.getMinecraft().thePlayer.closeScreen() } }
if (button.id < 1000) {
buttonList.remove(button)
} else if (button.id == 9000) {
Minecraft.getMinecraft().thePlayer.closeScreen()
}
} }
override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) { override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) {
@ -303,9 +355,9 @@ class RouteGui : GuiScreen() {
private fun populateRouteList() { private fun populateRouteList() {
for ((buttonId, m: RouteMarker) in SkyBlockTweaks.routeList.withIndex()) { for ((buttonId, m: RouteMarker) in SkyBlockTweaks.routeList.withIndex()) {
val markerField = GuiTextField(1000 + buttonId, fontRendererObj, width/2 - 200, 0, 100, 20) val markerField = GuiTextField(1000 + buttonId, fontRendererObj, width / 2 - 200, 0, 100, 20)
markerField.text = "${m.options.name} X:${m.x} Y:${m.y} Z:${m.z}" markerField.text = "${m.options.name} X:${m.x} Y:${m.y} Z:${m.z}"
val removeButton = RouteMarkerButton(2000 + buttonId, width/2 + 175, 0, 50, 20, "Remove") val removeButton = RouteMarkerButton(2000 + buttonId, width / 2 + 175, 0, 50, 20, "Remove")
buttonList.add(removeButton) buttonList.add(removeButton)
} }
} }

View File

@ -2,3 +2,5 @@ key.categories.sbt=SkyBlock Tweaks
key.addWaypoint=Add Route Point key.addWaypoint=Add Route Point
key.finishWaypoints=Finish Route key.finishWaypoints=Finish Route
key.clearWaypoints=Clear Route Points key.clearWaypoints=Clear Route Points
key.openRoutesGui=Open Route GUI
key.xrayToggle=Toggle ChestESP