Search in sources :

Example 1 with ItemPile

use of io.xol.chunkstories.api.item.inventory.ItemPile in project chunkstories-core by Hugobros3.

the class EntityPlayer method drawEntityOverlay.

@Override
public void drawEntityOverlay(RenderingInterface renderer) {
    // super.drawEntityOverlay(renderer);
    if (this.equals(((WorldClient) getWorld()).getClient().getPlayer().getControlledEntity())) {
        float scale = 2.0f;
        renderer.textures().getTexture("./textures/gui/hud/hud_survival.png").setLinearFiltering(false);
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 - 256 * 0.5f * scale, 64 + 64 + 16 - 32 * 0.5f * scale, 256 * scale, 32 * scale, 0, 32f / 256f, 1, 0, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, null);
        // Health bar
        int horizontalBitsToDraw = (int) (8 + 118 * Math2.clamp(getHealth() / getMaxHealth(), 0.0, 1.0));
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 - 128 * scale, 64 + 64 + 16 - 32 * 0.5f * scale, horizontalBitsToDraw * scale, 32 * scale, 0, 64f / 256f, horizontalBitsToDraw / 256f, 32f / 256f, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, new Vector4f(1.0f, 1.0f, 1.0f, 0.75f));
        // Food bar
        horizontalBitsToDraw = (int) (0 + 126 * Math2.clamp(getFoodLevel() / 100f, 0.0, 1.0));
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 + 0 * 128 * scale + 0, 64 + 64 + 16 - 32 * 0.5f * scale, horizontalBitsToDraw * scale, 32 * scale, 0.5f, 64f / 256f, 0.5f + horizontalBitsToDraw / 256f, 32f / 256f, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, new Vector4f(1.0f, 1.0f, 1.0f, 0.75f));
        // If we're using an item that can render an overlay
        if (this.getSelectedItemComponent().getSelectedItem() != null) {
            ItemPile pile = this.getSelectedItemComponent().getSelectedItem();
            if (pile.getItem() instanceof ItemOverlay)
                ((ItemOverlay) pile.getItem()).drawItemOverlay(renderer, pile);
        }
        // We don't want to render our own tag do we ?
        return;
    }
    // Renders the nametag above the player heads
    Vector3d pos = getLocation();
    // don't render tags too far out
    if (pos.distance(renderer.getCamera().getCameraPosition()) > 32f)
        return;
    // Don't render a dead player tag
    if (this.getHealth() <= 0)
        return;
    Vector3fc posOnScreen = renderer.getCamera().transform3DCoordinate(new Vector3f((float) (double) pos.x(), (float) (double) pos.y() + 2.0f, (float) (double) pos.z()));
    float scale = posOnScreen.z();
    // + rotH;
    String txt = name.getName();
    float dekal = renderer.getFontRenderer().defaultFont().getWidth(txt) * 16 * scale;
    // System.out.println("dekal"+dekal);
    if (scale > 0)
        renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), posOnScreen.x() - dekal / 2, posOnScreen.y(), txt, 16 * scale, 16 * scale, new Vector4f(1, 1, 1, 1));
}
Also used : Vector3fc(org.joml.Vector3fc) Vector4f(org.joml.Vector4f) Vector3d(org.joml.Vector3d) ItemOverlay(io.xol.chunkstories.api.item.interfaces.ItemOverlay) Vector3f(org.joml.Vector3f) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Example 2 with ItemPile

use of io.xol.chunkstories.api.item.inventory.ItemPile in project chunkstories-core by Hugobros3.

the class EntityComponentSelectedItem method push.

@Override
protected void push(StreamTarget destinator, DataOutputStream dos) throws IOException {
    dos.writeInt(selectedSlot);
    ItemPile pile = inventory.getItemPileAt(selectedSlot, 0);
    // don't bother writing the item pile if we're not master or if we'd be telling the controller about it
    if (pile == null || !(entity.getWorld() instanceof WorldMaster) || (destinator instanceof EntityControllable && destinator.equals(((EntityControllable) entity).getControllerComponent())))
        dos.writeBoolean(false);
    else {
        dos.writeBoolean(true);
        pile.saveIntoStream(entity.getWorld().getContentTranslator(), dos);
    }
}
Also used : ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) WorldMaster(io.xol.chunkstories.api.world.WorldMaster)

Example 3 with ItemPile

use of io.xol.chunkstories.api.item.inventory.ItemPile in project chunkstories-core by Hugobros3.

the class ItemMiningTool method tickInHand.

