Search in sources :

Example 1 with LocalPlayer

use of io.xol.chunkstories.api.client.LocalPlayer in project chunkstories-core by Hugobros3.

the class ItemFirearm method tickInHand.

/**
 * Should be called when the owner has this item selected
 *
 * @param owner
 */
@Override
public void tickInHand(Entity owner, ItemPile itemPile) {
    if (owner instanceof EntityControllable && ((EntityControllable) owner).getController() != null) {
        EntityControllable owner2 = ((EntityControllable) owner);
        Controller controller = owner2.getController();
        // For now only client-side players can trigger shooting actions
        if (controller instanceof LocalPlayer) {
            if (!((LocalPlayer) controller).hasFocus())
                return;
            LocalPlayer LocalPlayer = (LocalPlayer) controller;
            if (LocalPlayer.getInputsManager().getInputByName("mouse.left").isPressed()) {
                // Check for bullet presence (or creative mode)
                boolean bulletPresence = (owner instanceof EntityCreative && ((EntityCreative) owner).isCreativeMode()) || checkBullet(itemPile);
                if (!bulletPresence && !wasTriggerPressedLastTick) {
                    // Play sounds
                    if (LocalPlayer != null)
                        LocalPlayer.getSoundManager().playSoundEffect("sounds/dogez/weapon/default/dry.ogg", Mode.NORMAL, owner.getLocation(), 1.0f, 1.0f, 1f, (float) soundRange);
                // Dry.ogg
                // return;
                } else if ((automatic || !wasTriggerPressedLastTick) && (System.currentTimeMillis() - lastShot) / 1000.0d > 1.0 / (rpm / 60.0)) {
                    // Fire virtual input
                    // ClientInputPressedEvent event = new ClientInputPressedEvent(controller.getInputsManager().getInputByName("shootGun"));
                    // Client.getInstance().getPluginManager().fireEvent(event);
                    LocalPlayer.getInputsManager().onInputPressed(controller.getInputsManager().getInputByName("shootGun"));
                    lastShot = System.currentTimeMillis();
                }
            }
            isScoped = this.isScopedWeapon() && controller.getInputsManager().getInputByName("mouse.right").isPressed();
            wasTriggerPressedLastTick = controller.getInputsManager().getInputByName("mouse.left").isPressed();
        }
    }
}
Also used : LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) EntityCreative(io.xol.chunkstories.api.entity.interfaces.EntityCreative) Controller(io.xol.chunkstories.api.entity.Controller) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable)

Example 2 with LocalPlayer

use of io.xol.chunkstories.api.client.LocalPlayer in project chunkstories-core by Hugobros3.

the class ParticleLightningStrike method getRenderer.

@Override
public ParticleTypeRenderer getRenderer(ParticlesRenderer particlesRenderer) {
    return new ParticleTypeRenderer(particlesRenderer) {

        @Override
        public void forEach_Rendering(RenderingInterface renderingContext, ParticleData data) {
            Content content = ParticleLightningStrike.this.getType().store().parent();
            if (content instanceof ClientContent) {
                ClientContent clientContent = (ClientContent) content;
                LocalPlayer player = clientContent.getContext().getPlayer();
                Entity entity = player.getControlledEntity();
                if (entity != null) {
                    Location loc = entity.getLocation();
                    data.set((float) (double) data.x(), (float) (double) loc.y() + 1024, (float) (double) data.z());
                }
            }
            renderingContext.getLightsRenderer().queueLight(new Light(new Vector3f(226 / 255f, 255 / 255f, 226 / 255f).mul((float) (1f + Math.random())), new Vector3f((float) data.x(), (float) data.y(), (float) data.z()), 102004f + (float) Math.random() * 5f));
        }

        @Override
        public void destroy() {
        }
    };
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) ClientContent(io.xol.chunkstories.api.client.ClientContent) Content(io.xol.chunkstories.api.content.Content) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) Light(io.xol.chunkstories.api.rendering.lightning.Light) Vector3f(org.joml.Vector3f) RenderingInterface(io.xol.chunkstories.api.rendering.RenderingInterface) ClientContent(io.xol.chunkstories.api.client.ClientContent) Location(io.xol.chunkstories.api.Location)

Example 3 with LocalPlayer

