Sort out some issues with the new window

This commit is contained in:
Sollace 2018-06-08 22:11:14 +02:00
parent 46199208ce
commit 9ad00347a9
5 changed files with 57 additions and 9 deletions

View file

@ -0,0 +1,7 @@
package com.voxelmodpack.hdskins;
import net.minecraft.client.resources.DefaultResourcePack;
public interface IMinecraft {
DefaultResourcePack getDefaultResourcePack();
}

View file

@ -1,6 +1,7 @@
package com.voxelmodpack.hdskins.gui; package com.voxelmodpack.hdskins.gui;
import java.awt.Canvas; import java.awt.Canvas;
import java.awt.Color;
import java.awt.Frame; import java.awt.Frame;
import java.awt.dnd.DropTarget; import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetListener; import java.awt.dnd.DropTargetListener;
@ -21,9 +22,11 @@ import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode; import org.lwjgl.opengl.DisplayMode;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.voxelmodpack.hdskins.IMinecraft;
import com.voxelmodpack.hdskins.Later; import com.voxelmodpack.hdskins.Later;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.DefaultResourcePack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
public class GLWindow implements Closeable { public class GLWindow implements Closeable {
@ -64,6 +67,7 @@ public class GLWindow implements Closeable {
frame.setResizable(Display.isResizable()); frame.setResizable(Display.isResizable());
frame.setLocation(x, y); frame.setLocation(x, y);
frame.setSize(w, h); frame.setSize(w, h);
frame.setBackground(Color.BLACK);
frame.getContentPane().setLayout(null); frame.getContentPane().setLayout(null);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() { frame.addWindowListener(new WindowAdapter() {
@ -118,9 +122,11 @@ public class GLWindow implements Closeable {
private final void setIcons(JFrame frame) { private final void setIcons(JFrame frame) {
try { try {
DefaultResourcePack pack = ((IMinecraft)mc).getDefaultResourcePack();
frame.setIconImages(Lists.newArrayList( frame.setIconImages(Lists.newArrayList(
ImageIO.read(mc.getResourceManager().getResource(new ResourceLocation("icons/icon_16x16.png")).getInputStream()), ImageIO.read(pack.getInputStreamAssets(new ResourceLocation("icons/icon_16x16.png"))),
ImageIO.read(mc.getResourceManager().getResource(new ResourceLocation("icons/icon_32x32.png")).getInputStream()) ImageIO.read(pack.getInputStreamAssets(new ResourceLocation("icons/icon_32x32.png")))
)); ));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -10,7 +10,6 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mumfrey.liteloader.util.log.LiteLoaderLogger; import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
import com.voxelmodpack.hdskins.HDSkinManager; import com.voxelmodpack.hdskins.HDSkinManager;
import com.voxelmodpack.hdskins.Later;
import com.voxelmodpack.hdskins.skins.SkinUploadResponse; import com.voxelmodpack.hdskins.skins.SkinUploadResponse;
import com.voxelmodpack.hdskins.upload.awt.ThreadOpenFilePNG; import com.voxelmodpack.hdskins.upload.awt.ThreadOpenFilePNG;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;

View file

@ -1,29 +1,66 @@
package com.voxelmodpack.hdskins.mixin; package com.voxelmodpack.hdskins.mixin;
import java.io.IOException;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.voxelmodpack.hdskins.IMinecraft;
import com.voxelmodpack.hdskins.gui.GLWindow; import com.voxelmodpack.hdskins.gui.GLWindow;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.DefaultResourcePack;
import net.minecraft.crash.CrashReport; import net.minecraft.crash.CrashReport;
@Mixin(Minecraft.class) @Mixin(Minecraft.class)
public class MixinMinecraft { public abstract class MixinMinecraft implements IMinecraft {
@Accessor("mcDefaultResourcePack")
public abstract DefaultResourcePack getDefaultResourcePack();
//
// Due to how JFrame works the only way to know for sure when the game hash crashed
// is to have it call us explicitly.
//
// ShutdownListener.onShutDown is unlikely to be called as it depends on the
// Minecraft.running flag to be unset, which is unlikely to happen if the game crashes.
//
// Runtime.current().addShutdownHook won't be called it waits for all
// non-daemon threads to end, one of which is depending on the JFrame being
// disposed to tell it when to end.
//
// If you're thinking 'hey, what about Minecraft.isCrashed?'
// No, that's only set if the internal MinecraftServer crashes.
// Otherwise the value is always false and threads spinning to check any such value
// will only serve to hang up the VM.
//
// @forge
// Because the minecraft forge team are stupid, they call displayCrashReport on startup
// regardless of whether the game has crashed or not. Thus the window may flicker an additional
// time as the native window is forced back to the front.
// This is a minor issue as the window will simply reassert itself when it's next referenced
// (i.e. The skins GUI uses it for file drops) so I have no intention of fixing this.
//
// This is their problem.
//
//public void displayCrashReport(CrashReport crashReportIn) //public void displayCrashReport(CrashReport crashReportIn)
@Inject(method = "displayCrashReport(Lnet/minecraft/crash/CrashReport;)V", at = @At("HEAD")) @Inject(method = "displayCrashReport(Lnet/minecraft/crash/CrashReport;)V", at = @At("HEAD"))
private void onGameCrash(CrashReport report, CallbackInfo info) { private void onGameCrash(CrashReport report, CallbackInfo info) {
GLWindow.dispose(); GLWindow.dispose();
} }
@Inject(method = "init()V", at = @At("RETURN")) //
private void onInit(CallbackInfo info) throws LWJGLException, IOException { // To avoid flickering as much as possible, create the window as close to Minecraft
// creating its native window as possible.
//
// Litemods are initialised after this, init complete is called later, and forge mods
// are called EVEN LATER.
//
//private void createDisplay() throws LWJGLException
@Inject(method = "createDisplay()V", at = @At("RETURN"))
private void onCreateDisplay(CallbackInfo info) throws LWJGLException {
GLWindow.current(); GLWindow.current();
} }
} }

View file

@ -79,5 +79,4 @@ public class LiteModHDSkinsMod implements HDSkinsMod {
} }
} }
} }
} }