Search in sources :

Example 1 with EntityWithInventory

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

the class Ingame method handleInput.

@Override
public boolean handleInput(Input input) {
    // Block inputs if chatting
    if (input.equals("chat")) {
        gameWindow.setLayer(chatManager.new ChatPanelOverlay(gameWindow, this));
        focus(false);
        guiHidden = false;
        return true;
    } else if (input.equals("hideGui")) {
        guiHidden = !guiHidden;
        return true;
    } else if (input.equals("screenshot")) {
        chatManager.insert(world.getWorldRenderer().screenShot());
    } else if (input.equals("toggleDebugInfo")) {
        OptionBoolean debugInfo = (OptionBoolean) client.getConfiguration().getOption("client.debug.showDebugInfo");
        debugInfo.toggle();
        guiHidden = false;
        return true;
    } else if (input.equals("takeCubemap")) {
        // shouldTakeACubemap = true;
        return true;
    // CTRL-F12 reloads
    } else if (input.equals("reloadContent")) {
        // Rebuild the mod FS
        gameWindow.getClient().reloadAssets();
        // Reload plugins
        world.getPluginManager().reloadPlugins();
        // Mark some caches dirty
        world.getWorldRenderer().reloadContentSpecificStuff();
        return true;
    // CTRL-R redraws chunks
    } else if (input.equals("redrawChunks")) {
        ((ClientParticlesRenderer) world.getParticlesManager()).cleanAllParticles();
        world.redrawEverything();
        world.getWorldRenderer().flagChunksModified();
        return true;
    // Item slots selection
    } else if (input.getName().startsWith("inventorySlot")) {
        int requestedInventorySlot = Integer.parseInt(input.getName().replace("inventorySlot", ""));
        // Match zero onto last slot
        if (requestedInventorySlot == 0)
            requestedInventorySlot = 10;
        // Map to zero-indexed inventory
        requestedInventorySlot--;
        if (playerEntity != null && playerEntity instanceof EntityWithSelectedItem) {
            // Do not accept request to select non-existent inventories slots
            if (requestedInventorySlot > ((EntityWithInventory) playerEntity).getInventory().getWidth())
                return false;
            ItemPile p = ((EntityWithInventory) playerEntity).getInventory().getItemPileAt(requestedInventorySlot, 0);
            if (p != null)
                requestedInventorySlot = p.getX();
            ((EntityWithSelectedItem) playerEntity).setSelectedItemIndex(requestedInventorySlot);
        }
        return true;
    } else if (input.equals("exit")) /* Exit brings up the pause menu */
    {
        focus(false);
        guiHidden = false;
        gameWindow.setLayer(new PauseMenu(gameWindow, this));
        return true;
    } else if (input instanceof MouseScroll) {
        MouseScroll ms = (MouseScroll) input;
        if (playerEntity != null && playerEntity instanceof EntityWithSelectedItem) {
            ItemPile selected = null;
            int selectedInventorySlot = ((EntityWithSelectedItem) playerEntity).getSelectedItemIndex();
            int originalSlot = selectedInventorySlot;
            if (ms.amount() < 0) {
                selectedInventorySlot %= ((EntityWithInventory) playerEntity).getInventory().getWidth();
                selected = ((EntityWithInventory) playerEntity).getInventory().getItemPileAt(selectedInventorySlot, 0);
                if (selected != null)
                    selectedInventorySlot += selected.getItem().getDefinition().getSlotsWidth();
                else
                    selectedInventorySlot++;
            } else {
                selectedInventorySlot--;
                if (selectedInventorySlot < 0)
                    selectedInventorySlot += ((EntityWithInventory) playerEntity).getInventory().getWidth();
                selected = ((EntityWithInventory) playerEntity).getInventory().getItemPileAt(selectedInventorySlot, 0);
                if (selected != null)
                    selectedInventorySlot = selected.getX();
            }
            // Switch slot
            if (originalSlot != selectedInventorySlot)
                ((EntityWithSelectedItem) playerEntity).setSelectedItemIndex(selectedInventorySlot);
            return true;
        }
    }
    return false;
}
Also used : EntityWithInventory(io.xol.chunkstories.api.entity.interfaces.EntityWithInventory) EntityWithSelectedItem(io.xol.chunkstories.api.entity.interfaces.EntityWithSelectedItem) ChatPanelOverlay(io.xol.chunkstories.gui.layer.ingame.ChatManager.ChatPanelOverlay) OptionBoolean(io.xol.chunkstories.api.util.Configuration.OptionBoolean) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile) MouseScroll(io.xol.chunkstories.api.input.Mouse.MouseScroll) ClientParticlesRenderer(io.xol.chunkstories.renderer.particles.ClientParticlesRenderer)

Example 2 with EntityWithInventory

use of io.xol.chunkstories.api.entity.interfaces.EntityWithInventory in project chunkstories-api by Hugobros3.

the class PacketOpenInventory method process.

