Guest User

Untitled

a guest
Mar 6th, 2017
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. public class SpyglassGui extends Gui {
  2.  
  3.   private final static ResourceLocation overlay = new ModelResourceLocation("glassworks:textures/gui/spyglass.png");
  4.  
  5.   private final static int OVERLAY_WIDTH = 256;
  6.   private final static int OVERLAY_HEIGHT = 256;
  7.  
  8.   private Minecraft mc;
  9.  
  10.   public SpyglassGui(Minecraft mc) {
  11.     this.mc = mc;
  12.   }
  13.  
  14.   public void renderOverlay(int screenWidth, int screenHeight) {  
  15.     ScaledResolution scaledresolution = new ScaledResolution(mc);
  16.     int width = scaledresolution.getScaledWidth();
  17.     int height = scaledresolution.getScaledHeight();
  18.    
  19.     float scalefact = (float)screenHeight/(float)OVERLAY_HEIGHT;
  20.  
  21.     int xPos = width/2 -(int)((scalefact*OVERLAY_WIDTH)/2);
  22.     int yPos = height/2 -OVERLAY_HEIGHT/2;
  23.    
  24.    
  25.     GL11.glPushMatrix();
  26.     mc.renderEngine.bindTexture(overlay);
  27.     GL11.glScalef(scalefact,scalefact, 1);
  28.  
  29.     this.drawTexturedModalRect(xPos, 0, 0, 0, 256, 256);
  30.    
  31.     this.drawRect(0, 0, xPos, screenHeight, 0);
  32.     this.drawRect((int) (xPos+scalefact*256), 0, screenWidth, screenHeight, 0);
  33.     GL11.glPopMatrix();
  34.   }
  35. }
  36.  
  37.  
  38.  
  39. Called in
  40.  
  41. public SpyglassHandler(SpyglassGui overlay) {
  42.           spyglassOverlay = overlay;
  43.     }
  44.  
  45.     private SpyglassGui spyglassOverlay;
  46. @SubscribeEvent
  47.     public void preRenderOverlay(RenderGameOverlayEvent.Pre event)
  48.     {
  49.         //condition code
  50.         spyglassOverlay.renderOverlay(event.getResolution().getScaledWidth(), event.getResolution().getScaledHeight());
  51.     }
  52.  
  53.  
  54. set in
  55. @EventHandler
  56.     public void init(FMLInitializationEvent event)
  57.     {
  58.         MinecraftForge.EVENT_BUS.register(new SpyglassHandler(new SpyglassGui(Minecraft.getMinecraft())));
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment