Search in sources :

Example 6 with EntityLiving

use of io.xol.chunkstories.api.entity.EntityLiving 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)

Example 7 with EntityLiving

use of io.xol.chunkstories.api.entity.EntityLiving in project chunkstories by Hugobros3.

the class WorldImplementation method spawnPlayer.

public void spawnPlayer(Player player) {
    if (!(this instanceof WorldMaster))
        throw new UnsupportedOperationException("Only Master Worlds can do this");
    Entity savedEntity = null;
    SerializedEntityFile playerEntityFile = new SerializedEntityFile(this.getFolderPath() + "/players/" + player.getName().toLowerCase() + ".csf");
    if (playerEntityFile.exists())
        savedEntity = playerEntityFile.read(this);
    Location previousLocation = null;
    if (savedEntity != null)
        previousLocation = savedEntity.getLocation();
    PlayerSpawnEvent playerSpawnEvent = new PlayerSpawnEvent(player, (WorldMaster) this, savedEntity, previousLocation);
    getGameContext().getPluginManager().fireEvent(playerSpawnEvent);
    if (!playerSpawnEvent.isCancelled()) {
        Entity entity = playerSpawnEvent.getEntity();
        Location actualSpawnLocation = playerSpawnEvent.getSpawnLocation();
        if (actualSpawnLocation == null)
            actualSpawnLocation = this.getDefaultSpawnLocation();
        // TODO EntitySimplePlayer ?
        if (entity == null || ((entity instanceof EntityLiving) && (((EntityLiving) entity).isDead())))
            entity = this.gameContext.getContent().entities().getEntityDefinition("player").create(actualSpawnLocation);
        else
            // entity = new EntityPlayer(this, 0d, 0d, 0d, player.getName()); //Default entity
            entity.setUUID(-1);
        // Name your player !
        if (entity instanceof EntityNameable)
            ((EntityNameable) entity).getNameComponent().setName(player.getName());
        entity.setLocation(actualSpawnLocation);
        addEntity(entity);
        if (entity instanceof EntityControllable)
            player.setControlledEntity((EntityControllable) entity);
        else
            System.out.println("Error : entity is not controllable");
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) SerializedEntityFile(io.xol.chunkstories.entity.SerializedEntityFile) PlayerSpawnEvent(io.xol.chunkstories.api.events.player.PlayerSpawnEvent) EntityNameable(io.xol.chunkstories.api.entity.interfaces.EntityNameable) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) WorldMaster(io.xol.chunkstories.api.world.WorldMaster) Location(io.xol.chunkstories.api.Location)

Example 8 with EntityLiving

use of io.xol.chunkstories.api.entity.EntityLiving in project chunkstories by Hugobros3.

the class ClientConnection method handleSystemRequest.

