Skip to content

Commit 19d70c1

Browse files
Camii2407emyfopsbladektAvanatiker
authored
Added elytra flight mode boost (#50)
Co-authored-by: Edouard127 <46357922+Edouard127@users.noreply.github.com> Co-authored-by: Blade-gl <bladecore.kt@gmail.com> Co-authored-by: Constructor <fractalminds@protonmail.com>
1 parent 2db56bf commit 19d70c1

File tree

6 files changed

+81
-1
lines changed

6 files changed

+81
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.lambda.mixin.client.sound;
2+
3+
import com.lambda.event.EventFlow;
4+
import com.lambda.event.events.ClientEvent;
5+
import net.minecraft.client.sound.SoundInstance;
6+
import net.minecraft.client.sound.SoundSystem;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
12+
@Mixin(SoundSystem.class)
13+
public class SoundSystemMixin {
14+
@Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", at = @At(value = "HEAD"), cancellable = true)
15+
public void onPlay(SoundInstance sound, CallbackInfo ci) {
16+
if (EventFlow.post(new ClientEvent.Sound(sound)).isCanceled()) {
17+
ci.cancel();
18+
}
19+
}
20+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.lambda.event.events
22

33
import com.lambda.event.Event
4+
import com.lambda.event.callback.Cancellable
5+
import com.lambda.event.callback.ICancellable
6+
import net.minecraft.client.sound.SoundInstance
47

58

69
abstract class ClientEvent : Event {
710
class Shutdown : ClientEvent()
811
class Startup : ClientEvent()
9-
class Timer(var speed: Double) : Event
12+
class Timer(var speed: Double) : ClientEvent()
13+
class Sound(val sound: SoundInstance) : ClientEvent(), ICancellable by Cancellable()
1014
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.lambda.module.modules.movement
2+
3+
import com.lambda.event.events.ClientEvent
4+
import com.lambda.event.events.MovementEvent
5+
import com.lambda.event.listener.SafeListener.Companion.listener
6+
import com.lambda.module.Module
7+
import com.lambda.module.tag.ModuleTag
8+
import com.lambda.util.player.MovementUtils.addSpeed
9+
import net.minecraft.sound.SoundEvents
10+
11+
object ElytraFly : Module(
12+
name = "ElytraFly",
13+
description = "Allows you to fly with an elytra",
14+
defaultTags = setOf(ModuleTag.MOVEMENT, ModuleTag.GRIM)
15+
) {
16+
// private val page by setting("Page", Page.GENERAL) // Uncomment when needed
17+
private val mode by setting("Mode", Mode.BOOST)
18+
19+
private val speed by setting("Speed", 0.02, 0.0..0.5, 0.005, description = "Speed to add when flying") { mode == Mode.BOOST }
20+
private val mute by setting("Mute Elytra", false, "Mutes the elytra sound when gliding")
21+
22+
init {
23+
listener<MovementEvent.Pre> {
24+
when (mode) {
25+
Mode.BOOST -> {
26+
if (player.isFallFlying && !player.isUsingItem) {
27+
addSpeed(speed)
28+
}
29+
}
30+
}
31+
}
32+
33+
listener<ClientEvent.Sound> { event ->
34+
if (!mute) return@listener
35+
if (event.sound.id != SoundEvents.ITEM_ELYTRA_FLYING.id) return@listener
36+
event.cancel()
37+
}
38+
}
39+
40+
private enum class Page {
41+
GENERAL,
42+
// Add more when needed
43+
}
44+
45+
enum class Mode {
46+
BOOST,
47+
// Add more when needed
48+
}
49+
}

common/src/main/kotlin/com/lambda/util/primitives/extension/Entity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.lambda.util.primitives.extension
33
import com.lambda.interaction.rotation.Rotation
44
import com.lambda.util.math.MathUtils.lerp
55
import net.minecraft.entity.Entity
6+
import net.minecraft.entity.LivingEntity
67
import net.minecraft.util.math.Vec3d
78

89
val Entity.prevPos
@@ -11,4 +12,8 @@ val Entity.prevPos
1112
val Entity.rotation
1213
get() = Rotation(yaw, pitch)
1314

15+
var LivingEntity.isElytraFlying
16+
get() = isFallFlying
17+
set(value) { setFlag(7, value) }
18+
1419
fun Vec3d.interpolate(other: Vec3d, t: Double) = lerp(this, other, t)

common/src/main/resources/lambda.accesswidener

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ accessible method net/minecraft/entity/Entity movementInputToVelocity (Lnet/mine
1919
accessible method net/minecraft/entity/passive/AbstractHorseEntity setHorseFlag (IZ)V
2020
accessible method net/minecraft/entity/passive/AbstractHorseEntity updateSaddle ()V
2121
accessible field net/minecraft/entity/LivingEntity lastAttackedTicks I
22+
accessible method net/minecraft/entity/Entity setFlag (IZ)V
2223

2324
# Camera
2425
accessible method net/minecraft/client/render/Camera setPos (DDD)V

common/src/main/resources/lambda.mixins.common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"MinecraftClientMixin",
99
"baritone.MixinBaritonePlayerContext",
1010
"baritone.MixinLookBehavior",
11+
"client.sound.SoundSystemMixin",
1112
"entity.ClientPlayerEntityMixin",
1213
"entity.ClientPlayInteractionManagerMixin",
1314
"entity.EntityMixin",

0 commit comments

Comments
 (0)