@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
    inventory = InventoryTranslator.obtainInventoryHandle(in, processor);
    if (processor.getContext() instanceof ClientInterface) {
        ClientInterface client = (ClientInterface) processor.getContext();
        Entity currentControlledEntity = client.getPlayer().getControlledEntity();
        if (currentControlledEntity != null && currentControlledEntity instanceof EntityWithInventory)
            client.openInventories(((EntityWithInventory) currentControlledEntity).getInventory(), inventory);
        else
            client.openInventories(inventory);
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) EntityWithInventory(io.xol.chunkstories.api.entity.interfaces.EntityWithInventory) ClientInterface(io.xol.chunkstories.api.client.ClientInterface)

Example 3 with EntityWithInventory

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

the class ClearCommand method handleCommand.

@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
    if (!emitter.hasPermission("self.clearinventory")) {
        emitter.sendMessage("You don't have the permission.");
        return true;
    }
    if (!(emitter instanceof Player)) {
        emitter.sendMessage("You need to be a player to use this command.");
        return true;
    }
    // TODO check the player's entity has an inventory
    Player player = (Player) emitter;
    player.sendMessage("#FF969BRemoving " + ((EntityWithInventory) player.getControlledEntity()).getInventory().size() + " items from your inventory.");
    ((EntityWithInventory) player.getControlledEntity()).getInventory().clear();
    return true;
}
Also used : Player(io.xol.chunkstories.api.player.Player) EntityWithInventory(io.xol.chunkstories.api.entity.interfaces.EntityWithInventory)

Example 4 with EntityWithInventory

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

the class ItemsLogicListener method onDroppedItem.

@EventHandler
public void onDroppedItem(EventItemDroppedToWorld event) {
    // Create an EntityGroundItem and add it to the event
    Location throwLocation = event.getLocation();
    Vector3d throwForce = new Vector3d(0.0);
    // Throw it when dropping it from a player's inventory ?
    System.out.println(event.getInventoryFrom());
    if (event.getInventoryFrom() != null && event.getInventoryFrom().getHolder() != null && event.getInventoryFrom().getHolder() instanceof Entity) {
        System.out.println("from som 1");
        EntityWithInventory entity = ((EntityWithInventory) event.getInventoryFrom().getHolder());
        Location pos = entity.getLocation();
        if (entity instanceof EntityLiving) {
            System.out.println("he l i v e s");
            EntityLiving owner = (EntityLiving) entity;
            throwLocation = new Location(pos.getWorld(), pos.x(), pos.y() + ((EntityPlayer) owner).eyePosition, pos.z());
            throwForce = new Vector3d(((EntityPlayer) owner).getDirectionLookingAt()).mul(0.15 - Math2.clampd(((EntityPlayer) owner).getEntityRotationComponent().getVerticalRotation(), -45, 20) / 45f * 0.0f);
            throwForce.add(((EntityPlayer) owner).getVelocityComponent().getVelocity());
        }
    }
    EntityGroundItem thrownItem = (EntityGroundItem) core.getPluginExecutionContext().getContent().entities().getEntityDefinition("groundItem").create(throwLocation);
    thrownItem.positionComponent.setPosition(throwLocation);
    thrownItem.velocityComponent.setVelocity(throwForce);
    thrownItem.setItemPile(event.getItemPile());
    // EntityGroundItem entity = new EntityGroundItem(core.getPluginExecutionContext().getContent().entities().getEntityDefinitionByName("groundItem"), event.getLocation(), event.getItemPile());
    event.setItemEntity(thrownItem);
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) EntityGroundItem(io.xol.chunkstories.core.entity.EntityGroundItem) Vector3d(org.joml.Vector3d) EntityWithInventory(io.xol.chunkstories.api.entity.interfaces.EntityWithInventory) EntityPlayer(io.xol.chunkstories.core.entity.EntityPlayer) Location(io.xol.chunkstories.api.Location) EventHandler(io.xol.chunkstories.api.events.EventHandler)

Aggregations

EntityWithInventory (io.xol.chunkstories.api.entity.interfaces.EntityWithInventory)4 Entity (io.xol.chunkstories.api.entity.Entity)2 Location (io.xol.chunkstories.api.Location)1 ClientInterface (io.xol.chunkstories.api.client.ClientInterface)1 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)1 EntityWithSelectedItem (io.xol.chunkstories.api.entity.interfaces.EntityWithSelectedItem)1 EventHandler (io.xol.chunkstories.api.events.EventHandler)1 MouseScroll (io.xol.chunkstories.api.input.Mouse.MouseScroll)1 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)1 Player (io.xol.chunkstories.api.player.Player)1 OptionBoolean (io.xol.chunkstories.api.util.Configuration.OptionBoolean)1 EntityGroundItem (io.xol.chunkstories.core.entity.EntityGroundItem)1 EntityPlayer (io.xol.chunkstories.core.entity.EntityPlayer)1 ChatPanelOverlay (io.xol.chunkstories.gui.layer.ingame.ChatManager.ChatPanelOverlay)1 ClientParticlesRenderer (io.xol.chunkstories.renderer.particles.ClientParticlesRenderer)1 Vector3d (org.joml.Vector3d)1