diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/IMinecraft.java b/src/hdskins/java/com/voxelmodpack/hdskins/IMinecraft.java new file mode 100644 index 00000000..d578b9ac --- /dev/null +++ b/src/hdskins/java/com/voxelmodpack/hdskins/IMinecraft.java @@ -0,0 +1,7 @@ +package com.voxelmodpack.hdskins; + +import net.minecraft.client.resources.DefaultResourcePack; + +public interface IMinecraft { + DefaultResourcePack getDefaultResourcePack(); +} diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java index 25059878..464e8229 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GLWindow.java @@ -1,6 +1,7 @@ package com.voxelmodpack.hdskins.gui; import java.awt.Canvas; +import java.awt.Color; import java.awt.Frame; import java.awt.dnd.DropTarget; import java.awt.dnd.DropTargetListener; @@ -21,9 +22,11 @@ import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; import com.google.common.collect.Lists; +import com.voxelmodpack.hdskins.IMinecraft; import com.voxelmodpack.hdskins.Later; import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.DefaultResourcePack; import net.minecraft.util.ResourceLocation; public class GLWindow implements Closeable { @@ -64,6 +67,7 @@ public class GLWindow implements Closeable { frame.setResizable(Display.isResizable()); frame.setLocation(x, y); frame.setSize(w, h); + frame.setBackground(Color.BLACK); frame.getContentPane().setLayout(null); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @@ -118,9 +122,11 @@ public class GLWindow implements Closeable { private final void setIcons(JFrame frame) { try { + DefaultResourcePack pack = ((IMinecraft)mc).getDefaultResourcePack(); + frame.setIconImages(Lists.newArrayList( - ImageIO.read(mc.getResourceManager().getResource(new ResourceLocation("icons/icon_16x16.png")).getInputStream()), - ImageIO.read(mc.getResourceManager().getResource(new ResourceLocation("icons/icon_32x32.png")).getInputStream()) + ImageIO.read(pack.getInputStreamAssets(new ResourceLocation("icons/icon_16x16.png"))), + ImageIO.read(pack.getInputStreamAssets(new ResourceLocation("icons/icon_32x32.png"))) )); } catch (IOException e) { e.printStackTrace(); diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java index 9ab9853a..bbaba543 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/gui/GuiSkins.java @@ -10,7 +10,6 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTexture; import com.mumfrey.liteloader.util.log.LiteLoaderLogger; import com.voxelmodpack.hdskins.HDSkinManager; -import com.voxelmodpack.hdskins.Later; import com.voxelmodpack.hdskins.skins.SkinUploadResponse; import com.voxelmodpack.hdskins.upload.awt.ThreadOpenFilePNG; import net.minecraft.client.Minecraft; diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinMinecraft.java b/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinMinecraft.java index 8613f940..b35ad511 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinMinecraft.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinMinecraft.java @@ -1,29 +1,66 @@ package com.voxelmodpack.hdskins.mixin; -import java.io.IOException; - import org.lwjgl.LWJGLException; 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.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import com.voxelmodpack.hdskins.IMinecraft; import com.voxelmodpack.hdskins.gui.GLWindow; import net.minecraft.client.Minecraft; +import net.minecraft.client.resources.DefaultResourcePack; import net.minecraft.crash.CrashReport; @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) @Inject(method = "displayCrashReport(Lnet/minecraft/crash/CrashReport;)V", at = @At("HEAD")) private void onGameCrash(CrashReport report, CallbackInfo info) { 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(); } } diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/mod/LiteModHDSkinsMod.java b/src/hdskins/java/com/voxelmodpack/hdskins/mod/LiteModHDSkinsMod.java index d9a675b1..f8ad9f86 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/mod/LiteModHDSkinsMod.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/mod/LiteModHDSkinsMod.java @@ -79,5 +79,4 @@ public class LiteModHDSkinsMod implements HDSkinsMod { } } } - }