diff --git a/common/src/main/java/com/lambda/mixin/entity/FireworkRocketEntityMixin.java b/common/src/main/java/com/lambda/mixin/entity/FireworkRocketEntityMixin.java new file mode 100644 index 000000000..9fbeb63c7 --- /dev/null +++ b/common/src/main/java/com/lambda/mixin/entity/FireworkRocketEntityMixin.java @@ -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); + } +} diff --git a/common/src/main/java/com/lambda/mixin/render/LivingEntityRendererMixin.java b/common/src/main/java/com/lambda/mixin/render/LivingEntityRendererMixin.java index 5de183ea1..488f30745 100644 --- a/common/src/main/java/com/lambda/mixin/render/LivingEntityRendererMixin.java +++ b/common/src/main/java/com/lambda/mixin/render/LivingEntityRendererMixin.java @@ -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)); } 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 index d21dc8476..fef1b96ef 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt @@ -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( @@ -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 { - when (mode) { - Mode.BOOST -> { - if (player.isFallFlying && !player.isUsingItem) { - addSpeed(speed) - } - } + if (playerBoost && player.isFallFlying && !player.isUsingItem) { + addSpeed(playerSpeed) } } @@ -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 } } diff --git a/common/src/main/resources/lambda.mixins.common.json b/common/src/main/resources/lambda.mixins.common.json index 71f9d0ea9..640f64e30 100644 --- a/common/src/main/resources/lambda.mixins.common.json +++ b/common/src/main/resources/lambda.mixins.common.json @@ -42,7 +42,8 @@ "render.WorldRendererMixin", "world.BlockCollisionSpliteratorMixin", "world.ClientChunkManagerMixin", - "world.ClientWorldMixin" + "world.ClientWorldMixin", + "entity.FireworkRocketEntityMixin" ], "injectors": { "defaultRequire": 1