Search in sources :

Example 1 with PlayerMovementData

use of org.valkyrienskies.mod.common.network.PlayerMovementData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinCPacketPlayerClient method postConstructor.

@Inject(method = "<init>(Z)V", at = @At(value = "RETURN"))
private void postConstructor(final boolean onGround, final CallbackInfo info) {
    final PlayerMovementData playerMovementData = PlayerMovementDataGenerator.generatePlayerMovementDataForClient();
    IHasPlayerMovementData.class.cast(this).setPlayerMovementData(playerMovementData);
}
Also used : PlayerMovementData(org.valkyrienskies.mod.common.network.PlayerMovementData) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with PlayerMovementData

use of org.valkyrienskies.mod.common.network.PlayerMovementData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinCPacketPlayerPositionRotation method postConstructor.

@Inject(method = "<init>(DDDFFZ)V", at = @At(value = "RETURN"))
private void postConstructor(final double x, final double y, final double z, final float yawIn, final float pitchIn, final boolean onGround, final CallbackInfo info) {
    final PlayerMovementData playerMovementData = PlayerMovementDataGenerator.generatePlayerMovementDataForClient();
    IHasPlayerMovementData.class.cast(this).setPlayerMovementData(playerMovementData);
}
Also used : PlayerMovementData(org.valkyrienskies.mod.common.network.PlayerMovementData) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with PlayerMovementData

use of org.valkyrienskies.mod.common.network.PlayerMovementData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinNetHandlerPlayServer method preProcessPlayer.

/**
 * This mixin fixes "Player Moved Wrongly" errors.
 *
 * @param packetPlayer The packet the player sent us
 * @param info We can use this to cancel the invocation
 */
@Inject(method = "processPlayer", at = @At("HEAD"))
private void preProcessPlayer(final CPacketPlayer packetPlayer, final CallbackInfo info) {
    // Don't run any of this code on the network thread!
    if (this.player.getServerWorld().isCallingFromMinecraftThread()) {
        // This fixes players dying of fall damage when changing dimensions
        if (this.player.isInvulnerableDimensionChange()) {
            return;
        }
        final PlayerMovementData addedPlayerMovementData = IHasPlayerMovementData.class.cast(packetPlayer).getPlayerMovementData();
        final World world = player.world;
        final UUID lastTouchedShipId = addedPlayerMovementData.getLastTouchedShipId();
        final int ticksSinceTouchedLastShip = addedPlayerMovementData.getTicksSinceTouchedLastShip();
        if (ticksSinceTouchedLastShip > 40) {
            // If the player hasn't touched the ship in over 40 ticks, then ignore its coordinates relative to that ship.
            final IDraggable playerAsDraggable = IDraggable.class.cast(this.player);
            playerAsDraggable.setEntityShipMovementData(playerAsDraggable.getEntityShipMovementData().withLastTouchedShip(null).withAddedLinearVelocity(new Vector3d()).withAddedYawVelocity(0).withTicksPartOfGround(addedPlayerMovementData.getTicksPartOfGround()).withTicksSinceTouchedShip(ticksSinceTouchedLastShip));
            return;
        }
        final int ticksPartOfGround = addedPlayerMovementData.getTicksPartOfGround();
        final Vector3d playerPosInShip = new Vector3d(addedPlayerMovementData.getPlayerPosInShip());
        final Vector3d playerLookInShip = new Vector3d(addedPlayerMovementData.getPlayerLookInShip());
        ShipData lastTouchedShip = null;
        if (lastTouchedShipId != null) {
            final QueryableShipData queryableShipData = QueryableShipData.get(world);
            final Optional<ShipData> shipDataOptional = queryableShipData.getShip(lastTouchedShipId);
            if (shipDataOptional.isPresent()) {
                lastTouchedShip = shipDataOptional.get();
                final PhysicsObject shipObject = ValkyrienUtils.getServerShipManager(world).getPhysObjectFromUUID(lastTouchedShip.getUuid());
                if (shipObject != null) {
                    if (shipObject.getTicksSinceShipTeleport() > PhysicsObject.TICKS_SINCE_TELEPORT_TO_START_DRAGGING) {
                        final ShipTransform shipTransform = lastTouchedShip.getShipTransform();
                        shipTransform.transformPosition(playerPosInShip, TransformType.SUBSPACE_TO_GLOBAL);
                        shipTransform.transformDirection(playerLookInShip, TransformType.SUBSPACE_TO_GLOBAL);
                    } else {
                        // Don't move the player relative to the ship until the TicksSinceShipTeleport timer expires.
                        playerPosInShip.set(player.posX, player.posY, player.posZ);
                    }
                }
            } else {
                // info.cancel();
                return;
            }
        }
        // Get the player pitch/yaw from the look vector
        final Tuple<Double, Double> pitchYawTuple = VSMath.getPitchYawFromVector(playerLookInShip);
        final double playerPitchInGlobal = pitchYawTuple.getFirst();
        final double playerYawInGlobal = pitchYawTuple.getSecond();
        // Idk if this is needed, but I'm too bothered to change it
        packetPlayer.moving = true;
        // Then update the packet values to match the ones above.
        packetPlayer.x = playerPosInShip.x();
        packetPlayer.y = playerPosInShip.y();
        packetPlayer.z = playerPosInShip.z();
        packetPlayer.yaw = (float) playerYawInGlobal;
        packetPlayer.pitch = (float) playerPitchInGlobal;
        // Set the player motion values to tell the NetHandlerPlayServer that the player is allowed to move this fast.
        this.player.motionX = packetPlayer.x - this.firstGoodX;
        this.player.motionY = packetPlayer.y - this.firstGoodY;
        this.player.motionZ = packetPlayer.z - this.firstGoodZ;
        // Update the player draggable
        final IDraggable playerAsDraggable = IDraggable.class.cast(this.player);
        playerAsDraggable.setEntityShipMovementData(playerAsDraggable.getEntityShipMovementData().withLastTouchedShip(lastTouchedShip).withAddedLinearVelocity(new Vector3d()).withAddedYawVelocity(0).withTicksPartOfGround(ticksPartOfGround).withTicksSinceTouchedShip(ticksSinceTouchedLastShip));
    }
}
Also used : QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) ShipData(org.valkyrienskies.mod.common.ships.ShipData) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData) PlayerMovementData(org.valkyrienskies.mod.common.network.PlayerMovementData) World(net.minecraft.world.World) QueryableShipData(org.valkyrienskies.mod.common.ships.QueryableShipData) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) Vector3d(org.joml.Vector3d) ShipTransform(org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform) IDraggable(org.valkyrienskies.mod.common.ships.entity_interaction.IDraggable) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData)