@Override
public boolean handleSystemRequest(String message) {
    if (message.startsWith("info")) {
        this.clientsManager.sendServerInfo(this);
        return true;
    } else if (message.startsWith("login/")) {
        return loginHelper.handleLogin(message.substring(6, message.length()));
    } else if (message.equals("mods")) {
        sendTextMessage("info/mods:" + clientsManager.getServer().getModsProvider().getModsString());
        this.flush();
        return true;
    } else if (message.equals("icon-file")) {
        PacketSendFile iconPacket = new PacketSendFile();
        iconPacket.file = new File("server-icon.png");
        iconPacket.fileTag = "server-icon";
        this.pushPacket(iconPacket);
        this.flush();
        return true;
    }
    // Any other commands need an authentificated player !
    if (player == null)
        return false;
    // Login-mandatory requests ( you need to be authentificated to use them )
    if (message.equals("co/off")) {
        this.disconnect("Client-terminated connection");
    } else if (message.startsWith("send-mod/")) {
        String modDescriptor = message.substring(9);
        String md5 = modDescriptor.substring(4);
        logger.info(this + " asked to be sent mod " + md5);
        // Give him what he asked for.
        File found = clientsManager.getServer().getModsProvider().obtainModRedistribuable(md5);
        if (found == null) {
            logger.info("No such mod found.");
        } else {
            logger.info("Pushing mod md5 " + md5 + "to user.");
            PacketSendFile modUploadPacket = new PacketSendFile();
            modUploadPacket.file = found;
            modUploadPacket.fileTag = modDescriptor;
            this.pushPacket(modUploadPacket);
        }
    } else if (message.startsWith("world/")) {
        // TODO this bit will obviously need to be rewritten when I get arround to doing multiworld support
        WorldServer world = clientsManager.getServer().getWorld();
        message = message.substring(6, message.length());
        if (message.equals("enter")) {
            player.setWorld(world);
            // Sends the construction info for the world, and then the player entity
            PacketSendWorldInfo packet = new PacketSendWorldInfo((WorldInfoImplementation) world.getWorldInfo());
            pushPacket(packet);
            // TODO only spawn the player when he asks to
            world.spawnPlayer(player);
            return true;
        } else if (message.equals("translator")) {
            PacketContentTranslator packet = new PacketContentTranslator((AbstractContentTranslator) world.getContentTranslator());
            player.pushPacket(packet);
            return true;
        } else if (message.equals("respawn")) {
            // Only allow to respawn if the current entity is null or dead
            if (player.getControlledEntity() == null || (player.getControlledEntity() instanceof EntityLiving && ((EntityLiving) player.getControlledEntity()).isDead())) {
                world.spawnPlayer(player);
                player.sendMessage("Respawning ...");
            } else
                player.sendMessage("You're not dead, or you are controlling a non-living entity.");
            return true;
        }
        return false;
    } else if (message.startsWith("chat/")) {
        String chatMessage = message.substring(5, message.length());
        // Messages starting with / are commands
        if (chatMessage.startsWith("/")) {
            chatMessage = chatMessage.substring(1, chatMessage.length());
            String cmdName = chatMessage.toLowerCase();
            String[] args = {};
            if (chatMessage.contains(" ")) {
                cmdName = chatMessage.substring(0, chatMessage.indexOf(" "));
                args = chatMessage.substring(chatMessage.indexOf(" ") + 1, chatMessage.length()).split(" ");
            }
            clientsManager.getServer().getConsole().dispatchCommand(player, cmdName, args);
            return true;
        // The rest is just normal chat
        } else if (chatMessage.length() > 0) {
            PlayerChatEvent event = new PlayerChatEvent(player, chatMessage);
            clientsManager.getServer().getPluginManager().fireEvent(event);
            if (!event.isCancelled())
                server.broadcastMessage(event.getFormattedMessage());
            return true;
        } else {
            // Ignore empty messages
            return true;
        }
    }
    return false;
}
Also used : PlayerChatEvent(io.xol.chunkstories.api.events.player.PlayerChatEvent) PacketSendFile(io.xol.chunkstories.net.packets.PacketSendFile) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) PacketContentTranslator(io.xol.chunkstories.net.packets.PacketContentTranslator) WorldServer(io.xol.chunkstories.world.WorldServer) File(java.io.File) PacketSendFile(io.xol.chunkstories.net.packets.PacketSendFile) AbstractContentTranslator(io.xol.chunkstories.content.translator.AbstractContentTranslator) PacketSendWorldInfo(io.xol.chunkstories.net.packets.PacketSendWorldInfo)

Example 9 with EntityLiving

use of io.xol.chunkstories.api.entity.EntityLiving in project chunkstories by Hugobros3.

the class HealthCommand method handleCommand.

