Advertisement
Guest User

Untitled

a guest
May 30th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.92 KB | None | 0 0
  1. /**
  2.  *  the Real-Time Clock mod adds the system time to the Minecraft HUD.
  3.  *  Copyright (C) 2015  Xilef11
  4.  *  Licensed under the GNU General Public License version 3
  5.  *
  6.  *  File created by Xilef11 on 2015-04-19
  7.  */
  8. package xilef11.mc.realtimeclock.client.gui;
  9.  
  10. import java.util.Calendar;
  11. import java.util.Locale;
  12. import java.util.TimeZone;
  13.  
  14. import net.minecraft.client.Minecraft;
  15.  
  16. import org.lwjgl.opengl.GL11;
  17.  
  18. import xilef11.mc.realtimeclock.handler.ConfigurationHandler;
  19. import xilef11.mc.realtimeclock.utilities.RenderingPosHelper;
  20.  
  21. /**
  22.  * @author Xilef11
  23.  *
  24.  */
  25. public class Clock {
  26.     private static boolean enabled=true;
  27.    
  28.     public static void toggleEnabled(){enabled=!enabled;}
  29.    
  30.     public static boolean isEnabled(){return enabled;}
  31.    
  32.     /** Do we want to show the clock
  33.      * @return true to show the clock
  34.      */
  35.     public static boolean doesRender(Minecraft mc) {
  36.         //when to render
  37.         //render only if currently playing
  38.         if (mc.theWorld ==null ) return false;
  39.         //if(ConfigurationHandler.showPause && mc.currentScreen instanceof net.minecraft.client.gui.GuiIngameMenu)return true;
  40.         if(!enabled)return false;
  41.         return true;
  42.     }
  43.     //debugging
  44.     //private static int numTicks=0;
  45.     /**Draw the Time
  46.      *
  47.      */
  48.     public static void draw(Minecraft mc) {
  49.         //get the correct position and scale
  50.         int xPos=RenderingPosHelper.getXPosByScreenSize(mc, ConfigurationHandler.clockPosX);
  51.         int yPos=RenderingPosHelper.getYPosByScreenSize(mc, ConfigurationHandler.clockPosY);
  52.         float scale=ConfigurationHandler.clockScale/100;
  53.         //draw the time
  54.         GL11.glPushMatrix();
  55.         GL11.glScalef(scale, scale, 1);
  56.         mc.fontRenderer.drawString(getTimeString(mc), Math.round(xPos/scale), Math.round(yPos/scale), ConfigurationHandler.color,drawShadow(mc));
  57.         GL11.glPopMatrix();
  58.     }
  59.     /** returns a String with the current time according to config options
  60.      * @Param mc the instance of Minecraft, required to get the localization
  61.      * @return the current time as a String
  62.      */
  63.     private static String getTimeString(Minecraft mc){
  64.         // get the time
  65.         Calendar time = Calendar.getInstance(TimeZone.getDefault(), Locale.forLanguageTag(mc.gameSettings.language));
  66.         //get the hour depending on the time format to use
  67.         int hour;
  68.         if(ConfigurationHandler.use24hours){
  69.             hour=time.get(time.HOUR_OF_DAY);
  70.         }else{
  71.             hour=time.get(time.HOUR);
  72.         }
  73.         int minute = time.get(time.MINUTE);
  74.         //make sure the minutes have 2 digits
  75.         String minuteS= minute<10? "0"+minute : String.valueOf(minute);
  76.         return hour+" : "+minuteS;
  77.     }
  78.     /** should the string shadow be rendered? depends on the config and current GUI
  79.      *
  80.      * @param mc
  81.      * @return
  82.      */
  83.     private static boolean drawShadow(Minecraft mc){
  84.         //don't draw the shadow if the config says we shouldn't
  85.         if(!ConfigurationHandler.drawShadow) return false;
  86.         //don't draw the shadow in menus to avoid bugs (i.e achievements gui...)
  87.         if(mc.currentScreen != null) return false;
  88.         return true;
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement