Skip to content

Commit aa7febd

Browse files
authored
Removed Firework Mixin hack (#384)
1 parent 3fd22fe commit aa7febd

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.lambda;
2+
3+
import com.lambda.client.module.modules.movement.ElytraFlight;
4+
import com.lambda.mixin.accessor.AccessorEntityFireworkRocket;
5+
import com.lambda.mixin.entity.MixinEntityLivingBase;
6+
import net.minecraft.client.entity.EntityPlayerSP;
7+
import net.minecraft.entity.EntityLivingBase;
8+
9+
/**
10+
* Using {@link AccessorEntityFireworkRocket} in {@link MixinEntityLivingBase} causes a crash on older
11+
* Mixin versions (like the one Impact uses). Putting the methods using AccessorEntityFireworkRocket outside
12+
* the MixinEntityLivingBase seems to fix the issue.
13+
*/
14+
public class EntityLivingBaseFireworkHelper {
15+
public static boolean shouldWork(EntityLivingBase entity) {
16+
return EntityPlayerSP.class.isAssignableFrom(entity.getClass())
17+
&& ElytraFlight.INSTANCE.isEnabled()
18+
&& ElytraFlight.INSTANCE.getMode().getValue() == ElytraFlight.ElytraFlightMode.VANILLA;
19+
}
20+
21+
public static boolean shouldModify(EntityLivingBase entity) {
22+
return shouldWork(entity) && entity.world.loadedEntityList.stream().anyMatch(firework -> {
23+
if (firework instanceof AccessorEntityFireworkRocket) {
24+
EntityLivingBase boosted = ((AccessorEntityFireworkRocket) firework).getBoostedEntity();
25+
return boosted != null && boosted.equals(entity);
26+
}
27+
28+
return false;
29+
}
30+
);
31+
}
32+
33+
}

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

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.lambda.mixin.entity;
22

3+
import com.lambda.EntityLivingBaseFireworkHelper;
34
import com.lambda.client.module.modules.movement.ElytraFlight;
4-
import net.minecraft.client.entity.EntityPlayerSP;
55
import net.minecraft.entity.Entity;
66
import net.minecraft.entity.EntityLivingBase;
7-
import net.minecraft.entity.item.EntityFireworkRocket;
87
import net.minecraft.util.math.MathHelper;
98
import net.minecraft.util.math.Vec3d;
109
import net.minecraft.world.World;
11-
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
1210
import org.objectweb.asm.Opcodes;
1311
import org.spongepowered.asm.mixin.Mixin;
1412
import org.spongepowered.asm.mixin.Unique;
@@ -19,19 +17,10 @@
1917
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2018
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
2119

22-
import java.lang.reflect.Field;
23-
2420
@Mixin(EntityLivingBase.class)
2521
public abstract class MixinEntityLivingBase extends Entity {
2622
@Unique
2723
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-
}
3524

3625
public MixinEntityLivingBase(World worldIn) {
3726
super(worldIn);
@@ -42,7 +31,7 @@ public MixinEntityLivingBase(World worldIn) {
4231
at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/EntityLivingBase;getLookVec()Lnet/minecraft/util/math/Vec3d;", ordinal = 0)
4332
)
4433
private Vec3d vec3d(Vec3d original) {
45-
if (shouldWork()) {
34+
if (EntityLivingBaseFireworkHelper.shouldWork(EntityLivingBase.class.cast(this))) {
4635
float negPacketPitch = -ElytraFlight.INSTANCE.getPacketPitch();
4736
float f0 = MathHelper.cos((float) (-this.rotationYaw * 0.017453292f - Math.PI));
4837
float f1 = MathHelper.sin((float) (-this.rotationYaw * 0.017453292f - Math.PI));
@@ -60,7 +49,7 @@ private Vec3d vec3d(Vec3d original) {
6049
ordinal = 3
6150
)
6251
private float f(float original) {
63-
if (shouldWork()) {
52+
if (EntityLivingBaseFireworkHelper.shouldWork(EntityLivingBase.class.cast(this))) {
6453
return ElytraFlight.INSTANCE.getPacketPitch() * 0.017453292f;
6554
}
6655
return original;
@@ -87,7 +76,7 @@ private void getVec(
8776
at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lnet/minecraft/entity/EntityLivingBase;motionX:D", ordinal = 7)
8877
)
8978
public double motionX(EntityLivingBase it) {
90-
if (shouldModify()) {
79+
if (EntityLivingBaseFireworkHelper.shouldModify(EntityLivingBase.class.cast(this))) {
9180
it.motionX += modifiedVec.x * 0.1 + (modifiedVec.x * 1.5 - this.motionX) * 0.5;
9281
}
9382
return it.motionX;
@@ -98,7 +87,7 @@ public double motionX(EntityLivingBase it) {
9887
at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lnet/minecraft/entity/EntityLivingBase;motionY:D", ordinal = 7)
9988
)
10089
public double motionY(EntityLivingBase it) {
101-
if (shouldModify()) {
90+
if (EntityLivingBaseFireworkHelper.shouldModify(EntityLivingBase.class.cast(this))) {
10291
it.motionY += modifiedVec.y * 0.1 + (modifiedVec.y * 1.5 - this.motionY) * 0.5;
10392
}
10493
return it.motionY;
@@ -109,32 +98,10 @@ public double motionY(EntityLivingBase it) {
10998
at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lnet/minecraft/entity/EntityLivingBase;motionZ:D", ordinal = 7)
11099
)
111100
public double motionZ(EntityLivingBase it) {
112-
if (shouldModify()) {
101+
if (EntityLivingBaseFireworkHelper.shouldModify(EntityLivingBase.class.cast(this))) {
113102
it.motionZ += modifiedVec.z * 0.1 + (modifiedVec.z * 1.5 - this.motionZ) * 0.5;
114103
}
115104
return it.motionZ;
116105
}
117106

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-
}
140107
}

0 commit comments

Comments
 (0)