Search in sources :

Example 1 with IShipPilotClient

use of org.valkyrienskies.mod.common.piloting.IShipPilotClient in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class VSKeyHandler method playerTick.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void playerTick(PlayerTickEvent event) {
    if (event.side == Side.SERVER) {
        return;
    }
    if (event.phase == Phase.START) {
        IShipPilotClient clientPilot = (IShipPilotClient) event.player;
        clientPilot.onClientTick();
        if (dismountKey.isKeyDown() && clientPilot.isPilotingATile()) {
            BlockPos pilotedPos = clientPilot.getPosBeingControlled();
            MessagePlayerStoppedPiloting stopPilotingMessage = new MessagePlayerStoppedPiloting(pilotedPos);
            ValkyrienSkiesMod.controlNetwork.sendToServer(stopPilotingMessage);
            clientPilot.stopPilotingEverything();
        }
        if (dismountKey.isKeyDown() && clientPilot.getShipIDBeingControlled() != null) {
            MessagePlayerStoppedPiloting stopPilotingMessage = new MessagePlayerStoppedPiloting(clientPilot.getShipIDBeingControlled());
            ValkyrienSkiesMod.controlNetwork.sendToServer(stopPilotingMessage);
            clientPilot.stopPilotingEverything();
        }
    }
}
Also used : IShipPilotClient(org.valkyrienskies.mod.common.piloting.IShipPilotClient) BlockPos(net.minecraft.util.math.BlockPos) MessagePlayerStoppedPiloting(org.valkyrienskies.mod.common.network.MessagePlayerStoppedPiloting) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with IShipPilotClient

use of org.valkyrienskies.mod.common.piloting.IShipPilotClient in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MessageStartPilotingHandler method onMessage.

@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(MessageStartPiloting message, MessageContext ctx) {
    IThreadListener mainThread = Minecraft.getMinecraft();
    mainThread.addScheduledTask(() -> {
        IShipPilotClient pilot = (IShipPilotClient) Minecraft.getMinecraft().player;
        pilot.setControllerInputEnum(message.controlType);
        if (message.posToStartPiloting != null) {
            pilot.setPosBeingControlled(message.posToStartPiloting);
            if (message.setPhysicsWrapperEntityToPilot) {
                Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(Minecraft.getMinecraft().world, message.posToStartPiloting);
                if (physicsObject.isPresent()) {
                    pilot.setPilotedShip(physicsObject.get());
                } else {
                    new IllegalStateException("Received incorrect piloting message!").printStackTrace();
                }
            } else {
                pilot.setPilotedShip(null);
            }
        }
        if (message.shipPilotingId != null)
            pilot.setShipIDBeingControlled(message.shipPilotingId);
    });
    return null;
}
Also used : IShipPilotClient(org.valkyrienskies.mod.common.piloting.IShipPilotClient) IThreadListener(net.minecraft.util.IThreadListener) PhysicsObject(org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with IShipPilotClient

use of org.valkyrienskies.mod.common.piloting.IShipPilotClient in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class MessageStopPilotingHandler method onMessage.

@Override
public IMessage onMessage(MessageStopPiloting message, MessageContext ctx) {
    IThreadListener mainThread = Minecraft.getMinecraft();
    mainThread.addScheduledTask(() -> {
        IShipPilotClient pilot = (IShipPilotClient) Minecraft.getMinecraft().player;
        BlockPos posToStopPiloting = message.posToStopPiloting;
        if (pilot.getPosBeingControlled() != null && pilot.getPosBeingControlled().equals(posToStopPiloting)) {
            pilot.stopPilotingEverything();
        }
    });
    return null;
}
Also used : IShipPilotClient(org.valkyrienskies.mod.common.piloting.IShipPilotClient) IThreadListener(net.minecraft.util.IThreadListener) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IShipPilotClient (org.valkyrienskies.mod.common.piloting.IShipPilotClient)3 IThreadListener (net.minecraft.util.IThreadListener)2 BlockPos (net.minecraft.util.math.BlockPos)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 MessagePlayerStoppedPiloting (org.valkyrienskies.mod.common.network.MessagePlayerStoppedPiloting)1 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)1