-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathEntityMixin.java
More file actions
164 lines (143 loc) · 7.05 KB
/
EntityMixin.java
File metadata and controls
164 lines (143 loc) · 7.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright 2025 Lambda
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lambda.mixin.entity;
import com.lambda.Lambda;
import com.lambda.event.EventFlow;
import com.lambda.event.events.EntityEvent;
import com.lambda.event.events.PlayerEvent;
import com.lambda.interaction.request.rotating.RotationManager;
import com.lambda.interaction.request.rotating.RotationMode;
import com.lambda.module.modules.player.RotationLock;
import com.lambda.module.modules.render.NoRender;
import com.lambda.util.math.Vec2d;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MovementType;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Entity.class)
public abstract class EntityMixin {
@Shadow
public void move(MovementType movementType, Vec3d movement) {
}
@Shadow
public abstract float getYaw();
/**
* Modifies the player yaw when there is an active rotation to apply the player velocity correctly
*/
@Redirect(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
public float velocityYaw(Entity entity) {
if ((Object) this != Lambda.getMc().player) return getYaw();
Float y = RotationManager.getMovementYaw();
if (y == null) return getYaw();
return y;
}
/**
* Modifies the player yaw for the given tick delta for interpolation when there is an active rotation
* <pre>{@code
* public final Vec3d getRotationVec(float tickDelta) {
* return this.getRotationVector(this.getPitch(tickDelta), this.getYaw(tickDelta));
* }
* }</pre>
*/
@Redirect(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw(F)F"))
float fixDirectionYaw(Entity entity, float tickDelta) {
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
if (entity != Lambda.getMc().player || rot == null) return entity.getYaw(tickDelta);
return (float) rot.getX();
}
/**
* Modifies the player pitch for the given tick delta for interpolation when there is an active rotation
* <pre>{@code
* public final Vec3d getRotationVec(float tickDelta) {
* return this.getRotationVector(this.getPitch(tickDelta), this.getYaw(tickDelta));
* }
* }</pre>
*/
@Redirect(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch(F)F"))
float fixDirectionPitch(Entity entity, float tickDelta) {
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
if (entity != Lambda.getMc().player || rot == null) return entity.getPitch(tickDelta);
return (float) rot.getY();
}
/**
* Modifies the player yaw for the current rotation yaw
* <pre>{@code
* public Vec3d getRotationVector() {
* return this.getRotationVector(this.getPitch(), this.getYaw());
* }
* }</pre>
*/
@Redirect(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
float fixDirectionYaw2(Entity entity) {
Vec2d rot = RotationManager.getRotationForVector(1.0);
if (entity != Lambda.getMc().player || rot == null) return entity.getYaw();
return (float) rot.getX();
}
/**
* Modifies the player yaw for the current rotation pitch
* <pre>{@code
* public Vec3d getRotationVector() {
* return this.getRotationVector(this.getPitch(), this.getYaw());
* }
* }</pre>
*/
@Redirect(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch()F"))
float fixDirectionPitch2(Entity entity) {
Vec2d rot = RotationManager.getRotationForVector(1.0);
if (entity != Lambda.getMc().player || rot == null) return entity.getPitch();
return (float) rot.getY();
}
@Inject(method = "changeLookDirection", at = @At("HEAD"), cancellable = true)
private void changeLookDirection(double cursorDeltaX, double cursorDeltaY, CallbackInfo ci) {
if (EventFlow.post(new PlayerEvent.ChangeLookDirection(cursorDeltaX, cursorDeltaY)).isCanceled()) ci.cancel();
}
@Inject(method = "onTrackedDataSet(Lnet/minecraft/entity/data/TrackedData;)V", at = @At("TAIL"))
public void onTrackedDataSet(TrackedData<?> data, CallbackInfo ci) {
Entity entity = (Entity) (Object) this;
EventFlow.post(new EntityEvent.Update(entity, data));
}
@ModifyExpressionValue(method = "isInvisible", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getFlag(I)Z"))
private boolean modifyGetFlagInvisible(boolean original) {
return (NoRender.INSTANCE.isDisabled() || !NoRender.getNoInvisibility()) && original;
}
@ModifyExpressionValue(method = "isGlowing", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getFlag(I)Z"))
private boolean modifyGetFlagGlowing(boolean original) {
return (NoRender.INSTANCE.isDisabled() || !NoRender.getNoGlow()) && original;
}
@WrapWithCondition(method = "changeLookDirection", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setYaw(F)V"))
private boolean wrapSetYaw(Entity instance, float yaw) {
return (instance != Lambda.getMc().player ||
RotationLock.INSTANCE.isDisabled() ||
RotationLock.INSTANCE.getRotationConfig().getRotationMode() != RotationMode.Lock ||
RotationLock.getYawMode() == RotationLock.RotationMode.None);
}
@WrapWithCondition(method = "changeLookDirection", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setPitch(F)V"))
private boolean wrapSetPitch(Entity instance, float yaw) {
return (instance != Lambda.getMc().player ||
RotationLock.INSTANCE.isDisabled() ||
RotationLock.INSTANCE.getRotationConfig().getRotationMode() != RotationMode.Lock ||
RotationLock.getPitchMode() == RotationLock.RotationMode.None);
}
}