Skip to content

Commit 0732c52

Browse files
authored
rework jump event mixin to resolve compatibility issues (#287)
1 parent 67a8575 commit 0732c52

2 files changed

Lines changed: 18 additions & 35 deletions

File tree

src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@
2424
import com.lambda.module.modules.movement.ElytraFly;
2525
import com.lambda.module.modules.movement.Velocity;
2626
import com.lambda.module.modules.render.ViewModel;
27+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
2728
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
2829
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
2930
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
3031
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
32+
import com.llamalad7.mixinextras.sugar.Local;
33+
import com.llamalad7.mixinextras.sugar.ref.LocalFloatRef;
3134
import net.minecraft.entity.Entity;
3235
import net.minecraft.entity.LivingEntity;
33-
import net.minecraft.util.math.MathHelper;
3436
import net.minecraft.util.math.Vec3d;
3537
import org.spongepowered.asm.mixin.Mixin;
36-
import org.spongepowered.asm.mixin.Shadow;
3738
import org.spongepowered.asm.mixin.Unique;
3839
import org.spongepowered.asm.mixin.injection.At;
3940
import org.spongepowered.asm.mixin.injection.Inject;
@@ -45,44 +46,26 @@ public abstract class LivingEntityMixin extends EntityMixin {
4546

4647
@Unique private final LivingEntity lambda$instance = (LivingEntity) (Object) this;
4748

48-
@Shadow protected abstract float getJumpVelocity();
49+
@Inject(method = "jump", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/LivingEntity;getJumpVelocity()F"), cancellable = true)
50+
void onJump(CallbackInfo ci, @Local LocalFloatRef heightRef) {
51+
if (lambda$instance != Lambda.getMc().player) return;
4952

50-
/**
51-
* Overwrites the jump function to use our rotation and movements
52-
* <pre>{@code
53-
* protected void jump() {
54-
* Vec3d vec3d = this.getVelocity();
55-
* this.setVelocity(vec3d.x, (double)this.getJumpVelocity(), vec3d.z);
56-
* if (this.isSprinting()) {
57-
* float f = this.getYaw() * (float) (Math.PI / 180.0);
58-
* this.setVelocity(this.getVelocity().add((double)(-MathHelper.sin(f) * 0.2F), 0.0, (double)(MathHelper.cos(f) * 0.2F)));
59-
* }
60-
*
61-
* this.velocityDirty = true;
62-
* }
63-
* }</pre>
64-
*/
65-
@Inject(method = "jump", at = @At("HEAD"), cancellable = true)
66-
void onJump(CallbackInfo ci) {
67-
LivingEntity self = lambda$instance;
68-
if (self != Lambda.getMc().player) return;
69-
ci.cancel();
70-
71-
float height = this.getJumpVelocity();
53+
float height = heightRef.get();
7254
MovementEvent.Jump event = EventFlow.post(new MovementEvent.Jump(height));
55+
heightRef.set(event.getHeight());
7356

74-
if (event.isCanceled()) return;
75-
76-
Vec3d vec3d = self.getVelocity();
77-
self.setVelocity(vec3d.x, event.getHeight(), vec3d.z);
57+
if (event.isCanceled()) {
58+
ci.cancel();
59+
}
60+
}
7861

79-
if (self.isSprinting()) {
62+
@ModifyExpressionValue(method = "jump", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"))
63+
float hookModifyJumpYaw(float original) {
64+
if (lambda$instance == Lambda.getMc().player) {
8065
Float yaw = RotationManager.getMovementYaw();
81-
float f = ((yaw != null) ? yaw : self.getYaw()) * ((float) Math.PI / 180);
82-
self.setVelocity(self.getVelocity().add(-MathHelper.sin(f) * 0.2f, 0.0, MathHelper.cos(f) * 0.2f));
66+
return yaw == null ? original : yaw;
8367
}
84-
85-
self.velocityDirty = true;
68+
return original;
8669
}
8770

8871
@Inject(method = "travel", at = @At("HEAD"), cancellable = true)

src/main/kotlin/com/lambda/event/events/MovementEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,5 @@ sealed class MovementEvent {
123123
*
124124
* @property height The height of the jump. Can be modified!
125125
*/
126-
data class Jump(var height: Double) : ICancellable by Cancellable()
126+
data class Jump(var height: Float) : ICancellable by Cancellable()
127127
}

0 commit comments

Comments
 (0)