@Override
public void tickInHand(Entity owner, ItemPile itemPile) {
    World world = owner.getWorld();
    if (owner instanceof EntityControllable && owner instanceof EntityWorldModifier) {
        EntityControllable entityControllable = (EntityControllable) owner;
        Controller controller = entityControllable.getController();
        if (controller != null && controller instanceof Player) {
            InputsManager inputs = controller.getInputsManager();
            Location lookingAt = entityControllable.getBlockLookingAt(true);
            if (lookingAt != null && lookingAt.distance(owner.getLocation()) > 7f)
                lookingAt = null;
            if (inputs.getInputByName("mouse.left").isPressed() && lookingAt != null) {
                WorldCell cell = world.peekSafely(lookingAt);
                // Cancel mining if looking away or the block changed by itself
                if (lookingAt == null || (progress != null && (lookingAt.distance(progress.loc) > 0 || !cell.getVoxel().sameKind(progress.voxel)))) {
                    progress = null;
                }
                if (progress == null) {
                    // Try starting mining something
                    if (lookingAt != null)
                        progress = new MiningProgress(world.peekSafely(lookingAt));
                } else {
                    // Progress using efficiency / ticks per second
                    progress.progress += ItemMiningTool.this.miningEfficiency / 60f / progress.materialHardnessForThisTool;
                    if (progress.progress >= 1.0f) {
                        if (owner.getWorld() instanceof WorldMaster) {
                            FutureCell future = new FutureCell(cell);
                            future.setVoxel(this.getDefinition().store().parent().voxels().air());
                            // Check no one minds
                            PlayerVoxelModificationEvent event = new PlayerVoxelModificationEvent(cell, future, (WorldModificationCause) entityControllable, (Player) controller);
                            owner.getWorld().getGameContext().getPluginManager().fireEvent(event);
                            // Break the block
                            if (!event.isCancelled()) {
                                Vector3d rnd = new Vector3d();
                                for (int i = 0; i < 40; i++) {
                                    rnd.set(progress.loc);
                                    rnd.add(Math.random() * 0.98, Math.random() * 0.98, Math.random() * 0.98);
                                    world.getParticlesManager().spawnParticleAtPosition("voxel_frag", rnd);
                                }
                                world.getSoundManager().playSoundEffect("sounds/gameplay/voxel_remove.ogg", Mode.NORMAL, progress.loc, 1.0f, 1.0f);
                                Location itemSpawnLocation = new Location(world, progress.loc);
                                itemSpawnLocation.add(0.5, 0.0, 0.5);
                                // ItemPile droppedItemPile = null;
                                for (ItemPile droppedItemPile : cell.getVoxel().getLoot(cell, (WorldModificationCause) entityControllable)) {
                                    EntityGroundItem thrownItem = (EntityGroundItem) getDefinition().store().parent().entities().getEntityDefinition("groundItem").create(itemSpawnLocation);
                                    thrownItem.positionComponent.setPosition(itemSpawnLocation);
                                    thrownItem.velocityComponent.setVelocity(new Vector3d(Math.random() * 0.125 - 0.0625, 0.1, Math.random() * 0.125 - 0.0625));
                                    thrownItem.setItemPile(droppedItemPile);
                                    world.addEntity(thrownItem);
                                }
                                try {
                                    world.poke(future, (WorldModificationCause) entityControllable);
                                } catch (WorldException e) {
                                // Didn't work
                                // TODO make some ingame effect so as to clue in the player why it failed
                                }
                            }
                        }
                        progress = null;
                    }
                }
            } else {
                progress = null;
            }
            Player player = (Player) controller;
            if (player.getContext() instanceof ClientInterface) {
                Player me = ((ClientInterface) player.getContext()).getPlayer();
                if (me.equals(player)) {
                    myProgress = progress;
                }
            }
        }
    }
}
Also used : Player(io.xol.chunkstories.api.player.Player) WorldCell(io.xol.chunkstories.api.world.World.WorldCell) EntityGroundItem(io.xol.chunkstories.core.entity.EntityGroundItem) WorldException(io.xol.chunkstories.api.exceptions.world.WorldException) EntityWorldModifier(io.xol.chunkstories.api.entity.interfaces.EntityWorldModifier) ClientInterface(io.xol.chunkstories.api.client.ClientInterface) World(io.xol.chunkstories.api.world.World) Controller(io.xol.chunkstories.api.entity.Controller) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile) FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) PlayerVoxelModificationEvent(io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent) Vector3d(org.joml.Vector3d) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) WorldMaster(io.xol.chunkstories.api.world.WorldMaster) InputsManager(io.xol.chunkstories.api.input.InputsManager) Location(io.xol.chunkstories.api.Location)

Example 4 with ItemPile

use of io.xol.chunkstories.api.item.inventory.ItemPile in project chunkstories-core by Hugobros3.

the class VoxelMeta16 method getItems.

@Override
public ItemPile[] getItems() {
    ItemPile[] items = new ItemPile[16];
    for (int i = 0; i < 16; i++) {
        ItemVoxel itemVoxel = (ItemVoxel) store.parent().items().getItemDefinition("item_voxel").newItem();
        itemVoxel.voxel = this;
        itemVoxel.voxelMeta = i;
        items[i] = new ItemPile(itemVoxel);
    }
    ;
    return items;
}
Also used : ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Example 5 with ItemPile

use of io.xol.chunkstories.api.item.inventory.ItemPile in project chunkstories-api by Hugobros3.

the class Voxel method getItems.

/**
 * @return Returns an array of ItemPiles for all the player-placeable variants of this Voxel
 */
public ItemPile[] getItems() {
    // We spawn a ItemVoxel and set it to reflect this one
    ItemVoxel itemVoxel = (ItemVoxel) this.getDefinition().store().parent().items().getItemDefinition("item_voxel").newItem();
    itemVoxel.voxel = this;
    return new ItemPile[] { new ItemPile(itemVoxel) };
}
Also used : ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Aggregations

ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)14 ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)6 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)5 Vector3d (org.joml.Vector3d)4 Player (io.xol.chunkstories.api.player.Player)3 Vector4f (org.joml.Vector4f)3 Location (io.xol.chunkstories.api.Location)2 Entity (io.xol.chunkstories.api.entity.Entity)2 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)2 PlayerVoxelModificationEvent (io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent)2 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)2 Mouse (io.xol.chunkstories.api.input.Mouse)2 WorldCell (io.xol.chunkstories.api.world.World.WorldCell)2 WorldClient (io.xol.chunkstories.api.world.WorldClient)2 FutureCell (io.xol.chunkstories.api.world.cell.FutureCell)2 ClientInterface (io.xol.chunkstories.api.client.ClientInterface)1 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)1 Content (io.xol.chunkstories.api.content.Content)1 Controller (io.xol.chunkstories.api.entity.Controller)1 EntityWithInventory (io.xol.chunkstories.api.entity.interfaces.EntityWithInventory)1