DRY main MC window resizing
This commit is contained in:
@@ -5,6 +5,7 @@ import com.replaymod.core.mixin.MinecraftAccessor;
|
||||
import com.replaymod.replaystudio.protocol.PacketTypeRegistry;
|
||||
import com.replaymod.replaystudio.us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
import com.replaymod.replaystudio.us.myles.ViaVersion.packets.State;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.Dimension;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.options.KeyBinding;
|
||||
@@ -37,7 +38,9 @@ import java.util.ArrayList;
|
||||
|
||||
//#if MC>=11400
|
||||
import com.replaymod.core.mixin.AbstractButtonWidgetAccessor;
|
||||
import com.replaymod.render.mixin.MainWindowAccessor;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.client.gl.Framebuffer;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.AbstractButtonWidget;
|
||||
|
||||
@@ -196,6 +199,38 @@ public class MCVer {
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static Dimension getMainWindowSize(MinecraftClient mc) {
|
||||
return new Dimension(
|
||||
//#if MC>=11400
|
||||
getWindow(mc).getFramebufferWidth(),
|
||||
getWindow(mc).getFramebufferHeight()
|
||||
//#else
|
||||
//$$ mc.displayWidth,
|
||||
//$$ mc.displayHeight
|
||||
//#endif
|
||||
);
|
||||
}
|
||||
|
||||
public static void resizeMainWindow(MinecraftClient mc, int width, int height) {
|
||||
//#if MC>=11400
|
||||
Framebuffer fb = mc.getFramebuffer();
|
||||
if (fb.viewportWidth != width || fb.viewportHeight != height) {
|
||||
fb.resize(width, height, false);
|
||||
}
|
||||
//noinspection ConstantConditions
|
||||
MainWindowAccessor mainWindow = (MainWindowAccessor) (Object) getWindow(mc);
|
||||
mainWindow.setFramebufferWidth(width);
|
||||
mainWindow.setFramebufferHeight(height);
|
||||
//#if MC>=11500
|
||||
mc.gameRenderer.onResized(width, height);
|
||||
//#endif
|
||||
//#else
|
||||
//$$ if (width != mc.displayWidth || height != mc.displayHeight) {
|
||||
//$$ mc.resize(width, height);
|
||||
//$$ }
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static double Entity_getX(Entity entity) {
|
||||
//#if MC>=11500
|
||||
return entity.getX();
|
||||
|
||||
@@ -11,12 +11,9 @@ import de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.util.crash.CrashReport;
|
||||
|
||||
//#if MC>=11400
|
||||
import com.replaymod.render.mixin.MainWindowAccessor;
|
||||
import static com.replaymod.core.versions.MCVer.getWindow;
|
||||
//#endif
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.getMainWindowSize;
|
||||
import static com.replaymod.core.versions.MCVer.getRenderPartialTicks;
|
||||
import static com.replaymod.core.versions.MCVer.resizeMainWindow;
|
||||
|
||||
public class ScreenshotRenderer implements RenderInfo {
|
||||
|
||||
@@ -32,14 +29,7 @@ public class ScreenshotRenderer implements RenderInfo {
|
||||
|
||||
public boolean renderScreenshot() throws Throwable {
|
||||
try {
|
||||
//#if MC>=11400
|
||||
int displayWidthBefore = getWindow(mc).getFramebufferWidth();
|
||||
int displayHeightBefore = getWindow(mc).getFramebufferHeight();
|
||||
//#else
|
||||
//$$ int displayWidthBefore = mc.displayWidth;
|
||||
//$$ int displayHeightBefore = mc.displayHeight;
|
||||
//#endif
|
||||
|
||||
Dimension sizeBefore = getMainWindowSize(mc);
|
||||
boolean hideGUIBefore = mc.options.hudHidden;
|
||||
mc.options.hudHidden = true;
|
||||
|
||||
@@ -56,22 +46,7 @@ public class ScreenshotRenderer implements RenderInfo {
|
||||
clrg.uninstall();
|
||||
|
||||
mc.options.hudHidden = hideGUIBefore;
|
||||
//#if MC>=11400
|
||||
//noinspection ConstantConditions
|
||||
MainWindowAccessor acc = (MainWindowAccessor) (Object) getWindow(mc);
|
||||
acc.setFramebufferWidth(displayWidthBefore);
|
||||
acc.setFramebufferHeight(displayHeightBefore);
|
||||
mc.getFramebuffer().resize(displayWidthBefore, displayHeightBefore
|
||||
//#if MC>=11400
|
||||
, false
|
||||
//#endif
|
||||
);
|
||||
//#if MC>=11500
|
||||
mc.gameRenderer.onResized(displayWidthBefore, displayHeightBefore);
|
||||
//#endif
|
||||
//#else
|
||||
//$$ mc.resize(displayWidthBefore, displayHeightBefore);
|
||||
//#endif
|
||||
resizeMainWindow(mc, sizeBefore.getWidth(), sizeBefore.getHeight());
|
||||
return true;
|
||||
} catch (OutOfMemoryError e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.resizeMainWindow;
|
||||
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
|
||||
|
||||
@@ -164,7 +165,7 @@ public class ODSFrameCapturer implements FrameCapturer<ODSOpenGlFrame> {
|
||||
|
||||
@Override
|
||||
protected OpenGlFrame renderFrame(int frameId, float partialTicks, CubicOpenGlFrameCapturer.Data captureData) {
|
||||
resize(getFrameWidth(), getFrameHeight());
|
||||
resizeMainWindow(mc, getFrameWidth(), getFrameHeight());
|
||||
|
||||
pushMatrix();
|
||||
frameBuffer().beginWrite(true);
|
||||
|
||||
@@ -16,17 +16,13 @@ import org.lwjgl.opengl.GL12;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
//#if MC>=11400
|
||||
import com.replaymod.render.mixin.MainWindowAccessor;
|
||||
import static com.replaymod.core.versions.MCVer.getWindow;
|
||||
//#endif
|
||||
|
||||
//#if MC>=10800
|
||||
import static com.mojang.blaze3d.platform.GlStateManager.*;
|
||||
//#else
|
||||
//$$ import static com.replaymod.core.versions.MCVer.GlStateManager.*;
|
||||
//#endif
|
||||
|
||||
import static com.replaymod.core.versions.MCVer.resizeMainWindow;
|
||||
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
|
||||
|
||||
@@ -36,7 +32,7 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
|
||||
protected int framesDone;
|
||||
private Framebuffer frameBuffer;
|
||||
|
||||
private final MinecraftClient mc = MCVer.getMinecraft();
|
||||
protected final MinecraftClient mc = MCVer.getMinecraft();
|
||||
|
||||
public OpenGlFrameCapturer(WorldRenderer worldRenderer, RenderInfo renderInfo) {
|
||||
this.worldRenderer = worldRenderer;
|
||||
@@ -85,7 +81,7 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
|
||||
}
|
||||
|
||||
protected OpenGlFrame renderFrame(int frameId, float partialTicks, D captureData) {
|
||||
resize(getFrameWidth(), getFrameHeight());
|
||||
resizeMainWindow(mc, getFrameWidth(), getFrameHeight());
|
||||
|
||||
pushMatrix();
|
||||
frameBuffer().beginWrite(true);
|
||||
@@ -115,30 +111,6 @@ public abstract class OpenGlFrameCapturer<F extends Frame, D extends CaptureData
|
||||
return new OpenGlFrame(frameId, new Dimension(getFrameWidth(), getFrameHeight()), 4, buffer);
|
||||
}
|
||||
|
||||
protected void resize(int width, int height) {
|
||||
//#if MC>=11400
|
||||
Framebuffer fb = mc.getFramebuffer();
|
||||
if (fb.viewportWidth != width || fb.viewportHeight != height) {
|
||||
fb.resize(width, height
|
||||
//#if MC>=11400
|
||||
, false
|
||||
//#endif
|
||||
);
|
||||
}
|
||||
//noinspection ConstantConditions
|
||||
MainWindowAccessor mainWindow = (MainWindowAccessor) (Object) getWindow(mc);
|
||||
mainWindow.setFramebufferWidth(width);
|
||||
mainWindow.setFramebufferHeight(height);
|
||||
//#if MC>=11500
|
||||
mc.gameRenderer.onResized(width, height);
|
||||
//#endif
|
||||
//#else
|
||||
//$$ if (width != mc.displayWidth || height != mc.displayHeight) {
|
||||
//$$ mc.resize(width, height);
|
||||
//$$ }
|
||||
//#endif
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
@@ -425,22 +425,7 @@ public class VideoRenderer implements RenderInfo {
|
||||
}
|
||||
|
||||
// Finally, resize the Minecraft framebuffer to the actual width/height of the window
|
||||
//#if MC>=11400
|
||||
mc.getFramebuffer().resize(displayWidth, displayHeight
|
||||
//#if MC>=11400
|
||||
, false
|
||||
//#endif
|
||||
);
|
||||
//noinspection ConstantConditions
|
||||
MainWindowAccessor acc = (MainWindowAccessor) (Object) getWindow(mc);
|
||||
acc.setFramebufferWidth(displayWidth);
|
||||
acc.setFramebufferHeight(displayHeight);
|
||||
//#if MC>=11500
|
||||
mc.gameRenderer.onResized(displayWidth, displayHeight);
|
||||
//#endif
|
||||
//#else
|
||||
//$$ mc.resize(displayWidth, displayHeight);
|
||||
//#endif
|
||||
resizeMainWindow(mc, displayWidth, displayHeight);
|
||||
}
|
||||
|
||||
private void executeTaskQueue() {
|
||||
|
||||
Reference in New Issue
Block a user