Search in sources :

Example 1 with BlockTexture

use of org.asassecreations.voxelgame.world.block.texture.BlockTexture 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 BlockTexture

use of org.asassecreations.voxelgame.world.block.texture.BlockTexture in project Voxel_Game by ASasseCreations.

the class AssetLoader method createAtlas.

public static final AtlasResult createAtlas() throws URISyntaxException, IOException {
    int textureSize = 0;
    for (final BufferedImage image : RawAtlasTile.MODIFIED_IMAGE.values()) if (image.getHeight() > textureSize)
        textureSize = image.getHeight();
    final int rows = getTextureAtlasSize();
    final int imageSize = rows * textureSize;
    final BufferedImage image = new BufferedImage(imageSize, imageSize, BufferedImage.TYPE_INT_ARGB);
    {
        final int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
        for (int i = 0; i < pixels.length; i++) pixels[i] = 0x00000000;
    }
    final List<String> keys = new ArrayList<>(RawAtlasTile.MODIFIED_IMAGE.keySet());
    final List<BufferedImage> images = new ArrayList<>(RawAtlasTile.MODIFIED_IMAGE.values());
    final Map<String, BlockTexture> textures = new HashMap<>();
    final Graphics g = image.getGraphics();
    for (int y = 0; y < rows; y++) for (int x = 0; x < rows; x++) {
        if (x + y * rows >= images.size())
            continue;
        g.drawImage(images.get(x + y * rows), x * textureSize, y * textureSize, textureSize, textureSize, null);
        textures.put(keys.get(x + y * rows), new BlockTexture(x, y));
    }
    g.dispose();
    final AtlasResult result = new AtlasResult();
    final TextureProperties properties = new TextureProperties();
    properties.maxLevel = (int) (Math.log(textureSize) / Math.log(2));
    properties.minFilter = GL11.GL_NEAREST_MIPMAP_LINEAR;
    properties.magFilter = GL11.GL_NEAREST;
    properties.mipmaps = true;
    result.image = TextureLoader.getTexture(image, properties);
    result.textures = textures;
    return result;
}
Also used : Graphics(java.awt.Graphics) TextureProperties(org.asassecreations.engine.texture.TextureProperties) HashMap(java.util.HashMap) BlockTexture(org.asassecreations.voxelgame.world.block.texture.BlockTexture) ArrayList(java.util.ArrayList) BufferedImage(java.awt.image.BufferedImage)

Aggregations

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