Skip to content

Vanilla elytra flight rewrite and AutoOffhand changes #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object ConfigCommand : ClientCommand(
}
}

literal("set") {
literal("set", "load") {
string("name") { nameArg ->
execute("Change preset") {
configTypeArg.value.setPreset(nameArg.value)
Expand Down Expand Up @@ -137,9 +137,7 @@ object ConfigCommand : ClientCommand(
return if (ip == null || mc.isIntegratedServerRunning) {
MessageSendHelper.sendWarningMessage("You are not in a server!")
null
} else {
ip
}
} else ip
}

private fun IExecuteEvent.confirm(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,4 @@ internal object Coordinates : LabelHud(
}

private fun StringBuilder.appendWithComma(string: String) = append(if (isNotEmpty()) ", $string" else string)

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,39 @@ object AutoOffhand : Module(
description = "Manages item in your offhand",
category = Category.COMBAT
) {
// General
private val switchMessage by setting("Switch Message", true)
private val priority by setting("Priority", Priority.HOTBAR)
private val conditional by setting("Conditional", false)
private val type by setting("Type", Type.TOTEM)

// Totem
private val hpThreshold by setting("Hp Threshold", 5f, 1f..36f, 0.5f, { type == Type.TOTEM })
private val offhandTotem by setting("Offhand Totem", true, { type == Type.TOTEM })
private val bindTotem by setting("Bind Totem", Bind(), { type == Type.TOTEM })
private val checkDamage by setting("Check Damage", true, { type == Type.TOTEM })
private val mob by setting("Mob", true, { type == Type.TOTEM && checkDamage })
private val player by setting("Player", true, { type == Type.TOTEM && checkDamage })
private val crystal by setting("Crystal", true, { type == Type.TOTEM && checkDamage })
private val falling by setting("Falling", true, { type == Type.TOTEM && checkDamage })
private val hpThreshold by setting("Hp Threshold", 5f, 1f..36f, 0.5f, { type == Type.TOTEM && offhandTotem && conditional })
private val checkDamage by setting("Check Damage", true, { type == Type.TOTEM && offhandTotem && conditional })
private val mob by setting("Mob", true, { type == Type.TOTEM && offhandTotem && checkDamage && conditional })
private val player by setting("Player", true, { type == Type.TOTEM && offhandTotem && checkDamage && conditional })
private val crystal by setting("Crystal", true, { type == Type.TOTEM && offhandTotem && checkDamage && conditional })
private val falling by setting("Falling", true, { type == Type.TOTEM && offhandTotem && checkDamage && conditional })

// Gapple
private val offhandGapple by setting("Offhand Gapple", false, { type == Type.GAPPLE })
private val bindGapple by setting("Bind Gapple", Bind(), { type == Type.GAPPLE && offhandGapple })
private val checkAuraG by setting("Check Aura G", true, { type == Type.GAPPLE && offhandGapple })
private val checkWeaponG by setting("Check Weapon G", false, { type == Type.GAPPLE && offhandGapple })
private val checkCAGapple by setting("Check CrystalAura G", true, { type == Type.GAPPLE && offhandGapple && !offhandCrystal })
private val bindGapple by setting("Bind Gapple", Bind(), { type == Type.GAPPLE })
private val checkAuraG by setting("Check Aura G", true, { type == Type.GAPPLE && offhandGapple && conditional })
private val checkWeaponG by setting("Check Weapon G", false, { type == Type.GAPPLE && offhandGapple && conditional })
private val checkCAGapple by setting("Check CrystalAura G", true, { type == Type.GAPPLE && offhandGapple && !offhandCrystal && conditional })

// Strength
private val offhandStrength by setting("Offhand Strength", false, { type == Type.STRENGTH })
private val bindStrength by setting("Bind Strength", Bind(), { type == Type.STRENGTH && offhandStrength })
private val checkAuraS by setting("Check Aura S", true, { type == Type.STRENGTH && offhandStrength })
private val checkWeaponS by setting("Check Weapon S", false, { type == Type.STRENGTH && offhandStrength })
private val bindStrength by setting("Bind Strength", Bind(), { type == Type.STRENGTH })
private val checkAuraS by setting("Check Aura S", true, { type == Type.STRENGTH && offhandStrength && conditional })
private val checkWeaponS by setting("Check Weapon S", false, { type == Type.STRENGTH && offhandStrength && conditional })

// Crystal
private val offhandCrystal by setting("Offhand Crystal", false, { type == Type.CRYSTAL })
private val bindCrystal by setting("Bind Crystal", Bind(), { type == Type.CRYSTAL && offhandCrystal })
private val checkCACrystal by setting("Check Crystal Aura C", false, { type == Type.CRYSTAL && offhandCrystal })

// General
private val priority by setting("Priority", Priority.HOTBAR)
private val switchMessage by setting("Switch Message", true)
private val bindCrystal by setting("Bind Crystal", Bind(), { type == Type.CRYSTAL })
private val checkCACrystal by setting("Check Crystal Aura C", false, { type == Type.CRYSTAL && offhandCrystal && conditional })

// Represents the remaining number of items of type AutoOffhandType in the inventory
private var hudInfo = ""
Expand Down Expand Up @@ -100,7 +101,7 @@ object AutoOffhand : Module(

updateDamage()

switchToType(getType(), true)
if (player.heldItemOffhand.isEmpty) switchToType(getType())

hudInfo = player.allSlots.countByStack { type.filter(it) }.toString()
}
Expand All @@ -113,26 +114,27 @@ object AutoOffhand : Module(
checkStrength() -> Type.STRENGTH
checkGapple() -> Type.GAPPLE
checkCrystal() -> Type.CRYSTAL
player.heldItemOffhand.isEmpty -> Type.TOTEM
else -> null
}

private fun SafeClientEvent.checkTotem() = player.scaledHealth < hpThreshold
|| (checkDamage && player.scaledHealth - maxDamage < hpThreshold)
private fun SafeClientEvent.checkTotem() = offhandTotem
&& (!conditional || (player.scaledHealth < hpThreshold
|| (checkDamage && player.scaledHealth - maxDamage < hpThreshold)))

private fun SafeClientEvent.checkGapple() = offhandGapple
&& (checkAuraG && CombatManager.isActiveAndTopPriority(KillAura)
&& (!conditional || ((checkAuraG && CombatManager.isActiveAndTopPriority(KillAura)
|| checkWeaponG && player.heldItemMainhand.item.isWeapon
|| (checkCAGapple && !offhandCrystal) && CombatManager.isOnTopPriority(CrystalAura))
|| (checkCAGapple && !offhandCrystal) && CombatManager.isOnTopPriority(CrystalAura))))

private fun checkCrystal() = offhandCrystal
&& checkCACrystal && CrystalAura.isEnabled && CombatManager.isOnTopPriority(CrystalAura)
&& (!conditional || (checkCACrystal && CrystalAura.isEnabled
&& CombatManager.isOnTopPriority(CrystalAura)))

private fun SafeClientEvent.checkStrength() = offhandStrength
&& !player.isPotionActive(MobEffects.STRENGTH)
&& (!conditional || (!player.isPotionActive(MobEffects.STRENGTH)
&& player.inventoryContainer.inventory.any(Type.STRENGTH.filter)
&& (checkAuraS && CombatManager.isActiveAndTopPriority(KillAura)
|| checkWeaponS && player.heldItemMainhand.item.isWeapon)
|| checkWeaponS && player.heldItemMainhand.item.isWeapon)))

private fun SafeClientEvent.switchToType(typeOriginal: Type?, alternativeType: Boolean = false) {
// First check for whether player is holding the right item already or not
Expand All @@ -155,9 +157,7 @@ object AutoOffhand : Module(
getSlot(type)?.to(type)
?: if (attempts > 1) {
getItemSlot(type.next(), attempts - 1)
} else {
null
}
} else null

private fun SafeClientEvent.getSlot(type: Type): Slot? {
return player.offhandSlot.takeIf(filter(type))
Expand All @@ -175,9 +175,7 @@ object AutoOffhand : Module(
private fun List<Slot>.findItemByType(type: Type) =
find(filter(type))

private fun filter(type: Type) = { it: Slot ->
type.filter(it.stack)
}
private fun filter(type: Type) = { it: Slot -> type.filter(it.stack) }

private fun SafeClientEvent.updateDamage() {
maxDamage = 0f
Expand All @@ -189,12 +187,8 @@ object AutoOffhand : Module(
if (player.getDistance(entity) > 10.0f) continue

when {
mob && entity is EntityMob -> {
maxDamage = max(calcDamageFromMob(entity), maxDamage)
}
[email protected] && entity is EntityPlayer -> {
maxDamage = max(calcDamageFromPlayer(entity, true), maxDamage)
}
mob && entity is EntityMob -> maxDamage = max(calcDamageFromMob(entity), maxDamage)
[email protected] && entity is EntityPlayer -> maxDamage = max(calcDamageFromPlayer(entity, true), maxDamage)
crystal && entity is EntityEnderCrystal -> {
val damage = CombatManager.crystalMap[entity] ?: continue
maxDamage = max(damage.selfDamage, maxDamage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ object ElytraFlight : Module(


/* Vanilla */
private val upPitch by setting("Up Pitch", 30f, 0f..90f, 5f, { mode.value == ElytraFlightMode.VANILLA && page == Page.MODE_SETTINGS })
private val downPitch by setting("Down Pitch", 0f, 0f..90f, 5f, { mode.value == ElytraFlightMode.VANILLA && page == Page.MODE_SETTINGS })
private val rocketPitch by setting("Rocket Pitch", 50f, 0f..90f, 5f, { mode.value == ElytraFlightMode.VANILLA && page == Page.MODE_SETTINGS })
private val rocketPitch by setting("Rocket Pitch", 50f, 20f..80f, 2f, { mode.value == ElytraFlightMode.VANILLA && page == Page.MODE_SETTINGS }, description = "If you are boosted by a rocket, this pitch will be used. Note: on 2B2T, if you are moving too slowly when boosted, you will rubberband", unit = "°")
private val upPitch by setting("Up Pitch", 36f, 0f..60f, 2f, { mode.value == ElytraFlightMode.VANILLA && page == Page.MODE_SETTINGS }, description = "If you are moving up or you are pressing space, this pitch will be used", unit = "°")
private val downPitch by setting("Down Pitch", 35f, 0f..40f, 1f, { mode.value == ElytraFlightMode.VANILLA && page == Page.MODE_SETTINGS }, description = "Pitch used when you are moving down", unit = "°")
private val controlSpeed by setting("Control Speed", true, { mode.value == ElytraFlightMode.VANILLA && page == Page.MODE_SETTINGS }, description = "Enable to set pitch controls based on your speed")
private val speedThreshold by setting("Speed Threshold", 43, 5..100, 1, { mode.value == ElytraFlightMode.VANILLA && page == Page.MODE_SETTINGS && controlSpeed }, description = "If you are going faster then the speed threshold, the Up Pitch value will be used", unit = " MPS")
private val pitchPercentPath by setting("Pitch Percent Path", 60, 1..100, 1, { mode.value == ElytraFlightMode.VANILLA && page == Page.MODE_SETTINGS && controlSpeed }, description = "Rotates the pitch into the Down Pitch value. Low percents rotate faster, high percents rotate slower", unit = "%")

/* Fireworks */
private val fireworkUseMode by setting("Firework Use Mode", FireworkUseMode.SPEED, { mode.value == ElytraFlightMode.FIREWORKS && page == Page.MODE_SETTINGS })
Expand Down Expand Up @@ -151,8 +154,7 @@ object ElytraFlight : Module(
private var boostingTick = 0

/* Vanilla mode state */
private var firstY = 0.0
private var secondY = 0.0
private var upPitchTimer: Long = 0

/* Fireworks mode state */
private var fireworkTickTimer: TickTimer = TickTimer(TimeUnit.TICKS)
Expand Down Expand Up @@ -306,9 +308,7 @@ object ElytraFlight : Module(
if (!mc.isSingleplayer) mc.timer.tickLength = 200.0f /* Use timer to pause longer */
player.motionY = 0.0
}
else -> {
player.motionY = -0.2
}
else -> player.motionY = -0.2
}
}
}
Expand Down Expand Up @@ -529,13 +529,22 @@ object ElytraFlight : Module(
}

private fun SafeClientEvent.vanillaMode() {
secondY = player.posY
val playerSpeed = (sqrt(player.motionX * player.motionX + player.motionZ * player.motionZ)).toFloat()*20 // This is the player's speed
val speedPercentOfMax = playerSpeed/speedThreshold*100 // This is used to calculate the percent of the max speed. 50 means 50%
packetPitch = when {
// If the player is boosted with a firework, use -rocketPitch
world.loadedEntityList.any { it is EntityFireworkRocket && it.boostedEntity == player } -> -rocketPitch
firstY - secondY > 0 -> downPitch
else -> -upPitch
// If the player is moving up, the player is pressing space, or upPitchTimer is still going, use -upPitch
player.motionY > 0 || System.currentTimeMillis() < upPitchTimer || player.movementInput.jump -> -upPitch
// If controlSpeed is enabled and the speed is over the speedThreshold, then....
controlSpeed && playerSpeed > speedThreshold -> {
upPitchTimer = System.currentTimeMillis() + 1000 // Set upPitchTimer for 1 second
-upPitch} // Use -upPitch
// Simple expression that slowly curves the pitch into downPitch
controlSpeed && speedPercentOfMax < pitchPercentPath -> speedPercentOfMax/pitchPercentPath*downPitch
// If none of the other conditions are met, use downPitch
else -> downPitch
}
firstY = player.posY
}

private fun SafeClientEvent.fireworksMode() {
Expand Down