@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
    if (!(emitter instanceof Player)) {
        emitter.sendMessage("You need to be a player to use this command.");
        return true;
    }
    Player player = (Player) emitter;
    if (!emitter.hasPermission("self.sethealth")) {
        emitter.sendMessage("You don't have the permission.");
        return true;
    }
    if (arguments.length < 1 || !isNumeric(arguments[0])) {
        emitter.sendMessage("Syntax: /health <hp>");
        return true;
    }
    float health = Float.parseFloat(arguments[0]);
    Entity controlledEntity = player.getControlledEntity();
    if (controlledEntity != null && controlledEntity instanceof EntityLiving) {
        ((EntityLiving) controlledEntity).setHealth(health);
        player.sendMessage("Health set to: " + health + "/" + ((EntityLiving) controlledEntity).getMaxHealth());
        return true;
    }
    emitter.sendMessage("This action doesn't apply to your current entity.");
    return true;
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Player(io.xol.chunkstories.api.player.Player) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving)

Example 10 with EntityLiving

use of io.xol.chunkstories.api.entity.EntityLiving in project chunkstories-core by Hugobros3.

the class ItemFirearm method drawItemOverlay.

@Override
public void drawItemOverlay(RenderingInterface renderingInterface, ItemPile pile) {
    EntityLiving clientControlledEntity = (EntityLiving) renderingInterface.getClient().getPlayer().getControlledEntity();
    if (clientControlledEntity != null && pile.getInventory() != null && pile.getInventory().getHolder() != null && pile.getInventory().getHolder().equals(clientControlledEntity)) {
        if (isScoped())
            drawScope(renderingInterface);
        Vector3d eyeLocation = new Vector3d(clientControlledEntity.getLocation());
        if (clientControlledEntity instanceof EntityPlayer)
            eyeLocation.add(new Vector3d(0.0, ((EntityPlayer) clientControlledEntity).eyePosition, 0.0));
        Vector3d direction = new Vector3d(clientControlledEntity.getDirectionLookingAt());
        direction.add(new Vector3d(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5).normalize().mul(accuracy / 100d));
        direction.normalize();
        // display reload cooldownt text
        if (cooldownEnd > System.currentTimeMillis()) {
            String reloadText = "Reloading weapon, please wait";
            Font font = renderingInterface.getFontRenderer().defaultFont();
            // TrueTypeFont.arial11px.getWidth(reloadText);
            int cooldownLength = font.getWidth(reloadText);
            renderingInterface.getFontRenderer().drawString(font, -cooldownLength + renderingInterface.getWindow().getWidth() / 2, renderingInterface.getWindow().getHeight() / 2, reloadText, 2);
        }
    }
}
Also used : EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) Vector3d(org.joml.Vector3d) EntityPlayer(io.xol.chunkstories.core.entity.EntityPlayer) Font(io.xol.chunkstories.api.rendering.text.FontRenderer.Font)

Aggregations

EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)11 Entity (io.xol.chunkstories.api.entity.Entity)7 Location (io.xol.chunkstories.api.Location)6 Vector3d (org.joml.Vector3d)5 EntityPlayer (io.xol.chunkstories.core.entity.EntityPlayer)4 HitBox (io.xol.chunkstories.api.entity.EntityLiving.HitBox)3 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)3 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)3 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)3 CellData (io.xol.chunkstories.api.world.cell.CellData)3 Vector3dc (org.joml.Vector3dc)3 EntityCreative (io.xol.chunkstories.api.entity.interfaces.EntityCreative)2 Font (io.xol.chunkstories.api.rendering.text.FontRenderer.Font)2 Vector4f (org.joml.Vector4f)2 EntityComponentRotation (io.xol.chunkstories.api.entity.components.EntityComponentRotation)1 EntityNameable (io.xol.chunkstories.api.entity.interfaces.EntityNameable)1 EntityWithInventory (io.xol.chunkstories.api.entity.interfaces.EntityWithInventory)1 EntityWithSelectedItem (io.xol.chunkstories.api.entity.interfaces.EntityWithSelectedItem)1 EventHandler (io.xol.chunkstories.api.events.EventHandler)1 PlayerChatEvent (io.xol.chunkstories.api.events.player.PlayerChatEvent)1