Guest User

OverlaySanity.java

a guest
Mar 20th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. package com.ignatio.wilsonsanity;
  2.  
  3. import java.text.DecimalFormat;
  4.  
  5. import cpw.mods.fml.common.eventhandler.EventPriority;
  6. import cpw.mods.fml.common.eventhandler.SubscribeEvent;
  7. import net.minecraft.client.Minecraft;
  8. import net.minecraftforge.client.event.RenderGameOverlayEvent;
  9. import net.minecraftforge.common.MinecraftForge;
  10.  
  11. public class OverlaySanity {
  12.  
  13. public static class GUIRenderEventClass {
  14.  
  15. DecimalFormat df = new DecimalFormat("#.##"); //Format Sanity to a nice string with 2 decimals
  16.  
  17. @SubscribeEvent(priority = EventPriority.NORMAL)
  18. public void eventHandler(RenderGameOverlayEvent.Text event) { // on the rendergameoverlaytext event
  19.  
  20. ExtendedPlayer props = ExtendedPlayer.get(Minecraft.getMinecraft().thePlayer);
  21. int posX = (event.resolution.getScaledWidth()) / 2; //get the center of the screen coords
  22. int posY = (event.resolution.getScaledHeight()) / 2;
  23.  
  24. if (true) {
  25. //Draw the Sanity tag and print the variable with the decimal formatted to 2 places
  26. Minecraft.getMinecraft().fontRenderer.drawString("Sanity: " + df.format(props.getCurrentSanity()), posX + (posX / 2), posY + (posY / 3), 0xffffff);
  27. }
  28. }
  29. }
  30.  
  31.  
  32.  
  33. public OverlaySanity() {
  34. }
  35.  
  36. public Object instance;
  37.  
  38. public void load() {
  39. MinecraftForge.EVENT_BUS.register(new GUIRenderEventClass());
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment