Skip to content

Commit

Permalink
Fix players not being teleported to exact swap positions
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Jan 4, 2025
1 parent 8e0c3aa commit 8bed694
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import java.util.List;

import net.minecraft.entity.Entity;
import net.minecraft.network.packet.s2c.play.PositionFlag;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.Vec3d;

public record SwapData(Vec3d pos, Entity vehicle, List<Entity> passengers) {
public record SwapData(ServerWorld world, Vec3d pos, Entity vehicle, List<Entity> passengers) {
public void apply(ServerPlayerEntity player) {
player.stopRiding();
player.teleport(this.pos.getX(), this.pos.getY(), this.pos.getZ(), false);
player.teleport(world, this.pos.getX(), this.pos.getY(), this.pos.getZ(), PositionFlag.ROT, 0, 0, false);

if (this.vehicle != null) {
player.startRiding(this.vehicle, true);
Expand All @@ -21,6 +23,6 @@ public void apply(ServerPlayerEntity player) {
}

public static SwapData from(ServerPlayerEntity player) {
return new SwapData(player.getPos(), player.getVehicle(), player.getPassengerList());
return new SwapData(player.getServerWorld(), player.getPos(), player.getVehicle(), player.getPassengerList());
}
}

0 comments on commit 8bed694

Please sign in to comment.