Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.lambda.mixin.entity;

import com.lambda.module.modules.movement.ElytraFly;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.projectile.FireworkRocketEntity;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(FireworkRocketEntity.class)
public class FireworkRocketEntityMixin {
@Redirect(
method = "tick",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/LivingEntity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V"
)
)
private void redirectSetVelocity(LivingEntity shooter, Vec3d vec3d) {
if (!ElytraFly.getDoBoost()) return;
ElytraFly.boostRocket(shooter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void injectRender(T livingEntity, float f, float g, MatrixStack matrixSt
this.lambda$pitch = rotationPitch;
}

@Redirect(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;lerp(FFF)F", ordinal = 0))
@Redirect(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;lerp(FFF)F", ordinal = 0), require = 0)
private float injectRotationPitch(float g, float f, float s) {
return Objects.requireNonNullElseGet(lambda$pitch, () -> MathHelper.lerp(g, f, s));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ 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.threading.runSafe
import com.lambda.util.player.MovementUtils.addSpeed
import net.minecraft.entity.LivingEntity
import net.minecraft.sound.SoundEvents

object ElytraFly : Module(
Expand All @@ -14,19 +16,21 @@ object ElytraFly : Module(
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 playerBoost by setting("Player Boost", true, description = "Boosts the player when flying")
private val playerSpeed by setting("Player Speed", 0.02, 0.0..0.5, 0.005, description = "Speed to add when flying") { playerBoost }
private val rocketBoost by setting("Rocket Boost", false, description = "Boosts the player when using a firework")
private val rocketSpeed by setting("Rocket Speed", 2.0, 0.0 ..2.0, description = "Speed multiplier that the rocket gives you") { rocketBoost }

private val mute by setting("Mute Elytra", false, "Mutes the elytra sound when gliding")

@JvmStatic
val doBoost: Boolean get() = isEnabled && playerBoost

init {
listener<MovementEvent.Pre> {
when (mode) {
Mode.BOOST -> {
if (player.isFallFlying && !player.isUsingItem) {
addSpeed(speed)
}
}
if (playerBoost && player.isFallFlying && !player.isUsingItem) {
addSpeed(playerSpeed)
}
}

Expand All @@ -37,13 +41,27 @@ object ElytraFly : Module(
}
}

private enum class Page {
GENERAL,
// Add more when needed
@JvmStatic
fun boostRocket(shooter: LivingEntity) {
runSafe {
if (shooter != player) return@runSafe

val vec = player.rotationVector
val velocity = player.velocity

val d = 1.5 * rocketSpeed
val e = 0.1 * rocketSpeed

player.velocity = velocity.add(
vec.x * e + (vec.x * d - velocity.x) * 0.5,
vec.y * e + (vec.y * d - velocity.y) * 0.5,
vec.z * e + (vec.z * d - velocity.z) * 0.5
)
}
}

enum class Mode {
BOOST,
private enum class Page {
GENERAL,
// Add more when needed
}
}
3 changes: 2 additions & 1 deletion common/src/main/resources/lambda.mixins.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"render.WorldRendererMixin",
"world.BlockCollisionSpliteratorMixin",
"world.ClientChunkManagerMixin",
"world.ClientWorldMixin"
"world.ClientWorldMixin",
"entity.FireworkRocketEntityMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down