Skip to content

Commit

Permalink
open class MinecraftInstance -> interface
Browse files Browse the repository at this point in the history
  • Loading branch information
MukjepScarlet committed Dec 20, 2024
1 parent 2a7a769 commit d2689ab
Show file tree
Hide file tree
Showing 57 changed files with 71 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/ccbluex/liquidbounce/cape/CapeAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import java.io.File
import java.util.*
import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER

object CapeAPI : MinecraftInstance() {
object CapeAPI : MinecraftInstance {

private val capesCache = File(dir, "capes").apply {
mkdir()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ccbluex/liquidbounce/cape/CapeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import java.util.concurrent.atomic.AtomicLong
* We know this might cause sometimes users to not have their capes shown immediately when account switches, but we can reduce the stress
* on the API and the connection of the user.
*/
object CapeService : Listenable, MinecraftInstance() {
object CapeService : Listenable, MinecraftInstance {

/**
* The client cape user
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ccbluex/liquidbounce/chat/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import net.ccbluex.liquidbounce.utils.login.UserUtils
import java.net.URI
import java.util.*

abstract class Client : ClientListener, MinecraftInstance() {
abstract class Client : ClientListener, MinecraftInstance {

internal var channel: Channel? = null
var username = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import net.ccbluex.liquidbounce.utils.client.MinecraftInstance
import net.ccbluex.liquidbounce.utils.client.asResourceLocation
import net.ccbluex.liquidbounce.utils.client.playSound

abstract class Command(val command: String, vararg val alias: String) : MinecraftInstance() {
abstract class Command(val command: String, vararg val alias: String) : MinecraftInstance {
/**
* Execute commands with provided [args]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import net.ccbluex.liquidbounce.utils.timing.TickedActions.TickScheduler
import org.lwjgl.input.Keyboard
import java.util.concurrent.CopyOnWriteArraySet

private val SPLIT_REGEX = "(?<=[a-z])(?=[A-Z])".toRegex()

open class Module(
val name: String,
val category: Category,
Expand All @@ -35,12 +37,12 @@ open class Module(
private val forcedDescription: String? = null,

// Adds spaces between lowercase and uppercase letters (KillAura -> Kill Aura)
val spacedName: String = name.split("(?<=[a-z])(?=[A-Z])".toRegex()).joinToString(separator = " "),
val spacedName: String = name.splitToSequence(SPLIT_REGEX).joinToString(separator = " "),
val subjective: Boolean = category == Category.RENDER,
val gameDetecting: Boolean = canBeEnabled,
val hideModule: Boolean = false,

) : MinecraftInstance(), Listenable {
) : MinecraftInstance, Listenable {

// Value that determines whether the module should depend on GameDetector
private val onlyInGameValue = boolean("OnlyInGame", true, subjective = true) { GameDetector.state }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package net.ccbluex.liquidbounce.features.module.modules.movement.flymodes
import net.ccbluex.liquidbounce.event.*
import net.ccbluex.liquidbounce.utils.client.MinecraftInstance

open class FlyMode(val modeName: String) : MinecraftInstance() {
open class FlyMode(val modeName: String) : MinecraftInstance {
open fun onMove(event: MoveEvent) {}
open fun onPacket(event: PacketEvent) {}
open fun onRender3D(event: Render3DEvent) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import net.ccbluex.liquidbounce.event.JumpEvent
import net.ccbluex.liquidbounce.event.MoveEvent
import net.ccbluex.liquidbounce.utils.client.MinecraftInstance

open class LongJumpMode(val modeName: String) : MinecraftInstance() {
open class LongJumpMode(val modeName: String) : MinecraftInstance {
open fun onUpdate() {}
open fun onMove(event: MoveEvent) {}
open fun onJump(event: JumpEvent) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package net.ccbluex.liquidbounce.features.module.modules.movement.nowebmodes

import net.ccbluex.liquidbounce.utils.client.MinecraftInstance

open class NoWebMode(val modeName: String) : MinecraftInstance() {
open class NoWebMode(val modeName: String) : MinecraftInstance {
open fun onUpdate() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import net.ccbluex.liquidbounce.event.MoveEvent
import net.ccbluex.liquidbounce.event.PacketEvent
import net.ccbluex.liquidbounce.utils.client.MinecraftInstance

open class SpeedMode(val modeName: String) : MinecraftInstance() {
open class SpeedMode(val modeName: String) : MinecraftInstance {
open fun onMotion() {}
open fun onUpdate() {}
open fun onMove(event: MoveEvent) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package net.ccbluex.liquidbounce.features.module.modules.player.nofallmodes
import net.ccbluex.liquidbounce.event.*
import net.ccbluex.liquidbounce.utils.client.MinecraftInstance

open class NoFallMode(val modeName: String) : MinecraftInstance() {
open class NoFallMode(val modeName: String) : MinecraftInstance {
open fun onMove(event: MoveEvent) {}
open fun onPacket(event: PacketEvent) {}
open fun onRender3D(event: Render3DEvent) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object Animations : Module("Animations", Category.RENDER, gameDetecting = false,
*
* @author CCBlueX
*/
abstract class Animation(val name: String) : MinecraftInstance() {
abstract class Animation(val name: String) : MinecraftInstance {
abstract fun transform(f1: Float, f: Float, clientPlayer: AbstractClientPlayer)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ object ChestStealer : Module("ChestStealer", Category.WORLD, hideModule = false)
val sortableToSlot: Int?
)

private fun getItemsToSteal(): MutableList<ItemTakeRecord> {
private fun getItemsToSteal(): List<ItemTakeRecord> {
val sortBlacklist = BooleanArray(9)

var spaceInInventory = countSpaceInInventory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import net.minecraft.stats.StatList
import net.minecraft.util.BlockPos
import kotlin.math.truncate

object Tower : MinecraftInstance(), Listenable {
object Tower : MinecraftInstance, Listenable {

val towerModeValues = choices(
"TowerMode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import net.ccbluex.liquidbounce.utils.kotlin.RandomUtils.nextInt
import net.minecraft.network.EnumConnectionState
import net.minecraft.network.handshake.client.C00Handshake

object BungeeCordSpoof : MinecraftInstance(), Listenable {
object BungeeCordSpoof : MinecraftInstance, Listenable {
var enabled = false

val onPacket = handler<PacketEvent> { event ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import net.ccbluex.liquidbounce.utils.client.MinecraftInstance
import net.minecraft.network.PacketBuffer
import net.minecraft.network.play.client.C17PacketCustomPayload

object ClientFixes : MinecraftInstance(), Listenable {
object ClientFixes : MinecraftInstance, Listenable {

var fmlFixesEnabled = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.json.JSONObject
import java.io.IOException
import java.time.OffsetDateTime

object ClientRichPresence : MinecraftInstance() {
object ClientRichPresence : MinecraftInstance {

var showRPCValue = true
var showRPCServerIP = true
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ccbluex/liquidbounce/file/FileManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.io.File
private val FILE_CONFIGS = ArrayList<FileConfig>()

@SideOnly(Side.CLIENT)
object FileManager : MinecraftInstance(), Iterable<FileConfig> by FILE_CONFIGS {
object FileManager : MinecraftInstance, Iterable<FileConfig> by FILE_CONFIGS {

val dir = File(mc.mcDataDir, "$CLIENT_NAME-$MINECRAFT_VERSION")
val fontsDir = File(dir, "fonts")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ccbluex/liquidbounce/lang/Language.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import net.ccbluex.liquidbounce.utils.client.MinecraftInstance
fun translationMenu(key: String, vararg args: Any) = LanguageManager.getTranslation("menu.$key", *args)
fun translation(key: String, vararg args: Any) = LanguageManager.getTranslation(key, *args)

object LanguageManager : MinecraftInstance() {
object LanguageManager : MinecraftInstance {

// Current language
private val language: String
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ccbluex/liquidbounce/script/Script.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import java.io.File
import java.util.function.Function
import javax.script.ScriptEngine

class Script(val scriptFile: File) : MinecraftInstance() {
class Script(val scriptFile: File) : MinecraftInstance {

private val scriptEngine: ScriptEngine
private val scriptText = scriptFile.readText()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ class GuiAltManager(private val prevGui: GuiScreen) : AbstractScreen() {
7 -> { // Import button
val file = MiscUtils.openFileChooser() ?: return

file.readLines().forEach {
val accountData = it.split(":".toRegex(), limit = 2)
file.forEachLine {
val accountData = it.split(":", limit = 2)
if (accountData.size > 1) {
// Most likely a mojang account
accountsConfig.addMojangAccount(accountData[0], accountData[1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import kotlin.math.min
import kotlin.math.roundToInt

@SideOnly(Side.CLIENT)
abstract class Panel(val name: String, var x: Int, var y: Int, val width: Int, val height: Int, var open: Boolean) : MinecraftInstance() {
abstract class Panel(val name: String, var x: Int, var y: Int, val width: Int, val height: Int, var open: Boolean) : MinecraftInstance {
abstract val elements: List<Element>

var x2 = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package net.ccbluex.liquidbounce.ui.client.clickgui.elements

import net.ccbluex.liquidbounce.utils.client.MinecraftInstance

abstract class Element : MinecraftInstance() {
abstract class Element : MinecraftInstance {

var x = 0
var y = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.awt.Color
import java.math.BigDecimal
import kotlin.math.max

abstract class Style : MinecraftInstance() {
abstract class Style : MinecraftInstance {
protected var sliderValueHeld: Value<*>? = null
get() {
if (!Mouse.isButtonDown(0)) field = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.lwjgl.opengl.GL11.*
import kotlin.math.max
import kotlin.math.min

object HUD : MinecraftInstance() {
object HUD : MinecraftInstance {

val elements = mutableListOf<Element>()
val notifications = mutableListOf<Notification>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.lwjgl.input.Mouse
import org.lwjgl.opengl.GL11.*
import java.awt.Color

class EditorPanel(private val hudDesigner: GuiHudDesigner, var x: Int, var y: Int) : MinecraftInstance() {
class EditorPanel(private val hudDesigner: GuiHudDesigner, var x: Int, var y: Int) : MinecraftInstance {

var width = 80
private set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlin.math.min
*/
abstract class Element(
var x: Double = 2.0, var y: Double = 2.0, scale: Float = 1F, var side: Side = Side.default(),
) : MinecraftInstance() {
) : MinecraftInstance {

val info = javaClass.getAnnotation(ElementInfo::class.java)
?: throw IllegalArgumentException("Passed element with missing element info")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import kotlin.math.roundToInt
* Generate new bitmap based font renderer
*/
@SideOnly(Side.CLIENT)
class AWTFontRenderer(val font: Font, startChar: Int = 0, stopChar: Int = 255, private var loadingScreen: Boolean = false) : MinecraftInstance() {
class AWTFontRenderer(val font: Font, startChar: Int = 0, stopChar: Int = 255, private var loadingScreen: Boolean = false) : MinecraftInstance {
companion object {
var assumeNonVolatile = false
val activeFontRenderers = mutableListOf<AWTFontRenderer>()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/ccbluex/liquidbounce/ui/font/Fonts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ data class FontInfo(val name: String, val size: Int = -1, val isCustom: Boolean

private val FONT_REGISTRY = LinkedHashMap<FontInfo, FontRenderer>()

object Fonts : MinecraftInstance() {
object Fonts : MinecraftInstance {

val minecraftFont: FontRenderer = mc.fontRendererObj

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import net.minecraft.util.Vec3
import kotlin.math.cos
import kotlin.math.sin

object EntityUtils : MinecraftInstance() {
object EntityUtils : MinecraftInstance {

var targetInvisible = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import net.minecraft.util.ResourceLocation

typealias Collidable = (Block?) -> Boolean

object BlockUtils : MinecraftInstance() {
object BlockUtils : MinecraftInstance {

/**
* Get block name by [id]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import net.minecraft.network.status.client.C00PacketServerQuery
import net.minecraft.network.status.client.C01PacketPing
import net.minecraft.util.Vec3

object BlinkUtils : MinecraftInstance(), Listenable {
object BlinkUtils : MinecraftInstance, Listenable {

val publicPacket: Packet<*>? = null
val packets = mutableListOf<Packet<*>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.security.PublicKey
import javax.crypto.SecretKey

@SideOnly(Side.CLIENT)
object ClientUtils : MinecraftInstance() {
object ClientUtils : MinecraftInstance {
private var fastRenderField: Field? = runCatching {
GameSettings::class.java.getDeclaredField("ofFastRender")
}.getOrNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import net.minecraft.client.Minecraft
import net.minecraft.client.audio.PositionedSoundRecord
import net.minecraft.util.ResourceLocation

open class MinecraftInstance {
interface MinecraftInstance {
val mc: Minecraft
get() = Companion.mc

companion object {
@JvmField
val mc: Minecraft = Minecraft.getMinecraft()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlin.concurrent.read
import kotlin.concurrent.write
import kotlin.math.roundToInt

object PacketUtils : MinecraftInstance(), Listenable {
object PacketUtils : MinecraftInstance, Listenable {

private val queuedPackets = ArrayDeque<Packet<*>>()
private val queueLock = ReentrantReadWriteLock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import net.minecraftforge.fml.relauncher.SideOnly
import java.net.InetAddress

@SideOnly(Side.CLIENT)
object ServerUtils : MinecraftInstance() {
object ServerUtils : MinecraftInstance {
var serverData: ServerData? = null

@JvmOverloads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import net.minecraft.entity.item.EntityItem
import net.minecraft.item.ItemArmor
import net.minecraft.item.ItemStack

object ArmorComparator: MinecraftInstance() {
object ArmorComparator: MinecraftInstance {
fun getBestArmorSet(stacks: List<ItemStack?>, entityStacksMap: Map<ItemStack, EntityItem>? = null): ArmorSet? {
val thePlayer = mc.thePlayer ?: return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import net.ccbluex.liquidbounce.event.Listenable
import net.ccbluex.liquidbounce.event.loopHandler
import net.minecraft.client.gui.inventory.GuiInventory

object InventoryManager : MinecraftInstance(), Listenable {
object InventoryManager : MinecraftInstance, Listenable {

// Shared no move click values
val noMoveValue = boolean("NoMoveClicks", false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import net.minecraft.network.play.server.S09PacketHeldItemChange
import net.minecraft.network.play.server.S2DPacketOpenWindow
import net.minecraft.network.play.server.S2EPacketCloseWindow

object InventoryUtils : MinecraftInstance(), Listenable {
object InventoryUtils : MinecraftInstance, Listenable {
// Is inventory open on server-side?
var serverOpenInventory
get() = _serverOpenInventory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
import kotlin.math.roundToInt

object ItemUtils : MinecraftInstance() {
object ItemUtils : MinecraftInstance {
/**
* Allows you to create an item using the item json
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.utils.client.MinecraftInstance
import net.minecraft.network.play.client.C09PacketHeldItemChange

object SilentHotbar : Listenable, MinecraftInstance() {
object SilentHotbar : Listenable, MinecraftInstance {

var hotbarState: SilentHotbarState? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.time.LocalDateTime
import javax.swing.*
import javax.swing.filechooser.FileFilter

object MiscUtils : MinecraftInstance() {
object MiscUtils : MinecraftInstance {

private fun JTextArea.adjustTextAreaSize() {
val fontMetrics = getFontMetrics(font)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.*

fun me.liuli.elixir.compat.Session.intoMinecraftSession() = Session(username, uuid, token, type)

object LoginUtils : MinecraftInstance() {
object LoginUtils : MinecraftInstance {

fun loginSessionId(sessionToken: String): LoginResult {
val payload = try {
Expand Down
Loading

0 comments on commit d2689ab

Please sign in to comment.