Search in sources :

Example 6 with WorldClientRemote

use of io.xol.chunkstories.world.WorldClientRemote 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 7 with WorldClientRemote

use of io.xol.chunkstories.world.WorldClientRemote in project chunkstories by Hugobros3.

the class Ingame method render.

@Override
public void render(RenderingInterface renderer) {
    // Update client entity
    if ((playerEntity == null || playerEntity != getPlayer().getControlledEntity()) && getPlayer().getControlledEntity() != null) {
        playerEntity = getPlayer().getControlledEntity();
        if (playerEntity instanceof EntityWithSelectedItem)
            inventoryBarDrawer = ((EntityWithSelectedItem) playerEntity).getInventory() == null ? null : new InventoryGridRenderer((EntityWithSelectedItem) playerEntity);
        else
            inventoryBarDrawer = null;
    }
    if (playerEntity != null && ((EntityLiving) playerEntity).isDead() && !(gameWindow.getLayer() instanceof DeathScreen))
        gameWindow.setLayer(new DeathScreen(gameWindow, this));
    // Update the player
    if (playerEntity instanceof EntityControllable)
        ((EntityControllable) playerEntity).onEachFrame(getPlayer());
    Location selectedBlock = null;
    if (playerEntity instanceof EntityControllable)
        selectedBlock = ((EntityControllable) playerEntity).getBlockLookingAt(true);
    world.getPluginManager().fireEvent(new CameraSetupEvent(renderer.getCamera()));
    // Main render call
    world.getWorldRenderer().renderWorld(renderer);
    // Debug draws
    if (client.getConfiguration().getBooleanOption("client.debug.physicsVisualization") && playerEntity != null) {
        wireframeDebugger.render(renderer);
    }
    if (!guiHidden && selectedBlock != null && playerEntity instanceof EntityCreative && ((EntityCreative) playerEntity).getCreativeModeComponent().get())
        selectionRenderer.drawSelectionBox(renderer, selectedBlock);
    // Fades in & out the overlay
    if (!isCovered()) {
        if (pauseOverlayFade > 0.0)
            pauseOverlayFade -= 0.1;
    } else {
        float maxFade = 1.0f;
        if (gameWindow.getLayer() instanceof ChatPanelOverlay)
            maxFade = 0.25f;
        if (pauseOverlayFade < maxFade)
            pauseOverlayFade += 0.1;
    }
    // Blit the final 3d image
    world.getWorldRenderer().blitFinalImage(renderer, guiHidden);
    // Draw the GUI
    if (!guiHidden) {
        chatManager.render(renderer);
        // Draw inventory
        if (playerEntity != null && inventoryBarDrawer != null)
            inventoryBarDrawer.drawPlayerInventorySummary(renderer, renderer.getWindow().getWidth() / 2 - 7, 64 + 64);
        // Draw debug info
        if (client.getConfiguration().getBooleanOption("client.debug.showDebugInfo"))
            debugInfoRenderer.drawF3debugMenu(renderer);
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(getGameWindow().getWidth() / 2 - 8, getGameWindow().getHeight() / 2 - 8, 16, 16, 0, 1, 1, 0, renderer.textures().getTexture("./textures/gui/cursor.png"), false, true, null);
    }
    // Lack of overlay should infer autofocus
    if (!isCovered())
        focus(true);
    // Check connection didn't died and change scene if it has
    if (world instanceof WorldClientRemote) {
        if (!((WorldClientRemote) world).getConnection().isOpen())
            gameWindow.getClient().exitToMainMenu("Connection terminated : " + "(TODO: not this way)");
    }
    // Auto-switch to pause if it detects the game isn't in focus anymore
    if (!gameWindow.hasFocus() && !isCovered()) {
        focus(false);
        gameWindow.setLayer(new PauseMenu(gameWindow, gameWindow.getLayer()));
    }
}
Also used : EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) CameraSetupEvent(io.xol.chunkstories.api.events.rendering.CameraSetupEvent) InventoryGridRenderer(io.xol.chunkstories.gui.InventoryGridRenderer) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) EntityWithSelectedItem(io.xol.chunkstories.api.entity.interfaces.EntityWithSelectedItem) EntityCreative(io.xol.chunkstories.api.entity.interfaces.EntityCreative) ChatPanelOverlay(io.xol.chunkstories.gui.layer.ingame.ChatManager.ChatPanelOverlay) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) Location(io.xol.chunkstories.api.Location)

Aggregations

WorldClientRemote (io.xol.chunkstories.world.WorldClientRemote)7 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)3 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)2 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 Location (io.xol.chunkstories.api.Location)1 OnlineContentTranslator (io.xol.chunkstories.api.content.OnlineContentTranslator)1 Mod (io.xol.chunkstories.api.content.mods.Mod)1 Entity (io.xol.chunkstories.api.entity.Entity)1 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)1 EntityCreative (io.xol.chunkstories.api.entity.interfaces.EntityCreative)1 EntityWithSelectedItem (io.xol.chunkstories.api.entity.interfaces.EntityWithSelectedItem)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 CameraSetupEvent (io.xol.chunkstories.api.events.rendering.CameraSetupEvent)1 Layer (io.xol.chunkstories.api.gui.Layer)1