diff --git a/build.gradle b/build.gradle index da82ff7..ea692e0 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:4.+' classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" } } @@ -19,28 +19,27 @@ apply plugin: 'kotlin' apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' -compileKotlin { - kotlinOptions { - jvmTarget = "1.8" - useIR = true - freeCompilerArgs += '-Xlambdas=indy' - } -} - compileJava { sourceCompatibility = targetCompatibility = '1.8' options.encoding = 'UTF-8' } +compileKotlin.kotlinOptions { + freeCompilerArgs += '-Xlambdas=indy' + freeCompilerArgs += '-Xopt-in=kotlin.RequiresOptIn' + freeCompilerArgs += '-Xopt-in=kotlin.contracts.ExperimentalContracts' +} + repositories { maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } maven { url = 'https://impactdevelopment.github.io/maven/' } maven { url = "https://jitpack.io" } + mavenCentral() } minecraft { - mappings channel: 'stable', version: '39-1.12' + mappings channel: "$mappingsChannel", version: "$mappingsVersion" runs { client { @@ -51,12 +50,6 @@ minecraft { property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' property 'forge.logging.console.level', 'debug' - - mods { - pluginexample { - source sourceSets.main - } - } } } } @@ -72,13 +65,12 @@ configurations { } dependencies { - minecraft 'net.minecraftforge:forge:1.12.2-14.23.5.2855' + minecraft "net.minecraftforge:forge:$minecraftVersion-$forgeVersion" - // API coming soon -// implementation 'com.github.lambda-client:lambda:2.06' - implementation(files("lib/lambda-2.06.xx-dev-api.jar")) + // Online maven dependency coming soon + implementation files("lib/lambda-3.1-api.jar") - implementation('org.spongepowered:mixin:0.7.11-SNAPSHOT') { + implementation('org.spongepowered:mixin:0.8.3') { exclude module: 'commons-io' exclude module: 'gson' exclude module: 'guava' @@ -87,51 +79,69 @@ dependencies { } // Hacky way to get mixin work - annotationProcessor('org.spongepowered:mixin:0.8.2:processor') { + annotationProcessor('org.spongepowered:mixin:0.8.3:processor') { exclude module: 'gson' } // Kotlin libs // kotlin-stdlib-common and annotations aren't required at runtime - implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version") { + implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion") { exclude module: 'kotlin-stdlib-common' exclude module: 'annotations' } - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version") { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion") { exclude module: 'kotlin-stdlib-common' exclude module: 'annotations' } - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version") { + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion") { exclude module: 'kotlin-stdlib-common' exclude module: 'annotations' } - implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlin_version") { + implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") { exclude module: 'kotlin-stdlib-common' exclude module: 'annotations' } - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinx_coroutines_version") { + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion") { exclude module: 'kotlin-stdlib-common' exclude module: 'annotations' } // Add them back to compileOnly (provided) - compileOnly "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version" - compileOnly 'org.jetbrains:annotations:20.1.0' + compileOnly "org.jetbrains.kotlin:kotlin-stdlib-common:1.6.21" + compileOnly 'org.jetbrains:annotations:23.0.0' // This Baritone will NOT be included in the jar implementation 'com.github.cabaletta:baritone:1.2.14' + // Unit Testing frameworks + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2' + // Add your dependencies below // jarLibs 'com.lambda:example:1.0.0' } mixin { defaultObfuscationEnv 'searge' - add sourceSets.main, 'mixins.lambda.refmap.json' + add sourceSets.main, 'mixins.ElytraBot.refmap.json' +} + +processResources { + exclude '**/rawimagefiles' + + from(sourceSets.main.resources.srcDirs) { + duplicatesStrategy = DuplicatesStrategy.INCLUDE + include 'plugin_info.json' + expand 'version': project.version + } +} + +test { + useJUnitPlatform() } jar.finalizedBy('reobfJar') \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 7731b33..c95d327 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,13 @@ -kotlin.code.style=official org.gradle.jvmargs=-Xmx3G +org.gradle.parallel=true + modGroup=com.lambda modVersion=1.0 -kotlin_version=1.5.10 -kotlinx_coroutines_version=1.5.0-RC -org.gradle.parallel=true \ No newline at end of file + +minecraftVersion=1.12.2 +forgeVersion=14.23.5.2860 +mappingsChannel=stable +mappingsVersion=39-1.12 + +kotlinVersion=1.6.20 +kotlinxCoroutinesVersion=1.6.1 \ No newline at end of file diff --git a/lib/lambda-2.06.xx-dev-api.jar b/lib/lambda-2.06.xx-dev-api.jar deleted file mode 100644 index 828fc8a..0000000 Binary files a/lib/lambda-2.06.xx-dev-api.jar and /dev/null differ diff --git a/lib/lambda-3.1-api-source.jar b/lib/lambda-3.1-api-source.jar new file mode 100644 index 0000000..75cb1fd Binary files /dev/null and b/lib/lambda-3.1-api-source.jar differ diff --git a/lib/lambda-3.1-api.jar b/lib/lambda-3.1-api.jar new file mode 100644 index 0000000..944e69f Binary files /dev/null and b/lib/lambda-3.1-api.jar differ diff --git a/src/main/kotlin/ElytraBotHUD.kt b/src/main/kotlin/ElytraBotHUD.kt new file mode 100644 index 0000000..46cd997 --- /dev/null +++ b/src/main/kotlin/ElytraBotHUD.kt @@ -0,0 +1,20 @@ +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.plugin.api.PluginLabelHud +import com.lambda.client.util.color.ColorHolder + +internal object ElytraBotStatus : PluginLabelHud( + name = "Elytra Bot Status", + category = Category.CLIENT, + description = "Elytra Bot Status", + pluginMain = ElytraBotPlugin +) { + + private val textColor by setting("Text Color", ColorHolder(0, 255, 0, 255)) + + override fun SafeClientEvent.updateText() { + if(ElytraBotModule.isEnabled){ + displayText.addLine("Going to ${ElytraBotModule.goal?.x}, ${ElytraBotModule.goal?.y}, ${ElytraBotModule.goal?.z}", textColor) + } + } + +} \ No newline at end of file diff --git a/src/main/kotlin/ElytraBotModule.kt b/src/main/kotlin/ElytraBotModule.kt index bd90a5b..1a27ffd 100644 --- a/src/main/kotlin/ElytraBotModule.kt +++ b/src/main/kotlin/ElytraBotModule.kt @@ -1,4 +1,7 @@ import com.lambda.client.event.SafeClientEvent +import com.lambda.client.event.events.PacketEvent +import com.lambda.client.event.events.RenderWorldEvent +import com.lambda.client.event.listener.listener import com.lambda.client.manager.managers.HotbarManager import com.lambda.client.manager.managers.HotbarManager.serverSideItem import com.lambda.client.manager.managers.HotbarManager.spoofHotbar @@ -10,45 +13,49 @@ import com.lambda.client.plugin.api.PluginModule import com.lambda.client.util.MovementUtils.speed import com.lambda.client.util.TickTimer import com.lambda.client.util.TimeUnit -import com.lambda.client.util.items.* +import com.lambda.client.util.Wrapper.player +import com.lambda.client.util.color.ColorHolder +import com.lambda.client.util.graphics.ESPRenderer +import com.lambda.client.util.items.firstItem +import com.lambda.client.util.items.hotbarSlots +import com.lambda.client.util.items.swapToSlot import com.lambda.client.util.math.Direction -import com.lambda.client.util.math.Vec2f +import com.lambda.client.util.math.RotationUtils.getRotationTo +import com.lambda.client.util.math.Vec3f import com.lambda.client.util.math.VectorUtils import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.math.VectorUtils.multiply import com.lambda.client.util.math.VectorUtils.toVec3d import com.lambda.client.util.text.MessageSendHelper.sendChatMessage -import com.lambda.client.util.threads.defaultScope import com.lambda.client.util.threads.runSafe import com.lambda.client.util.threads.runSafeR import com.lambda.client.util.threads.safeListener import com.lambda.client.util.world.getGroundPos -import kotlinx.coroutines.launch import net.minecraft.init.Items import net.minecraft.init.SoundEvents import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketEntityAction +import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerTryUseItem import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.MathHelper import net.minecraft.util.math.Vec3d +import net.minecraftforge.client.event.InputUpdateEvent import net.minecraftforge.fml.common.gameevent.TickEvent +import java.awt.Color import kotlin.math.abs -import kotlin.math.atan2 -import kotlin.math.sqrt internal object ElytraBotModule : PluginModule( name = "ElytraBot", category = Category.MOVEMENT, - description = "Baritone like Elytra bot module, credit CookieClient", + description = "Baritone like Elytra bot module, credit CookieClient, recoded by kamigen cuz others are lazy (?)", pluginMain = ElytraBotPlugin ) { - private var path = mutableListOf() + private var path = ArrayList() var goal: BlockPos? = null private var previous: BlockPos? = null private var lastSecondPos: BlockPos? = null @@ -64,6 +71,8 @@ internal object ElytraBotModule : PluginModule( private val packetTimer = TickTimer(TimeUnit.MILLISECONDS) private val fireworkTimer = TickTimer(TimeUnit.MILLISECONDS) private val takeoffTimer = TickTimer(TimeUnit.MILLISECONDS) + private val renderer = ESPRenderer() + private lateinit var spoofv3f: Vec3f //TODO enum class ElytraBotMode { Highway, Overworld @@ -74,12 +83,16 @@ internal object ElytraBotModule : PluginModule( } enum class ElytraBotFlyMode { - Firework + Creative + } + + enum class RotationMode { + OFF, SPOOF, VIEW_LOCK } var travelMode by setting("Travel Mode", ElytraBotMode.Overworld) private var takeoffMode by setting("Takeoff Mode", ElytraBotTakeOffMode.Jump) - private var elytraMode by setting("Flight Mode", ElytraBotFlyMode.Firework) + private var elytraMode by setting("Flight Mode", ElytraBotFlyMode.Creative) private val highPingOptimize by setting("High Ping Optimize", false) private val minTakeoffHeight by setting("Min Takeoff Height", 0.5f, 0.0f..1.5f, 0.1f, { !highPingOptimize }) private val spoofHotbar by setting("Spoof Hotbar", true) @@ -87,19 +100,14 @@ internal object ElytraBotModule : PluginModule( private val minElytraVelocity by setting("MinElytraVelocity", 1.0, 0.1..5.0, 0.1) private val aStarLoops by setting("aStarLoops", 500, 1..1000, 1) private val interacting by setting("Rotation Mode", RotationMode.VIEW_LOCK) -// private val elytraFlySpeed by setting("Elytra Speed", 1f, 0.1f..20.0f, 0.25f, { ElytraMode != ElytraBotFlyMode.Firework }) + //private val elytraFlySpeed by setting("Elytra Speed", 1f, 0.1f..20.0f, 0.25f, { ElytraMode != ElytraBotFlyMode.Firework }) private val elytraFlyManeuverSpeed by setting("Maneuver Speed", 1f, 0.0f..10.0f, 0.25f) - private val fireworkDelay by setting("Firework Delay", 1f, 0.0f..10.0f, 0.25f, { elytraMode == ElytraBotFlyMode.Firework }) -// var pathfinding by setting("Pathfinding", true) + private val fireworkDelay by setting("Firework Delay", 1f, 0.0f..10.0f, 0.25f, { elytraMode == ElytraBotFlyMode.Creative }) + var renderingPath by setting("Render path", true) var avoidLava by setting("AvoidLava", true) private var directional by setting("Directional", false) -// private var toggleOnPop by setting("ToggleOnPop", false) -// private val maxY by setting("Max Y", 1f, 0.0f..300.0f, 0.25f) + private var toggleOnPop by setting("ToggleOnPop", false) - @Suppress("UNUSED") - private enum class RotationMode { - OFF, SPOOF, VIEW_LOCK - } init { onEnable { @@ -108,9 +116,9 @@ internal object ElytraBotModule : PluginModule( //Calculate the direction so it will put it to diagonal if the player is on diagonal highway. goal = BlockPos(Direction.fromEntity(player).directionVec.multiply(6942069)) } else { if (goal == null) { - sendChatMessage("You need a goal position") - disable() - } + sendChatMessage("You need a goal position") + disable() + } } blocksPerSecondTimer.reset() } @@ -118,7 +126,7 @@ internal object ElytraBotModule : PluginModule( onDisable { runSafe { - path = mutableListOf() + path = ArrayList() useBaritoneCounter = 0 lagback = false lagbackCounter = 0 @@ -129,6 +137,56 @@ internal object ElytraBotModule : PluginModule( } } + safeListener(69420){ + if(renderingPath){ + renderer.aOutline = 50 + renderer.thickness = 2F + path.forEach { + val _it = BlockPos(it.x.toDouble(), (it.y - 1.5), it.z.toDouble()) + renderer.add(_it, ColorHolder(Color.RED)) + } + renderer.render(true) + } + } + listener(6969) { + /* TODO yo someone can make this shit cleaner ?*/ + if(path.isNotEmpty()){ + val yRange = (path.first().y - 2..path.first().y + 2) + if(interacting === RotationMode.VIEW_LOCK){ + + if(!yRange.contains(mc.player.position.y)) { + if(mc.player.position.y < yRange.first){ + it.movementInput.jump + } + if(mc.player.position.y > yRange.last){ + it.movementInput.sneak + } + } + + + it.movementInput.moveForward = 1.0f + } + else { + sendPlayerPacket { + move(BlockPos(mc.player.position.x, mc.player.position.y+1, mc.player.position.z).toVec3d()) + } + if(mc.player.position.y < path.first().y) { + sendPlayerPacket { + move(BlockPos(mc.player.position.x, mc.player.position.y+1, mc.player.position.z).toVec3d()) + } + } + } + } + } + safeListener { + if (it.packet is CPacketPlayer.Position) { + val packet = it.packet as CPacketPlayer + //TODO add packet rotation shit etc and moving forward based from the player rotation server side + } + } + + + safeListener { if (goal == null) { disable() @@ -154,13 +212,6 @@ internal object ElytraBotModule : PluginModule( return@safeListener } - //Toggle off if no fireworks while using firework mode - if (elytraMode == ElytraBotFlyMode.Firework && - player.inventorySlots.countItem(Items.FIREWORKS) <= 0) { - sendChatMessage("You need fireworks as your using firework mode") - disable() - return@safeListener - } //Wait still if in unloaded chunk if (!world.getChunk(player.position).isLoaded) { @@ -190,37 +241,21 @@ internal object ElytraBotModule : PluginModule( mc.timer.tickLength = 50.0f packetsSent = 0 - // If we arent moving anywhere then activate use baritone + // If we arent moving anywhere then try to move around val speed = player.speed - - if (elytraMode == ElytraBotFlyMode.Firework) { - // Prevent lagback on 2b2t by not clicking on fireworks. I hope hause would fix hes plugins tho - if (speed > 3) { - lagback = true - } - - //Remove lagback thing after it stops and click on fireworks again. - if (lagback) { - if (speed < 1) { - lagbackCounter++ - if (lagbackCounter > 3) { - lagback = false - lagbackCounter = 0 - } - } else { - lagbackCounter = 0 + if(speed == 0.0){ + /* TODO move around if there's no blocks at left or right, else disable, use baritone walk to a bit and restart */ + repeat(2){ + sendPlayerPacket { + move(BlockPos(mc.player.position.x, mc.player.position.y-1, mc.player.position.z).toVec3d()) } } - - //Click on fireworks - if (player.speed < minElytraVelocity && !lagback && fireworkTimer.tick((fireworkDelay * 1000).toInt())) { - activateFirework() - } } + } //Generate more path - if (path.size <= 20 || isNextPathTooFar()) { + if (path.size <= 10 || isNextPathTooFar()) { generatePath() } @@ -228,6 +263,7 @@ internal object ElytraBotModule : PluginModule( //The higher it is the smoother the movement will be but it will need more space. var distance = 12 if (travelMode == ElytraBotMode.Highway) { + /* TODO gotta add highway support */ distance = 2 } @@ -242,37 +278,34 @@ internal object ElytraBotModule : PluginModule( path.remove(pos) previous = pos } - if (path.isNotEmpty() && elytraMode == ElytraBotFlyMode.Firework) { - path.lastOrNull()?.let { pathPos -> - val pos = Vec3d(pathPos).add(0.5, 0.5, 0.5) - - val eyesPos = Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ) - val diffX = pos.x - eyesPos.x - val diffY = pos.y - eyesPos.y - val diffZ = pos.z - eyesPos.z - val diffXZ = sqrt(diffX * diffX + diffZ * diffZ) - val yaw = Math.toDegrees(atan2(diffZ, diffX)).toFloat() - 90f - val pitch = (-Math.toDegrees(atan2(diffY, diffXZ))).toFloat() - - val rotation = Vec2f(player.rotationYaw + MathHelper.wrapDegrees(yaw - player.rotationYaw), player.rotationPitch + MathHelper.wrapDegrees(pitch - player.rotationPitch)) - - when (interacting) { - RotationMode.SPOOF -> { - sendPlayerPacket { - rotate(rotation) - } - } - RotationMode.VIEW_LOCK -> { - player.rotationYaw = rotation.x - player.rotationPitch = rotation.y - } - else -> { - // RotationMode.OFF - } + + if (path.isNotEmpty()) { + rotateUpdate(path.first()) /** Rotate the player head to the first (last block of the render) block **/ + } + } + } + private fun rotateUpdate(blockPos: BlockPos){ + if (path.isNotEmpty() && elytraMode == ElytraBotFlyMode.Creative) { + when (interacting) { + RotationMode.SPOOF -> { + sendPlayerPacket { + //TODO Someone can do that for me ? 🥺🥺🥺 plz + //TODO Someone can do that for me ? 🥺🥺🥺 plz + rotate(getRotationTo(mc.player.position.toVec3d(), blockPos.toVec3d())) + //TODO Someone can do that for me ? 🥺🥺🥺 plz + //TODO Someone can do that for me ? 🥺🥺🥺 plz } } + RotationMode.VIEW_LOCK -> { + player?.rotationYaw = getRotationTo(mc.player.position.toVec3d(), blockPos.toVec3d()).x + player?.rotationPitch = getRotationTo(mc.player.position.toVec3d(), blockPos.toVec3d()).y + } + else -> { + // RotationMode.OFF + } } } + } private fun isItemBroken(itemStack: ItemStack): Boolean { // (100 * damage / max damage) >= (100 - 70) @@ -345,7 +378,7 @@ internal object ElytraBotModule : PluginModule( } } - private fun SafeClientEvent.activateFirework() { + private fun SafeClientEvent.activateFirework() { //TODO Someone can do that for me ? 🥺🥺🥺 plz if (player.heldItemMainhand.item != Items.FIREWORKS) { if (spoofHotbar) { val slot = if (player.serverSideItem.item == Items.FIREWORKS) HotbarManager.serverSideHotbar @@ -367,10 +400,10 @@ internal object ElytraBotModule : PluginModule( private fun SafeClientEvent.isNextPathTooFar(): Boolean { return path.lastOrNull()?.let { - player.position.distanceTo(it) > 15 + player.position.distanceTo(it) >= 10 } ?: run { false } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/ElytraBotPlugin.kt b/src/main/kotlin/ElytraBotPlugin.kt index 7118e80..11b4760 100644 --- a/src/main/kotlin/ElytraBotPlugin.kt +++ b/src/main/kotlin/ElytraBotPlugin.kt @@ -6,7 +6,7 @@ internal object ElytraBotPlugin : Plugin() { // Load any modules, commands, or HUD elements here modules.add(ElytraBotModule) commands.add(ElytraBotCommand) - + hudElements.add(ElytraBotStatus) } override fun onUnload() {} diff --git a/src/main/resources/mixins.ElytraBot.json b/src/main/resources/mixins.ElytraBot.json new file mode 100644 index 0000000..21361a4 --- /dev/null +++ b/src/main/resources/mixins.ElytraBot.json @@ -0,0 +1,9 @@ +{ + "required": true, + "compatibilityLevel": "JAVA_8", + "package": "com.lambda.mixin", + "refmap": "mixins.ExamplePlugin.refmap.json", + "client": [ + "MixinMinecraft" + ] +} \ No newline at end of file diff --git a/src/main/resources/plugin_info.json b/src/main/resources/plugin_info.json index 2e93151..b4753a1 100644 --- a/src/main/resources/plugin_info.json +++ b/src/main/resources/plugin_info.json @@ -1,12 +1,13 @@ { "name": "ElytraBot", - "version": "1.0", + "version": "1.1", "authors": [ + "Kamigen :troll:", "bebeli555", "czho", "Constructor" ], "description": "AStar elytra bot", "main_class": "ElytraBotPlugin", - "min_api_version": "2.05.01" + "min_api_version": "3.0" } \ No newline at end of file