1
1
package com .lambda .mixin .entity ;
2
2
3
+ import com .lambda .EntityLivingBaseFireworkHelper ;
3
4
import com .lambda .client .module .modules .movement .ElytraFlight ;
4
- import net .minecraft .client .entity .EntityPlayerSP ;
5
5
import net .minecraft .entity .Entity ;
6
6
import net .minecraft .entity .EntityLivingBase ;
7
- import net .minecraft .entity .item .EntityFireworkRocket ;
8
7
import net .minecraft .util .math .MathHelper ;
9
8
import net .minecraft .util .math .Vec3d ;
10
9
import net .minecraft .world .World ;
11
- import net .minecraftforge .fml .common .ObfuscationReflectionHelper ;
12
10
import org .objectweb .asm .Opcodes ;
13
11
import org .spongepowered .asm .mixin .Mixin ;
14
12
import org .spongepowered .asm .mixin .Unique ;
19
17
import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
20
18
import org .spongepowered .asm .mixin .injection .callback .LocalCapture ;
21
19
22
- import java .lang .reflect .Field ;
23
-
24
20
@ Mixin (EntityLivingBase .class )
25
21
public abstract class MixinEntityLivingBase extends Entity {
26
22
@ Unique
27
23
private Vec3d modifiedVec = null ;
28
- // This is a bit silly and bad for performance but fixes compatibility with old mixin versions like the one used by impact
29
- @ Unique
30
- private static final Field boostedEntity ;
31
-
32
- static {
33
- boostedEntity = ObfuscationReflectionHelper .findField (EntityFireworkRocket .class , "field_191513_e" );
34
- }
35
24
36
25
public MixinEntityLivingBase (World worldIn ) {
37
26
super (worldIn );
@@ -42,7 +31,7 @@ public MixinEntityLivingBase(World worldIn) {
42
31
at = @ At (value = "INVOKE_ASSIGN" , target = "Lnet/minecraft/entity/EntityLivingBase;getLookVec()Lnet/minecraft/util/math/Vec3d;" , ordinal = 0 )
43
32
)
44
33
private Vec3d vec3d (Vec3d original ) {
45
- if (shouldWork ()) {
34
+ if (EntityLivingBaseFireworkHelper . shouldWork (EntityLivingBase . class . cast ( this ) )) {
46
35
float negPacketPitch = -ElytraFlight .INSTANCE .getPacketPitch ();
47
36
float f0 = MathHelper .cos ((float ) (-this .rotationYaw * 0.017453292f - Math .PI ));
48
37
float f1 = MathHelper .sin ((float ) (-this .rotationYaw * 0.017453292f - Math .PI ));
@@ -60,7 +49,7 @@ private Vec3d vec3d(Vec3d original) {
60
49
ordinal = 3
61
50
)
62
51
private float f (float original ) {
63
- if (shouldWork ()) {
52
+ if (EntityLivingBaseFireworkHelper . shouldWork (EntityLivingBase . class . cast ( this ) )) {
64
53
return ElytraFlight .INSTANCE .getPacketPitch () * 0.017453292f ;
65
54
}
66
55
return original ;
@@ -87,7 +76,7 @@ private void getVec(
87
76
at = @ At (value = "FIELD" , opcode = Opcodes .GETFIELD , target = "Lnet/minecraft/entity/EntityLivingBase;motionX:D" , ordinal = 7 )
88
77
)
89
78
public double motionX (EntityLivingBase it ) {
90
- if (shouldModify ()) {
79
+ if (EntityLivingBaseFireworkHelper . shouldModify (EntityLivingBase . class . cast ( this ) )) {
91
80
it .motionX += modifiedVec .x * 0.1 + (modifiedVec .x * 1.5 - this .motionX ) * 0.5 ;
92
81
}
93
82
return it .motionX ;
@@ -98,7 +87,7 @@ public double motionX(EntityLivingBase it) {
98
87
at = @ At (value = "FIELD" , opcode = Opcodes .GETFIELD , target = "Lnet/minecraft/entity/EntityLivingBase;motionY:D" , ordinal = 7 )
99
88
)
100
89
public double motionY (EntityLivingBase it ) {
101
- if (shouldModify ()) {
90
+ if (EntityLivingBaseFireworkHelper . shouldModify (EntityLivingBase . class . cast ( this ) )) {
102
91
it .motionY += modifiedVec .y * 0.1 + (modifiedVec .y * 1.5 - this .motionY ) * 0.5 ;
103
92
}
104
93
return it .motionY ;
@@ -109,32 +98,10 @@ public double motionY(EntityLivingBase it) {
109
98
at = @ At (value = "FIELD" , opcode = Opcodes .GETFIELD , target = "Lnet/minecraft/entity/EntityLivingBase;motionZ:D" , ordinal = 7 )
110
99
)
111
100
public double motionZ (EntityLivingBase it ) {
112
- if (shouldModify ()) {
101
+ if (EntityLivingBaseFireworkHelper . shouldModify (EntityLivingBase . class . cast ( this ) )) {
113
102
it .motionZ += modifiedVec .z * 0.1 + (modifiedVec .z * 1.5 - this .motionZ ) * 0.5 ;
114
103
}
115
104
return it .motionZ ;
116
105
}
117
106
118
- @ Unique
119
- private boolean shouldWork () {
120
- return EntityPlayerSP .class .isAssignableFrom (getClass ())
121
- && ElytraFlight .INSTANCE .isEnabled ()
122
- && ElytraFlight .INSTANCE .getMode ().getValue () == ElytraFlight .ElytraFlightMode .VANILLA ;
123
- }
124
-
125
- @ Unique
126
- private boolean shouldModify () {
127
- return shouldWork () && world .loadedEntityList .stream ().anyMatch (entity -> {
128
- if (entity instanceof EntityFireworkRocket ) {
129
- try {
130
- EntityLivingBase boosted = (EntityLivingBase ) boostedEntity .get (entity );
131
- return boosted != null && boosted .equals (this );
132
- } catch (IllegalAccessException e ) {
133
- throw new RuntimeException (e ); // This should absolutely never happen
134
- }
135
- }
136
- return false ;
137
- }
138
- );
139
- }
140
107
}
0 commit comments