Search in sources :

Example 1 with SpriteRaw

use of buildcraft.lib.client.sprite.SpriteRaw in project BuildCraft by BuildCraft.

the class GuiIcon method offset.

public GuiIcon offset(double u, double v) {
    SpriteRaw raw = (SpriteRaw) sprite;
    double uMin = raw.uMin + u / textureSize;
    double vMin = raw.vMin + v / textureSize;
    return new GuiIcon(new SpriteRaw(raw.location, uMin, vMin, raw.width, raw.height), textureSize);
}
Also used : SpriteRaw(buildcraft.lib.client.sprite.SpriteRaw)

Example 2 with SpriteRaw

use of buildcraft.lib.client.sprite.SpriteRaw in project BuildCraft by BuildCraft.

the class SpriteUtil method getFaceSprite.

public static ISprite getFaceSprite(GameProfile profile) {
    if (profile == null) {
        return BCLibSprites.HELP;
    }
    Minecraft mc = Minecraft.getMinecraft();
    if (CACHED.containsKey(profile) && CACHED.get(profile) == null && Math.random() >= 0.99) {
        CACHED.remove(profile);
    }
    if (!CACHED.containsKey(profile)) {
        CACHED.put(profile, TileEntitySkull.updateGameprofile(profile));
    }
    GameProfile p2 = CACHED.get(profile);
    if (p2 == null) {
        return BCLibSprites.LOCK;
    }
    profile = p2;
    Map<Type, MinecraftProfileTexture> map = mc.getSkinManager().loadSkinFromCache(profile);
    MinecraftProfileTexture tex = map.get(Type.SKIN);
    if (tex != null) {
        ResourceLocation loc = mc.getSkinManager().loadSkin(tex, Type.SKIN);
        return new SpriteRaw(loc, 8, 8, 8, 8, 64);
    }
    return BCLibSprites.LOADING;
}
Also used : Type(com.mojang.authlib.minecraft.MinecraftProfileTexture.Type) GameProfile(com.mojang.authlib.GameProfile) ResourceLocation(net.minecraft.util.ResourceLocation) SpriteRaw(buildcraft.lib.client.sprite.SpriteRaw) MinecraftProfileTexture(com.mojang.authlib.minecraft.MinecraftProfileTexture) Minecraft(net.minecraft.client.Minecraft)

Example 3 with SpriteRaw

use of buildcraft.lib.client.sprite.SpriteRaw in project BuildCraft by BuildCraft.

the class ElementTypeSprite method deserialize0.

@Override
public IGuiElement deserialize0(BuildCraftJsonGui gui, IGuiPosition parent, JsonGuiInfo info, JsonGuiElement json) {
    FunctionContext ctx = createContext(json);
    inheritProperty(json, "pos[0]", "area[0]");
    inheritProperty(json, "pos[1]", "area[1]");
    inheritProperty(json, "size[0]", "area[2]");
    inheritProperty(json, "size[1]", "area[3]");
    inheritProperty(json, "source.pos[0]", "source.area[0]");
    inheritProperty(json, "source.pos[1]", "source.area[1]");
    inheritProperty(json, "source.size[0]", "source.area[2]");
    inheritProperty(json, "source.size[1]", "source.area[3]");
    inheritProperty(json, "area", "source.area");
    inheritProperty(json, "area[0]", "source.area[0]");
    inheritProperty(json, "area[1]", "source.area[1]");
    inheritProperty(json, "area[2]", "source.area[2]");
    inheritProperty(json, "area[3]", "source.area[3]");
    IGuiArea area = resolveArea(json, "area", parent, ctx);
    IGuiArea srcArea = resolveArea(json, "source.area", PositionAbsolute.ORIGIN, ctx);
    INodeBoolean visible = getEquationBool(json, "visible", ctx, true);
    boolean foreground = resolveEquationBool(json, "foreground", ctx, false);
    // TODO: Allow the source sprite to be changing as well!
    SrcTexture tex = resolveTexture(info, json, "source");
    String origin = tex.origin;
    int texSize = tex.texSize;
    if (// 
    !json.properties.containsKey("source.area[2]") && // 
    !json.properties.containsKey("source.area[3]") && !json.properties.containsKey("source.area")) {
        srcArea = new GuiRectangle(texSize, texSize);
    }
    ISprite sprite = gui.properties.get(origin, ISprite.class);
    if (sprite == null) {
        ResourceLocation loc = SpriteUtil.transformLocation(new ResourceLocation(origin));
        sprite = new SpriteRaw(loc, 0, 0, 1, 1);
    }
    if (srcArea instanceof GuiRectangle) {
        double u = srcArea.getX();
        double v = srcArea.getY();
        double uSize = srcArea.getWidth();
        double vSize = srcArea.getHeight();
        sprite = GuiUtil.subRelative(sprite, u, v, uSize, vSize, texSize);
    } else {
        final IGuiArea a = srcArea;
        INodeDouble u = () -> a.getX() / texSize;
        INodeDouble v = () -> a.getY() / texSize;
        INodeDouble uSize = () -> a.getEndX() / texSize;
        INodeDouble vSize = () -> a.getEndY() / texSize;
        sprite = new SubSpriteChanging(sprite, u, v, uSize, vSize);
    }
    ISimpleDrawable icon = new GuiSpriteScaled(sprite, area.offsetToOrigin());
    GuiElementDrawable element = new GuiElementDrawable(gui, area, icon, foreground, visible);
    return element;
}
Also used : IGuiArea(buildcraft.lib.gui.pos.IGuiArea) ISimpleDrawable(buildcraft.lib.gui.ISimpleDrawable) GuiRectangle(buildcraft.lib.gui.pos.GuiRectangle) ISprite(buildcraft.api.core.render.ISprite) GuiElementDrawable(buildcraft.lib.gui.elem.GuiElementDrawable) INodeBoolean(buildcraft.lib.expression.api.IExpressionNode.INodeBoolean) FunctionContext(buildcraft.lib.expression.FunctionContext) SubSpriteChanging(buildcraft.lib.client.sprite.SubSpriteChanging) INodeDouble(buildcraft.lib.expression.api.IExpressionNode.INodeDouble) ResourceLocation(net.minecraft.util.ResourceLocation) GuiSpriteScaled(buildcraft.lib.gui.GuiSpriteScaled) SpriteRaw(buildcraft.lib.client.sprite.SpriteRaw)

