Search in sources :

Example 6 with ItemVoxel

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

the class Voxel method getLoot.

/**
 * Returns what's dropped when a cell using this voxel type is destroyed
 */
public ItemPile[] getLoot(CellData cell, WorldModificationCause cause) {
    ItemVoxel itemVoxel = (ItemVoxel) this.getDefinition().store().parent().items().getItemDefinition("item_voxel").newItem();
    itemVoxel.voxel = this;
    itemVoxel.voxelMeta = cell.getMetaData();
    ItemPile pile = new ItemPile(itemVoxel);
    return new ItemPile[] { pile };
}
Also used : ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Example 7 with ItemVoxel

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

the class EntityPlayer method onControllerInput.

@Override
public boolean onControllerInput(Input input, Controller controller) {
    // We are moving inventory bringup here !
    if (input.getName().equals("inventory") && world instanceof WorldClient) {
        if (creativeMode.get()) {
            ((WorldClient) getWorld()).getClient().openInventories(this.inventoryComponent.getInventory(), new InventoryLocalCreativeMenu(world));
        } else {
            ((WorldClient) getWorld()).getClient().openInventories(this.inventoryComponent.getInventory(), this.armor.getInventory());
        }
        return true;
    }
    Location blockLocation = this.getBlockLookingAt(true);
    double maxLen = 1024;
    if (blockLocation != null) {
        Vector3d diff = new Vector3d(blockLocation).sub(this.getLocation());
        // Vector3d dir = diff.clone().normalize();
        maxLen = diff.length();
    }
    Vector3d initialPosition = new Vector3d(getLocation());
    initialPosition.add(new Vector3d(0, eyePosition, 0));
    Vector3dc direction = getDirectionLookingAt();
    Iterator<Entity> i = world.collisionsManager().rayTraceEntities(initialPosition, direction, maxLen);
    while (i.hasNext()) {
        Entity e = i.next();
        if (e.handleInteraction(this, input))
            return true;
    }
    ItemPile itemSelected = getSelectedItemComponent().getSelectedItem();
    if (itemSelected != null) {
        // See if the item handles the interaction
        if (itemSelected.getItem().onControllerInput(this, itemSelected, input, controller))
            return true;
    }
    if (getWorld() instanceof WorldMaster) {
        // Creative mode features building and picking.
        if (this.getCreativeModeComponent().get()) {
            if (input.getName().equals("mouse.left")) {
                if (blockLocation != null) {
                    // Player events mod
                    if (controller instanceof Player) {
                        Player player = (Player) controller;
                        WorldCell cell = world.peekSafely(blockLocation);
                        FutureCell future = new FutureCell(cell);
                        future.setVoxel(this.getDefinition().store().parent().voxels().air());
                        future.setBlocklight(0);
                        future.setSunlight(0);
                        future.setMetaData(0);
                        PlayerVoxelModificationEvent event = new PlayerVoxelModificationEvent(cell, future, EntityCreative.CREATIVE_MODE, player);
                        // Anyone has objections ?
                        world.getGameContext().getPluginManager().fireEvent(event);
                        if (event.isCancelled())
                            return true;
                        Vector3d rnd = new Vector3d();
                        for (int k = 0; k < 40; k++) {
                            rnd.set(blockLocation);
                            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, blockLocation, 1.0f, 1.0f);
                        try {
                            world.poke(future, this);
                        // world.poke((int)blockLocation.x, (int)blockLocation.y, (int)blockLocation.z, null, 0, 0, 0, this);
                        } catch (WorldException e) {
                        // Discard but maybe play some effect ?
                        }
                        return true;
                    }
                }
            } else if (input.getName().equals("mouse.middle")) {
                if (blockLocation != null) {
                    CellData ctx = this.getWorld().peekSafely(blockLocation);
                    if (!ctx.getVoxel().isAir()) {
                        // Spawn new itemPile in his inventory
                        ItemVoxel item = (ItemVoxel) world.getGameContext().getContent().items().getItemDefinition("item_voxel").newItem();
                        item.voxel = ctx.getVoxel();
                        item.voxelMeta = ctx.getMetaData();
                        ItemPile itemVoxel = new ItemPile(item);
                        this.getInventory().setItemPileAt(getSelectedItemComponent().getSelectedSlot(), 0, itemVoxel);
                        return true;
                    }
                }
            }
        }
    }
    // Then we check if the world minds being interacted with
    return world.handleInteraction(this, blockLocation, input);
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Player(io.xol.chunkstories.api.player.Player) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) WorldCell(io.xol.chunkstories.api.world.World.WorldCell) WorldException(io.xol.chunkstories.api.exceptions.world.WorldException) WorldClient(io.xol.chunkstories.api.world.WorldClient) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile) CellData(io.xol.chunkstories.api.world.cell.CellData) Vector3dc(org.joml.Vector3dc) FutureCell(io.xol.chunkstories.api.world.cell.FutureCell) PlayerVoxelModificationEvent(io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent) Vector3d(org.joml.Vector3d) InventoryLocalCreativeMenu(io.xol.chunkstories.core.item.inventory.InventoryLocalCreativeMenu) WorldMaster(io.xol.chunkstories.api.world.WorldMaster) Location(io.xol.chunkstories.api.Location)

Example 8 with ItemVoxel

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

the class VoxelDoor method getItems.

@Override
public ItemPile[] getItems() {
    // Top part shouldn't be placed
    if (top)
        return new ItemPile[] {};
    ItemVoxel itemVoxel = (ItemVoxel) store.parent().items().getItemDefinition("item_voxel_1x2").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

ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)8 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)6 Voxel (io.xol.chunkstories.api.voxel.Voxel)3 CellData (io.xol.chunkstories.api.world.cell.CellData)3 Player (io.xol.chunkstories.api.player.Player)2 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)2 DummyCell (io.xol.chunkstories.api.world.cell.DummyCell)2 Vector3f (org.joml.Vector3f)2 Location (io.xol.chunkstories.api.Location)1 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)1 Content (io.xol.chunkstories.api.content.Content)1 Entity (io.xol.chunkstories.api.entity.Entity)1 PlayerVoxelModificationEvent (io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent)1 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)1 Item (io.xol.chunkstories.api.item.Item)1 ItemDefinition (io.xol.chunkstories.api.item.ItemDefinition)1 Light (io.xol.chunkstories.api.rendering.lightning.Light)1 Shader (io.xol.chunkstories.api.rendering.shader.Shader)1 ServerInterface (io.xol.chunkstories.api.server.ServerInterface)1 WorldCell (io.xol.chunkstories.api.world.World.WorldCell)1