From 5abca8310bb7d44c092485c6ed51c0c04e02594d Mon Sep 17 00:00:00 2001 From: LAX1DUDE Date: Mon, 16 May 2022 21:09:23 -0700 Subject: [PATCH] made F+6 hide the coords, improved framebuffer swap system --- .../adapter/EaglerAdapterImpl2.java | 2 +- .../lax1dude/eaglercraft/ConfigConstants.java | 2 +- .../net/lax1dude/eaglercraft/EnumBrowser.java | 47 ++++++++++++++ .../java/net/minecraft/client/Minecraft.java | 13 +++- .../java/net/minecraft/src/GameSettings.java | 5 ++ .../java/net/minecraft/src/GuiIngame.java | 62 ++++++++++++------- .../adapter/EaglerAdapterImpl2.java | 52 +++++++++++++--- 7 files changed, 151 insertions(+), 32 deletions(-) create mode 100644 src/main/java/net/lax1dude/eaglercraft/EnumBrowser.java diff --git a/src/lwjgl/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java b/src/lwjgl/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java index e879661..324a5ac 100644 --- a/src/lwjgl/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java +++ b/src/lwjgl/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java @@ -1393,7 +1393,7 @@ public class EaglerAdapterImpl2 { } public static final String getUserAgent() { - return System.getProperty("os.name"); + return "Desktop/" + System.getProperty("os.name"); } public static final String getClipboard() { diff --git a/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java b/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java index f3ffe6c..27b9dcb 100644 --- a/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java +++ b/src/main/java/net/lax1dude/eaglercraft/ConfigConstants.java @@ -4,7 +4,7 @@ public class ConfigConstants { public static boolean profanity = false; - public static final String version = "22w19a"; + public static final String version = "22w20a"; public static final String mainMenuString = "eaglercraft " + version; public static final String forkMe = "https://github.com/LAX1DUDE/eaglercraft"; diff --git a/src/main/java/net/lax1dude/eaglercraft/EnumBrowser.java b/src/main/java/net/lax1dude/eaglercraft/EnumBrowser.java new file mode 100644 index 0000000..8b3ca5b --- /dev/null +++ b/src/main/java/net/lax1dude/eaglercraft/EnumBrowser.java @@ -0,0 +1,47 @@ +package net.lax1dude.eaglercraft; + +public enum EnumBrowser { + + DESKTOP("Desktop"), CHROME("Chrome"), EDGE("Edge"), IE("IE"), FIREFOX("Firefox"), SAFARI("Safari"), OPERA("Opera"), WEBKIT("WebKit"), GECKO("Gecko"), UNKNOWN("Unknown"); + + public final String name; + + private EnumBrowser(String string) { + this.name = string; + } + + private static EnumBrowser identifiedBrowser = null; + + public static EnumBrowser getBrowser() { + if(identifiedBrowser == null) { + String ua = " " + EaglerAdapter.getUserAgent().toLowerCase(); + if(ua.contains(" edg/")) { + identifiedBrowser = EDGE; + }else if(ua.contains(" opr/")) { + identifiedBrowser = OPERA; + }else if(ua.contains(" chrome/")) { + identifiedBrowser = CHROME; + }else if(ua.contains(" firefox/")) { + identifiedBrowser = FIREFOX; + }else if(ua.contains(" safari/")) { + identifiedBrowser = SAFARI; + }else if(ua.contains(" trident/") || ua.contains(" msie")) { + identifiedBrowser = IE; + }else if(ua.contains(" webkit/")) { + identifiedBrowser = WEBKIT; + }else if(ua.contains(" gecko/")) { + identifiedBrowser = GECKO; + }else if(ua.contains(" desktop/")) { + identifiedBrowser = DESKTOP; + }else { + identifiedBrowser = UNKNOWN; + } + } + return identifiedBrowser; + } + + public String toString() { + return name; + } + +} diff --git a/src/main/java/net/minecraft/client/Minecraft.java b/src/main/java/net/minecraft/client/Minecraft.java index 4f58dbf..aca9f49 100644 --- a/src/main/java/net/minecraft/client/Minecraft.java +++ b/src/main/java/net/minecraft/client/Minecraft.java @@ -157,6 +157,8 @@ public class Minecraft implements Runnable { int fpsCounter = 0; long prevFrameTime = -1L; + public int showHints = 140; + long secondTimer = 0l; private HashSet shownPlayerMessages = new HashSet(); @@ -1233,6 +1235,11 @@ public class Minecraft implements Runnable { this.gameSettings.thirdPersonView = 0; } } + + if (EaglerAdapter.getEventKey() == 7 && this.gameSettings.keyBindFunction.pressed) { + this.gameSettings.showCoordinates = !this.gameSettings.showCoordinates; + this.gameSettings.saveOptions(); + } if (EaglerAdapter.getEventKey() == 9 && this.gameSettings.keyBindFunction.pressed) { this.gameSettings.smoothCamera = !this.gameSettings.smoothCamera; @@ -1330,11 +1337,15 @@ public class Minecraft implements Runnable { if (this.theWorld != null) { if (this.thePlayer != null) { ++this.joinPlayerCounter; - + if (this.joinPlayerCounter == 30) { this.joinPlayerCounter = 0; this.theWorld.joinEntityInSurroundings(this.thePlayer); } + + if(this.showHints > 0) { + --this.showHints; + } } this.mcProfiler.endStartSection("gameRenderer"); diff --git a/src/main/java/net/minecraft/src/GameSettings.java b/src/main/java/net/minecraft/src/GameSettings.java index af2fa66..7c6c805 100644 --- a/src/main/java/net/minecraft/src/GameSettings.java +++ b/src/main/java/net/minecraft/src/GameSettings.java @@ -95,6 +95,8 @@ public class GameSettings { /** true if debug info should be displayed instead of version */ public boolean showDebugInfo; public boolean showDebugProfilerChart; + + public boolean showCoordinates; /** The lastServer string. */ public String lastServer; @@ -131,6 +133,7 @@ public class GameSettings { this.thirdPersonView = 0; this.showDebugInfo = false; this.showDebugProfilerChart = true; + this.showCoordinates = false; this.lastServer = ""; this.noclip = false; this.smoothCamera = false; @@ -496,6 +499,7 @@ public class GameSettings { if(yee.hasKey("chatScale")) this.chatScale = yee.getFloat("chatScale"); if(yee.hasKey("chatWidth")) this.chatWidth = yee.getFloat("chatWidth"); if(yee.hasKey("patchAnisotropic")) this.patchAnisotropic = yee.getBoolean("patchAnisotropic"); + if(yee.hasKey("showCoordinates")) this.showCoordinates = yee.getBoolean("showCoordinates"); for (int var4 = 0; var4 < this.keyBindings.length; ++var4) { if(yee.hasKey(keyBindings[var4].keyDescription)) this.keyBindings[var4].keyCode = yee.getInteger(keyBindings[var4].keyDescription); @@ -549,6 +553,7 @@ public class GameSettings { yee.setFloat("chatScale", this.chatScale); yee.setFloat("chatWidth", this.chatWidth); yee.setBoolean("patchAnisotropic", this.patchAnisotropic); + yee.setBoolean("showCoordinates", this.showCoordinates); for (int var4 = 0; var4 < this.keyBindings.length; ++var4) { yee.setInteger(keyBindings[var4].keyDescription, keyBindings[var4].keyCode); diff --git a/src/main/java/net/minecraft/src/GuiIngame.java b/src/main/java/net/minecraft/src/GuiIngame.java index 2a3b0a8..5a402f7 100644 --- a/src/main/java/net/minecraft/src/GuiIngame.java +++ b/src/main/java/net/minecraft/src/GuiIngame.java @@ -8,6 +8,7 @@ import net.minecraft.client.Minecraft; import net.lax1dude.eaglercraft.ConfigConstants; import net.lax1dude.eaglercraft.EaglerAdapter; import net.lax1dude.eaglercraft.EaglercraftRandom; +import net.lax1dude.eaglercraft.EnumBrowser; import net.lax1dude.eaglercraft.TextureLocation; import net.lax1dude.eaglercraft.adapter.Tessellator; import net.lax1dude.eaglercraft.glemu.EffectPipeline; @@ -397,17 +398,27 @@ public class GuiIngame extends Gui { var8.drawStringWithShadow(this.mc.getEntityDebug(), 2, 22, 16777215); var8.drawStringWithShadow(this.mc.debugInfoEntities(), 2, 32, 16777215); var8.drawStringWithShadow(this.mc.getWorldProviderName(), 2, 42, 16777215); - long var39; - long var37; - long var41; - var39 = EaglerAdapter.maxMemory(); - var37 = EaglerAdapter.totalMemory(); - var41 = EaglerAdapter.freeMemory(); - long var44 = var37 - var41; - String var45 = "Used memory: " + var44 * 100L / var39 + "% (" + var44 / 1024L / 1024L + "MB) of " + var39 / 1024L / 1024L + "MB"; - this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 2, 14737632); - var45 = "Allocated memory: " + var37 * 100L / var39 + "% (" + var37 / 1024L / 1024L + "MB)"; - this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 12, 14737632); + String var45; + int offset = 0; + if(EaglerAdapter._wisWebGL()) { + var45 = "Game is running in a browser (" + EnumBrowser.getBrowser().toString() + ")"; + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 2, 14737632); + offset = -10; + }else { + long var39; + long var37; + long var41; + var39 = EaglerAdapter.maxMemory(); + var37 = EaglerAdapter.totalMemory(); + var41 = EaglerAdapter.freeMemory(); + long var44 = var37 - var41; + var45 = "Used memory: " + var44 * 100L / var39 + "% (" + var44 / 1024L / 1024L + "MB) of " + var39 / 1024L / 1024L + "MB"; + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 2, 14737632); + var45 = "Allocated memory: " + var37 * 100L / var39 + "% (" + var37 / 1024L / 1024L + "MB)"; + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 12, 14737632); + offset = 0; + } + this.drawString(var8, "Player is not using an xbox live account", 2, 64, 0xFFBBBB); this.drawString(var8, "Using cracked server @ " + mc.getServerURI(), 2, 73, 0xFFBBBB); var47 = MathHelper.floor_double(this.mc.thePlayer.posX); @@ -418,28 +429,29 @@ public class GuiIngame extends Gui { this.drawString(var8, "z: "+doubleToShorterString(this.mc.thePlayer.posZ)+" ("+var23+") // c: "+(var23 >> 4)+" ("+(var23 & 15)+")", 2, 108, 14737632); var24 = MathHelper.floor_double((double) (this.mc.thePlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; this.drawString(var8, "f: " + var24 + " (" + Direction.directions[var24] + ") / " + MathHelper.wrapAngleTo180_float(this.mc.thePlayer.rotationYaw), 2, 116, 14737632); + this.drawString(var8, "Press F+6 to " + (mc.gameSettings.showCoordinates ? "disable" : "enable") + " showing coords in ingame GUI", 2, 135, 0xFFFFFFFF); //this.drawString(var8, String.format("ws: %.3f, fs: %.3f, g: %b, fl: %d", new Object[] { Float.valueOf(this.mc.thePlayer.capabilities.getWalkSpeed()), Float.valueOf(this.mc.thePlayer.capabilities.getFlySpeed()), // Boolean.valueOf(this.mc.thePlayer.onGround), Integer.valueOf(this.mc.theWorld.getHeightValue(var47, var23)) }), 2, 104, 14737632); var45 = "opengl emulator status - v1.0"; - this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 36, 14737632); + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, offset + 36, 14737632); var45 = "lists: "+EaglerAdapter.getDisplayListCount()+", upload: "+(EaglerAdapter.getBitsPerSecond() / 1000000)+"mbps"; - this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 46, 14737632); + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, offset + 46, 14737632); var45 = "verts: "+(EaglerAdapter.getVertexesPerSecond() / 1000)+"k, triangles: "+(EaglerAdapter.getTrianglesPerSecond() / 1000)+"k"; - this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 56, 14737632); + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, offset + 56, 14737632); var45 = "rendering backend: "+(EaglerAdapter.isWebGL ? "webgl20" : "opengl30"); - this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 66, 14737632); + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, offset + 66, 14737632); var45 = "glsl "+(EaglerAdapter._wgetShaderHeader() +", 32 bytes/vert"); - this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 76, 14737632); + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, offset + 76, 14737632); var45 = "Bound Shaders:"; - this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 100, 14737632); + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, offset + 100, 14737632); var45 = "/glsl/core.glsl"; - this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 110, 14737632); + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, offset + 110, 14737632); var45 = "/glsl/occl.glsl"; - this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 120, 14737632); + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, offset + 120, 14737632); for(int i = 0; i < EffectPipeline.pipeline.length; i++) { var45 = EffectPipeline.pipeline[i]; - this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, 130 + i*10, 14737632); + this.drawString(var8, var45, var6 - var8.getStringWidth(var45) - 2, offset + 130 + i*10, 14737632); } EaglerAdapter.glPopMatrix(); this.mc.mcProfiler.endSection(); @@ -447,7 +459,15 @@ public class GuiIngame extends Gui { EaglerAdapter.glPushMatrix(); EaglerAdapter.glScalef(0.75f, 0.75f, 0.75f); var8.drawStringWithShadow(this.mc.renderGlobal.getDebugInfoShort(), 2, 2, 16777215); - var8.drawStringWithShadow("x: "+MathHelper.floor_double(this.mc.thePlayer.posX)+", y: "+MathHelper.floor_double(this.mc.thePlayer.posY)+", z: "+MathHelper.floor_double(this.mc.thePlayer.posZ), 2, 12, 16777215); + + if(mc.gameSettings.showCoordinates) { + var8.drawStringWithShadow("x: "+MathHelper.floor_double(this.mc.thePlayer.posX)+", y: "+MathHelper.floor_double(this.mc.thePlayer.posY)+", z: "+MathHelper.floor_double(this.mc.thePlayer.posZ), 2, 12, 16777215); + }else { + if(mc.showHints > 0) { + var8.drawStringWithShadow("Press F+6 to show coordinates", 2, 12, 16777215); + } + } + int offset = this.mc.isChatOpen() ? 135 : 0; int offset2 = this.mc.isChatOpen() ? 4 : 0; String str = "not using an xbox live account"; diff --git a/src/teavm/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java b/src/teavm/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java index d3c1645..3c45ee3 100644 --- a/src/teavm/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java +++ b/src/teavm/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java @@ -164,6 +164,8 @@ public class EaglerAdapterImpl2 { public static HTMLDocument doc = null; public static HTMLElement parent = null; public static HTMLCanvasElement canvas = null; + public static CanvasRenderingContext2D frameBuffer = null; + public static HTMLCanvasElement renderingCanvas = null; public static WebGL2RenderingContext webgl = null; public static Window win = null; private static byte[] loadedPackage = null; @@ -207,8 +209,14 @@ public class EaglerAdapterImpl2 { doc = win.getDocument(); canvas = (HTMLCanvasElement)doc.createElement("canvas"); canvas.setAttribute("id", "deevis589723589"); + canvas.setWidth(parent.getClientWidth()); + canvas.setHeight(parent.getClientHeight()); rootElement.appendChild(canvas); - webgl = (WebGL2RenderingContext) canvas.getContext("webgl2", youEagler()); + renderingCanvas = (HTMLCanvasElement)doc.createElement("canvas"); + renderingCanvas.setWidth(canvas.getWidth()); + renderingCanvas.setHeight(canvas.getHeight()); + frameBuffer = (CanvasRenderingContext2D) canvas.getContext("2d"); + webgl = (WebGL2RenderingContext) renderingCanvas.getContext("webgl2", youEagler()); if(webgl == null) { throw new RuntimeException("WebGL 2.0 is not supported in your browser ("+getString("window.navigator.userAgent")+")"); } @@ -1540,16 +1548,48 @@ public class EaglerAdapterImpl2 { return false; } + @Async + private static native Object interrupt(); + + private static void interrupt(final AsyncCallback cb) { + Window.setTimeout(new TimerHandler() { + + @Override + public void onTimer() { + cb.complete(null); + } + + }, 0); + } + @JSBody(params = { "obj" }, script = "if(obj.commit) obj.commit();") private static native int commitContext(JSObject obj); public static final void updateDisplay() { - commitContext(webgl); + //commitContext(webgl); + int w = parent.getClientWidth(); + int h = parent.getClientHeight(); + if(canvas.getWidth() != w) { + canvas.setWidth(w); + } + if(canvas.getHeight() != h) { + canvas.setHeight(h); + } + frameBuffer.drawImage(renderingCanvas, 0, 0, w, h); + if(renderingCanvas.getWidth() != w) { + renderingCanvas.setWidth(w); + } + if(renderingCanvas.getHeight() != h) { + renderingCanvas.setHeight(h); + } + /* try { Thread.sleep(1l); } catch (InterruptedException e) { ; } + */ + interrupt(); } public static final void setVSyncEnabled(boolean p1) { @@ -1580,14 +1620,10 @@ public class EaglerAdapterImpl2 { return win.getScreen().getAvailHeight(); } public static final int getCanvasWidth() { - int w = parent.getClientWidth(); - canvas.setWidth(w); - return w; + return renderingCanvas.getWidth(); } public static final int getCanvasHeight() { - int h = parent.getClientHeight(); - canvas.setHeight(h); - return h; + return renderingCanvas.getHeight(); } public static final void setDisplaySize(int x, int y) {