Search in sources :

Example 1 with ItemVoxel

use of io.xol.chunkstories.api.item.ItemVoxel 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 2 with ItemVoxel

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

the class GiveCommand method handleCommand.

@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
    if (!emitter.hasPermission("server.give")) {
        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;
    }
    Content gameContent = server.getContent();
    Player player = (Player) emitter;
    if (arguments.length == 0) {
        player.sendMessage("#FF969BSyntax : /give <item> [amount] [to]");
        return true;
    }
    int amount = 1;
    Player to = player;
    String itemName = arguments[0];
    // Look for the item first
    ItemDefinition type = gameContent.items().getItemDefinition(itemName);
    // If the type was found we are simply trying to spawn an item
    Item item = null;
    if (type != null)
        item = type.newItem();
    else {
        String voxelName = itemName;
        int voxelMeta = 0;
        if (voxelName.contains(":")) {
            voxelMeta = Integer.parseInt(voxelName.split(":")[1]);
            voxelName = voxelName.split(":")[0];
        }
        // Try to find a matching voxel
        Voxel voxel = gameContent.voxels().getVoxel(itemName);
        if (voxel != null) {
            // Spawn new itemPile in his inventory
            ItemVoxel itemVoxel = (ItemVoxel) gameContent.items().getItemDefinition("item_voxel").newItem();
            itemVoxel.voxel = voxel;
            itemVoxel.voxelMeta = voxelMeta;
            item = itemVoxel;
        }
    }
    if (item == null) {
        player.sendMessage("#FF969BItem or voxel \"" + arguments[0] + " can't be found.");
        return true;
    }
    if (arguments.length >= 2) {
        amount = Integer.parseInt(arguments[1]);
    }
    if (arguments.length >= 3) {
        if (gameContent instanceof ServerInterface)
            to = ((ServerInterface) gameContent).getPlayerByName(arguments[2]);
        else {
            player.sendMessage("#FF969BThis is a singleplayer world - there are no other players");
            return true;
        }
    }
    if (to == null) {
        player.sendMessage("#FF969BPlayer \"" + arguments[2] + " can't be found.");
        return true;
    }
    ItemPile itemPile = new ItemPile(item);
    itemPile.setAmount(amount);
    ((EntityWithInventory) to.getControlledEntity()).getInventory().addItemPile(itemPile);
    player.sendMessage("#FF969BGave " + (amount > 1 ? amount + "x " : "") + "#4CFF00" + itemPile.getItem().getName() + " #FF969Bto " + to.getDisplayName());
    return true;
}
Also used : Item(io.xol.chunkstories.api.item.Item) Player(io.xol.chunkstories.api.player.Player) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) ServerInterface(io.xol.chunkstories.api.server.ServerInterface) Content(io.xol.chunkstories.api.content.Content) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Voxel(io.xol.chunkstories.api.voxel.Voxel) ItemDefinition(io.xol.chunkstories.api.item.ItemDefinition) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Example 3 with ItemVoxel

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

Example 4 with ItemVoxel

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

the class VoxelItemRenderer method renderItemInWorld.

@Override
public void renderItemInWorld(RenderingInterface renderer, ItemPile pile, World world, Location location, Matrix4f handTransformation) {
    /*if (((ItemVoxel) pile.getItem()).getVoxel() instanceof VoxelCustomIcon) {
			fallbackRenderer.renderItemInWorld(renderer, pile, world, location, handTransformation);
			return;
		}*/
    Voxel voxel = ((ItemVoxel) pile.getItem()).getVoxel();
    if (voxel == null)
        return;
    CellData fakeCell = new DummyCell(0, 0, 0, voxel, 0, 0, 0) {

        CellData air = new DummyCell(0, 1, 0, voxel.store().air(), 0, 0, 0);

        @Override
        public int getBlocklight() {
            return voxel.getEmittedLightLevel(this);
        }

        @Override
        public CellData getNeightbor(int side) {
            return air;
        }

        @Override
        public int getMetaData() {
            return ((ItemVoxel) pile.getItem()).getVoxelMeta();
        }
    };
    float s = 0.45f;
    handTransformation.scale(new Vector3f(s, s, s));
    handTransformation.translate(new Vector3f(-0.25f, -0.5f, -0.5f));
    renderer.setObjectMatrix(handTransformation);
    // Add a light only on the opaque pass
    if (fakeCell.getBlocklight() > 0 && renderer.getCurrentPass().name.contains("gBuffers")) {
        Vector4f lightposition = new Vector4f(0.0f, 0.0f, 0.0f, 1.0f);
        handTransformation.transform(lightposition);
        Light heldBlockLight = new Light(new Vector3f(0.6f, 0.50f, 0.4f).mul(0.5f), new Vector3f(lightposition.x(), lightposition.y(), lightposition.z()), 15f);
        renderer.getLightsRenderer().queueLight(heldBlockLight);
        // If we hold a light source, prepare the shader accordingly
        renderer.currentShader().setUniform2f("worldLightIn", Math.max(world.peekSafely(location).getBlocklight(), fakeCell.getBlocklight()), world.peekSafely(location).getSunlight());
    }
    Texture2D texture = content.voxels().textures().getDiffuseAtlasTexture();
    texture.setLinearFiltering(false);
    renderer.bindAlbedoTexture(texture);
    Texture2D normalTexture = content.voxels().textures().getNormalAtlasTexture();
    normalTexture.setLinearFiltering(false);
    renderer.bindNormalTexture(normalTexture);
    Texture2D materialTexture = content.voxels().textures().getMaterialAtlasTexture();
    materialTexture.setLinearFiltering(false);
    renderer.bindMaterialTexture(materialTexture);
    renderFakeVoxel(renderer, fakeCell);
}
Also used : ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Vector4f(org.joml.Vector4f) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Voxel(io.xol.chunkstories.api.voxel.Voxel) Light(io.xol.chunkstories.api.rendering.lightning.Light) Vector3f(org.joml.Vector3f) CellData(io.xol.chunkstories.api.world.cell.CellData) DummyCell(io.xol.chunkstories.api.world.cell.DummyCell)

