Skip to content

Commit fdcbf32

Browse files
committed
fix entity velocity packet fix
will now decide whether to send shorts or ints tested on singleplayer and server, works
1 parent dc56bd0 commit fdcbf32

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

src/main/java/fermiummixins/mixin/vanilla/SPacketEntityVelocity_LimitMixin.java

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
package fermiummixins.mixin.vanilla;
22

3+
import net.minecraft.network.PacketBuffer;
34
import net.minecraft.network.play.server.SPacketEntityVelocity;
5+
import org.objectweb.asm.Opcodes;
46
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Shadow;
8+
import org.spongepowered.asm.mixin.Unique;
9+
import org.spongepowered.asm.mixin.injection.At;
510
import org.spongepowered.asm.mixin.injection.Constant;
11+
import org.spongepowered.asm.mixin.injection.Inject;
612
import org.spongepowered.asm.mixin.injection.ModifyConstant;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
714

815
/**
916
* Fix by Nischhelm
1017
*/
18+
// see https://youtu.be/Q_MkxSD33Vw?si=uDKlxttiKw21lXuW&t=1335
1119
@Mixin(SPacketEntityVelocity.class)
1220
public abstract class SPacketEntityVelocity_LimitMixin {
13-
14-
// see https://youtu.be/Q_MkxSD33Vw?si=uDKlxttiKw21lXuW&t=1335
21+
22+
@Shadow private int motionX;
23+
@Shadow private int motionY;
24+
@Shadow private int motionZ;
25+
@Unique private boolean fermiummixins$isOverLimit = false;
26+
27+
//Don't clamp values to fit short limit
1528
@ModifyConstant(
1629
method = "<init>(IDDD)V",
1730
constant = @Constant(doubleValue = -3.9D)
@@ -27,4 +40,45 @@ private double fermiummixins_vanillaSPacketEntityVelocity_init_negLimit(double c
2740
private double fermiummixins_vanillaSPacketEntityVelocity_init_posLimit(double constant) {
2841
return Double.MAX_VALUE;
2942
}
43+
44+
//Check if over short limit (~ 8000 x +-3.9)
45+
@Inject(
46+
method = "<init>(IDDD)V",
47+
at = @At("TAIL")
48+
)
49+
private void fermiummixins_vanillaSPacketEntityVelocity_init(int entityIdIn, double motionXIn, double motionYIn, double motionZIn, CallbackInfo ci) {
50+
this.fermiummixins$isOverLimit = Math.abs(motionXIn) > 3.9 || Math.abs(motionYIn) > 3.9 || Math.abs(motionZIn) > 3.9;
51+
}
52+
53+
//read extra boolean and switch to int if over limit
54+
@Inject(
55+
method = "readPacketData",
56+
at = @At(value = "FIELD", target = "Lnet/minecraft/network/play/server/SPacketEntityVelocity;entityID:I", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER),
57+
cancellable = true
58+
)
59+
private void fermiummixins_vanillaSPacketEntityVelocity_readPacketData(PacketBuffer buf, CallbackInfo ci){
60+
this.fermiummixins$isOverLimit = buf.readBoolean();
61+
if(!this.fermiummixins$isOverLimit) return;
62+
63+
this.motionX = buf.readInt();
64+
this.motionY = buf.readInt();
65+
this.motionZ = buf.readInt();
66+
ci.cancel();
67+
}
68+
69+
//write extra boolean and switch to int if over limit
70+
@Inject(
71+
method = "writePacketData",
72+
at = @At(value = "FIELD", target = "Lnet/minecraft/network/play/server/SPacketEntityVelocity;motionX:I", opcode = Opcodes.GETFIELD),
73+
cancellable = true
74+
)
75+
private void fermiummixins_vanillaSPacketEntityVelocity_writePacketData(PacketBuffer buf, CallbackInfo ci){
76+
buf.writeBoolean(this.fermiummixins$isOverLimit);
77+
if(!this.fermiummixins$isOverLimit) return;
78+
79+
buf.writeInt(this.motionX);
80+
buf.writeInt(this.motionY);
81+
buf.writeInt(this.motionZ);
82+
ci.cancel();
83+
}
3084
}

0 commit comments

Comments
 (0)