diff --git a/common/src/main/java/com/lambda/mixin/client/sound/SoundSystemMixin.java b/common/src/main/java/com/lambda/mixin/client/sound/SoundSystemMixin.java new file mode 100644 index 000000000..406d48ecc --- /dev/null +++ b/common/src/main/java/com/lambda/mixin/client/sound/SoundSystemMixin.java @@ -0,0 +1,20 @@ +package com.lambda.mixin.client.sound; + +import com.lambda.event.EventFlow; +import com.lambda.event.events.ClientEvent; +import net.minecraft.client.sound.SoundInstance; +import net.minecraft.client.sound.SoundSystem; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(SoundSystem.class) +public class SoundSystemMixin { + @Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", at = @At(value = "HEAD"), cancellable = true) + public void onPlay(SoundInstance sound, CallbackInfo ci) { + if (EventFlow.post(new ClientEvent.Sound(sound)).isCanceled()) { + ci.cancel(); + } + } +} diff --git a/common/src/main/kotlin/com/lambda/event/events/ClientEvent.kt b/common/src/main/kotlin/com/lambda/event/events/ClientEvent.kt index 0e692d8a6..42d8f50b6 100644 --- a/common/src/main/kotlin/com/lambda/event/events/ClientEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/ClientEvent.kt @@ -1,10 +1,14 @@ package com.lambda.event.events import com.lambda.event.Event +import com.lambda.event.callback.Cancellable +import com.lambda.event.callback.ICancellable +import net.minecraft.client.sound.SoundInstance abstract class ClientEvent : Event { class Shutdown : ClientEvent() class Startup : ClientEvent() - class Timer(var speed: Double) : Event + class Timer(var speed: Double) : ClientEvent() + class Sound(val sound: SoundInstance) : ClientEvent(), ICancellable by Cancellable() } \ No newline at end of file diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt new file mode 100644 index 000000000..d21dc8476 --- /dev/null +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt @@ -0,0 +1,49 @@ +package com.lambda.module.modules.movement + +import com.lambda.event.events.ClientEvent +import com.lambda.event.events.MovementEvent +import com.lambda.event.listener.SafeListener.Companion.listener +import com.lambda.module.Module +import com.lambda.module.tag.ModuleTag +import com.lambda.util.player.MovementUtils.addSpeed +import net.minecraft.sound.SoundEvents + +object ElytraFly : Module( + name = "ElytraFly", + description = "Allows you to fly with an elytra", + defaultTags = setOf(ModuleTag.MOVEMENT, ModuleTag.GRIM) +) { + // private val page by setting("Page", Page.GENERAL) // Uncomment when needed + private val mode by setting("Mode", Mode.BOOST) + + private val speed by setting("Speed", 0.02, 0.0..0.5, 0.005, description = "Speed to add when flying") { mode == Mode.BOOST } + private val mute by setting("Mute Elytra", false, "Mutes the elytra sound when gliding") + + init { + listener { + when (mode) { + Mode.BOOST -> { + if (player.isFallFlying && !player.isUsingItem) { + addSpeed(speed) + } + } + } + } + + listener { event -> + if (!mute) return@listener + if (event.sound.id != SoundEvents.ITEM_ELYTRA_FLYING.id) return@listener + event.cancel() + } + } + + private enum class Page { + GENERAL, + // Add more when needed + } + + enum class Mode { + BOOST, + // Add more when needed + } +} diff --git a/common/src/main/kotlin/com/lambda/util/primitives/extension/Entity.kt b/common/src/main/kotlin/com/lambda/util/primitives/extension/Entity.kt index 86ed6f794..06ac94ea9 100644 --- a/common/src/main/kotlin/com/lambda/util/primitives/extension/Entity.kt +++ b/common/src/main/kotlin/com/lambda/util/primitives/extension/Entity.kt @@ -3,6 +3,7 @@ package com.lambda.util.primitives.extension import com.lambda.interaction.rotation.Rotation import com.lambda.util.math.MathUtils.lerp import net.minecraft.entity.Entity +import net.minecraft.entity.LivingEntity import net.minecraft.util.math.Vec3d val Entity.prevPos @@ -11,4 +12,8 @@ val Entity.prevPos val Entity.rotation get() = Rotation(yaw, pitch) +var LivingEntity.isElytraFlying + get() = isFallFlying + set(value) { setFlag(7, value) } + fun Vec3d.interpolate(other: Vec3d, t: Double) = lerp(this, other, t) \ No newline at end of file diff --git a/common/src/main/resources/lambda.accesswidener b/common/src/main/resources/lambda.accesswidener index bd4ab6ec7..63a995c34 100644 --- a/common/src/main/resources/lambda.accesswidener +++ b/common/src/main/resources/lambda.accesswidener @@ -19,6 +19,7 @@ accessible method net/minecraft/entity/Entity movementInputToVelocity (Lnet/mine accessible method net/minecraft/entity/passive/AbstractHorseEntity setHorseFlag (IZ)V accessible method net/minecraft/entity/passive/AbstractHorseEntity updateSaddle ()V accessible field net/minecraft/entity/LivingEntity lastAttackedTicks I +accessible method net/minecraft/entity/Entity setFlag (IZ)V # Camera accessible method net/minecraft/client/render/Camera setPos (DDD)V diff --git a/common/src/main/resources/lambda.mixins.common.json b/common/src/main/resources/lambda.mixins.common.json index ff8a0378b..d9c7a6fb4 100644 --- a/common/src/main/resources/lambda.mixins.common.json +++ b/common/src/main/resources/lambda.mixins.common.json @@ -8,6 +8,7 @@ "MinecraftClientMixin", "baritone.MixinBaritonePlayerContext", "baritone.MixinLookBehavior", + "client.sound.SoundSystemMixin", "entity.ClientPlayerEntityMixin", "entity.ClientPlayInteractionManagerMixin", "entity.EntityMixin",