Skip to content

Commit cfe04d4

Browse files
committed
Travel events
1 parent 45f689d commit cfe04d4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ void onJump(CallbackInfo ci) {
4545
self.velocityDirty = true;
4646
}
4747

48+
@Inject(method = "travel", at = @At("HEAD"), cancellable = true)
49+
void onTravelPre(Vec3d movementInput, CallbackInfo ci) {
50+
LivingEntity self = (LivingEntity) (Object) this;
51+
if (self != Lambda.getMc().player) return;
52+
53+
if (EventFlow.post(new MovementEvent.Travel.Pre()).isCanceled()) ci.cancel();
54+
}
55+
56+
@Inject(method = "travel", at = @At("TAIL"))
57+
void onTravelPost(Vec3d movementInput, CallbackInfo ci) {
58+
LivingEntity self = (LivingEntity) (Object) this;
59+
if (self != Lambda.getMc().player) return;
60+
61+
EventFlow.post(new MovementEvent.Travel.Post());
62+
}
63+
4864
@Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getPitch()F"))
4965
private float hookModifyFallFlyingPitch(LivingEntity entity) {
5066
Float pitch = RotationManager.getMovementPitch();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ abstract class MovementEvent : Event {
99
class Pre : MovementEvent()
1010
class Post : MovementEvent()
1111

12+
abstract class Travel : MovementEvent() {
13+
class Pre : MovementEvent(), ICancellable by Cancellable()
14+
class Post : MovementEvent()
15+
}
16+
1217
class InputUpdate(
1318
val input: Input,
1419
var slowDown: Boolean,

0 commit comments

Comments
 (0)