Search in sources :

Example 1 with Color4I

use of com.feed_the_beast.ftblib.lib.icon.Color4I in project YABBA by LatvianModder.

the class YabbaClient method loadModelsAndSkins.

public static void loadModelsAndSkins() {
    TEXTURES.clear();
    MODELS.clear();
    SKINS.clear();
    ALL_MODELS.clear();
    ALL_SKINS.clear();
    IResourceManager manager = ClientUtils.MC.getResourceManager();
    for (String domain : manager.getResourceDomains()) {
        try {
            for (IResource resource : manager.getAllResources(new ResourceLocation(domain, "yabba_models/_index.json"))) {
                for (JsonElement element : DataReader.get(resource).json().getAsJsonArray()) {
                    try {
                        JsonObject modelFile = DataReader.get(manager.getResource(new ResourceLocation(domain, "yabba_models/" + element.getAsString() + ".json"))).json().getAsJsonObject();
                        BarrelModel model = new BarrelModel(new ResourceLocation(domain, element.getAsString()), modelFile);
                        MODELS.put(model.id, model);
                        for (TextureSet textureSet : model.textures.values()) {
                            TEXTURES.addAll(textureSet.getTextures());
                        }
                    } catch (Exception ex1) {
                    }
                }
            }
        } catch (Exception ex) {
            if (!(ex instanceof FileNotFoundException)) {
                ex.printStackTrace();
            }
        }
        try {
            for (IResource resource : manager.getAllResources(new ResourceLocation(domain, "yabba_models/_skins.json"))) {
                parseSkinsJson(DataReader.get(resource).json().getAsJsonArray());
                VARIABLES.clear();
            }
        } catch (Exception ex) {
            if (!(ex instanceof FileNotFoundException)) {
                ex.printStackTrace();
            }
        }
    }
    for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) {
        FluidStack stack = new FluidStack(fluid, 1000);
        String displayName = stack.getLocalizedName();
        Color4I color = Color4I.rgba(fluid.getColor(stack));
        if (color.equals(Color4I.WHITE)) {
            color = Icon.EMPTY;
        }
        ResourceLocation still = fluid.getStill(stack);
        BarrelSkin skin = new BarrelSkin(fluid.getName() + "_still", TextureSet.of("all=" + still));
        skin.displayName = StringUtils.translate("lang.fluid.still", displayName);
        skin.color = color;
        skin.layer = BlockRenderLayer.TRANSLUCENT;
        REGISTER_SKIN.addSkin(skin);
        ResourceLocation flowing = fluid.getFlowing(stack);
        if (!still.equals(flowing)) {
            skin = new BarrelSkin(fluid.getName() + "_flowing", TextureSet.of("up&down=" + still + ",all=" + flowing));
            skin.displayName = StringUtils.translate("lang.fluid.flowing", displayName);
            skin.color = color;
            skin.layer = BlockRenderLayer.TRANSLUCENT;
            REGISTER_SKIN.addSkin(skin);
        }
    }
    new YabbaSkinsEvent(REGISTER_SKIN).post();
    for (BarrelSkin skin : SKINS.values()) {
        if (skin.displayName.isEmpty() && skin.state != CommonUtils.AIR_STATE) {
            try {
                skin.displayName = new ItemStack(skin.state.getBlock(), 1, skin.state.getBlock().getMetaFromState(skin.state)).getDisplayName();
            } catch (Exception ex) {
            }
        }
        if (skin.displayName.isEmpty() || skin.displayName.contains("air")) {
            skin.displayName = "";
        }
        if (skin.icon.isEmpty()) {
            skin.icon = ItemIcon.getItemIcon(((BlockItemBarrel) YabbaItems.ITEM_BARREL).createStack(YabbaItems.ITEM_BARREL.getDefaultState(), BarrelLook.get(Yabba.MOD_ID + ":block", skin.id), Tier.WOOD));
        }
    }
    ALL_MODELS.addAll(MODELS.values());
    DEFAULT_MODEL = MODELS.get(BarrelLook.DEFAULT_MODEL_ID);
    if (DEFAULT_MODEL == null) {
        DEFAULT_MODEL = ALL_MODELS.isEmpty() ? null : ALL_MODELS.get(0);
    }
    Yabba.LOGGER.info("Models: " + ALL_MODELS.size());
    if (FTBLibConfig.debugging.print_more_info) {
        for (BarrelModel model : ALL_MODELS) {
            Yabba.LOGGER.info("-- " + model.id + " :: " + model);
        }
    }
    ALL_SKINS.addAll(SKINS.values());
    ALL_SKINS.sort(StringUtils.ID_COMPARATOR);
    DEFAULT_SKIN = SKINS.get(BarrelLook.DEFAULT_SKIN_ID);
    if (DEFAULT_SKIN == null) {
        DEFAULT_SKIN = ALL_SKINS.isEmpty() ? null : ALL_SKINS.get(0);
    }
    Yabba.LOGGER.info("Skins: " + ALL_SKINS.size());
    if (FTBLibConfig.debugging.print_more_info) {
        for (BarrelSkin skin : ALL_SKINS) {
            Yabba.LOGGER.info("-- " + skin.id + " :: " + skin);
        }
    }
    for (BarrelModel model : ALL_MODELS) {
        model.icon = ItemIcon.getItemIcon(((BlockItemBarrel) YabbaItems.ITEM_BARREL).createStack(YabbaItems.ITEM_BARREL.getDefaultState(), BarrelLook.get(model.id, ""), Tier.WOOD));
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) FileNotFoundException(java.io.FileNotFoundException) JsonObject(com.google.gson.JsonObject) Color4I(com.feed_the_beast.ftblib.lib.icon.Color4I) YabbaSkinsEvent(com.latmod.yabba.api.YabbaSkinsEvent) FileNotFoundException(java.io.FileNotFoundException) TextureSet(com.feed_the_beast.ftblib.lib.util.misc.TextureSet) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) IResourceManager(net.minecraft.client.resources.IResourceManager) ItemStack(net.minecraft.item.ItemStack) IResource(net.minecraft.client.resources.IResource) BarrelSkin(com.latmod.yabba.api.BarrelSkin) BlockItemBarrel(com.latmod.yabba.block.BlockItemBarrel)

Example 2 with Color4I

use of com.feed_the_beast.ftblib.lib.icon.Color4I in project YABBA by LatvianModder.

the class RenderBarrel method render.

@Override
public void render(T barrel, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
    if (barrel.isInvalid()) {
        return;
    }
    if (destroyStage >= 0) {
        ClientUtils.MC.getTextureManager().bindTexture(DESTROY_STAGES[destroyStage]);
        GlStateManager.pushMatrix();
        GlStateManager.translate(x, y, z);
        GlStateManager.glNormal3f(0F, 1F, 0F);
        CachedVertexData data = new CachedVertexData(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
        data.cube(barrel.getAABB(barrel.getBlockState()));
        data.draw(Tessellator.getInstance(), Tessellator.getInstance().getBuffer());
        GlStateManager.popMatrix();
    } else {
        GlStateManager.color(1F, 1F, 1F, alpha);
    }
    boolean hasIcon = hasIcon(barrel);
    boolean isSneaking = ClientUtils.MC.player.isSneaking();
    RayTraceResult ray = ClientUtils.MC.objectMouseOver;
    boolean mouseOver = ray != null && ray.typeOfHit == RayTraceResult.Type.BLOCK && ray.getBlockPos().equals(barrel.getPos());
    if (!hasIcon && !isSneaking) {
        return;
    }
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    GlStateManager.glNormal3f(0F, 1F, 0F);
    GlStateManager.translate(0.5F, 0.5F, 0.5F);
    GlStateManager.rotate(180F, 0F, 0F, 1F);
    GlStateManager.rotate(barrel.getRotationAngleY(), 0F, 1F, 0F);
    GlStateManager.rotate(barrel.getRotationAngleX(), 1F, 0F, 0F);
    GlStateManager.translate(-0.5F, -0.5F, -0.5F);
    setLightmapDisabled(true);
    GlStateManager.disableLighting();
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    GlStateManager.depthMask(true);
    GlStateManager.enableAlpha();
    BarrelModel model = barrel.getLook().getModel();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder buffer = tessellator.getBuffer();
    if (mouseOver || YabbaClientConfig.general.always_display_data.get(barrel.alwaysDisplayData.getBoolean())) {
        boolean isCreative = barrel.getTier().creative();
        float textDistance = model.textDistance;
        boolean infinite = isCreative || barrel.getTier().infiniteCapacity();
        if (hasIcon) {
            if (!infinite && !isSneaking && YabbaClientConfig.general.display_bar.get(barrel.displayBar.getBoolean())) {
                GlStateManager.pushMatrix();
                GlStateManager.disableTexture2D();
                buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
                double b = 0.02D;
                double b2 = b * 2D;
                double bx = 0.0625D;
                double by = 0.0625D;
                double bw = 1D - bx * 2D;
                double bh = 0.15D;
                double filled = MathHelper.clamp(getFilled(barrel), 0D, 1D);
                Color4I colBorder = YabbaClientConfig.bar_color.getBorderColor();
                Color4I colFree = YabbaClientConfig.bar_color.getFreeColor();
                Color4I colFilled = YabbaClientConfig.bar_color.getFilledColor();
                rect(buffer, bx, by, textDistance, b, bh, colBorder, alpha);
                rect(buffer, 1D - b - bx, by, textDistance, b, bh, colBorder, alpha);
                rect(buffer, bx + b, by, textDistance, bw - b2, b, colBorder, alpha);
                rect(buffer, bx + b, by + bh - b, textDistance, bw - b2, b, colBorder, alpha);
                rect(buffer, bx + b, by + b, textDistance, (bw - b2) * filled, bh - b2, colFree, alpha);
                rect(buffer, bx + b + (bw - b2) * filled, by + b, textDistance, (bw - b2) * (1D - filled), bh - b2, colFilled, alpha);
                tessellator.draw();
                GlStateManager.enableTexture2D();
                GlStateManager.popMatrix();
            } else {
                GlStateManager.pushMatrix();
                GlStateManager.translate(0.5F, 0.075F, textDistance);
                String s1 = barrel.getItemDisplayCount(isSneaking, isCreative, infinite);
                int sw = getFontRenderer().getStringWidth(s1);
                float f = 1F / (float) Math.max((sw + 10), 64);
                GlStateManager.scale(f, f, 1F);
                getFontRenderer().drawString(s1, -sw / 2, 0, 0xFFFFFFFF);
                GlStateManager.popMatrix();
            }
            GlStateManager.pushMatrix();
            GlStateManager.translate(0.5F, 0.80F, textDistance);
            boolean flag = getFontRenderer().getUnicodeFlag();
            getFontRenderer().setUnicodeFlag(true);
            String s2 = barrel.getItemDisplayName();
            int sw1 = getFontRenderer().getStringWidth(s2);
            float f1 = 1F / (float) Math.max((sw1 + 10), 64);
            GlStateManager.scale(f1, f1, 1F);
            getFontRenderer().drawString(s2, -sw1 / 2, 0, 0xFFFFFFFF);
            getFontRenderer().setUnicodeFlag(flag);
            GlStateManager.popMatrix();
        }
    }
    setLightmapDisabled(false);
    if (hasIcon) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(0.5F, 0.5F, model.iconDistance);
        ClientUtils.MC.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        ClientUtils.MC.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false);
        GlStateManager.enableRescaleNormal();
        GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F);
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
        GlStateManager.color(1F, 1F, 1F, 1F);
        renderIcon(barrel);
        GlStateManager.disableRescaleNormal();
        GlStateManager.disableLighting();
        ClientUtils.MC.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        ClientUtils.MC.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap();
        GlStateManager.popMatrix();
    }
    GlStateManager.enableLighting();
    GlStateManager.color(1F, 1F, 1F, 1F);
    GlStateManager.popMatrix();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) CachedVertexData(com.feed_the_beast.ftblib.lib.client.CachedVertexData) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) RayTraceResult(net.minecraft.util.math.RayTraceResult) Color4I(com.feed_the_beast.ftblib.lib.icon.Color4I)

Aggregations

Color4I (com.feed_the_beast.ftblib.lib.icon.Color4I)2 CachedVertexData (com.feed_the_beast.ftblib.lib.client.CachedVertexData)1 TextureSet (com.feed_the_beast.ftblib.lib.util.misc.TextureSet)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 BarrelSkin (com.latmod.yabba.api.BarrelSkin)1 YabbaSkinsEvent (com.latmod.yabba.api.YabbaSkinsEvent)1 BlockItemBarrel (com.latmod.yabba.block.BlockItemBarrel)1 FileNotFoundException (java.io.FileNotFoundException)1 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 IResource (net.minecraft.client.resources.IResource)1 IResourceManager (net.minecraft.client.resources.IResourceManager)1 ItemStack (net.minecraft.item.ItemStack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Fluid (net.minecraftforge.fluids.Fluid)1 FluidStack (net.minecraftforge.fluids.FluidStack)1