-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathLivingEntityMixin.java
More file actions
172 lines (151 loc) · 6.54 KB
/
LivingEntityMixin.java
File metadata and controls
172 lines (151 loc) · 6.54 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
165
166
167
168
169
170
171
172
/*
* 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.MovementEvent;
import com.lambda.module.modules.render.ViewModel;
import com.lambda.interaction.request.rotating.RotationManager;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends EntityMixin {
@Shadow
protected abstract float getJumpVelocity();
@Unique
private final LivingEntity lambda$instance = (LivingEntity) (Object) this;
/**
* Overwrites the jump function to use our rotation and movements
* <pre>{@code
* protected void jump() {
* Vec3d vec3d = this.getVelocity();
* this.setVelocity(vec3d.x, (double)this.getJumpVelocity(), vec3d.z);
* if (this.isSprinting()) {
* float f = this.getYaw() * (float) (Math.PI / 180.0);
* this.setVelocity(this.getVelocity().add((double)(-MathHelper.sin(f) * 0.2F), 0.0, (double)(MathHelper.cos(f) * 0.2F)));
* }
*
* this.velocityDirty = true;
* }
* }</pre>
*/
@Inject(method = "jump", at = @At("HEAD"), cancellable = true)
void onJump(CallbackInfo ci) {
LivingEntity self = lambda$instance;
if (self != Lambda.getMc().player) return;
ci.cancel();
float height = this.getJumpVelocity();
MovementEvent.Jump event = EventFlow.post(new MovementEvent.Jump(height));
if (event.isCanceled()) return;
Vec3d vec3d = self.getVelocity();
self.setVelocity(vec3d.x, event.getHeight(), vec3d.z);
if (self.isSprinting()) {
Float yaw = RotationManager.getMovementYaw();
float f = ((yaw != null) ? yaw : self.getYaw()) * ((float) Math.PI / 180);
self.setVelocity(self.getVelocity().add(-MathHelper.sin(f) * 0.2f, 0.0, MathHelper.cos(f) * 0.2f));
}
self.velocityDirty = true;
}
@Inject(method = "travel", at = @At("HEAD"), cancellable = true)
void onTravelPre(Vec3d movementInput, CallbackInfo ci) {
if (EventFlow.post(new MovementEvent.Entity.Pre(lambda$instance, movementInput)).isCanceled()) {
ci.cancel();
}
}
@Inject(method = "travel", at = @At("TAIL"))
void onTravelPost(Vec3d movementInput, CallbackInfo ci) {
EventFlow.post(new MovementEvent.Entity.Post(lambda$instance, movementInput));
}
/**
* Modifies the entity pitch with the current rotation when the entity is fall flying
*/
@Redirect(method = "calcGlidingVelocity(Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getPitch()F"))
private float hookModifyFallFlyingPitch(LivingEntity entity) {
Float pitch = RotationManager.getMovementPitch();
if (entity != Lambda.getMc().player || pitch == null) return entity.getPitch();
return pitch;
}
/**
* Modifies the entity yaw with the active rotation yaw when the entity swing its hand
* <pre>{@code
* protected float turnHead(float bodyRotation, float headRotation) {
* float f = MathHelper.wrapDegrees(bodyRotation - this.bodyYaw);
* this.bodyYaw += f * 0.3F;
* float g = MathHelper.wrapDegrees(this.getYaw() - this.bodyYaw);
* float h = this.getMaxRelativeHeadRotation();
* if (Math.abs(g) > h) {
* this.bodyYaw = this.bodyYaw + (g - (float)MathHelper.sign((double)g) * h);
* }
*
* boolean bl = g < -90.0F || g >= 90.0F;
* if (bl) {
* headRotation *= -1.0F;
* }
*
* return headRotation;
* }
* }</pre>
*/
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"), slice = @Slice(to = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F", ordinal = 1)))
private float rotBody(LivingEntity entity) {
if (lambda$instance != Lambda.getMc().player) {
return entity.getYaw();
}
Float yaw = RotationManager.getHeadYaw();
return (yaw == null) ? entity.getYaw() : yaw;
}
/**
* Modifies the entity yaw with the active rotation yaw
* <pre>{@code
* protected float turnHead(float bodyRotation, float headRotation) {
* float f = MathHelper.wrapDegrees(bodyRotation - this.bodyYaw);
* this.bodyYaw += f * 0.3F;
* float g = MathHelper.wrapDegrees(this.getYaw() - this.bodyYaw);
* float h = this.getMaxRelativeHeadRotation();
* if (Math.abs(g) > h) {
* this.bodyYaw = this.bodyYaw + (g - (float)MathHelper.sign((double)g) * h);
* }
*
* boolean bl = g < -90.0F || g >= 90.0F;
* if (bl) {
* headRotation *= -1.0F;
* }
*
* return headRotation;
* }
* }</pre>
*/
@Redirect(method = "turnHead", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"))
private float rotHead(LivingEntity entity) {
if (lambda$instance != Lambda.getMc().player) {
return entity.getYaw();
}
Float yaw = RotationManager.getHeadYaw();
return (yaw == null) ? entity.getYaw() : yaw;
}
@ModifyConstant(method = "getHandSwingDuration", constant = @Constant(intValue = 6))
private int getHandSwingDuration(int constant) {
if (lambda$instance != Lambda.getMc().player || ViewModel.INSTANCE.isDisabled()) return constant;
return ViewModel.INSTANCE.getSwingDuration();
}
}