77package gay .ampflower .polysit .mixin ;
88
99import com .mojang .authlib .GameProfile ;
10+ import net .minecraft .entity .Entity ;
1011import net .minecraft .entity .player .PlayerEntity ;
12+ import net .minecraft .entity .player .PlayerPosition ;
13+ import net .minecraft .network .packet .s2c .play .EntityPassengersSetS2CPacket ;
14+ import net .minecraft .network .packet .s2c .play .PositionFlag ;
15+ import net .minecraft .server .network .ServerPlayNetworkHandler ;
1116import net .minecraft .server .network .ServerPlayerEntity ;
1217import net .minecraft .util .math .BlockPos ;
18+ import net .minecraft .util .math .Vec3d ;
1319import net .minecraft .world .World ;
1420import org .spongepowered .asm .mixin .Mixin ;
1521import org .spongepowered .asm .mixin .Shadow ;
1622import org .spongepowered .asm .mixin .injection .At ;
1723import org .spongepowered .asm .mixin .injection .Inject ;
1824import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
25+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
1926
2027/**
2128 * Forcefully teleports the player on dismount.
2734 **/
2835@ Mixin (ServerPlayerEntity .class )
2936public abstract class MixinServerPlayerEntity extends PlayerEntity {
37+ @ Shadow
38+ public ServerPlayNetworkHandler networkHandler ;
39+
3040 @ Shadow
3141 public abstract void requestTeleport (final double destX , final double destY , final double destZ );
3242
@@ -42,6 +52,19 @@ public MixinServerPlayerEntity(final World world, final BlockPos pos, final floa
4252 */
4353 @ Inject (method = "requestTeleportAndDismount" , at = @ At ("RETURN" ))
4454 private void onDismount (double x , double y , double z , CallbackInfo ci ) {
45- this .requestTeleport (x , y , z );
55+ // Modified requestTeleport for also sending the current velocity.
56+ // Enforces that the client can't just shove the player because there's a block
57+ // edge to go to.
58+ this .networkHandler .requestTeleport (new PlayerPosition (new Vec3d (x , y , z ), this .getVelocity (), 0.F , 0.F ),
59+ PositionFlag .ROT );
60+ }
61+
62+ /**
63+ * Forces a passenger update packet to the player, removing the chance for the
64+ * client to assert movement.
65+ */
66+ @ Inject (method = "startRiding" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;requestTeleport(Lnet/minecraft/entity/player/PlayerPosition;Ljava/util/Set;)V" ))
67+ private void onMount (Entity vehicle , boolean force , CallbackInfoReturnable <Boolean > ci ) {
68+ this .networkHandler .sendPacket (new EntityPassengersSetS2CPacket (vehicle ));
4669 }
4770}
0 commit comments