Skip to content

Commit 9f50881

Browse files
Camii2407emyfopsbladektAvanatiker
authored
[1.20.x] [All] ElytraFly: Rocket Boost (#75)
Provide a brief description of the changes made in this PR: - **What does this PR do?** - Adds RocketBoost mode to ElytraFly module --------- 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 8bc3fba commit 9f50881

File tree

4 files changed

+58
-15
lines changed

4 files changed

+58
-15
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.lambda.mixin.entity;
2+
3+
import com.lambda.module.modules.movement.ElytraFly;
4+
import net.minecraft.entity.LivingEntity;
5+
import net.minecraft.entity.projectile.FireworkRocketEntity;
6+
import net.minecraft.util.math.Vec3d;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Redirect;
10+
11+
@Mixin(FireworkRocketEntity.class)
12+
public class FireworkRocketEntityMixin {
13+
@Redirect(
14+
method = "tick",
15+
at = @At(
16+
value = "INVOKE",
17+
target = "Lnet/minecraft/entity/LivingEntity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V"
18+
)
19+
)
20+
private void redirectSetVelocity(LivingEntity shooter, Vec3d vec3d) {
21+
if (!ElytraFly.getDoBoost()) return;
22+
ElytraFly.boostRocket(shooter);
23+
}
24+
}

common/src/main/java/com/lambda/mixin/render/LivingEntityRendererMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private void injectRender(T livingEntity, float f, float g, MatrixStack matrixSt
3434
this.lambda$pitch = rotationPitch;
3535
}
3636

37-
@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))
37+
@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)
3838
private float injectRotationPitch(float g, float f, float s) {
3939
return Objects.requireNonNullElseGet(lambda$pitch, () -> MathHelper.lerp(g, f, s));
4040
}

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

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import com.lambda.event.events.MovementEvent
55
import com.lambda.event.listener.SafeListener.Companion.listener
66
import com.lambda.module.Module
77
import com.lambda.module.tag.ModuleTag
8+
import com.lambda.threading.runSafe
89
import com.lambda.util.player.MovementUtils.addSpeed
10+
import net.minecraft.entity.LivingEntity
911
import net.minecraft.sound.SoundEvents
1012

1113
object ElytraFly : Module(
@@ -14,19 +16,21 @@ object ElytraFly : Module(
1416
defaultTags = setOf(ModuleTag.MOVEMENT, ModuleTag.GRIM)
1517
) {
1618
// private val page by setting("Page", Page.GENERAL) // Uncomment when needed
17-
private val mode by setting("Mode", Mode.BOOST)
1819

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 playerBoost by setting("Player Boost", true, description = "Boosts the player when flying")
21+
private val playerSpeed by setting("Player Speed", 0.02, 0.0..0.5, 0.005, description = "Speed to add when flying") { playerBoost }
22+
private val rocketBoost by setting("Rocket Boost", false, description = "Boosts the player when using a firework")
23+
private val rocketSpeed by setting("Rocket Speed", 2.0, 0.0 ..2.0, description = "Speed multiplier that the rocket gives you") { rocketBoost }
24+
2025
private val mute by setting("Mute Elytra", false, "Mutes the elytra sound when gliding")
2126

27+
@JvmStatic
28+
val doBoost: Boolean get() = isEnabled && playerBoost
29+
2230
init {
2331
listener<MovementEvent.Pre> {
24-
when (mode) {
25-
Mode.BOOST -> {
26-
if (player.isFallFlying && !player.isUsingItem) {
27-
addSpeed(speed)
28-
}
29-
}
32+
if (playerBoost && player.isFallFlying && !player.isUsingItem) {
33+
addSpeed(playerSpeed)
3034
}
3135
}
3236

@@ -37,13 +41,27 @@ object ElytraFly : Module(
3741
}
3842
}
3943

40-
private enum class Page {
41-
GENERAL,
42-
// Add more when needed
44+
@JvmStatic
45+
fun boostRocket(shooter: LivingEntity) {
46+
runSafe {
47+
if (shooter != player) return@runSafe
48+
49+
val vec = player.rotationVector
50+
val velocity = player.velocity
51+
52+
val d = 1.5 * rocketSpeed
53+
val e = 0.1 * rocketSpeed
54+
55+
player.velocity = velocity.add(
56+
vec.x * e + (vec.x * d - velocity.x) * 0.5,
57+
vec.y * e + (vec.y * d - velocity.y) * 0.5,
58+
vec.z * e + (vec.z * d - velocity.z) * 0.5
59+
)
60+
}
4361
}
4462

45-
enum class Mode {
46-
BOOST,
63+
private enum class Page {
64+
GENERAL,
4765
// Add more when needed
4866
}
4967
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"render.WorldRendererMixin",
4343
"world.BlockCollisionSpliteratorMixin",
4444
"world.ClientChunkManagerMixin",
45-
"world.ClientWorldMixin"
45+
"world.ClientWorldMixin",
46+
"entity.FireworkRocketEntityMixin"
4647
],
4748
"injectors": {
4849
"defaultRequire": 1

0 commit comments

Comments
 (0)