Skip to content

Commit 60cd9e3

Browse files
committed
Force send to client passengers and velocity packets
Fixes the client attempting to push itself out of a block.
1 parent 7c31d88 commit 60cd9e3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/main/java/gay/ampflower/polysit/mixin/MixinServerPlayerEntity.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@
77
package gay.ampflower.polysit.mixin;
88

99
import com.mojang.authlib.GameProfile;
10+
import net.minecraft.entity.Entity;
1011
import 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;
1116
import net.minecraft.server.network.ServerPlayerEntity;
1217
import net.minecraft.util.math.BlockPos;
18+
import net.minecraft.util.math.Vec3d;
1319
import net.minecraft.world.World;
1420
import org.spongepowered.asm.mixin.Mixin;
1521
import org.spongepowered.asm.mixin.Shadow;
1622
import org.spongepowered.asm.mixin.injection.At;
1723
import org.spongepowered.asm.mixin.injection.Inject;
1824
import 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.
@@ -27,6 +34,9 @@
2734
**/
2835
@Mixin(ServerPlayerEntity.class)
2936
public 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

Comments
 (0)