Example 4 with SpriteRaw

use of buildcraft.lib.client.sprite.SpriteRaw in project BuildCraft by BuildCraft.

the class ElementTypeButton method resolveDrawable.

private static ISimpleDrawable resolveDrawable(FunctionContext ctx, JsonGuiInfo guiInfo, JsonGuiElement json, BuildCraftJsonGui gui, int sizeX, int sizeY, String key) {
    double[] uvs = new double[4];
    for (int i = 0; i < 4; i++) {
        uvs[i] = resolveEquationDouble(json, key + "[" + i + "]", ctx);
    }
    SrcTexture texture = resolveTexture(guiInfo, json, key);
    ISprite sprite = gui.properties.get(texture.origin, ISprite.class);
    if (sprite != null) {
        sprite = GuiUtil.subRelative(sprite, uvs[0], uvs[1], uvs[2], uvs[3], texture.texSize);
    } else {
        ResourceLocation loc = SpriteUtil.transformLocation(new ResourceLocation(texture.origin));
        sprite = new SpriteRaw(loc, uvs[0], uvs[1], uvs[2], uvs[3], texture.texSize);
    }
    return new GuiSpriteScaled(sprite, sizeX, sizeY);
}
Also used : ISprite(buildcraft.api.core.render.ISprite) ResourceLocation(net.minecraft.util.ResourceLocation) GuiSpriteScaled(buildcraft.lib.gui.GuiSpriteScaled) SpriteRaw(buildcraft.lib.client.sprite.SpriteRaw)

Aggregations

SpriteRaw (buildcraft.lib.client.sprite.SpriteRaw)4 ResourceLocation (net.minecraft.util.ResourceLocation)3 ISprite (buildcraft.api.core.render.ISprite)2 GuiSpriteScaled (buildcraft.lib.gui.GuiSpriteScaled)2 SubSpriteChanging (buildcraft.lib.client.sprite.SubSpriteChanging)1 FunctionContext (buildcraft.lib.expression.FunctionContext)1 INodeBoolean (buildcraft.lib.expression.api.IExpressionNode.INodeBoolean)1 INodeDouble (buildcraft.lib.expression.api.IExpressionNode.INodeDouble)1 ISimpleDrawable (buildcraft.lib.gui.ISimpleDrawable)1 GuiElementDrawable (buildcraft.lib.gui.elem.GuiElementDrawable)1 GuiRectangle (buildcraft.lib.gui.pos.GuiRectangle)1 IGuiArea (buildcraft.lib.gui.pos.IGuiArea)1 GameProfile (com.mojang.authlib.GameProfile)1 MinecraftProfileTexture (com.mojang.authlib.minecraft.MinecraftProfileTexture)1 Type (com.mojang.authlib.minecraft.MinecraftProfileTexture.Type)1 Minecraft (net.minecraft.client.Minecraft)1