Search in sources :

Example 1 with ItemPreset

use of org.asassecreations.voxelgame.inventory.ItemPreset in project Voxel_Game by ASasseCreations.

the class AssetLoader method loadBlocks.

public static final Map<String, Block> loadBlocks(final Map<String, BlockTexture> atlasPos) throws MalformedURLException, IOException, URISyntaxException {
    final List<String> fileNames = getItems("/def/block", "def");
    fileNames.addAll(getItems(Content.MOD_BLOCK_FOLDER, "def", true));
    final Map<String, Block> finalBlocks = new HashMap<>();
    for (int i = 0; i < fileNames.size(); i++) {
        final String block = getName(fileNames.get(i), 3);
        final BlockTexture texture = new BlockTexture(0, 0);
        boolean breakable = true;
        ItemPreset item = null;
        final Properties properties = new Properties();
        properties.load(Tools.getReader(fileNames.get(i)));
        {
            texture.left_uv = atlasPos.get(properties.getProperty("left")).left_uv;
            texture.right_uv = atlasPos.get(properties.getProperty("right")).right_uv;
            texture.top_uv = atlasPos.get(properties.getProperty("top")).top_uv;
            texture.bottom_uv = atlasPos.get(properties.getProperty("bottom")).bottom_uv;
            texture.front_uv = atlasPos.get(properties.getProperty("front")).front_uv;
            texture.back_uv = atlasPos.get(properties.getProperty("back")).back_uv;
            if (properties.getProperty("breakable") != null)
                breakable = Boolean.parseBoolean(properties.getProperty("breakable"));
            if (properties.getProperty("item") != null)
                item = ItemPreset.get(properties.getProperty("item"));
        }
        finalBlocks.put(block, new Block(i, texture, BlockAudio.BLOCK_CLOTH, item, breakable));
    }
    return finalBlocks;
}
Also used : HashMap(java.util.HashMap) BlockTexture(org.asassecreations.voxelgame.world.block.texture.BlockTexture) Block(org.asassecreations.voxelgame.world.block.Block) ItemPreset(org.asassecreations.voxelgame.inventory.ItemPreset) TextureProperties(org.asassecreations.engine.texture.TextureProperties) Properties(java.util.Properties)

Example 2 with ItemPreset

use of org.asassecreations.voxelgame.inventory.ItemPreset in project Voxel_Game by ASasseCreations.

the class AssetLoader method loadItems.

public static final void loadItems() throws IOException, URISyntaxException {
    final List<String> itemFileNames = getItems("/def/item", "def");
    itemFileNames.addAll(getItems(Content.MOD_ITEM_FOLDER, "def", true));
    for (final String s : itemFileNames) {
        final String name = getName(s, 3);
        final Properties properties = new Properties();
        properties.load(Tools.getReader(s));
        final ItemPreset item = new ItemPreset();
        final String p = properties.getProperty("texture");
        item.id = Integer.parseInt(properties.getProperty("id"));
        {
            for (final String str : ItemPreset.ITEMS.keySet()) {
                final ItemPreset i = ItemPreset.ITEMS.get(str);
                if (i.id == item.id) {
                    JOptionPane.showMessageDialog(null, "Item id conflict with \"" + str + "\" and \"" + name + "\" with id " + item.id, "Item not loaded!", JOptionPane.ERROR_MESSAGE);
                    continue;
                }
            }
        }
        if (p.startsWith(":"))
            item.image = RawAtlasTile.ORIGINAL_IMAGE.get(p.substring(1));
        else
            item.image = RawAtlasTile.MODIFIED_IMAGE.get(p);
        ItemPreset.ITEMS.put(name, item);
    }
}
Also used : ItemPreset(org.asassecreations.voxelgame.inventory.ItemPreset) TextureProperties(org.asassecreations.engine.texture.TextureProperties) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)2 TextureProperties (org.asassecreations.engine.texture.TextureProperties)2 ItemPreset (org.asassecreations.voxelgame.inventory.ItemPreset)2 HashMap (java.util.HashMap)1 Block (org.asassecreations.voxelgame.world.block.Block)1 BlockTexture (org.asassecreations.voxelgame.world.block.texture.BlockTexture)1