Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PotionHud implements IHud
- {
- private boolean iconsOnly;
- private HudBox box;
- protected static final ResourceLocation icons = new ResourceLocation("textures/gui/container/inventory.png");
- public PotionHud()
- {
- this.box = new HudBox(0, 0, 100, 25);
- iconsOnly = false;
- }
- @Override
- public void draw()
- {
- // Check whether the inventory is opened, if so, don't render potions
- if (!(RenderHelper.getMC().currentScreen instanceof InventoryEffectRenderer))
- {
- int x = 10;
- int y = 10;
- int yOffGlob = 0;
- // Get all active potion effects
- LinkedList<?> activePotions = new LinkedList<Object>(RenderHelper.getMC().thePlayer.getActivePotionEffects());
- Collections.sort(activePotions, new Comparator<Object>()
- {
- @Override
- public int compare(Object o, Object o2)
- {
- return ((PotionEffect) o2).getDuration() - ((PotionEffect) o).getDuration();
- }
- });
- // If there are any active effects, render them into the screen
- if (!activePotions.isEmpty())
- {
- GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
- GL11.glDisable(GL11.GL_LIGHTING);
- int yOff = 28;
- if (activePotions.size() > 5)
- {
- yOff = 132 / (activePotions.size() - 1);
- }
- if (iconsOnly)
- {
- box.setPosition(10, 10);
- box.setSize(120, 25);
- box.draw();
- }
- for (int i = 0; i < activePotions.size(); i++)
- {
- PotionEffect effect = (PotionEffect) activePotions.toArray()[i];
- Potion potion = Potion.potionTypes[effect.getPotionID()];
- GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
- float alpha = 1F;
- // Slowly fade out the potion
- if (effect.getDuration() <= 20)
- {
- GL11.glEnable(GL11.GL_BLEND);
- GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- alpha = 1F / (21 - effect.getDuration());
- GL11.glColor4f(1, 1, 1, alpha);
- }
- if (!iconsOnly)
- {
- if (RenderHelper.getMC().gameSettings.guiScale == 1 && (box.getWidth() == 100 || box.getWidth() == 120))
- {
- box.setSize(140, 25);
- yOffGlob = 1;
- } else if (box.getWidth() == 140 || box.getWidth() == 120)
- {
- box.setSize(100, 25);
- yOffGlob = 0;
- }
- box.setPosition(x, y + yOff * i);
- box.draw();
- if (potion.hasStatusIcon())
- {
- int icon = potion.getStatusIconIndex();
- RenderHelper.drawRectangle(icons, x + 5, y + i * yOff + 4, icon % 8 * 18, 198 + icon / 8 * 18, 18, 18, 1);
- }
- String name = I18n.format(potion.getName());
- if (effect.getAmplifier() == 1)
- {
- name = name + " II";
- } else if (effect.getAmplifier() == 2)
- {
- name = name + " III";
- } else if (effect.getAmplifier() == 3)
- {
- name = name + " IV";
- }
- int alphaColorName = ((int) Math.floor(255 * alpha)) << 24 | 0xFFFFFF;
- int alphaColorDuration = ((int) Math.floor(255 * alpha)) << 24 | 0xCCCCCC;
- RenderHelper.drawSmallString(name, x + 7 + 18, y + i * yOff + 4, alphaColorName, true, 1);
- String duration = Potion.getDurationString(effect);
- RenderHelper.drawSmallString(duration, x + 7 + 18, y + i * yOff + 4 + 8 + yOffGlob, alphaColorDuration, true, 1);
- } else
- {
- if (potion.hasStatusIcon())
- {
- int icon = potion.getStatusIconIndex();
- RenderHelper.drawRectangle(icons, 15 + i * 19, 14, icon % 8 * 18, 198 + icon / 8 * 18, 18, 18, 1);
- }
- }
- }
- }
- }
- }
- public void toggleMode()
- {
- this.iconsOnly = !iconsOnly;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement