Java Code Examples for net.minecraft.potion.Potion#getPotionDurationString()

The following examples show how to use net.minecraft.potion.Potion#getPotionDurationString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PotionEffectsComponent.java    From seppuku with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
    super.render(mouseX, mouseY, partialTicks);

    final List<PotionEffect> effects =
            new ArrayList<>(Minecraft.getMinecraft().player.getActivePotionEffects());

    final Comparator<PotionEffect> comparator = (first, second) -> {
        final String firstEffect = PotionUtil.getFriendlyPotionName(first) + " " + ChatFormatting.GRAY + Potion.getPotionDurationString(first, 1.0F);
        final String secondEffect = PotionUtil.getFriendlyPotionName(second) + " " + ChatFormatting.GRAY + Potion.getPotionDurationString(second, 1.0F);
        final float dif = Minecraft.getMinecraft().fontRenderer.getStringWidth(secondEffect) - Minecraft.getMinecraft().fontRenderer.getStringWidth(firstEffect);
        return dif != 0 ? (int) dif : secondEffect.compareTo(firstEffect);
    };

    effects.sort(comparator);

    float xOffset = 0;
    float yOffset = 0;
    float maxWidth = 0;

    for (PotionEffect potionEffect : effects) {
        if (potionEffect != null) {
            final String effect = PotionUtil.getFriendlyPotionName(potionEffect) + " " + ChatFormatting.GRAY + Potion.getPotionDurationString(potionEffect, 1.0F);

            final float width = Minecraft.getMinecraft().fontRenderer.getStringWidth(effect);

            if (width >= maxWidth) {
                maxWidth = width;
            }

            if (this.getAnchorPoint() != null) {
                switch (this.getAnchorPoint().getPoint()) {
                    case TOP_CENTER:
                        xOffset = (this.getW() - Minecraft.getMinecraft().fontRenderer.getStringWidth(effect)) / 2;
                        break;
                    case TOP_LEFT:
                    case BOTTOM_LEFT:
                        xOffset = 0;
                        break;
                    case TOP_RIGHT:
                    case BOTTOM_RIGHT:
                        xOffset = this.getW() - Minecraft.getMinecraft().fontRenderer.getStringWidth(effect);
                        break;
                }
            }

            if (this.getAnchorPoint() != null) {
                switch (this.getAnchorPoint().getPoint()) {
                    case TOP_CENTER:
                    case TOP_LEFT:
                    case TOP_RIGHT:
                        Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(effect, this.getX() + xOffset, this.getY() + yOffset, potionEffect.getPotion().getLiquidColor());
                        yOffset += (Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT + 1);
                        break;
                    case BOTTOM_LEFT:
                    case BOTTOM_RIGHT:
                        Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(effect, this.getX() + xOffset, this.getY() + (this.getH() - Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT) + yOffset, potionEffect.getPotion().getLiquidColor());
                        yOffset -= (Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT + 1);
                        break;
                }
            } else {
                Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(effect, this.getX() + xOffset, this.getY() + yOffset, potionEffect.getPotion().getLiquidColor());
                yOffset += (Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT + 1);
            }
        }
    }

    this.setW(maxWidth);
    this.setH(Math.abs(yOffset));
}
 
Example 2
Source File: GuiHandyBag.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void drawActivePotionEffects()
{
    int x = this.guiLeft - 124;
    int y = this.guiTop;

    Collection<PotionEffect> collection = this.mc.player.getActivePotionEffects();

    if (collection.isEmpty() == false)
    {
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.disableLighting();
        int entryHeight = 33;

        if (collection.size() > 5)
        {
            entryHeight = 132 / (collection.size() - 1);
        }

        for (PotionEffect potioneffect : Ordering.natural().sortedCopy(collection))
        {
            Potion potion = potioneffect.getPotion();

            if (potion.shouldRender(potioneffect) == false)
            {
                continue;
            }

            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
            this.mc.getTextureManager().bindTexture(INVENTORY_BACKGROUND);
            this.drawTexturedModalRect(x, y, 0, 166, 140, 32);

            if (potion.hasStatusIcon())
            {
                int i1 = potion.getStatusIconIndex();
                this.drawTexturedModalRect(x + 6, y + 7, 0 + i1 % 8 * 18, 198 + i1 / 8 * 18, 18, 18);
            }

            potion.renderInventoryEffect(potioneffect, this, x, y, this.zLevel);

            if (potion.shouldRenderInvText(potioneffect) == false)
            {
                y += entryHeight;
                continue;
            }

            String s1 = I18n.format(potion.getName());
            int amp = potioneffect.getAmplifier();

            if (amp >= 1 && amp <= 3)
            {
                s1 = s1 + " " + I18n.format("enchantment.level." + (amp + 1));
            }

            this.fontRenderer.drawStringWithShadow(s1, (float)(x + 10 + 18), (float)(y + 6), 16777215);
            String s = Potion.getPotionDurationString(potioneffect, 1.0F);
            this.fontRenderer.drawStringWithShadow(s, (float)(x + 10 + 18), (float)(y + 6 + 10), 8355711);
            y += entryHeight;
        }
    }
}