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;
}
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;
}
Aggregations