Example 4 with PlayerMovementData

use of org.valkyrienskies.mod.common.network.PlayerMovementData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinCPacketPlayerPosition method postConstructor.

@Inject(method = "<init>(DDDZ)V", at = @At(value = "RETURN"))
private void postConstructor(final double x, final double y, final double z, final boolean onGround, final CallbackInfo info) {
    final PlayerMovementData playerMovementData = PlayerMovementDataGenerator.generatePlayerMovementDataForClient();
    IHasPlayerMovementData.class.cast(this).setPlayerMovementData(playerMovementData);
}
Also used : PlayerMovementData(org.valkyrienskies.mod.common.network.PlayerMovementData) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with PlayerMovementData

use of org.valkyrienskies.mod.common.network.PlayerMovementData in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MixinCPacketPlayerRotation method postConstructor.

@Inject(method = "<init>(FFZ)V", at = @At(value = "RETURN"))
private void postConstructor(final float yawIn, final float pitchIn, final boolean onGround, final CallbackInfo info) {
    final PlayerMovementData playerMovementData = PlayerMovementDataGenerator.generatePlayerMovementDataForClient();
    IHasPlayerMovementData.class.cast(this).setPlayerMovementData(playerMovementData);
}
Also used : PlayerMovementData(org.valkyrienskies.mod.common.network.PlayerMovementData) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData) IHasPlayerMovementData(org.valkyrienskies.mod.common.network.IHasPlayerMovementData) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

IHasPlayerMovementData (org.valkyrienskies.mod.common.network.IHasPlayerMovementData)5 PlayerMovementData (org.valkyrienskies.mod.common.network.PlayerMovementData)5 Inject (org.spongepowered.asm.mixin.injection.Inject)4 World (net.minecraft.world.World)1 Vector3d (org.joml.Vector3d)1 QueryableShipData (org.valkyrienskies.mod.common.ships.QueryableShipData)1 ShipData (org.valkyrienskies.mod.common.ships.ShipData)1 IDraggable (org.valkyrienskies.mod.common.ships.entity_interaction.IDraggable)1 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)1 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)1