use of io.xol.chunkstories.api.client.LocalPlayer in project chunkstories by Hugobros3.

the class Lwjgl3ClientInputsManager method onInputPressed.

public boolean onInputPressed(Input input) {
    if (input.equals("fullscreen")) {
        gameWindow.toggleFullscreen();
        return true;
    }
    // System.out.println("Input pressed "+input.getName());
    // Try the client-side event press
    ClientInputPressedEvent event = new ClientInputPressedEvent(gameWindow.getClient(), input);
    ClientPluginManager cpm = gameWindow.getClient().getPluginManager();
    if (cpm != null) {
        cpm.fireEvent(event);
        if (event.isCancelled())
            return false;
    }
    // Try the GUI handling
    Layer layer = gameWindow.getLayer();
    if (layer.handleInput(input))
        return true;
    // System.out.println("wasn't handled");
    final LocalPlayer player = Client.getInstance().getPlayer();
    if (player == null)
        return false;
    final EntityControllable entityControlled = player.getControlledEntity();
    // There has to be a controlled entity for sending inputs to make sense.
    if (entityControlled == null)
        return false;
    // Send input to server
    World world = entityControlled.getWorld();
    if (world instanceof WorldClientRemote) {
        // MouseScroll inputs are strictly client-side
        if (!(input instanceof MouseScroll)) {
            ServerConnection connection = ((WorldClientRemote) entityControlled.getWorld()).getConnection();
            PacketInput packet = new PacketInput(world);
            packet.input = input;
            packet.isPressed = true;
            connection.pushPacket(packet);
        }
        return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
    } else {
        PlayerInputPressedEvent event2 = new PlayerInputPressedEvent(Client.getInstance().getPlayer(), input);
        cpm.fireEvent(event2);
        if (event2.isCancelled())
            return false;
    // entity.handleInteraction(input, entity.getControllerComponent().getController());
    }
    // Handle interaction locally
    return entityControlled.onControllerInput(input, Client.getInstance().getPlayer());
}
Also used : ClientPluginManager(io.xol.chunkstories.api.plugin.ClientPluginManager) PacketInput(io.xol.chunkstories.net.packets.PacketInput) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) ServerConnection(io.xol.chunkstories.client.net.ServerConnection) ClientInputPressedEvent(io.xol.chunkstories.api.events.client.ClientInputPressedEvent) World(io.xol.chunkstories.api.world.World) Layer(io.xol.chunkstories.api.gui.Layer) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) MouseScroll(io.xol.chunkstories.api.input.Mouse.MouseScroll) PlayerInputPressedEvent(io.xol.chunkstories.api.events.player.PlayerInputPressedEvent)

Example 4 with LocalPlayer

use of io.xol.chunkstories.api.client.LocalPlayer in project chunkstories by Hugobros3.

the class Lwjgl3ClientInputsManager method onInputReleased.

@Override
public boolean onInputReleased(Input input) {
    ClientInputReleasedEvent event = new ClientInputReleasedEvent(gameWindow.getClient(), input);
    ClientPluginManager cpm = gameWindow.getClient().getPluginManager();
    if (cpm != null) {
        cpm.fireEvent(event);
    }
    final LocalPlayer player = Client.getInstance().getPlayer();
    if (player == null)
        return false;
    final EntityControllable entityControlled = player.getControlledEntity();
    // There has to be a controlled entity for sending inputs to make sense.
    if (entityControlled == null)
        return false;
    // Send input to server
    World world = entityControlled.getWorld();
    if (world instanceof WorldClientRemote) {
        ServerConnection connection = ((WorldClientRemote) entityControlled.getWorld()).getConnection();
        PacketInput packet = new PacketInput(world);
        packet.input = input;
        packet.isPressed = false;
        connection.pushPacket(packet);
        return true;
    } else {
        PlayerInputReleasedEvent event2 = new PlayerInputReleasedEvent(Client.getInstance().getPlayer(), input);
        cpm.fireEvent(event2);
        return true;
    }
}
Also used : ClientPluginManager(io.xol.chunkstories.api.plugin.ClientPluginManager) PacketInput(io.xol.chunkstories.net.packets.PacketInput) ClientInputReleasedEvent(io.xol.chunkstories.api.events.client.ClientInputReleasedEvent) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) ServerConnection(io.xol.chunkstories.client.net.ServerConnection) PlayerInputReleasedEvent(io.xol.chunkstories.api.events.player.PlayerInputReleasedEvent) World(io.xol.chunkstories.api.world.World) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable)

