Search in sources :

Example 1 with ItemDefinition

use of net.runelite.cache.definitions.ItemDefinition in project runelite by runelite.

the class ItemSpriteFactoryTest method test.

@Test
@Ignore
public void test() throws IOException {
    File base = StoreLocation.LOCATION, outDir = folder.newFolder();
    int count = 0;
    try (Store store = new Store(base)) {
        store.load();
        ItemManager itemManager = new ItemManager(store);
        itemManager.load();
        ModelProvider modelProvider = new ModelProvider() {

            @Override
            public ModelDefinition provide(int modelId) throws IOException {
                Index models = store.getIndex(IndexType.MODELS);
                Archive archive = models.getArchive(modelId);
                byte[] data = archive.decompress(store.getStorage().loadArchive(archive));
                ModelDefinition inventoryModel = new ModelLoader().load(modelId, data);
                return inventoryModel;
            }
        };
        SpriteManager spriteManager = new SpriteManager(store);
        spriteManager.load();
        TextureManager textureManager = new TextureManager(store);
        textureManager.load();
        for (ItemDefinition itemDef : itemManager.getItems()) {
            if (itemDef.name == null || itemDef.name.equalsIgnoreCase("null")) {
                continue;
            }
            try {
                BufferedImage sprite = ItemSpriteFactory.createSprite(itemManager, modelProvider, spriteManager, textureManager, itemDef.id, 1, 1, 3153952, false);
                File out = new File(outDir, itemDef.id + ".png");
                BufferedImage img = sprite;
                ImageIO.write(img, "PNG", out);
                ++count;
            } catch (Exception ex) {
                log.warn("error dumping item {}", itemDef.id, ex);
            }
        }
    }
    log.info("Dumped {} item images to {}", count, outDir);
}
Also used : Archive(net.runelite.cache.fs.Archive) ItemManager(net.runelite.cache.ItemManager) ModelProvider(net.runelite.cache.definitions.providers.ModelProvider) ItemDefinition(net.runelite.cache.definitions.ItemDefinition) Store(net.runelite.cache.fs.Store) Index(net.runelite.cache.fs.Index) SpriteManager(net.runelite.cache.SpriteManager) BufferedImage(java.awt.image.BufferedImage) IOException(java.io.IOException) ModelLoader(net.runelite.cache.definitions.loaders.ModelLoader) TextureManager(net.runelite.cache.TextureManager) ModelDefinition(net.runelite.cache.definitions.ModelDefinition) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ItemDefinition

use of net.runelite.cache.definitions.ItemDefinition in project runelite by runelite.

the class ItemManager method java.

public void java(File java) throws IOException {
    System.setProperty("line.separator", "\n");
    java.mkdirs();
    File targ = new File(java, "ItemID.java");
    try (PrintWriter fw = new PrintWriter(targ)) {
        fw.println("/* This file is automatically generated. Do not edit. */");
        fw.println("package net.runelite.api;");
        fw.println("");
        fw.println("public final class ItemID");
        fw.println("{");
        for (ItemDefinition def : items.values()) {
            if (def.name.equalsIgnoreCase("NULL")) {
                continue;
            }
            String name = namer.name(def.name, def.id);
            if (name == null) {
                continue;
            }
            fw.println("	public static final int " + name + " = " + def.id + ";");
        }
        fw.println("}");
    }
}
Also used : ItemDefinition(net.runelite.cache.definitions.ItemDefinition) File(java.io.File) FSFile(net.runelite.cache.fs.FSFile) PrintWriter(java.io.PrintWriter)

Example 3 with ItemDefinition

use of net.runelite.cache.definitions.ItemDefinition in project runelite by runelite.

the class ItemManager method export.

public void export(File out) throws IOException {
    out.mkdirs();
    for (ItemDefinition def : items.values()) {
        ItemExporter exporter = new ItemExporter(def);
        File targ = new File(out, def.id + ".json");
        exporter.exportTo(targ);
    }
}
Also used : ItemExporter(net.runelite.cache.definitions.exporters.ItemExporter) ItemDefinition(net.runelite.cache.definitions.ItemDefinition) File(java.io.File) FSFile(net.runelite.cache.fs.FSFile)

Example 4 with ItemDefinition

use of net.runelite.cache.definitions.ItemDefinition in project ostracker by OSTracker.

the class ItemRasterizer method rasterize.

public BufferedImage rasterize(int itemId) {
    ItemDefinition definition = getItemDefinitionForId(itemId);
    if (definition.placeholderTemplateId == -1 && definition.boughtTemplateId == -1) {
        SpritePixels sprite = createItemSprite(definition, false, true);
        if (sprite != null) {
            try {
                BufferedImage image = new BufferedImage(sprite.width, sprite.height, BufferedImage.TYPE_INT_ARGB);
                for (int i = 0; i < sprite.width; ++i) {
                    for (int j = 0; j < sprite.height; ++j) {
                        int pixel = sprite.image[j * sprite.width + i];
                        if ((pixel & 0xFF000000) == 0 && (pixel & 0xFFFFFF) != 0) {
                            pixel |= 0xFF000000;
                        }
                        image.setRGB(i, j, pixel);
                    }
                }
                return image;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
    return null;
}
Also used : ItemDefinition(net.runelite.cache.definitions.ItemDefinition) BufferedImage(java.awt.image.BufferedImage)

Example 5 with ItemDefinition

use of net.runelite.cache.definitions.ItemDefinition in project runelite by runelite.

the class ItemLoader method load.

public ItemDefinition load(int id, byte[] b) {
    ItemDefinition def = new ItemDefinition(id);
    InputStream is = new InputStream(b);
    while (true) {
        int opcode = is.readUnsignedByte();
        if (opcode == 0) {
            break;
        }
        this.decodeValues(opcode, def, is);
    }
    return def;
}
Also used : InputStream(net.runelite.cache.io.InputStream) ItemDefinition(net.runelite.cache.definitions.ItemDefinition)

Aggregations

ItemDefinition (net.runelite.cache.definitions.ItemDefinition)9 FSFile (net.runelite.cache.fs.FSFile)4 File (java.io.File)3 BufferedImage (java.awt.image.BufferedImage)2 IOException (java.io.IOException)2 ItemLoader (net.runelite.cache.definitions.loaders.ItemLoader)2 Archive (net.runelite.cache.fs.Archive)2 ArchiveFiles (net.runelite.cache.fs.ArchiveFiles)2 Index (net.runelite.cache.fs.Index)2 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 ItemManager (net.runelite.cache.ItemManager)1 SpriteManager (net.runelite.cache.SpriteManager)1 TextureManager (net.runelite.cache.TextureManager)1 ModelDefinition (net.runelite.cache.definitions.ModelDefinition)1 ItemExporter (net.runelite.cache.definitions.exporters.ItemExporter)1 ModelLoader (net.runelite.cache.definitions.loaders.ModelLoader)1 ModelProvider (net.runelite.cache.definitions.providers.ModelProvider)1 File (net.runelite.cache.fs.File)1