Skip to content

Commit f16d6fb

Browse files
authored
Merge pull request #4 from juliand665/1.15
1.16 Support
2 parents 86226ce + 8821d7e commit f16d6fb

File tree

8 files changed

+138
-57
lines changed

8 files changed

+138
-57
lines changed

build.gradle

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'fabric-loom' version '0.2.3-SNAPSHOT'
2+
id 'fabric-loom' version '0.5-SNAPSHOT'
33
id 'maven-publish'
44
}
55

@@ -19,19 +19,16 @@ repositories {
1919

2020
dependencies {
2121
minecraft "com.mojang:minecraft:${project.minecraft_version}"
22-
mappings "net.fabricmc:yarn:${project.yarn_mappings}"
22+
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
2323
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"
2424

2525
// Fabric API. This is technically optional, but you probably want it anyway.
2626
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
2727

2828
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
2929
// You may need to force-disable transitivity on them.
30-
modCompile "com.jamieswhiteshirt:developer-mode:${project.developer_mode_version}"
30+
//modCompile "com.jamieswhiteshirt:developer-mode:${project.developer_mode_version}"
3131
modCompile "io.github.prospector:modmenu:${project.mod_menu_version}"
32-
33-
// Nullability Annotations
34-
implementation "com.google.code.findbugs:jsr305:${project.findbugs_version}"
3532
}
3633

3734
processResources {
@@ -71,7 +68,7 @@ publishing {
7168
publications {
7269
mavenJava(MavenPublication) {
7370
// add all the jars that should be included when publishing to maven
74-
artifact(jar) {
71+
artifact(remapJar) {
7572
builtBy remapJar
7673
}
7774
artifact(sourcesJar) {

gradle.properties

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ org.gradle.jvmargs=-Xmx1G
33

44
# Fabric Properties
55
# check these on https://fabricmc.net/use
6-
minecraft_version=1.14.4
7-
yarn_mappings=1.14.4+build.9
8-
loader_version=0.4.8+build.159
6+
minecraft_version=1.16.4
7+
yarn_mappings=1.16.4+build.7
8+
loader_version=0.10.8
99

1010
# Mod Properties
11-
mod_version = 1.0.2
11+
mod_version = 1.0.3
1212
maven_group = juliand665
1313
archives_base_name = resolution-control
1414

1515
# Dependencies
1616
# https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/
17-
fabric_version=0.3.1+build.208
17+
fabric_version=0.27.1+1.16
1818

19-
developer_mode_version=1.0.14
20-
mod_menu_version=1.7.7+build.116
21-
22-
findbugs_version=3.0.2
19+
developer_mode_version=1.0.15
20+
mod_menu_version=1.14.13+build.19

src/main/java/resolutioncontrol/ResolutionControlMod.java

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
66
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
77
import net.minecraft.client.MinecraftClient;
8-
import net.minecraft.client.gl.GlFramebuffer;
8+
import net.minecraft.client.gl.Framebuffer;
99
import net.minecraft.client.util.InputUtil;
1010
import net.minecraft.client.util.Window;
1111
import net.minecraft.util.Identifier;
12+
import org.jetbrains.annotations.Nullable;
1213
import org.lwjgl.glfw.GLFW;
1314
import resolutioncontrol.client.gui.screen.SettingsScreen;
1415
import resolutioncontrol.util.*;
1516

16-
import javax.annotation.Nullable;
17+
1718

1819
public class ResolutionControlMod implements ModInitializer {
1920
public static final String MOD_ID = "resolutioncontrol";
@@ -22,6 +23,8 @@ public static Identifier identifier(String path) {
2223
return new Identifier(MOD_ID, path);
2324
}
2425

26+
private static MinecraftClient client = MinecraftClient.getInstance();
27+
2528
private static ResolutionControlMod instance;
2629

2730
public static ResolutionControlMod getInstance() {
@@ -31,13 +34,17 @@ public static ResolutionControlMod getInstance() {
3134
private static FabricKeyBinding settingsKeyBinding = FabricKeyBinding.Builder.create(
3235
identifier("settings"),
3336
InputUtil.Type.KEYSYM,
34-
GLFW.GLFW_KEY_P,
37+
GLFW.GLFW_KEY_O,
3538
"key.categories.misc"
3639
).build();
3740

3841
private boolean shouldScale = false;
42+
43+
@Nullable
44+
private Framebuffer framebuffer;
45+
3946
@Nullable
40-
private GlFramebuffer framebuffer;
47+
private Framebuffer clientFramebuffer;
4148

4249
@Override
4350
public void onInitialize() {
@@ -51,7 +58,7 @@ public void onInitialize() {
5158
ClientTickCallback.EVENT.register(new KeyBindingHandler(settingsKeyBinding) {
5259
@Override
5360
public void handlePress() {
54-
MinecraftClient.getInstance().openScreen(new SettingsScreen());
61+
client.openScreen(new SettingsScreen());
5562
}
5663
});
5764
}
@@ -61,22 +68,38 @@ public void setShouldScale(boolean shouldScale) {
6168

6269
if (getScaleFactor() == 1) return;
6370

64-
Window window = MinecraftClient.getInstance().window;
71+
Window window = getWindow();
6572
if (framebuffer == null) {
6673
this.shouldScale = true; // so we get the right dimensions
67-
framebuffer = new GlFramebuffer(window.getFramebufferWidth(), window.getFramebufferHeight(), true, MinecraftClient.IS_SYSTEM_MAC);
74+
framebuffer = new Framebuffer(
75+
window.getFramebufferWidth(),
76+
window.getFramebufferHeight(),
77+
true,
78+
MinecraftClient.IS_SYSTEM_MAC
79+
);
6880
}
6981

7082
this.shouldScale = shouldScale;
7183

84+
client.getProfiler().swap(shouldScale ? "startScaling" : "finishScaling");
85+
7286
// swap out framebuffers as needed
73-
boolean shouldUpdateViewport = false;
87+
boolean shouldUpdateViewport = true;
7488
if (shouldScale) {
89+
clientFramebuffer = client.getFramebuffer();
90+
setClientFramebuffer(framebuffer);
7591
framebuffer.beginWrite(shouldUpdateViewport);
92+
// nothing on the client's framebuffer yet
7693
} else {
77-
MinecraftClient.getInstance().getFramebuffer().beginWrite(shouldUpdateViewport);
78-
framebuffer.draw(window.getFramebufferWidth(), window.getFramebufferHeight());
94+
setClientFramebuffer(clientFramebuffer);
95+
client.getFramebuffer().beginWrite(shouldUpdateViewport);
96+
framebuffer.draw(
97+
window.getFramebufferWidth(),
98+
window.getFramebufferHeight()
99+
);
79100
}
101+
102+
client.getProfiler().swap("level");
80103
}
81104

82105
public int getScaleFactor() {
@@ -88,13 +111,6 @@ public void setScaleFactor(int scaleFactor) {
88111

89112
Config.getInstance().scaleFactor = scaleFactor;
90113

91-
if (shouldScale) {
92-
updateViewport();
93-
if (scaleFactor == 1) {
94-
MinecraftClient.getInstance().getFramebuffer().beginWrite(false);
95-
}
96-
}
97-
98114
updateFramebufferSize();
99115

100116
ConfigHandler.instance.saveConfig();
@@ -110,16 +126,35 @@ public void onResolutionChanged() {
110126

111127
private void updateFramebufferSize() {
112128
if (framebuffer == null) return;
113-
if (getScaleFactor() == 1) return;
114129

115-
Window window = MinecraftClient.getInstance().window;
130+
if (getScaleFactor() != 1) {
131+
// resize if not unused
132+
resize(framebuffer);
133+
}
134+
135+
resize(client.worldRenderer.getEntityOutlinesFramebuffer());
136+
}
137+
138+
public void resize(Framebuffer framebuffer) {
116139
boolean prev = shouldScale;
117140
shouldScale = true;
118-
framebuffer.resize(window.getFramebufferWidth(), window.getFramebufferHeight(), MinecraftClient.IS_SYSTEM_MAC);
141+
framebuffer.resize(
142+
getWindow().getFramebufferWidth(),
143+
getWindow().getFramebufferHeight(),
144+
MinecraftClient.IS_SYSTEM_MAC
145+
);
119146
shouldScale = prev;
120147
}
121148

122-
private void updateViewport() {
123-
MinecraftClient.getInstance().window.method_4493(MinecraftClient.IS_SYSTEM_MAC);
149+
private Window getWindow() {
150+
return client.getWindow();
151+
}
152+
153+
private void setClientFramebuffer(Framebuffer framebuffer) {
154+
((MutableMinecraftClient) client).setFramebuffer(framebuffer);
155+
}
156+
157+
public interface MutableMinecraftClient {
158+
void setFramebuffer(Framebuffer framebuffer);
124159
}
125160
}

src/main/java/resolutioncontrol/client/gui/screen/SettingsScreen.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import net.minecraft.client.gui.screen.Screen;
66
import net.minecraft.client.gui.widget.ButtonWidget;
77
import net.minecraft.client.resource.language.I18n;
8+
import net.minecraft.client.util.math.MatrixStack;
9+
import net.minecraft.text.LiteralText;
810
import net.minecraft.text.Text;
911
import net.minecraft.text.TranslatableText;
1012
import net.minecraft.util.Identifier;
13+
import org.jetbrains.annotations.Nullable;
1114
import resolutioncontrol.ResolutionControlMod;
1215

13-
import javax.annotation.Nullable;
1416

1517
public final class SettingsScreen extends Screen {
1618
private static final Identifier backgroundTexture = ResolutionControlMod.identifier("textures/gui/settings.png");
@@ -62,59 +64,60 @@ protected void init() {
6264
decreaseButton = new ButtonWidget(
6365
centerX - buttonOffset - buttonSize / 2, buttonY,
6466
buttonSize, buttonSize,
65-
"-",
67+
new LiteralText("-"),
6668
button -> changeScaleFactor(-1));
6769
addButton(decreaseButton);
6870

6971
increaseButton = new ButtonWidget(
7072
centerX + buttonOffset - buttonSize / 2, buttonY,
7173
buttonSize, buttonSize,
72-
"+",
74+
new LiteralText("+"),
7375
button -> changeScaleFactor(+1)
7476
);
7577
addButton(increaseButton);
7678

7779
doneButton = new ButtonWidget(
7880
centerX - 100 / 2, startY + containerHeight - 10 - 20,
7981
100, buttonSize,
80-
I18n.translate("gui.done"),
81-
button -> minecraft.openScreen(parent)
82+
new TranslatableText("gui.done"),
83+
button -> client.openScreen(parent)
8284
);
8385
addButton(doneButton);
8486

8587
updateButtons();
8688
}
8789

8890
@Override
89-
public void render(int mouseX, int mouseY, float time) {
90-
assert minecraft != null;
91+
public void render(MatrixStack matrices, int mouseX, int mouseY, float time) {
92+
assert client != null;
9193

92-
if (minecraft.world == null) {
93-
renderDirtBackground(0);
94+
if (client.world == null) {
95+
renderBackgroundTexture(0);
9496
}
9597

9698
GlStateManager.enableAlphaTest();
97-
minecraft.getTextureManager().bindTexture(backgroundTexture);
99+
client.getTextureManager().bindTexture(backgroundTexture);
98100
GlStateManager.color4f(1, 1, 1, 1);
99101

100102
int textureWidth = 256;
101103
int textureHeight = 192;
102-
blit(
104+
drawTexture(
105+
matrices,
103106
centerX - textureWidth / 2, centerY - textureHeight / 2,
104107
0, 0,
105108
textureWidth, textureHeight
106109
);
107110

108-
drawCenteredString(getTitle().asFormattedString(), centerX, startY + 10, 0x404040);
111+
drawCenteredString(matrices, getTitle().getString(), centerX, startY + 10, 0x404040);
109112

110113
Text scaleFactor = text("current", mod.getScaleFactor());
111-
drawCenteredString(scaleFactor.asFormattedString(), centerX, centerY - 20, 0x000000);
114+
drawCenteredString(matrices, scaleFactor.getString(), centerX, centerY - 20, 0x000000);
112115

113-
super.render(mouseX, mouseY, time); // buttons
116+
super.render(matrices, mouseX, mouseY, time); // buttons
114117
}
115118

116-
private void drawCenteredString(String text, int x, int y, int color) {
117-
font.draw(text, x - font.getStringWidth(text) / 2, y, color);
119+
private void drawCenteredString(MatrixStack matrices, String text, int x, int y, int color) {
120+
textRenderer.draw(matrices, text, x - textRenderer.getWidth(text) / 2, y, color);
118121
}
119122

120123
private void changeScaleFactor(int change) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package resolutioncontrol.mixin;
2+
3+
import net.minecraft.client.MinecraftClient;
4+
import net.minecraft.client.gl.Framebuffer;
5+
import org.spongepowered.asm.mixin.*;
6+
import resolutioncontrol.ResolutionControlMod;
7+
8+
@Mixin(MinecraftClient.class)
9+
public abstract class MinecraftClientMixin implements ResolutionControlMod.MutableMinecraftClient {
10+
@Mutable
11+
@Final
12+
@Shadow
13+
private Framebuffer framebuffer;
14+
15+
@Override
16+
public void setFramebuffer(Framebuffer framebuffer) {
17+
this.framebuffer = framebuffer;
18+
}
19+
}

src/main/java/resolutioncontrol/mixin/WindowMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ private void onFramebufferSizeChanged(CallbackInfo callbackInfo) {
3535
ResolutionControlMod.getInstance().onResolutionChanged();
3636
}
3737

38-
@Inject(at = @At("RETURN"), method = "method_4483")
39-
private void onMethod4483(CallbackInfo callbackInfo) {
38+
@Inject(at = @At("RETURN"), method = "updateFramebufferSize")
39+
private void onUpdateFramebufferSize(CallbackInfo callbackInfo) {
4040
ResolutionControlMod.getInstance().onResolutionChanged();
4141
}
4242
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package resolutioncontrol.mixin;
2+
3+
import net.minecraft.client.gl.Framebuffer;
4+
import net.minecraft.client.render.WorldRenderer;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.Shadow;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Inject;
9+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
10+
import resolutioncontrol.ResolutionControlMod;
11+
12+
@Mixin(WorldRenderer.class)
13+
public abstract class WorldRendererMixin {
14+
@Shadow
15+
private Framebuffer entityOutlinesFramebuffer;
16+
17+
@Inject(at = @At("RETURN"), method = "loadEntityOutlineShader")
18+
private void onLoadEntityOutlineShader(CallbackInfo callbackInfo) {
19+
ResolutionControlMod.getInstance().resize(entityOutlinesFramebuffer);
20+
}
21+
22+
@Inject(at = @At("RETURN"), method = "onResized")
23+
private void onOnResized(CallbackInfo callbackInfo) {
24+
if (entityOutlinesFramebuffer == null) return;
25+
ResolutionControlMod.getInstance().resize(entityOutlinesFramebuffer);
26+
}
27+
}

src/main/resources/resolutioncontrol.mixins.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
],
77
"client": [
88
"WindowMixin",
9-
"GameRendererMixin"
9+
"GameRendererMixin",
10+
"MinecraftClientMixin",
11+
"WorldRendererMixin"
1012
],
1113
"injectors": {
1214
"defaultRequire": 1

0 commit comments

Comments
 (0)