Search in sources :

Example 1 with WordImage

use of pl.asie.charset.module.tablet.format.words.WordImage in project Charset by CharsetMC.

the class CommandImg method call.

@Override
public void call(ITypesetter out, ITokenizer tokenizer) throws TruthError {
    String imgName = tokenizer.getParameter("domain:path/to/image.png");
    String scaleOrWidth = tokenizer.getOptionalParameter();
    String heightS = tokenizer.getOptionalParameter();
    ResourceLocation rl = new ResourceLocation(imgName);
    try {
        Minecraft mc = Minecraft.getMinecraft();
        IResource r = mc.getResourceManager().getResource(rl);
        if (r == null) {
            throw new TruthError("Not found: " + imgName);
        }
    } catch (Throwable e) {
        e.printStackTrace();
        throw new TruthError(e.getMessage());
    }
    WordImage img;
    if (heightS != null) {
        int width = Integer.parseInt(scaleOrWidth);
        int height = Integer.parseInt(heightS);
        img = new WordImage(rl, width, height);
    } else {
        img = new WordImage(rl);
        if (scaleOrWidth != null) {
            img.scale(Double.parseDouble(scaleOrWidth));
        }
    }
    if (out.hasFixedWidth()) {
        img.fitToPage(out.getWidth(), Integer.MAX_VALUE);
    }
    out.write(img);
}
Also used : TruthError(pl.asie.charset.module.tablet.format.api.TruthError) ResourceLocation(net.minecraft.util.ResourceLocation) WordImage(pl.asie.charset.module.tablet.format.words.WordImage) Minecraft(net.minecraft.client.Minecraft) IResource(net.minecraft.client.resources.IResource)

Aggregations

Minecraft (net.minecraft.client.Minecraft)1 IResource (net.minecraft.client.resources.IResource)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 TruthError (pl.asie.charset.module.tablet.format.api.TruthError)1 WordImage (pl.asie.charset.module.tablet.format.words.WordImage)1