Example 5 with ItemVoxel

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

the class VoxelItemRenderer method renderItemInInventory.

@Override
public void renderItemInInventory(RenderingInterface renderer, ItemPile pile, float screenPositionX, float screenPositionY, int scaling) {
    /*if (((ItemVoxel) pile.getItem()).getVoxel() instanceof VoxelCustomIcon) {
			fallbackRenderer.renderItemInInventory(renderer, pile, screenPositionX, screenPositionY, scaling);
			return;
		}*/
    int slotSize = 24 * scaling;
    Shader program = renderer.useShader("inventory_blockmodel");
    renderer.setCullingMode(CullingMode.COUNTERCLOCKWISE);
    renderer.setDepthTestMode(DepthTestMode.LESS_OR_EQUAL);
    program.setUniform2f("screenSize", renderer.getWindow().getWidth(), renderer.getWindow().getHeight());
    program.setUniform2f("dekal", screenPositionX + pile.getItem().getDefinition().getSlotsWidth() * slotSize / 2, screenPositionY + pile.getItem().getDefinition().getSlotsHeight() * slotSize / 2);
    program.setUniform1f("scaling", slotSize / 1.65f);
    transformation.identity();
    transformation.scale(new Vector3f(-1f, 1f, 1f));
    transformation.rotate(toRad(-22.5f), new Vector3f(1.0f, 0.0f, 0.0f));
    transformation.rotate(toRad(45f), new Vector3f(0.0f, 1.0f, 0.0f));
    transformation.translate(new Vector3f(-0.5f, -0.5f, -0.5f));
    program.setUniformMatrix4f("transformation", transformation);
    Voxel voxel = ((ItemVoxel) pile.getItem()).getVoxel();
    if (voxel == null) {
        int width = slotSize * pile.getItem().getDefinition().getSlotsWidth();
        int height = slotSize * pile.getItem().getDefinition().getSlotsHeight();
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(screenPositionX, screenPositionY, width, height, 0, 1, 1, 0, content.textures().getTexture("./items/icons/notex.png"), true, true, null);
        return;
    }
    Texture2D texture = content.voxels().textures().getDiffuseAtlasTexture();
    texture.setLinearFiltering(false);
    renderer.bindAlbedoTexture(texture);
    Texture2D normalTexture = content.voxels().textures().getNormalAtlasTexture();
    normalTexture.setLinearFiltering(false);
    renderer.bindNormalTexture(normalTexture);
    Texture2D materialTexture = content.voxels().textures().getMaterialAtlasTexture();
    materialTexture.setLinearFiltering(false);
    renderer.bindMaterialTexture(materialTexture);
    CellData fakeCell = new DummyCell(0, 0, 0, voxel, 0, 0, 0) {

        CellData air = new DummyCell(0, 1, 0, voxel.store().air(), 0, 0, 0);

        @Override
        public int getBlocklight() {
            return voxel.getEmittedLightLevel(this);
        }

        @Override
        public CellData getNeightbor(int side) {
            return air;
        }

        @Override
        public int getMetaData() {
            return ((ItemVoxel) pile.getItem()).getVoxelMeta();
        }
    };
    renderFakeVoxel(renderer, fakeCell);
}
Also used : ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Voxel(io.xol.chunkstories.api.voxel.Voxel) Vector3f(org.joml.Vector3f) Shader(io.xol.chunkstories.api.rendering.shader.Shader) CellData(io.xol.chunkstories.api.world.cell.CellData) DummyCell(io.xol.chunkstories.api.world.cell.DummyCell)

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