Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright(C) Thepattybeast 2015
- * */
- package net.minecraft.launchwrapper;
- import java.awt.Canvas;
- import java.awt.GraphicsEnvironment;
- import java.awt.Rectangle;
- import java.io.File;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URISyntaxException;
- import java.net.URL;
- import java.net.URLClassLoader;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- public class Launch {
- public static void main(String[] args) throws InterruptedException, IOException{
- System.setProperty("org.lwjgl.opengl.Window.undecorated", "true");//Activate borderless window
- URL[] cp = ((URLClassLoader)Launch.class.getClassLoader()).getURLs();//Get the classpath(-cp) the program was launched with
- String jarName = getJar().getName();
- //scan for the classpath entry that is this jar file and replace it with the classpatth entry of the actual realauncher
- for(int i = 0; i < cp.length; i++){
- System.out.println(cp[i].getPath() + " <-- " + jarName);
- if(cp[i].getPath().contains(jarName))
- System.out.println("OK");
- try {
- cp[i] = new URL("file:///"+cp[i].getPath().replace(jarName, "launchwrapper.jar"));
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- }
- final URLClassLoader loader = new URLClassLoader(cp, null);
- try{
- //the only way to get centered borderless is to remove the borders completely by attaching the LWJGL Display to a canvas
- JFrame MCWindow = new JFrame("MC Window");
- //Get the size of the default display
- //the LWJGL Display will always be at 0, 0 regardless JFrame position
- Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds();
- MCWindow.setSize(bounds.width, bounds.height);
- MCWindow.setUndecorated(true);
- MCWindow.setLocationRelativeTo(null);
- MCWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Canvas parent = new Canvas();
- MCWindow.add(parent);
- MCWindow.setVisible(true);
- Class<?> c = loader.loadClass("org.lwjgl.opengl.Display");//get an instance of the LWJGL display class
- c.getMethod("setParent", Canvas.class).invoke(null, parent);//LWJGL Display parent to our canvas
- } catch (Throwable e) {
- e.printStackTrace();
- JOptionPane.showMessageDialog(null, e.toString());
- }
- try {
- //load the main class
- loader.loadClass("net.minecraft.launchwrapper.Launch").getMethod("main", String[].class).invoke(null, (Object)args);
- } catch (Exception e) {
- e.printStackTrace();
- }
- loader.close();
- }
- /**@returns the path to the application jar file*/
- public static File getJar(){
- try {
- return new File(Launch.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
- } catch (URISyntaxException e) {
- e.printStackTrace();
- }
- System.err.println("Error locating jar file returning runtime directory.");
- return new File("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement