| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import java.util.Collection;
|
| 4 | import net.minecraft.client.gui.inventory.GuiContainer;
|
| 5 | import net.minecraft.client.resources.I18n;
|
| 6 | import net.minecraft.inventory.Container;
|
| 7 | import net.minecraft.potion.Potion;
|
| 8 | import net.minecraft.potion.PotionEffect;
|
| 9 |
|
| 10 | public abstract class InventoryEffectRenderer extends GuiContainer
|
| 11 | {
|
| 12 | /** True if there is some potion effect to display */
|
| 13 | private boolean hasActivePotionEffects;
|
| 14 |
|
| 15 | public InventoryEffectRenderer(Container inventorySlotsIn)
|
| 16 | {
|
| 17 | super(inventorySlotsIn);
|
| 18 | }
|
| 19 |
|
| 20 | /**
|
| 21 | * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
| 22 | * window resizes, the buttonList is cleared beforehand.
|
| 23 | */
|
| 24 | public void initGui()
|
| 25 | {
|
| 26 | super.initGui();
|
| 27 | this.updateActivePotionEffects();
|
| 28 | }
|
| 29 |
|
| 30 | protected void updateActivePotionEffects()
|
| 31 | {
|
| 32 | if (!this.mc.thePlayer.getActivePotionEffects().isEmpty())
|
| 33 | {
|
| 34 | this.guiLeft = 160 + (this.width - this.xSize - 200) / 2;
|
| 35 | this.hasActivePotionEffects = true;
|
| 36 | }
|
| 37 | else
|
| 38 | {
|
| 39 | this.guiLeft = (this.width - this.xSize) / 2;
|
| 40 | this.hasActivePotionEffects = false;
|
| 41 | }
|
| 42 | }
|
| 43 |
|
| 44 | /**
|
| 45 | * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
|
| 46 | */
|
| 47 | public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
| 48 | {
|
| 49 | super.drawScreen(mouseX, mouseY, partialTicks);
|
| 50 |
|
| 51 | if (this.hasActivePotionEffects)
|
| 52 | {
|
| 53 | this.drawActivePotionEffects();
|
| 54 | }
|
| 55 | }
|
| 56 |
|
| 57 | /**
|
| 58 | * Display the potion effects list
|
| 59 | */
|
| 60 | private void drawActivePotionEffects()
|
| 61 | {
|
| 62 | int i = this.guiLeft - 124;
|
| 63 | int j = this.guiTop;
|
| 64 | int k = 166;
|
| 65 | Collection<PotionEffect> collection = this.mc.thePlayer.getActivePotionEffects();
|
| 66 |
|
| 67 | if (!collection.isEmpty())
|
| 68 | {
|
| 69 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 70 | GlStateManager.disableLighting();
|
| 71 | int l = 33;
|
| 72 |
|
| 73 | if (collection.size() > 5)
|
| 74 | {
|
| 75 | l = 132 / (collection.size() - 1);
|
| 76 | }
|
| 77 |
|
| 78 | for (PotionEffect potioneffect : this.mc.thePlayer.getActivePotionEffects())
|
| 79 | {
|
| 80 | Potion potion = Potion.potionTypes[potioneffect.getPotionID()];
|
| 81 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 82 | this.mc.getTextureManager().bindTexture(inventoryBackground);
|
| 83 | this.drawTexturedModalRect(i, j, 0, 166, 140, 32);
|
| 84 |
|
| 85 | if (potion.hasStatusIcon())
|
| 86 | {
|
| 87 | int i1 = potion.getStatusIconIndex();
|
| 88 | this.drawTexturedModalRect(i + 6, j + 7, 0 + i1 % 8 * 18, 198 + i1 / 8 * 18, 18, 18);
|
| 89 | }
|
| 90 |
|
| 91 | String s1 = I18n.format(potion.getName(), new Object[0]);
|
| 92 |
|
| 93 | if (potioneffect.getAmplifier() == 1)
|
| 94 | {
|
| 95 | s1 = s1 + " " + I18n.format("enchantment.level.2", new Object[0]);
|
| 96 | }
|
| 97 | else if (potioneffect.getAmplifier() == 2)
|
| 98 | {
|
| 99 | s1 = s1 + " " + I18n.format("enchantment.level.3", new Object[0]);
|
| 100 | }
|
| 101 | else if (potioneffect.getAmplifier() == 3)
|
| 102 | {
|
| 103 | s1 = s1 + " " + I18n.format("enchantment.level.4", new Object[0]);
|
| 104 | }
|
| 105 |
|
| 106 | this.fontRendererObj.drawStringWithShadow(s1, (float)(i + 10 + 18), (float)(j + 6), 16777215);
|
| 107 | String s = Potion.getDurationString(potioneffect);
|
| 108 | this.fontRendererObj.drawStringWithShadow(s, (float)(i + 10 + 18), (float)(j + 6 + 10), 8355711);
|
| 109 | j += l;
|
| 110 | }
|
| 111 | }
|
| 112 | }
|
| 113 | }
|
| 114 |
|