Example 5 with LocalPlayer

use of io.xol.chunkstories.api.client.LocalPlayer in project chunkstories-api by Hugobros3.

the class EntityComponentController method pull.

@Override
public void pull(StreamSource from, DataInputStream dis) throws IOException {
    long controllerUUID = 0;
    boolean isControllerNotNull = dis.readBoolean();
    if (isControllerNotNull)
        controllerUUID = dis.readLong();
    // This is strictly illegal, only remotely connected client worlds will accept such requests
    if (!(entity.getWorld() instanceof WorldClientNetworkedRemote)) {
        // Terminate connections immediately
        if (from instanceof Player)
            ((Player) from).disconnect("Illegal controller set attempt, terminating client connection for " + from);
        return;
    }
    LocalPlayer player = ((ClientInterface) entity.getWorld().getGameContext()).getPlayer();
    assert player != null;
    if (isControllerNotNull) {
        // long controllerUUID = dis.readLong();
        long clientUUID = player.getUUID();
        System.out.println("Entity " + entity + " is now in control of " + controllerUUID + " me=" + clientUUID);
        // This update tells us we are now in control of this entity
        if (clientUUID == controllerUUID) {
            EntityControllable controlledEntity = (EntityControllable) entity;
            // TODO sort out local hosted worlds properly ?
            // Client.getInstance().getServerConnection().subscribe(entity);
            controller = player;
            player.setControlledEntity(controlledEntity);
            System.out.println("The client is now in control of entity " + controlledEntity);
        } else {
            // If we receive a different UUID than ours in a EntityComponent change, it means that we don't control it anymore and someone else does.
            if (player.getControlledEntity() != null && player.getControlledEntity().equals(entity)) {
                player.setControlledEntity(null);
                // Client.getInstance().getServerConnection().unsubscribe(entity);
                controller = null;
                System.out.println("Lost control of entity " + entity + " to " + controllerUUID);
            }
        }
    } else {
        // If we receive a different UUID than ours in a EntityComponent change, it means that we don't control it anymore and someone else does.
        if (player.getControlledEntity() != null && player.getControlledEntity().equals(entity)) {
            player.setControlledEntity(null);
            // Client.getInstance().getServerConnection().unsubscribe(entity);
            controller = null;
            System.out.println("Lost control of entity " + entity);
        }
    }
}
Also used : Player(io.xol.chunkstories.api.player.Player) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) ClientInterface(io.xol.chunkstories.api.client.ClientInterface) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) WorldClientNetworkedRemote(io.xol.chunkstories.api.world.WorldClientNetworkedRemote)

Aggregations

LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)5 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)4 ClientPluginManager (io.xol.chunkstories.api.plugin.ClientPluginManager)2 World (io.xol.chunkstories.api.world.World)2 ServerConnection (io.xol.chunkstories.client.net.ServerConnection)2 PacketInput (io.xol.chunkstories.net.packets.PacketInput)2 WorldClientRemote (io.xol.chunkstories.world.WorldClientRemote)2 Location (io.xol.chunkstories.api.Location)1 ClientContent (io.xol.chunkstories.api.client.ClientContent)1 ClientInterface (io.xol.chunkstories.api.client.ClientInterface)1 Content (io.xol.chunkstories.api.content.Content)1 Controller (io.xol.chunkstories.api.entity.Controller)1 Entity (io.xol.chunkstories.api.entity.Entity)1 EntityCreative (io.xol.chunkstories.api.entity.interfaces.EntityCreative)1 ClientInputPressedEvent (io.xol.chunkstories.api.events.client.ClientInputPressedEvent)1 ClientInputReleasedEvent (io.xol.chunkstories.api.events.client.ClientInputReleasedEvent)1 PlayerInputPressedEvent (io.xol.chunkstories.api.events.player.PlayerInputPressedEvent)1 PlayerInputReleasedEvent (io.xol.chunkstories.api.events.player.PlayerInputReleasedEvent)1 Layer (io.xol.chunkstories.api.gui.Layer)1 MouseScroll (io.xol.chunkstories.api.input.Mouse.MouseScroll)1