Skip to content

Commit 3b5b0a4

Browse files
committed
i believe this fixes the incompatibility with meteors fork of baritone. Also adds fake fly in bounce efly, but this implementation doesnt work on 2b currently
1 parent 8397006 commit 3b5b0a4

11 files changed

Lines changed: 119 additions & 43 deletions

File tree

src/main/java/com/lambda/mixin/entity/EntityMixin.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.lambda.event.events.PlayerEvent;
2323
import com.lambda.interaction.managers.rotating.RotationManager;
2424
import com.lambda.module.modules.movement.elytrafly.ElytraFly;
25+
import com.lambda.module.modules.movement.elytrafly.ElytraFly.FlyMode;
2526
import com.lambda.module.modules.render.NoRender;
2627
import com.lambda.util.math.Vec2d;
2728
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
@@ -169,7 +170,7 @@ private boolean injectIsSprinting(boolean original) {
169170
var player = getMc().player;
170171
if ((Object) this != getMc().player) return original;
171172

172-
if (ElytraFly.INSTANCE.isEnabled() && ElytraFly.getMode() == ElytraFly.FlyMode.Bounce && player.isGliding())
173+
if (ElytraFly.INSTANCE.isEnabled() && ElytraFly.getMode() == FlyMode.Bounce && player.isGliding())
173174
return true;
174175

175176
return original;
@@ -180,7 +181,7 @@ private EntityPose injectGetPose(EntityPose original) {
180181
var player = getMc().player;
181182
if ((Object) this != getMc().player) return original;
182183

183-
if (ElytraFly.INSTANCE.isDisabled() || ElytraFly.getMode() != ElytraFly.FlyMode.Bounce || !player.isGliding()) return original;
184+
if (ElytraFly.INSTANCE.isDisabled() || ElytraFly.getMode() != FlyMode.Bounce || !player.isGliding()) return original;
184185

185186
return EntityPose.GLIDING;
186187
}
@@ -192,7 +193,7 @@ private float modifyGetYaw(float original) {
192193

193194
@Inject(method = "getVelocity", at = @At("HEAD"), cancellable = true)
194195
private void injectGetVelocity(CallbackInfoReturnable<Vec3d> cir) {
195-
if (ElytraFly.INSTANCE.isDisabled() || ElytraFly.getMode() != ElytraFly.FlyMode.Bounce) return;
196-
cir.setReturnValue(ElytraFly.getBounceMode().getModifiedBounceVelocity(velocity));
196+
if (ElytraFly.INSTANCE.isDisabled() || ElytraFly.getMode() != FlyMode.Bounce) return;
197+
cir.setReturnValue(ElytraFly.getBounceMode().getModifiedVelocity(velocity));
197198
}
198199
}

src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ private void wrapPushAwayFrom(Entity entity, Operation<Void> original) {
177177
private boolean injectIsGliding(boolean original) {
178178
if (lambda$instance != Lambda.getMc().player) return original;
179179

180-
return ElytraFly.INSTANCE.isEnabled() ? ElytraFly.getBounceMode().isGliding() : original;
180+
return (ElytraFly.INSTANCE.isEnabled() && ElytraFly.getMode() == ElytraFly.FlyMode.Bounce)
181+
? ElytraFly.getBounceMode().isGliding()
182+
: original;
181183
}
182184
}

src/main/kotlin/com/lambda/interaction/BaritoneHandler.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import com.lambda.config.categories.LambdaCategory
3131
import com.lambda.config.entries.Setting.Companion.onValueChange
3232
import com.lambda.context.Automated
3333
import com.lambda.util.BlockUtils.blockPos
34-
import net.fabricmc.loader.api.FabricLoader
3534
import net.minecraft.util.BlockMirror
3635
import net.minecraft.util.BlockRotation
3736

@@ -40,10 +39,15 @@ object BaritoneHandler : Config(
4039
"baritone",
4140
LambdaCategory
4241
), Automated by AutomationConfig.DEFAULT {
43-
val isBaritoneLoaded = FabricLoader.getInstance().isModLoaded("baritone")
42+
val baritoneAvailable by lazy {
43+
runCatching {
44+
Class.forName("baritone.api.BaritoneAPI")
45+
true
46+
}.getOrDefault(false)
47+
}
4448

45-
private val baritone = if (isBaritoneLoaded) BaritoneAPI.getProvider() else null
46-
val baritoneSettings: Settings? = if (isBaritoneLoaded) BaritoneAPI.getSettings() else null
49+
private val baritone = if (baritoneAvailable) BaritoneAPI.getProvider() else null
50+
val baritoneSettings: Settings? = if (baritoneAvailable) BaritoneAPI.getSettings() else null
4751

4852
// The new config system, as its using reflections to gather metadata about the settings before registering them, does not allow for nullability.
4953
// Partially because it would be a lot of work to account for all edge cases, but also because we use the by keyword to register ConfigBlock's as delegates.
@@ -59,13 +63,13 @@ object BaritoneHandler : Config(
5963
* Whether Baritone is currently pathing
6064
*/
6165
val isPathing: Boolean
62-
get() = isBaritoneLoaded && primary?.pathingBehavior?.isPathing == true
66+
get() = baritoneAvailable && primary?.pathingBehavior?.isPathing == true
6367

6468
/**
6569
* Whether Baritone is active (pathing, calculating goal, etc.)
6670
*/
6771
val isActive: Boolean
68-
get() = isBaritoneLoaded &&
72+
get() = baritoneAvailable &&
6973
(primary?.customGoalProcess?.isActive == true ||
7074
primary?.pathingBehavior?.isPathing == true ||
7175
primary?.pathingControlManager?.mostRecentInControl()?.orElse(null)?.isActive == true ||
@@ -75,28 +79,28 @@ object BaritoneHandler : Config(
7579
* Sets the current Baritone goal and starts pathing
7680
*/
7781
fun setGoalAndPath(goal: Goal) {
78-
if (!isBaritoneLoaded) return
82+
if (!baritoneAvailable) return
7983
primary?.customGoalProcess?.setGoalAndPath(goal)
8084
}
8185

8286
/**
8387
* Sets the current Baritone goal without starting pathing
8488
*/
8589
fun setGoal(goal: Goal) {
86-
if (!isBaritoneLoaded || primary?.elytraProcess?.isLoaded != true) return
90+
if (!baritoneAvailable || primary?.elytraProcess?.isLoaded != true) return
8791
primary.customGoalProcess?.goal = goal
8892
}
8993

9094
fun setGoalAndElytraPath(goal: Goal) {
91-
if (!isBaritoneLoaded || primary?.elytraProcess?.isLoaded != true) return
95+
if (!baritoneAvailable || primary?.elytraProcess?.isLoaded != true) return
9296
primary.elytraProcess?.pathTo(goal)
9397
}
9498

9599
/**
96100
* Force cancel Baritone
97101
*/
98102
fun cancel() {
99-
if (!isBaritoneLoaded) return
103+
if (!baritoneAvailable) return
100104
primary?.pathingBehavior?.cancelEverything()
101105
primary?.elytraProcess?.resetState()
102106
}

src/main/kotlin/com/lambda/interaction/construction/simulation/result/results/BreakResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ sealed class BreakResult : BuildResult() {
182182
override val rank = Rank.BreakPlayerOnTop
183183
private val color = Color(252, 3, 207, 100)
184184

185-
override val goal = if (BaritoneHandler.isBaritoneLoaded) GoalInverted(GoalBlock(pos)) else null
185+
override val goal = if (BaritoneHandler.baritoneAvailable) GoalInverted(GoalBlock(pos)) else null
186186

187187
override fun RenderBuilder.render() {
188188
box(pos) {

src/main/kotlin/com/lambda/interaction/construction/simulation/result/results/GenericResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ sealed class GenericResult : BuildResult() {
134134
misses.minOfOrNull { pov.distanceTo(it.first) } ?: 0.0
135135
}
136136

137-
override val goal = if (BaritoneHandler.isBaritoneLoaded) GoalNear(pos, 3) else null
137+
override val goal = if (BaritoneHandler.baritoneAvailable) GoalNear(pos, 3) else null
138138

139139
override fun RenderBuilder.render() {
140140
val center = pos.toCenterPos()

src/main/kotlin/com/lambda/interaction/construction/simulation/result/results/InteractResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ sealed class InteractResult : BuildResult() {
105105
override val pos: BlockPos
106106
) : Navigable, InteractResult() {
107107
override val rank = Rank.PlaceBlockedByPlayer
108-
override val goal = if (BaritoneHandler.isBaritoneLoaded) GoalInverted(GoalBlock(pos)) else null
108+
override val goal = if (BaritoneHandler.baritoneAvailable) GoalInverted(GoalBlock(pos)) else null
109109
}
110110

111111
/**

src/main/kotlin/com/lambda/interaction/construction/simulation/result/results/PreSimResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ sealed class PreSimResult : BuildResult() {
5454
override val rank = Rank.ChunkNotLoaded
5555
private val color = Color(252, 165, 3, 100)
5656

57-
override val goal = if (BaritoneHandler.isBaritoneLoaded) GoalBlock(pos) else null
57+
override val goal = if (BaritoneHandler.baritoneAvailable) GoalBlock(pos) else null
5858

5959
override fun RenderBuilder.render() {
6060
box(pos) {

src/main/kotlin/com/lambda/module/hud/Baritone.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object Baritone : HudModule(
3030
tag = ModuleTag.HUD,
3131
) {
3232
override fun ImGuiBuilder.buildLayout() {
33-
if (!BaritoneHandler.isBaritoneLoaded) {
33+
if (!BaritoneHandler.baritoneAvailable) {
3434
text("Baritone is not loaded")
3535
return
3636
}

src/main/kotlin/com/lambda/module/modules/movement/elytrafly/ElytraFly.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import com.lambda.event.events.MovementEvent
2828
import com.lambda.event.events.PacketEvent
2929
import com.lambda.event.listener.SafeListener.Companion.listen
3030
import com.lambda.module.Module
31-
import com.lambda.module.modules.movement.BetterFirework.canOpenElytra
32-
import com.lambda.module.modules.movement.BetterFirework.isElytraEquipped
3331
import com.lambda.module.modules.movement.elytrafly.modes.BounceElytraFly
3432
import com.lambda.module.modules.movement.elytrafly.modes.ControlElytraFly
3533
import com.lambda.module.modules.movement.elytrafly.modes.GrimControlElytraFly
@@ -38,7 +36,6 @@ import com.lambda.module.tag.ModuleTag
3836
import com.lambda.threading.runSafe
3937
import com.lambda.util.extension.isElytraFlying
4038
import com.lambda.util.player.MovementUtils.addSpeed
41-
import net.minecraft.client.network.ClientPlayerEntity
4239
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket
4340
import net.minecraft.sound.SoundEvents
4441

@@ -69,9 +66,6 @@ object ElytraFly : Module(
6966
@Tab(EXTRA_TAB) private val rocketSpeed by setting("Rocket Speed", 1.0, 0.0..2.0, description = "Speed multiplier that the rocket gives you")
7067
@Tab(EXTRA_TAB) private val mute by setting("Mute Elytra", false, "Mutes the elytra sound when gliding")
7168

72-
val ClientPlayerEntity.canTakeoff: Boolean
73-
get() = (isOnGround || canOpenElytra) && isElytraEquipped
74-
7569
init {
7670
setDefaultAutomationConfig()
7771
.withEdits {

src/main/kotlin/com/lambda/module/modules/movement/elytrafly/modes/BounceElytraFly.kt

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,30 @@ import com.lambda.event.events.MovementEvent
2424
import com.lambda.event.events.TickEvent
2525
import com.lambda.event.listener.SafeListener.Companion.listen
2626
import com.lambda.interaction.BaritoneHandler
27+
import com.lambda.interaction.managers.inventory.InventoryRequest
28+
import com.lambda.interaction.managers.inventory.InventoryRequest.Companion.inventoryRequest
2729
import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotationRequest
2830
import com.lambda.interaction.managers.rotating.RotationManager
31+
import com.lambda.interaction.material.StackSelection.Companion.selectStack
2932
import com.lambda.module.hud.Speedometer
30-
import com.lambda.module.modules.movement.BetterFirework.canOpenElytra
33+
import com.lambda.module.modules.movement.BetterFirework.isElytraEquipped
34+
import com.lambda.module.modules.movement.elytrafly.ElytraFly
3135
import com.lambda.module.modules.movement.elytrafly.ElytraFly.FlyMode
32-
import com.lambda.module.modules.movement.elytrafly.ElytraFly.canTakeoff
33-
import com.lambda.module.modules.movement.elytrafly.ElytraFly.mode
3436
import com.lambda.module.modules.movement.elytrafly.ObstaclePassingMode
3537
import com.lambda.module.modules.movement.elytrafly.PasserSettings
3638
import com.lambda.threading.runSafe
39+
import com.lambda.util.CommunicationUtils.logError
3740
import com.lambda.util.SpeedUnit
3841
import com.lambda.util.TickTimer
42+
import com.lambda.util.player.SlotUtils.armorSlots
43+
import com.lambda.util.player.SlotUtils.hotbarSlots
44+
import com.lambda.util.player.SlotUtils.inventorySlots
45+
import net.minecraft.client.network.ClientPlayerEntity
3946
import net.minecraft.entity.Entity
47+
import net.minecraft.entity.EquipmentSlot
48+
import net.minecraft.entity.effect.StatusEffects
49+
import net.minecraft.item.Items
50+
import net.minecraft.screen.slot.Slot
4051
import net.minecraft.util.math.Vec3d
4152
import kotlin.math.abs
4253

@@ -52,7 +63,9 @@ class BounceElytraFly(
5263
private val autoPitch by c.setting("Auto Pitch", true, "Automatically pitches the players rotation down to bounce at faster speeds")
5364
private val pitch by c.setting("Pitch", 80.0, -90.0..90.0, 0.000001) { autoPitch }
5465
private val jump by c.setting("Jump", true, "Automatically jumps")
66+
private val fakeFly by c.setting("Fake Fly", false, "Rapidly swaps the chestplate and elytra to give the appearance the player is flying without an elytra. May also reduce durability loss")
5567
private val flagPause by c.setting("FlagPause Pause", 5, 0..100, 1, "How long to pause if the server flags you for a movement check", "ticks")
68+
private val minimizePackets by c.setting("Minimize Packets", true, "Shrinks the amount of start fly packets sent to the server as much as possible")
5669

5770
@Group(Y_MOTION_GROUP) val yMotionSetting by c.setting("Y Motion", false, "Cancels the players y velocity to aid speed")
5871
@Group(Y_MOTION_GROUP) val onlyOnDiagonal: Boolean by c.setting("Only On Diagonal", true, "Only use y motion when the player is flying on a non-axial angle") { yMotionSetting }
@@ -75,6 +88,18 @@ class BounceElytraFly(
7588
private var prevGliding: Boolean? = null
7689
private val pauseTimer = TickTimer()
7790

91+
private val ClientPlayerEntity.canTakeoff: Boolean
92+
get() = (isOnGround || canOpenElytra) && (isElytraEquipped xor fakeFly)
93+
94+
private val ClientPlayerEntity.canOpenElytra: Boolean
95+
get() = !isGliding &&
96+
!isClimbing &&
97+
!isTouchingWater &&
98+
!abilities.flying &&
99+
!isOnGround &&
100+
!this.hasVehicle() &&
101+
!this.hasStatusEffect(StatusEffects.LEVITATION)
102+
78103
init {
79104
listen<TickEvent.Pre> {
80105
pauseTimer.tick()
@@ -95,14 +120,48 @@ class BounceElytraFly(
95120
return@listen
96121
}
97122

98-
if (!player.getFlag(Entity.GLIDING_FLAG_INDEX) || yMotion) {
99-
player.setFlag(Entity.GLIDING_FLAG_INDEX, true)
100-
startFlyPacket()
123+
if (minimizePackets && player.getFlag(Entity.GLIDING_FLAG_INDEX) && !fakeFly && !yMotion) return@listen
124+
125+
if (!fakeFly) {
126+
fly()
127+
return@listen
128+
}
129+
130+
player.inventory.equipment.get(EquipmentSlot.CHEST).let { chestStack ->
131+
if (chestStack.item == Items.ELYTRA) {
132+
logError("Fake Fly requires that you don't have an elytra equipped")
133+
ElytraFly.disable()
134+
return@listen
135+
}
136+
}
137+
138+
val elytraSlot = findElytra() ?: run {
139+
logError("Fake Fly requires an elytra in your inventory, preferably in your hotbar.")
140+
ElytraFly.disable()
141+
return@listen
142+
}
143+
val elytraInHotbar = elytraSlot.index in 0..8
144+
145+
val chestSlot = player.armorSlots[1]
146+
val chestSlotEmpty = chestSlot.stack.isEmpty
147+
148+
fun InventoryRequest.InvRequestBuilder.swapChest() {
149+
if (elytraInHotbar) swap(chestSlot.id, elytraSlot.index)
150+
else {
151+
moveSlot(elytraSlot.id, chestSlot.id)
152+
if (!chestSlotEmpty) pickup(elytraSlot.id)
153+
}
101154
}
155+
156+
inventoryRequest {
157+
swapChest()
158+
action { fly() }
159+
swapChest()
160+
}.submit(false)
102161
}
103162

104163
listen<MovementEvent.InputUpdate> { event ->
105-
if (mode == FlyMode.Bounce && ((player.isGliding && jump) || jumpThisTick)) {
164+
if ((player.isGliding && jump) || jumpThisTick) {
106165
event.input.jump()
107166
jumpThisTick = false
108167
}
@@ -111,7 +170,23 @@ class BounceElytraFly(
111170
onFlag { pauseTimer.reset() }
112171
}
113172

114-
fun getModifiedBounceVelocity(original: Vec3d) =
173+
fun SafeContext.findElytra(): Slot? =
174+
selectStack {
175+
isItem(Items.ELYTRA)
176+
.and { it.damage < it.maxDamage }
177+
}.run {
178+
filterSlots(player.hotbarSlots)
179+
.firstOrNull()
180+
?: filterSlots(player.inventorySlots)
181+
.firstOrNull()
182+
}
183+
184+
fun SafeContext.fly() {
185+
player.setFlag(Entity.GLIDING_FLAG_INDEX, true)
186+
startFlyPacket()
187+
}
188+
189+
fun getModifiedVelocity(original: Vec3d) =
115190
runSafe {
116191
if (!yMotion) return@runSafe original
117192
else Vec3d(original.x, 0.0, original.z)
@@ -120,11 +195,9 @@ class BounceElytraFly(
120195
override fun isGliding(): Boolean? = runSafe {
121196
val original: Boolean = player.getFlag(Entity.GLIDING_FLAG_INDEX)
122197
return if (
123-
mode == FlyMode.Bounce &&
124198
prevGliding == true &&
125199
pauseTimer.hasSurpassed(flagPause) &&
126-
!BaritoneHandler.isActive
127-
) true
200+
!BaritoneHandler.isActive) true
128201
else {
129202
prevGliding = original
130203
original

0 commit comments

Comments
 (0)