AWT is forbidden on 1.13+ (this includes BufferedImage)

Instead use NativeImage on 1.13+ via newly introduced Image class.
See Image docs for details.

Also fixes an issue with thumbnail taking on 1.13+: The original
ScreenshotHelper method is now async, luckily there's a sync
variant and as a bonus it directly returns a NativeImage so we can
skip having to read the screenshot from disk.
This commit is contained in:
Jonas Herzig
2019-06-30 11:11:02 +02:00
parent 732e1ab32e
commit 7241036e61
14 changed files with 132 additions and 134 deletions

View File

@@ -21,6 +21,7 @@ import de.johni0702.minecraft.gui.popup.GuiInfoPopup;
import de.johni0702.minecraft.gui.utils.Colors;
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
import de.johni0702.minecraft.gui.versions.Image;
import de.johni0702.minecraft.gui.versions.MCVer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.crash.CrashReport;
@@ -48,11 +49,9 @@ import net.minecraft.client.util.DefaultSkinHelper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManagerFactory;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -89,14 +88,14 @@ public class Utils {
//#endif
}
public static final BufferedImage DEFAULT_THUMBNAIL;
public static final Image DEFAULT_THUMBNAIL;
static {
BufferedImage thumbnail;
Image thumbnail;
try {
thumbnail = ImageIO.read(getResourceAsStream("/default_thumb.jpg"));
thumbnail = Image.read(getResourceAsStream("/default_thumb.jpg"));
} catch (Exception e) {
thumbnail = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);
thumbnail = new Image(1, 1);
e.printStackTrace();
}
DEFAULT_THUMBNAIL = thumbnail;

View File

@@ -19,6 +19,8 @@ import net.minecraft.util.SystemUtil;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.chunk.WorldChunk;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
//#if MC>=11400
import com.replaymod.core.mixin.AbstractButtonWidgetAccessor;
@@ -90,6 +92,7 @@ import net.minecraft.SharedConstants;
//#endif
import java.io.File;
import java.net.URI;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
@@ -99,6 +102,8 @@ import java.util.function.Consumer;
* Abstraction over things that have changed between different MC versions.
*/
public class MCVer {
private static Logger LOGGER = LogManager.getLogger();
//#if MC<11400
//$$ public static IEventBus FORGE_BUS = MinecraftForge.EVENT_BUS;
//#if MC>=10809
@@ -578,6 +583,22 @@ public class MCVer {
//#endif
}
public static void openURL(URI url) {
//#if MC>=11300
//#if MC>=11400
SystemUtil.getOperatingSystem().open(url);
//#else
//$$ Util.getOSType().openURI(url);
//#endif
//#else
//$$ try {
//$$ Desktop.getDesktop().browse(url);
//$$ } catch (Throwable e) {
//$$ LOGGER.error("Failed to open URL: ", e);
//$$ }
//#endif
}
//#if MC>=11300
private static Boolean hasOptifine;
public static boolean hasOptifine() {