diff --git a/.gitignore b/.gitignore index 8f9956c5..f151e5b2 100644 --- a/.gitignore +++ b/.gitignore @@ -113,6 +113,7 @@ gradle-app.setting # Common working directory run/ +neoforge/runs # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) !gradle-wrapper.jar diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 4c3c8059..00000000 --- a/build.gradle +++ /dev/null @@ -1,130 +0,0 @@ -plugins { - id 'org.ajoberstar.grgit' version '5.2.1' - id 'fabric-loom' version '1.5-SNAPSHOT' - id 'maven-publish' - id 'signing' -} - -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - -archivesBaseName = project.archives_base_name -version = "${project.mod_version}${getVersionType(project.version_type, project.revision)}+mc${project.minecraft_version}-${getVersionMetadata()}" -group = project.maven_group - -repositories { - maven { - name = "Modrinth" - url = "https://api.modrinth.com/maven" - content { - includeGroup "maven.modrinth" - } - } - maven { - url "https://maven.flashyreese.me/releases" - } - maven { - url "https://maven.flashyreese.me/snapshots" - } -} - -dependencies { - //to change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" - - //modImplementation "me.jellysquid.mods:sodium-fabric:0.5.6-snapshot+mc1.20.3-build.1" - modImplementation "maven.modrinth:sodium:${project.sodium_version}" - //modImplementation "maven.modrinth:iris:${project.iris_version}" - - //modRuntimeOnly "maven.modrinth:lazydfu:0.1.3" -} - -processResources { - inputs.property "version", project.version - - filesMatching("fabric.mod.json") { - expand "version": project.version - } -} - -tasks.withType(JavaCompile).configureEach { - it.options.release = 17 -} - -java { - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. - withSourcesJar() -} - -jar { - from "LICENSE.txt" -} - - -// configure the maven publication -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - } - } - - // select the repositories you want to publish to - repositories { - // uncomment to publish to the local maven - maven { - name = "FlashyReeseReleases" - url = "https://maven.flashyreese.me/releases" - credentials { - username = System.getenv("MAVEN_USERNAME") - password = System.getenv("MAVEN_PASSWORD") - } - } - maven { - name = "FlashyReeseSnapshots" - url = "https://maven.flashyreese.me/snapshots" - credentials { - username = System.getenv("MAVEN_USERNAME") - password = System.getenv("MAVEN_PASSWORD") - } - } - } -} - -def getVersionMetadata() { - def build_id = System.getenv("GITHUB_RUN_NUMBER") - - // CI builds only - if (build_id != null) { - return "build.${build_id}" - } - - if (grgit != null) { - def head = grgit.head() - def id = head.abbreviatedId - - // Flag the build if the build tree is not clean - if (!grgit.status().clean) { - id += "-dirty" - } - - return "rev.${id}" - } - - // No tracking information could be found about the build - return "unknown" -} - -static def getVersionType(String version_type, String revision) { - version_type = version_type.trim().toLowerCase() - revision = revision.trim().toLowerCase() - if (version_type != "release") { - return "-${version_type}${revision}" - } - return "" -} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..379f54ba --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,79 @@ + +plugins { + id("java") +} + +val MINECRAFT_VERSION by extra { "1.20.4" } +val NEOFORGE_VERSION by extra { "20.4.219" } +val FABRIC_LOADER_VERSION by extra { "0.15.6" } +val FABRIC_API_VERSION by extra { "0.96.0+1.20.4" } + +// https://semver.org/ +val MOD_VERSION by extra { "2.0.0" } + +allprojects { + apply(plugin = "java") + apply(plugin = "maven-publish") +} +tasks.withType { + options.encoding = "UTF-8" +} + +subprojects { + repositories { + maven(url = "https://maven.flashyreese.me/releases") + maven(url = "https://maven.flashyreese.me/snapshots") + } + + apply(plugin = "maven-publish") + + java.toolchain.languageVersion = JavaLanguageVersion.of(17) + + + fun createVersionString(): String { + val builder = StringBuilder() + + val isReleaseBuild = project.hasProperty("build.release") + val buildId = System.getenv("GITHUB_RUN_NUMBER") + + if (isReleaseBuild) { + builder.append(MOD_VERSION) + } else { + builder.append(MOD_VERSION.substringBefore('-')) + builder.append("-snapshot") + } + + builder.append("+mc").append(MINECRAFT_VERSION) + + if (!isReleaseBuild) { + if (buildId != null) { + builder.append("-build.${buildId}") + } else { + builder.append("-local") + } + } + + return builder.toString() + } + + tasks.processResources { + filesMatching("META-INF/mods.toml") { + expand(mapOf("version" to createVersionString())) + } + } + + version = createVersionString() + group = "me.flashyreese.mods" + + tasks.withType { + options.encoding = "UTF-8" + options.release.set(17) + } + + // Disables Gradle's custom module metadata from being published to maven. The + // metadata includes mapped dependencies which are not reasonably consumable by + // other mod developers. + tasks.withType().configureEach { + enabled = false + } +} \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts new file mode 100644 index 00000000..cb97d419 --- /dev/null +++ b/common/build.gradle.kts @@ -0,0 +1,70 @@ +import net.fabricmc.loom.task.AbstractRemapJarTask + +plugins { + id("java") + id("idea") + id("fabric-loom") version "1.6.5" +} + +val MINECRAFT_VERSION: String by rootProject.extra +val FABRIC_LOADER_VERSION: String by rootProject.extra +val FABRIC_API_VERSION: String by rootProject.extra + +dependencies { + "minecraft"(group = "com.mojang", name = "minecraft", version = MINECRAFT_VERSION) + "mappings"(loom.officialMojangMappings()) + compileOnly("io.github.llamalad7:mixinextras-common:0.3.5") + annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.5") + compileOnly("net.fabricmc:sponge-mixin:0.13.2+mixin.0.8.5") + + implementation(group = "net.caffeinemc.mods", name = "sodium-common-1.20.4", version = "0.6.0-snapshot+mc1.20.4-local") + modImplementation(group = "net.caffeinemc.mods", name = "sodium-common-1.20.4", version = "0.6.0-snapshot+mc1.20.4-local") + //modImplementation(group = "net.caffeinemc.mods", name = "sodium", version = "0.6.0-snapshot+mc1.20.4-local") +} + +tasks.withType().forEach { + it.targetNamespace = "named" +} + + +loom { + mixin { + defaultRefmapName = "reeses-sodium-options.refmap.json" + } + + mods { + val main by creating { // to match the default mod generated for Forge + sourceSet("main") + } + } +} + +publishing { + publications { + create("mavenJava") { + from(components["java"]) + } + } + + repositories { + maven { + name = "FlashyReeseReleases" + url = uri("https://maven.flashyreese.me/releases") + credentials { + username = System.getenv("MAVEN_USERNAME") + password = System.getenv("MAVEN_PASSWORD") + } + } + maven { + name = "FlashyReeseSnapshots" + url = uri("https://maven.flashyreese.me/snapshots") + credentials { + username = System.getenv("MAVEN_USERNAME") + password = System.getenv("MAVEN_PASSWORD") + } + } + maven { + url = uri("file://" + System.getenv("local_maven")) + } + } +} \ No newline at end of file diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/Dim2iExtended.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/Dim2iExtended.java similarity index 82% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/Dim2iExtended.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/Dim2iExtended.java index 6b1e0638..bf7bf27a 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/Dim2iExtended.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/Dim2iExtended.java @@ -1,6 +1,6 @@ package me.flashyreese.mods.reeses_sodium_options.client.gui; -import me.jellysquid.mods.sodium.client.util.Dim2i; +import net.caffeinemc.mods.sodium.client.util.Dim2i; public interface Dim2iExtended { void setPoint2i(Point2i point2i); diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/FlatButtonWidgetExtended.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/FlatButtonWidgetExtended.java similarity index 80% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/FlatButtonWidgetExtended.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/FlatButtonWidgetExtended.java index c82795a3..5336194f 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/FlatButtonWidgetExtended.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/FlatButtonWidgetExtended.java @@ -1,6 +1,6 @@ package me.flashyreese.mods.reeses_sodium_options.client.gui; -import me.jellysquid.mods.sodium.client.util.Dim2i; +import net.caffeinemc.mods.sodium.client.util.Dim2i; public interface FlatButtonWidgetExtended { boolean isLeftAligned(); diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/OptionExtended.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/OptionExtended.java similarity index 87% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/OptionExtended.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/OptionExtended.java index 848d9db9..58f8088e 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/OptionExtended.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/OptionExtended.java @@ -1,6 +1,6 @@ package me.flashyreese.mods.reeses_sodium_options.client.gui; -import me.jellysquid.mods.sodium.client.util.Dim2i; +import net.caffeinemc.mods.sodium.client.util.Dim2i; public interface OptionExtended { boolean isHighlight(); diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/Point2i.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/Point2i.java similarity index 100% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/Point2i.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/Point2i.java diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SliderControlElementExtended.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SliderControlElementExtended.java similarity index 100% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SliderControlElementExtended.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SliderControlElementExtended.java diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SodiumVideoOptionsScreen.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SodiumVideoOptionsScreen.java similarity index 72% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SodiumVideoOptionsScreen.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SodiumVideoOptionsScreen.java index e0c6b5db..02eca056 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SodiumVideoOptionsScreen.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/SodiumVideoOptionsScreen.java @@ -6,25 +6,24 @@ import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.tab.Tab; import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.tab.TabFrame; import me.flashyreese.mods.reeses_sodium_options.compat.IrisCompat; -import me.jellysquid.mods.sodium.client.SodiumClientMod; -import me.jellysquid.mods.sodium.client.data.fingerprint.HashedFingerprint; -import me.jellysquid.mods.sodium.client.gui.SodiumGameOptions; -import me.jellysquid.mods.sodium.client.gui.options.Option; -import me.jellysquid.mods.sodium.client.gui.options.OptionFlag; -import me.jellysquid.mods.sodium.client.gui.options.OptionPage; -import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage; -import me.jellysquid.mods.sodium.client.gui.prompt.ScreenPrompt; -import me.jellysquid.mods.sodium.client.gui.prompt.ScreenPromptable; -import me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.option.VideoOptionsScreen; -import net.minecraft.text.StringVisitable; -import net.minecraft.text.Text; -import net.minecraft.util.Util; +import net.caffeinemc.mods.sodium.client.SodiumClientMod; +import net.caffeinemc.mods.sodium.client.data.fingerprint.HashedFingerprint; +import net.caffeinemc.mods.sodium.client.gui.SodiumGameOptions; +import net.caffeinemc.mods.sodium.client.gui.options.Option; +import net.caffeinemc.mods.sodium.client.gui.options.OptionFlag; +import net.caffeinemc.mods.sodium.client.gui.options.OptionPage; +import net.caffeinemc.mods.sodium.client.gui.options.storage.OptionStorage; +import net.caffeinemc.mods.sodium.client.gui.prompt.ScreenPrompt; +import net.caffeinemc.mods.sodium.client.gui.prompt.ScreenPromptable; +import net.caffeinemc.mods.sodium.client.gui.widgets.FlatButtonWidget; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.Util; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.VideoSettingsScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.FormattedText; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -40,7 +39,7 @@ public class SodiumVideoOptionsScreen extends Screen implements ScreenPromptable { - private static final AtomicReference tabFrameSelectedTab = new AtomicReference<>(null); + private static final AtomicReference tabFrameSelectedTab = new AtomicReference<>(null); private static final AtomicReference tabFrameScrollBarOffset = new AtomicReference<>(0); private static final AtomicReference optionPageScrollBarOffset = new AtomicReference<>(0); @@ -59,7 +58,7 @@ public class SodiumVideoOptionsScreen extends Screen implements ScreenPromptable private @Nullable ScreenPrompt prompt; public SodiumVideoOptionsScreen(Screen prev, List pages) { - super(Text.literal("Reese's Sodium Menu")); + super(Component.literal("Reese's Sodium Menu")); this.prevScreen = prev; this.pages.addAll(pages); @@ -68,14 +67,14 @@ public SodiumVideoOptionsScreen(Screen prev, List pages) { private void checkPromptTimers() { // Never show the prompt in developer workspaces. - if (FabricLoader.getInstance().isDevelopmentEnvironment()) { - return; - } + /*if (FabricLoader.getInstance().isDevelopmentEnvironment()) { //fixme: + //return; + }*/ var options = SodiumClientMod.options(); // If the user has disabled the nags forcefully (by config), or has already seen the prompt, don't show it again. - if (options.notifications.hasSeenDonationPrompt) { + if (options.notifications.hasClearedDonationButton || options.notifications.hasSeenDonationPrompt) { return; } @@ -106,7 +105,7 @@ private void checkPromptTimers() { private void openDonationPrompt(SodiumGameOptions options) { var prompt = new ScreenPrompt(this, DONATION_PROMPT_MESSAGE, 320, 190, - new ScreenPrompt.Action(Text.literal("Buy us a coffee"), this::openDonationPage)); + new ScreenPrompt.Action(Component.literal("Buy us a coffee"), this::openDonationPage)); prompt.setFocused(true); options.notifications.hasSeenDonationPrompt = true; @@ -121,13 +120,13 @@ private void openDonationPrompt(SodiumGameOptions options) { // Hackalicious! Rebuild UI public void rebuildUI() { - this.clearAndInit(); + this.rebuildWidgets(); } @Override protected void init() { this.frame = this.parentFrameBuilder().build(); - this.addDrawableChild(this.frame); + this.addRenderableWidget(this.frame); this.searchTextField.setFocused(!lastSearch.get().trim().isEmpty()); if (this.searchTextField.isFocused()) { @@ -153,18 +152,18 @@ protected BasicFrame.Builder parentFrameBuilder() { Dim2i applyButtonDim = new Dim2i(tabFrameDim.getLimitX() - 134, tabFrameDim.getLimitY() + 5, 65, 20); Dim2i closeButtonDim = new Dim2i(tabFrameDim.getLimitX() - 65, tabFrameDim.getLimitY() + 5, 65, 20); - Text donationText = Text.translatable("sodium.options.buttons.donate"); - int donationTextWidth = this.client.textRenderer.getWidth(donationText); + Component donationText = Component.translatable("sodium.options.buttons.donate"); + int donationTextWidth = this.minecraft.font.width(donationText); Dim2i donateButtonDim = new Dim2i(tabFrameDim.getLimitX() - 32 - donationTextWidth, tabFrameDim.y() - 26, 10 + donationTextWidth, 20); Dim2i hideDonateButtonDim = new Dim2i(tabFrameDim.getLimitX() - 20, tabFrameDim.y() - 26, 20, 20); - this.undoButton = new FlatButtonWidget(undoButtonDim, Text.translatable("sodium.options.buttons.undo"), this::undoChanges); - this.applyButton = new FlatButtonWidget(applyButtonDim, Text.translatable("sodium.options.buttons.apply"), this::applyChanges); - this.closeButton = new FlatButtonWidget(closeButtonDim, Text.translatable("gui.done"), this::close); + this.undoButton = new FlatButtonWidget(undoButtonDim, Component.translatable("sodium.options.buttons.undo"), this::undoChanges); + this.applyButton = new FlatButtonWidget(applyButtonDim, Component.translatable("sodium.options.buttons.apply"), this::applyChanges); + this.closeButton = new FlatButtonWidget(closeButtonDim, Component.translatable("gui.done"), this::onClose); this.donateButton = new FlatButtonWidget(donateButtonDim, donationText, this::openDonationPage); - this.hideDonateButton = new FlatButtonWidget(hideDonateButtonDim, Text.literal("x"), this::hideDonationButton); + this.hideDonateButton = new FlatButtonWidget(hideDonateButtonDim, Component.literal("x"), this::hideDonationButton); if (SodiumClientMod.options().notifications.hasClearedDonationButton) { this.setDonationButtonVisibility(false); @@ -183,7 +182,7 @@ protected BasicFrame.Builder parentFrameBuilder() { if (IrisCompat.isIrisPresent()) { // FabricLoader.getInstance().isModLoaded("iris")) { //int size = this.client.textRenderer.getWidth(Text.translatable(IrisApi.getInstance().getMainScreenLanguageKey())); - int size = this.client.textRenderer.getWidth(Text.translatable(IrisCompat.getIrisShaderPacksScreenLanguageKey())); + int size = this.minecraft.font.width(Component.translatable(IrisCompat.getIrisShaderPacksScreenLanguageKey())); Dim2i shaderPackButtonDim; if (!(SodiumClientMod.options().notifications.hasClearedDonationButton)) { shaderPackButtonDim = new Dim2i(donateButtonDim.x() - 12 - size, tabFrameDim.y() - 26, 10 + size, 20); @@ -193,7 +192,7 @@ protected BasicFrame.Builder parentFrameBuilder() { searchTextFieldDim = new Dim2i(tabFrameDim.x(), tabFrameDim.y() - 26, tabFrameDim.width() - (tabFrameDim.getLimitX() - shaderPackButtonDim.x()) - 2, 20); //FlatButtonWidget shaderPackButton = new FlatButtonWidget(shaderPackButtonDim, Text.translatable(IrisApi.getInstance().getMainScreenLanguageKey()), () -> this.client.setScreen((Screen) IrisApi.getInstance().openMainIrisScreenObj(this))); - FlatButtonWidget shaderPackButton = new FlatButtonWidget(shaderPackButtonDim, Text.translatable(IrisCompat.getIrisShaderPacksScreenLanguageKey()), () -> this.client.setScreen(IrisCompat.getIrisShaderPacksScreen(this))); + FlatButtonWidget shaderPackButton = new FlatButtonWidget(shaderPackButtonDim, Component.translatable(IrisCompat.getIrisShaderPacksScreenLanguageKey()), () -> this.minecraft.setScreen(IrisCompat.getIrisShaderPacksScreen(this))); basicFrameBuilder.addChild(dim -> shaderPackButton); } @@ -232,7 +231,7 @@ public BasicFrame.Builder parentBasicFrameBuilder(Dim2i parentBasicFrameDim, Dim } @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { + public void render(GuiGraphics drawContext, int mouseX, int mouseY, float delta) { super.renderBackground(drawContext, mouseX, mouseY, delta); this.updateControls(); this.frame.render(drawContext, this.prompt != null ? -1 : mouseX, this.prompt != null ? -1 : mouseY, delta); @@ -282,8 +281,8 @@ private void hideDonationButton() { } private void openDonationPage() { - Util.getOperatingSystem() - .open("https://caffeinemc.net/donate"); + Util.getPlatform() + .openUri("https://caffeinemc.net/donate"); } private Stream> getAllOptions() { @@ -306,17 +305,21 @@ private void applyChanges() { dirtyStorages.add(option.getStorage()); })); - MinecraftClient client = MinecraftClient.getInstance(); + Minecraft client = Minecraft.getInstance(); if (flags.contains(OptionFlag.REQUIRES_RENDERER_RELOAD)) { - client.worldRenderer.reload(); + client.levelRenderer.allChanged(); } if (flags.contains(OptionFlag.REQUIRES_ASSET_RELOAD)) { - client.setMipmapLevels(client.options.getMipmapLevels().getValue()); - client.reloadResourcesConcurrently(); + client.updateMaxMipLevel(client.options.mipmapLevels().get()); + client.delayTextureReload(); } + /*if (flags.contains(OptionFlag.REQUIRES_GAME_RESTART)) { //todo: + Console.instance().logMessage(MessageLevel.WARN, "sodium.console.game_restart", true, 10.0); + }*/ + for (OptionStorage storage : dirtyStorages) { storage.save(); } @@ -327,23 +330,10 @@ private void undoChanges() { .forEach(Option::reset); } - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (this.prompt != null) { - return this.prompt.mouseClicked(mouseX, mouseY, button); - } - - return super.mouseClicked(mouseX, mouseY, button); - } - @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (this.prompt != null) { - return this.prompt.keyPressed(keyCode, scanCode, modifiers); - } - if (keyCode == GLFW.GLFW_KEY_P && (modifiers & GLFW.GLFW_MOD_SHIFT) != 0 && !(this.searchTextField != null && this.searchTextField.isFocused())) { - MinecraftClient.getInstance().setScreen(new VideoOptionsScreen(this.prevScreen, MinecraftClient.getInstance().options)); + this.minecraft.setScreen(new VideoSettingsScreen(this.prevScreen, this.minecraft.options)); return true; } @@ -357,10 +347,10 @@ public boolean shouldCloseOnEsc() { } @Override - public void close() { + public void onClose() { lastSearch.set(""); lastSearchIndex.set(0); - this.client.setScreen(this.prevScreen); + this.minecraft.setScreen(this.prevScreen); } @Override @@ -379,15 +369,15 @@ public Dim2i getDimensions() { } - private static final List DONATION_PROMPT_MESSAGE; + private static final List DONATION_PROMPT_MESSAGE; static { DONATION_PROMPT_MESSAGE = List.of( - StringVisitable.concat(Text.literal("Hello!")), - StringVisitable.concat(Text.literal("It seems that you've been enjoying "), Text.literal("Sodium").withColor(0x27eb92), Text.literal(", the free and open-source optimization mod for Minecraft.")), - StringVisitable.concat(Text.literal("Mods like these are complex. They require "), Text.literal("thousands of hours").withColor(0xff6e00), Text.literal(" of development, debugging, and tuning to create the experience that players have come to expect.")), - StringVisitable.concat(Text.literal("If you'd like to show your token of appreciation, and support the development of our mod in the process, then consider "), Text.literal("buying us a coffee").withColor(0xed49ce), Text.literal(".")), - StringVisitable.concat(Text.literal("And thanks again for using our mod! We hope it helps you (and your computer.)")) + FormattedText.composite(Component.literal("Hello!")), + FormattedText.composite(Component.literal("It seems that you've been enjoying "), Component.literal("Sodium").withColor(0x27eb92), Component.literal(", the free and open-source optimization mod for Minecraft.")), + FormattedText.composite(Component.literal("Mods like these are complex. They require "), Component.literal("thousands of hours").withColor(0xff6e00), Component.literal(" of development, debugging, and tuning to create the experience that players have come to expect.")), + FormattedText.composite(Component.literal("If you'd like to show your token of appreciation, and support the development of our mod in the process, then consider "), Component.literal("buying us a coffee").withColor(0xed49ce), Component.literal(".")), + FormattedText.composite(Component.literal("And thanks again for using our mod! We hope it helps you (and your computer.)")) ); } } diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/AbstractFrame.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/AbstractFrame.java similarity index 54% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/AbstractFrame.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/AbstractFrame.java index 03c49387..67910b84 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/AbstractFrame.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/AbstractFrame.java @@ -1,28 +1,32 @@ package me.flashyreese.mods.reeses_sodium_options.client.gui.frame; import com.mojang.blaze3d.systems.RenderSystem; -import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement; -import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.*; -import net.minecraft.client.gui.navigation.GuiNavigation; -import net.minecraft.client.gui.navigation.GuiNavigationPath; +import net.caffeinemc.mods.sodium.client.gui.options.control.ControlElement; +import net.caffeinemc.mods.sodium.client.gui.widgets.AbstractWidget; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ComponentPath; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.components.Renderable; +import net.minecraft.client.gui.components.events.ContainerEventHandler; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.navigation.FocusNavigationEvent; +import net.minecraft.client.gui.navigation.ScreenRectangle; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; -public abstract class AbstractFrame extends AbstractWidget implements ParentElement { +public abstract class AbstractFrame extends AbstractWidget implements ContainerEventHandler { protected final Dim2i dim; protected final List children = new ArrayList<>(); - protected final List drawable = new ArrayList<>(); + protected final List drawable = new ArrayList<>(); protected final List> controlElements = new ArrayList<>(); protected boolean renderOutline; - private Element focused; + private GuiEventListener focused; private boolean dragging; - private Consumer focusListener; + private Consumer focusListener; public AbstractFrame(Dim2i dim, boolean renderOutline) { this.dim = dim; @@ -30,38 +34,38 @@ public AbstractFrame(Dim2i dim, boolean renderOutline) { } public void buildFrame() { - for (Element element : this.children) { + for (GuiEventListener element : this.children) { if (element instanceof AbstractFrame) { this.controlElements.addAll(((AbstractFrame) element).controlElements); } if (element instanceof ControlElement) { this.controlElements.add((ControlElement) element); } - if (element instanceof Drawable) { - this.drawable.add((Drawable) element); + if (element instanceof Renderable) { + this.drawable.add((Renderable) element); } } } @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { + public void render(GuiGraphics drawContext, int mouseX, int mouseY, float delta) { if (this.renderOutline) { this.drawBorder(drawContext, this.dim.x(), this.dim.y(), this.dim.getLimitX(), this.dim.getLimitY(), 0xFFAAAAAA); } - for (Drawable drawable : this.drawable) { + for (Renderable drawable : this.drawable) { drawable.render(drawContext, mouseX, mouseY, delta); } } public void applyScissor(int x, int y, int width, int height, Runnable action) { - double scale = MinecraftClient.getInstance().getWindow().getScaleFactor(); - RenderSystem.enableScissor((int) (x * scale), (int) (MinecraftClient.getInstance().getWindow().getFramebufferHeight() - (y + height) * scale), + double scale = Minecraft.getInstance().getWindow().getGuiScale(); + RenderSystem.enableScissor((int) (x * scale), (int) (Minecraft.getInstance().getWindow().getHeight() - (y + height) * scale), (int) (width * scale), (int) (height * scale)); action.run(); RenderSystem.disableScissor(); } - public void registerFocusListener(Consumer focusListener) { + public void registerFocusListener(Consumer focusListener) { this.focusListener = focusListener; } @@ -77,12 +81,12 @@ public void setDragging(boolean dragging) { @Nullable @Override - public Element getFocused() { + public GuiEventListener getFocused() { return this.focused; } @Override - public void setFocused(@Nullable Element focused) { + public void setFocused(@Nullable GuiEventListener focused) { this.focused = focused; if (this.focusListener != null) { this.focusListener.accept(focused); @@ -90,7 +94,7 @@ public void setFocused(@Nullable Element focused) { } @Override - public List children() { + public List children() { return this.children; } @@ -100,12 +104,12 @@ public boolean isMouseOver(double mouseX, double mouseY) { } @Override - public @Nullable GuiNavigationPath getNavigationPath(GuiNavigation navigation) { - return ParentElement.super.getNavigationPath(navigation); + public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent navigation) { + return ContainerEventHandler.super.nextFocusPath(navigation); } @Override - public ScreenRect getNavigationFocus() { - return new ScreenRect(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height()); + public ScreenRectangle getRectangle() { + return new ScreenRectangle(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height()); } } diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/BasicFrame.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/BasicFrame.java similarity index 85% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/BasicFrame.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/BasicFrame.java index 4189ea1a..08f594fe 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/BasicFrame.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/BasicFrame.java @@ -1,8 +1,8 @@ package me.flashyreese.mods.reeses_sodium_options.client.gui.frame; -import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.minecraft.client.gui.DrawContext; +import net.caffeinemc.mods.sodium.client.gui.widgets.AbstractWidget; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.client.gui.GuiGraphics; import org.apache.commons.lang3.Validate; import java.util.ArrayList; @@ -35,7 +35,7 @@ public void buildFrame() { } @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { + public void render(GuiGraphics drawContext, int mouseX, int mouseY, float delta) { super.render(drawContext, mouseX, mouseY, delta); } diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/OptionPageFrame.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/OptionPageFrame.java similarity index 76% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/OptionPageFrame.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/OptionPageFrame.java index 6c629ae5..60f6230f 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/OptionPageFrame.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/OptionPageFrame.java @@ -3,21 +3,21 @@ import me.flashyreese.mods.reeses_sodium_options.client.gui.Dim2iExtended; import me.flashyreese.mods.reeses_sodium_options.client.gui.OptionExtended; import me.flashyreese.mods.reeses_sodium_options.client.gui.Point2i; -import me.jellysquid.mods.sodium.client.gui.options.Option; -import me.jellysquid.mods.sodium.client.gui.options.OptionGroup; -import me.jellysquid.mods.sodium.client.gui.options.OptionImpact; -import me.jellysquid.mods.sodium.client.gui.options.OptionPage; -import me.jellysquid.mods.sodium.client.gui.options.control.Control; -import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.navigation.GuiNavigation; -import net.minecraft.client.gui.navigation.GuiNavigationPath; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Language; +import net.caffeinemc.mods.sodium.client.gui.options.Option; +import net.caffeinemc.mods.sodium.client.gui.options.OptionGroup; +import net.caffeinemc.mods.sodium.client.gui.options.OptionImpact; +import net.caffeinemc.mods.sodium.client.gui.options.OptionPage; +import net.caffeinemc.mods.sodium.client.gui.options.control.Control; +import net.caffeinemc.mods.sodium.client.gui.options.control.ControlElement; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ComponentPath; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.navigation.FocusNavigationEvent; +import net.minecraft.locale.Language; +import net.minecraft.network.chat.Component; +import net.minecraft.util.FormattedCharSequence; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.Nullable; @@ -97,7 +97,7 @@ public void buildFrame() { } @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { + public void render(GuiGraphics drawContext, int mouseX, int mouseY, float delta) { ControlElement hoveredElement = this.controlElements.stream() .filter(controlElement -> ((Dim2iExtended) (Object) controlElement.getDimensions()).overlapWith(this.originalDim)) .filter(ControlElement::isHovered) @@ -121,7 +121,7 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) } } - private void renderOptionTooltip(DrawContext drawContext, ControlElement element) { + private void renderOptionTooltip(GuiGraphics drawContext, ControlElement element) { if (this.lastTime + 500 > System.currentTimeMillis()) return; Dim2i dim = element.getDimensions(); @@ -136,12 +136,12 @@ private void renderOptionTooltip(DrawContext drawContext, ControlElement elem int boxX = dim.x(); Option option = element.getOption(); - List tooltip = new ArrayList<>(MinecraftClient.getInstance().textRenderer.wrapLines(option.getTooltip(), boxWidth - (textPadding * 2))); + List tooltip = new ArrayList<>(Minecraft.getInstance().font.split(option.getTooltip(), boxWidth - (textPadding * 2))); OptionImpact impact = option.getImpact(); if (impact != null) { - tooltip.add(Language.getInstance().reorder(Text.translatable("sodium.options.performance_impact_string", impact.getLocalizedName()).formatted(Formatting.GRAY))); + tooltip.add(Language.getInstance().getVisualOrder(Component.translatable("sodium.options.performance_impact_string", impact.getLocalizedName()).withStyle(ChatFormatting.GRAY))); } int boxHeight = (tooltip.size() * 12) + boxPadding; @@ -157,20 +157,20 @@ private void renderOptionTooltip(DrawContext drawContext, ControlElement elem boxY = dim.getLimitY(); } - drawContext.getMatrices().push(); - drawContext.getMatrices().translate(0, 0, 90); + drawContext.pose().pushPose(); + drawContext.pose().translate(0, 0, 90); this.drawRect(drawContext, boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0xE0000000); this.drawBorder(drawContext, boxX, boxY, boxX + boxWidth, boxY + boxHeight, 0xFF94E4D3); for (int i = 0; i < tooltip.size(); i++) { - drawContext.drawText(MinecraftClient.getInstance().textRenderer, tooltip.get(i), boxX + textPadding, boxY + textPadding + (i * 12), 0xFFFFFFFF, true); + drawContext.drawString(Minecraft.getInstance().font, tooltip.get(i), boxX + textPadding, boxY + textPadding + (i * 12), 0xFFFFFFFF, true); } - drawContext.getMatrices().pop(); + drawContext.pose().popPose(); } @Override - public @Nullable GuiNavigationPath getNavigationPath(GuiNavigation navigation) { - return super.getNavigationPath(navigation); + public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent navigation) { + return super.nextFocusPath(navigation); } public static class Builder { diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/ScrollableFrame.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/ScrollableFrame.java similarity index 93% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/ScrollableFrame.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/ScrollableFrame.java index eb0551de..8c453d1b 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/ScrollableFrame.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/ScrollableFrame.java @@ -2,11 +2,11 @@ import me.flashyreese.mods.reeses_sodium_options.client.gui.Dim2iExtended; import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.components.ScrollBarComponent; -import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.navigation.GuiNavigation; -import net.minecraft.client.gui.navigation.GuiNavigationPath; +import net.caffeinemc.mods.sodium.client.gui.options.control.ControlElement; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.client.gui.ComponentPath; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.navigation.FocusNavigationEvent; import org.jetbrains.annotations.Nullable; import java.util.concurrent.atomic.AtomicReference; @@ -133,7 +133,7 @@ public void buildFrame() { } @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { + public void render(GuiGraphics drawContext, int mouseX, int mouseY, float delta) { if (this.canScrollHorizontal || this.canScrollVertical) { if (this.renderOutline) { this.drawBorder(drawContext, this.dim.x(), this.dim.y(), this.dim.getLimitX(), this.dim.getLimitY(), 0xFFAAAAAA); @@ -153,9 +153,9 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) } @Override - public @Nullable GuiNavigationPath getNavigationPath(GuiNavigation navigation) { + public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent navigation) { //this.snapFocusedInViewport(); - return super.getNavigationPath(navigation); + return super.nextFocusPath(navigation); } @Override diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/ScrollBarComponent.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/ScrollBarComponent.java similarity index 86% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/ScrollBarComponent.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/ScrollBarComponent.java index 09b86b63..4b938507 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/ScrollBarComponent.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/ScrollBarComponent.java @@ -1,11 +1,12 @@ package me.flashyreese.mods.reeses_sodium_options.client.gui.frame.components; -import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.ScreenRect; -import net.minecraft.client.util.InputUtil; -import net.minecraft.util.math.MathHelper; + +import com.mojang.blaze3d.platform.InputConstants; +import net.caffeinemc.mods.sodium.client.gui.widgets.AbstractWidget; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.navigation.ScreenRectangle; +import net.minecraft.util.Mth; import java.util.function.Consumer; @@ -50,7 +51,7 @@ public void updateThumbPosition() { } @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { + public void render(GuiGraphics drawContext, int mouseX, int mouseY, float delta) { this.drawBorder(drawContext, this.dim.x(), this.dim.y(), this.dim.getLimitX(), this.dim.getLimitY(), 0xFFAAAAAA); //this.drawRectOutline(this.dim.x(), this.dim.y(), this.dim.getLimitX(), this.dim.getLimitY(), 0xFFAAAAAA); this.drawRect(drawContext, this.scrollThumb.x(), this.scrollThumb.y(), this.scrollThumb.getLimitX(), this.scrollThumb.getLimitY(), 0xFFAAAAAA); @@ -125,14 +126,14 @@ public int getOffset() { } public void setOffset(int value) { - this.offset = MathHelper.clamp(value, 0, this.maxScrollBarOffset); + this.offset = Mth.clamp(value, 0, this.maxScrollBarOffset); this.updateThumbPosition(); this.onSetOffset.accept(this.offset); } @Override - public ScreenRect getNavigationFocus() { - return new ScreenRect(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height()); + public ScreenRectangle getRectangle() { + return new ScreenRectangle(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height()); } @Override @@ -141,18 +142,18 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { return false; if (this.mode == Mode.VERTICAL) { - if (keyCode == InputUtil.GLFW_KEY_UP) { + if (keyCode == InputConstants.KEY_UP) { this.setOffset(this.getOffset() - SCROLL_OFFSET); return true; - } else if (keyCode == InputUtil.GLFW_KEY_DOWN) { + } else if (keyCode == InputConstants.KEY_DOWN) { this.setOffset(this.getOffset() + SCROLL_OFFSET); return true; } } else { - if (keyCode == InputUtil.GLFW_KEY_LEFT) { + if (keyCode == InputConstants.KEY_LEFT) { this.setOffset(this.getOffset() - SCROLL_OFFSET); return true; - } else if (keyCode == InputUtil.GLFW_KEY_RIGHT) { + } else if (keyCode == InputConstants.KEY_RIGHT) { this.setOffset(this.getOffset() + SCROLL_OFFSET); return true; } diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/SearchTextFieldComponent.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/SearchTextFieldComponent.java similarity index 81% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/SearchTextFieldComponent.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/SearchTextFieldComponent.java index 2a4761c5..a4ff626c 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/SearchTextFieldComponent.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/components/SearchTextFieldComponent.java @@ -3,24 +3,24 @@ import me.flashyreese.mods.reeses_sodium_options.client.gui.OptionExtended; import me.flashyreese.mods.reeses_sodium_options.client.gui.SodiumVideoOptionsScreen; import me.flashyreese.mods.reeses_sodium_options.util.StringUtils; -import me.jellysquid.mods.sodium.client.gui.options.Option; -import me.jellysquid.mods.sodium.client.gui.options.OptionPage; -import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget; -import me.jellysquid.mods.sodium.client.util.Dim2i; +import net.caffeinemc.mods.sodium.client.gui.options.Option; +import net.caffeinemc.mods.sodium.client.gui.options.OptionPage; +import net.caffeinemc.mods.sodium.client.gui.widgets.AbstractWidget; +import net.caffeinemc.mods.sodium.client.util.Dim2i; import net.minecraft.SharedConstants; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.ScreenRect; -import net.minecraft.client.gui.navigation.GuiNavigation; -import net.minecraft.client.gui.navigation.GuiNavigationPath; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.render.RenderLayer; -import net.minecraft.text.OrderedText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Util; -import net.minecraft.util.math.MathHelper; +import net.minecraft.Util; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ComponentPath; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.navigation.FocusNavigationEvent; +import net.minecraft.client.gui.navigation.ScreenRectangle; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -33,10 +33,10 @@ public class SearchTextFieldComponent extends AbstractWidget { protected final Dim2i dim; protected final List pages; - private final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; + private final Font textRenderer = Minecraft.getInstance().font; private final Predicate textPredicate = Objects::nonNull; - private final BiFunction renderTextProvider = (string, firstCharacterIndex) -> OrderedText.styledForwardsVisitedString(string, Style.EMPTY); - private final AtomicReference tabFrameSelectedTab; + private final BiFunction renderTextProvider = (string, firstCharacterIndex) -> FormattedCharSequence.forward(string, Style.EMPTY); + private final AtomicReference tabFrameSelectedTab; private final AtomicReference tabFrameScrollBarOffset; private final AtomicReference optionPageScrollBarOffset; private final int tabDimHeight; @@ -53,7 +53,7 @@ public class SearchTextFieldComponent extends AbstractWidget { private int selectionEnd; private int lastCursorPosition = this.getCursor(); - public SearchTextFieldComponent(Dim2i dim, List pages, AtomicReference tabFrameSelectedTab, AtomicReference tabFrameScrollBarOffset, AtomicReference optionPageScrollBarOffset, int tabDimHeight, SodiumVideoOptionsScreen sodiumVideoOptionsScreen, AtomicReference lastSearch, AtomicReference lastSearchIndex) { + public SearchTextFieldComponent(Dim2i dim, List pages, AtomicReference tabFrameSelectedTab, AtomicReference tabFrameScrollBarOffset, AtomicReference optionPageScrollBarOffset, int tabDimHeight, SodiumVideoOptionsScreen sodiumVideoOptionsScreen, AtomicReference lastSearch, AtomicReference lastSearchIndex) { this.dim = dim; this.pages = pages; this.tabFrameSelectedTab = tabFrameSelectedTab; @@ -69,22 +69,22 @@ public SearchTextFieldComponent(Dim2i dim, List pages, AtomicReferen } @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { + public void render(GuiGraphics context, int mouseX, int mouseY, float delta) { if (!this.isVisible()) { return; } if (!this.isFocused() && this.text.isBlank()) { String key = "rso.search_bar_empty"; - Text text = Text.translatable(key); + Component text = Component.translatable(key); if (text.getString().equals(key)) - text = Text.literal("Search options..."); + text = Component.literal("Search options..."); this.drawString(context, text, this.dim.x() + 6, this.dim.y() + 6, 0xFFAAAAAA); } this.drawRect(context, this.dim.x(), this.dim.y(), this.dim.getLimitX(), this.dim.getLimitY(), this.isFocused() ? 0xE0000000 : 0x90000000); int j = this.selectionStart - this.firstCharacterIndex; int k = this.selectionEnd - this.firstCharacterIndex; - String string = this.textRenderer.trimToWidth(this.text.substring(this.firstCharacterIndex), this.getInnerWidth()); + String string = this.textRenderer.plainSubstrByWidth(this.text.substring(this.firstCharacterIndex), this.getInnerWidth()); boolean bl = j >= 0 && j <= string.length(); int l = this.dim.x() + 6; int m = this.dim.y() + 6; @@ -94,7 +94,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { } if (!string.isEmpty()) { String string2 = bl ? string.substring(0, j) : string; - n = context.drawTextWithShadow(this.textRenderer, this.renderTextProvider.apply(string2, this.firstCharacterIndex), n, m, 0xFFFFFFFF); + n = context.drawString(this.textRenderer, this.renderTextProvider.apply(string2, this.firstCharacterIndex), n, m, 0xFFFFFFFF); } boolean bl3 = this.selectionStart < this.text.length() || this.text.length() >= this.getMaxLength(); int o = n; @@ -105,16 +105,16 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { --n; } if (!string.isEmpty() && bl && j < string.length()) { - context.drawTextWithShadow(this.textRenderer, this.renderTextProvider.apply(string.substring(j), this.selectionStart), n, m, 0xFFFFFFFF); + context.drawString(this.textRenderer, this.renderTextProvider.apply(string.substring(j), this.selectionStart), n, m, 0xFFFFFFFF); } // Cursor if (this.isFocused()) { - context.fill(RenderLayer.getGuiOverlay(), o, m - 1, o + 1, m + 1 + this.textRenderer.fontHeight, -3092272); + context.fill(RenderType.guiOverlay(), o, m - 1, o + 1, m + 1 + this.textRenderer.lineHeight, -3092272); } // Highlighted text if (k != j) { - int p = l + this.textRenderer.getWidth(string.substring(0, k)); - this.drawSelectionHighlight(context, o, m - 1, p - 1, m + 1 + this.textRenderer.fontHeight); + int p = l + this.textRenderer.width(string.substring(0, k)); + this.drawSelectionHighlight(context, o, m - 1, p - 1, m + 1 + this.textRenderer.lineHeight); } /*this.drawRect(context, this.dim.x(), this.dim.y(), this.dim.getLimitX(), this.dim.getLimitY(), 0x90000000); @@ -124,9 +124,9 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { - int i = MathHelper.floor(mouseX) - this.dim.x() - 6; - String string = this.textRenderer.trimToWidth(this.text.substring(this.firstCharacterIndex), this.getInnerWidth()); - this.setCursor(this.textRenderer.trimToWidth(string, i).length() + this.firstCharacterIndex); + int i = Mth.floor(mouseX) - this.dim.x() - 6; + String string = this.textRenderer.plainSubstrByWidth(this.text.substring(this.firstCharacterIndex), this.getInnerWidth()); + this.setCursor(this.textRenderer.plainSubstrByWidth(string, i).length() + this.firstCharacterIndex); this.setFocused(this.dim.containsCursor(mouseX, mouseY)); this.pages.forEach(page -> page @@ -144,7 +144,7 @@ public void setFocused(boolean focused) { this.focused = focused; } - private void drawSelectionHighlight(DrawContext context, int x1, int y1, int x2, int y2) { + private void drawSelectionHighlight(GuiGraphics context, int x1, int y1, int x2, int y2) { int i; if (x1 < x2) { i = x1; @@ -162,7 +162,7 @@ private void drawSelectionHighlight(DrawContext context, int x1, int y1, int x2, if (x1 > this.dim.x() + this.dim.width()) { x1 = this.dim.x() + this.dim.width(); } - context.fill(RenderLayer.getGuiTextHighlight(), x1, y1, x2, y2, -16776961); + context.fill(RenderType.guiTextHighlight(), x1, y1, x2, y2, -16776961); } private int getMaxLength() { @@ -181,7 +181,7 @@ public void write(String text) { int i = Math.min(this.selectionStart, this.selectionEnd); int j = Math.max(this.selectionStart, this.selectionEnd); int k = this.maxLength - this.text.length() - (i - j); - String string = SharedConstants.stripInvalidChars(text); + String string = SharedConstants.filterText(text); int l = string.length(); if (k < l) { string = string.substring(0, k); @@ -312,11 +312,11 @@ public void moveCursor(int offset) { } private int getCursorPosWithOffset(int offset) { - return Util.moveCursor(this.text, this.selectionStart, offset); + return Util.offsetByCodepoints(this.text, this.selectionStart, offset); } public void setSelectionStart(int cursor) { - this.selectionStart = MathHelper.clamp(cursor, 0, this.text.length()); + this.selectionStart = Mth.clamp(cursor, 0, this.text.length()); } public void setCursorToStart() { @@ -329,17 +329,17 @@ public void setCursorToEnd() { public void setSelectionEnd(int index) { int i = this.text.length(); - this.selectionEnd = MathHelper.clamp(index, 0, i); + this.selectionEnd = Mth.clamp(index, 0, i); if (this.textRenderer != null) { if (this.firstCharacterIndex > i) { this.firstCharacterIndex = i; } int j = this.getInnerWidth(); - String string = this.textRenderer.trimToWidth(this.text.substring(this.firstCharacterIndex), j); + String string = this.textRenderer.plainSubstrByWidth(this.text.substring(this.firstCharacterIndex), j); int k = string.length() + this.firstCharacterIndex; if (this.selectionEnd == this.firstCharacterIndex) { - this.firstCharacterIndex -= this.textRenderer.trimToWidth(this.text, j, true).length(); + this.firstCharacterIndex -= this.textRenderer.plainSubstrByWidth(this.text, j, true).length(); } if (this.selectionEnd > k) { @@ -348,7 +348,7 @@ public void setSelectionEnd(int index) { this.firstCharacterIndex -= this.firstCharacterIndex - this.selectionEnd; } - this.firstCharacterIndex = MathHelper.clamp(this.firstCharacterIndex, 0, i); + this.firstCharacterIndex = Mth.clamp(this.firstCharacterIndex, 0, i); } } @@ -361,7 +361,7 @@ public boolean charTyped(char chr, int modifiers) { if (!this.isActive()) { return false; } - if (SharedConstants.isValidChar(chr)) { + if (SharedConstants.isAllowedChatCharacter(chr)) { if (this.editable) { this.lastSearch.set(this.text.trim()); this.write(Character.toString(chr)); @@ -389,16 +389,16 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { this.setSelectionEnd(0); return true; } else if (Screen.isCopy(keyCode)) { - MinecraftClient.getInstance().keyboard.setClipboard(this.getSelectedText()); + Minecraft.getInstance().keyboardHandler.setClipboard(this.getSelectedText()); return true; } else if (Screen.isPaste(keyCode)) { if (this.editable) { - this.write(MinecraftClient.getInstance().keyboard.getClipboard()); + this.write(Minecraft.getInstance().keyboardHandler.getClipboard()); } return true; } else if (Screen.isCut(keyCode)) { - MinecraftClient.getInstance().keyboard.setClipboard(this.getSelectedText()); + Minecraft.getInstance().keyboardHandler.setClipboard(this.getSelectedText()); if (this.editable) { this.write(""); } @@ -508,14 +508,14 @@ public int getInnerWidth() { } @Override - public @Nullable GuiNavigationPath getNavigationPath(GuiNavigation navigation) { + public @Nullable ComponentPath nextFocusPath(FocusNavigationEvent navigation) { if (!this.visible) return null; - return super.getNavigationPath(navigation); + return super.nextFocusPath(navigation); } @Override - public ScreenRect getNavigationFocus() { - return new ScreenRect(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height()); + public ScreenRectangle getRectangle() { + return new ScreenRectangle(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height()); } } \ No newline at end of file diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/Tab.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/Tab.java similarity index 79% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/Tab.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/Tab.java index 3d8eb810..330204dd 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/Tab.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/Tab.java @@ -3,20 +3,20 @@ import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.AbstractFrame; import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.OptionPageFrame; import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.ScrollableFrame; -import me.jellysquid.mods.sodium.client.gui.options.OptionPage; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.minecraft.text.Text; +import net.caffeinemc.mods.sodium.client.gui.options.OptionPage; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.network.chat.Component; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; -public record Tab(Text title, Function frameFunction) { +public record Tab(Component title, Function frameFunction) { public static Tab.Builder createBuilder() { return new Tab.Builder<>(); } - public Text getTitle() { + public Component getTitle() { return title; } @@ -25,10 +25,10 @@ public Function getFrameFunction() { } public static class Builder { - private Text title; + private Component title; private Function frameFunction; - public Builder setTitle(Text title) { + public Builder setTitle(Component title) { this.title = title; return this; } diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/TabFrame.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/TabFrame.java similarity index 92% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/TabFrame.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/TabFrame.java index 40cfa967..bc085df5 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/TabFrame.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/client/gui/frame/tab/TabFrame.java @@ -5,12 +5,11 @@ import me.flashyreese.mods.reeses_sodium_options.client.gui.Point2i; import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.AbstractFrame; import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.components.ScrollBarComponent; -import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement; -import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget; -import me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.Text; +import net.caffeinemc.mods.sodium.client.gui.widgets.AbstractWidget; +import net.caffeinemc.mods.sodium.client.gui.widgets.FlatButtonWidget; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; import java.util.ArrayList; @@ -26,12 +25,12 @@ public class TabFrame extends AbstractFrame { private final Dim2i frameSection; private final List> tabs = new ArrayList<>(); private final Runnable onSetTab; - private final AtomicReference tabSectionSelectedTab; + private final AtomicReference tabSectionSelectedTab; private ScrollBarComponent tabSectionScrollBar = null; private Tab selectedTab; private AbstractFrame selectedFrame; - public TabFrame(Dim2i dim, boolean renderOutline, List> tabs, Runnable onSetTab, AtomicReference tabSectionSelectedTab, AtomicReference tabSectionScrollBarOffset) { + public TabFrame(Dim2i dim, boolean renderOutline, List> tabs, Runnable onSetTab, AtomicReference tabSectionSelectedTab, AtomicReference tabSectionScrollBarOffset) { super(dim, renderOutline); this.tabs.addAll(tabs); int tabSectionY = this.tabs.size() * 18; @@ -143,7 +142,7 @@ private void rebuildTabFrame() { } @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { + public void render(GuiGraphics drawContext, int mouseX, int mouseY, float delta) { this.applyScissor(this.dim.x(), this.dim.y(), this.dim.width(), this.dim.height(), () -> { for (AbstractWidget widget : this.children) { if (widget != this.selectedFrame) { @@ -182,7 +181,7 @@ public static class Builder { private Dim2i dim; private boolean renderOutline; private Runnable onSetTab; - private AtomicReference tabSectionSelectedTab = new AtomicReference<>(null); + private AtomicReference tabSectionSelectedTab = new AtomicReference<>(null); private AtomicReference tabSectionScrollBarOffset = new AtomicReference<>(0); public Builder setDimension(Dim2i dim) { @@ -205,7 +204,7 @@ public Builder onSetTab(Runnable onSetTab) { return this; } - public Builder setTabSectionSelectedTab(AtomicReference tabSectionSelectedTab) { + public Builder setTabSectionSelectedTab(AtomicReference tabSectionSelectedTab) { this.tabSectionSelectedTab = tabSectionSelectedTab; return this; } diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/compat/IrisCompat.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/compat/IrisCompat.java similarity index 97% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/compat/IrisCompat.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/compat/IrisCompat.java index 0cd71107..cd2e3c51 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/compat/IrisCompat.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/compat/IrisCompat.java @@ -1,6 +1,7 @@ package me.flashyreese.mods.reeses_sodium_options.compat; -import net.minecraft.client.gui.screen.Screen; + +import net.minecraft.client.gui.screens.Screen; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinControlElement.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinControlElement.java similarity index 52% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinControlElement.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinControlElement.java index 256d3476..f1c6e806 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinControlElement.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinControlElement.java @@ -1,14 +1,14 @@ package me.flashyreese.mods.reeses_sodium_options.mixin.sodium; import me.flashyreese.mods.reeses_sodium_options.client.gui.OptionExtended; -import me.jellysquid.mods.sodium.client.gui.options.Option; -import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement; -import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.screen.narration.NarrationPart; -import net.minecraft.util.Formatting; +import net.caffeinemc.mods.sodium.client.gui.options.Option; +import net.caffeinemc.mods.sodium.client.gui.options.control.ControlElement; +import net.caffeinemc.mods.sodium.client.gui.widgets.AbstractWidget; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.narration.NarratedElementType; +import net.minecraft.client.gui.narration.NarrationElementOutput; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -33,28 +33,29 @@ public void postInit(Option option, Dim2i dim, CallbackInfo ci) { } } - @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/gui/options/control/ControlElement;drawString(Lnet/minecraft/client/gui/DrawContext;Ljava/lang/String;III)V")) - public void drawString(ControlElement instance, DrawContext drawContext, String s, int x, int y, int color) { + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/gui/options/control/ControlElement;drawString(Lnet/minecraft/client/gui/GuiGraphics;Ljava/lang/String;III)V")) + public void drawString(ControlElement instance, GuiGraphics drawContext, String s, int x, int y, int color) { if (this.option instanceof OptionExtended optionExtended && optionExtended.isHighlight()) { - String replacement = optionExtended.getSelected() ? Formatting.DARK_GREEN.toString() : Formatting.YELLOW.toString(); + String replacement = optionExtended.getSelected() ? ChatFormatting.DARK_GREEN.toString() : ChatFormatting.YELLOW.toString(); - s = s.replace(Formatting.WHITE.toString(), Formatting.WHITE + replacement); - s = s.replace(Formatting.STRIKETHROUGH.toString(), Formatting.STRIKETHROUGH + replacement); - s = s.replace(Formatting.ITALIC.toString(), Formatting.ITALIC + replacement); + s = s.replace(ChatFormatting.WHITE.toString(), ChatFormatting.WHITE + replacement); + s = s.replace(ChatFormatting.STRIKETHROUGH.toString(), ChatFormatting.STRIKETHROUGH + replacement); + s = s.replace(ChatFormatting.ITALIC.toString(), ChatFormatting.ITALIC + replacement); } this.drawString(drawContext, s, x, y, color); } - @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/util/Dim2i;containsCursor(DD)Z")) + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/util/Dim2i;containsCursor(DD)Z")) public boolean render(Dim2i dim2i, double x, double y) { return this.isMouseOver(x, y); } + @Override - public void appendNarrations(NarrationMessageBuilder builder) { - builder.put(NarrationPart.TITLE, this.option.getName()); - super.appendNarrations(builder); + public void updateNarration(NarrationElementOutput builder) { + builder.add(NarratedElementType.TITLE, this.option.getName()); + super.updateNarration(builder); } @Override diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinCyclingControlElement.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinCyclingControlElement.java similarity index 74% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinCyclingControlElement.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinCyclingControlElement.java index 1396d246..84ba4cd2 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinCyclingControlElement.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinCyclingControlElement.java @@ -1,13 +1,13 @@ package me.flashyreese.mods.reeses_sodium_options.mixin.sodium; -import me.jellysquid.mods.sodium.client.gui.options.Option; -import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement; -import me.jellysquid.mods.sodium.client.util.Dim2i; +import net.caffeinemc.mods.sodium.client.gui.options.Option; +import net.caffeinemc.mods.sodium.client.gui.options.control.ControlElement; +import net.caffeinemc.mods.sodium.client.util.Dim2i; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -@Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.control.CyclingControl$CyclingControlElement") +@Mixin(targets = "net.caffeinemc.mods.sodium.client.gui.options.control.CyclingControl$CyclingControlElement") public abstract class MixinCyclingControlElement> extends ControlElement { @Shadow diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinDim2i.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinDim2i.java similarity index 95% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinDim2i.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinDim2i.java index 9120df06..a5c9c57c 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinDim2i.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinDim2i.java @@ -2,7 +2,7 @@ import me.flashyreese.mods.reeses_sodium_options.client.gui.Dim2iExtended; import me.flashyreese.mods.reeses_sodium_options.client.gui.Point2i; -import me.jellysquid.mods.sodium.client.util.Dim2i; +import net.caffeinemc.mods.sodium.client.util.Dim2i; import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinFlatButtonWidget.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinFlatButtonWidget.java similarity index 63% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinFlatButtonWidget.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinFlatButtonWidget.java index e2637d7d..173dfc90 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinFlatButtonWidget.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinFlatButtonWidget.java @@ -1,11 +1,11 @@ package me.flashyreese.mods.reeses_sodium_options.mixin.sodium; import me.flashyreese.mods.reeses_sodium_options.client.gui.FlatButtonWidgetExtended; -import me.jellysquid.mods.sodium.client.gui.widgets.AbstractWidget; -import me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.text.Text; +import net.caffeinemc.mods.sodium.client.gui.widgets.AbstractWidget; +import net.caffeinemc.mods.sodium.client.gui.widgets.FlatButtonWidget; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -23,8 +23,8 @@ public abstract class MixinFlatButtonWidget extends AbstractWidget implements Fl @Unique private boolean leftAligned; - @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/gui/widgets/FlatButtonWidget;drawString(Lnet/minecraft/client/gui/DrawContext;Lnet/minecraft/text/Text;III)V")) - public void redirectDrawString(FlatButtonWidget instance, DrawContext drawContext, Text text, int x, int y, int color) { + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/gui/widgets/FlatButtonWidget;drawString(Lnet/minecraft/client/gui/GuiGraphics;Lnet/minecraft/network/chat/Component;III)V")) + public void redirectDrawString(FlatButtonWidget instance, GuiGraphics drawContext, Component text, int x, int y, int color) { if (this.leftAligned) { this.drawString(drawContext, text, this.dim.x() + 10, y, color); } else { @@ -32,8 +32,8 @@ public void redirectDrawString(FlatButtonWidget instance, DrawContext drawContex } } - @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/gui/widgets/FlatButtonWidget;drawRect(Lnet/minecraft/client/gui/DrawContext;IIIII)V", ordinal = 1)) - public void redirectDrawRect(FlatButtonWidget instance, DrawContext drawContext, int x1, int y1, int x2, int y2, int color) { + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/gui/widgets/FlatButtonWidget;drawRect(Lnet/minecraft/client/gui/GuiGraphics;IIIII)V", ordinal = 1)) + public void redirectDrawRect(FlatButtonWidget instance, GuiGraphics drawContext, int x1, int y1, int x2, int y2, int color) { if (this.leftAligned) { this.drawRect(drawContext, x1, this.dim.y(), x1 + 1, y2, color); } else { diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinOptionImpl.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinOptionImpl.java similarity index 91% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinOptionImpl.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinOptionImpl.java index b2f6beb3..ea5859af 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinOptionImpl.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinOptionImpl.java @@ -1,8 +1,8 @@ package me.flashyreese.mods.reeses_sodium_options.mixin.sodium; import me.flashyreese.mods.reeses_sodium_options.client.gui.OptionExtended; -import me.jellysquid.mods.sodium.client.gui.options.OptionImpl; -import me.jellysquid.mods.sodium.client.util.Dim2i; +import net.caffeinemc.mods.sodium.client.gui.options.OptionImpl; +import net.caffeinemc.mods.sodium.client.util.Dim2i; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSliderControlElement.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSliderControlElement.java similarity index 74% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSliderControlElement.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSliderControlElement.java index d113c66a..85d2d0fd 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSliderControlElement.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSliderControlElement.java @@ -1,15 +1,15 @@ package me.flashyreese.mods.reeses_sodium_options.mixin.sodium; +import com.mojang.blaze3d.platform.InputConstants; import me.flashyreese.mods.reeses_sodium_options.client.gui.SliderControlElementExtended; -import me.jellysquid.mods.sodium.client.gui.options.Option; -import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement; -import me.jellysquid.mods.sodium.client.gui.options.control.ControlValueFormatter; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.InputUtil; -import net.minecraft.client.util.math.Rect2i; -import net.minecraft.util.math.MathHelper; +import net.caffeinemc.mods.sodium.client.gui.options.Option; +import net.caffeinemc.mods.sodium.client.gui.options.control.ControlElement; +import net.caffeinemc.mods.sodium.client.gui.options.control.ControlValueFormatter; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.renderer.Rect2i; +import net.minecraft.util.Mth; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -19,7 +19,7 @@ import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.control.SliderControl$Button") +@Mixin(targets = "net.caffeinemc.mods.sodium.client.gui.options.control.SliderControl$Button") public abstract class MixinSliderControlElement extends ControlElement implements SliderControlElementExtended { @Shadow @@ -76,35 +76,35 @@ private Dim2i getSliderBounds() { // fixme: insanity } @Inject(method = "renderSlider", at = @At(value = "TAIL")) - public void rso$renderSlider(DrawContext drawContext, CallbackInfo ci) { + public void rso$renderSlider(GuiGraphics drawContext, CallbackInfo ci) { int sliderX = this.getSliderBounds().x(); int sliderY = this.getSliderBounds().y(); int sliderWidth = this.getSliderBounds().width(); int sliderHeight = this.getSliderBounds().height(); this.thumbPosition = this.getThumbPositionForValue(this.option.getValue()); - double thumbOffset = MathHelper.clamp((double) (this.getIntValue() - this.min) / (double) this.range * (double) sliderWidth, 0.0, sliderWidth); + double thumbOffset = Mth.clamp((double) (this.getIntValue() - this.min) / (double) this.range * (double) sliderWidth, 0.0, sliderWidth); double thumbX = (double) sliderX + thumbOffset - 2.0; if (this.isFocused() && this.isEditMode()) { this.drawRect(drawContext, (int) (thumbX - 1), sliderY - 1, (int) (thumbX + 5), sliderY + sliderHeight + 1, 0xFFFFFFFF); } } - @Redirect(method = "renderStandaloneValue", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/Rect2i;getX()I")) + @Redirect(method = "renderStandaloneValue", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Rect2i;getX()I")) public int rso$renderStandaloneValueSliderBoundsGetX(Rect2i instance) { return this.getSliderBounds().x(); } - @Redirect(method = "renderStandaloneValue", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/Rect2i;getY()I")) + @Redirect(method = "renderStandaloneValue", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Rect2i;getY()I")) public int renderStandaloneValueSliderBoundsGetY(Rect2i instance) { return this.getSliderBounds().y(); } - @Redirect(method = "renderSlider", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/Rect2i;getX()I")) + @Redirect(method = "renderSlider", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Rect2i;getX()I")) public int rso$renderSliderSliderBoundsGetX(Rect2i instance) { return this.getSliderBounds().x(); } - @Redirect(method = "renderSlider", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/Rect2i;getY()I")) + @Redirect(method = "renderSlider", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Rect2i;getY()I")) public int rso$renderSliderSliderBoundsGetY(Rect2i instance) { return this.getSliderBounds().y(); } @@ -113,17 +113,17 @@ public int renderStandaloneValueSliderBoundsGetY(Rect2i instance) { public boolean keyPressed(int keyCode, int scanCode, int modifiers) { if (!isFocused()) return false; - if (keyCode == InputUtil.GLFW_KEY_ENTER) { + if (keyCode == InputConstants.KEY_RETURN) { this.setEditMode(!this.isEditMode());; return true; } if (this.isEditMode()) { - if (keyCode == InputUtil.GLFW_KEY_LEFT) { - this.option.setValue(MathHelper.clamp(this.option.getValue() - interval, min, max)); + if (keyCode == InputConstants.KEY_LEFT) { + this.option.setValue(Mth.clamp(this.option.getValue() - interval, min, max)); return true; - } else if (keyCode == InputUtil.GLFW_KEY_RIGHT) { - this.option.setValue(MathHelper.clamp(this.option.getValue() + interval, min, max)); + } else if (keyCode == InputConstants.KEY_RIGHT) { + this.option.setValue(Mth.clamp(this.option.getValue() + interval, min, max)); return true; } } @@ -137,7 +137,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { ci.cancel(); } - @Redirect(method = "mouseClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/Rect2i;contains(II)Z")) + @Redirect(method = "mouseClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Rect2i;contains(II)Z")) public boolean rso$mouseClicked(Rect2i instance, int x, int y) { return this.getSliderBounds().containsCursor(x, y); } diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSodiumOptionsGUI.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSodiumOptionsGUI.java similarity index 66% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSodiumOptionsGUI.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSodiumOptionsGUI.java index 2b99aa57..fdbf545c 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSodiumOptionsGUI.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinSodiumOptionsGUI.java @@ -1,10 +1,10 @@ package me.flashyreese.mods.reeses_sodium_options.mixin.sodium; import me.flashyreese.mods.reeses_sodium_options.client.gui.SodiumVideoOptionsScreen; -import me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI; -import me.jellysquid.mods.sodium.client.gui.options.OptionPage; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; +import net.caffeinemc.mods.sodium.client.gui.SodiumOptionsGUI; +import net.caffeinemc.mods.sodium.client.gui.options.OptionPage; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -25,12 +25,12 @@ public abstract class MixinSodiumOptionsGUI extends Screen { @Final private Screen prevScreen; - protected MixinSodiumOptionsGUI(Text title) { + protected MixinSodiumOptionsGUI(Component title) { super(title); } @Inject(method = "init", at = @At("TAIL")) public void postInit(CallbackInfo ci) { - this.client.setScreen(new SodiumVideoOptionsScreen(this.prevScreen, this.pages)); + this.minecraft.setScreen(new SodiumVideoOptionsScreen(this.prevScreen, this.pages)); } } diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinTickBoxControlElement.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinTickBoxControlElement.java similarity index 62% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinTickBoxControlElement.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinTickBoxControlElement.java index 77091651..ed0de957 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinTickBoxControlElement.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/mixin/sodium/MixinTickBoxControlElement.java @@ -1,25 +1,25 @@ package me.flashyreese.mods.reeses_sodium_options.mixin.sodium; -import me.jellysquid.mods.sodium.client.gui.options.Option; -import me.jellysquid.mods.sodium.client.gui.options.control.ControlElement; -import me.jellysquid.mods.sodium.client.util.Dim2i; -import net.minecraft.client.util.math.Rect2i; +import net.caffeinemc.mods.sodium.client.gui.options.Option; +import net.caffeinemc.mods.sodium.client.gui.options.control.ControlElement; +import net.caffeinemc.mods.sodium.client.util.Dim2i; +import net.minecraft.client.renderer.Rect2i; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -@Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.control.TickBoxControl$TickBoxControlElement") +@Mixin(targets = "net.caffeinemc.mods.sodium.client.gui.options.control.TickBoxControl$TickBoxControlElement") public abstract class MixinTickBoxControlElement extends ControlElement { public MixinTickBoxControlElement(Option option, Dim2i dim) { super(option, dim); } - @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/Rect2i;getX()I")) + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Rect2i;getX()I")) public int rso$renderSliderBoundsGetX(Rect2i instance) { return this.dim.getLimitX() - 16; } - @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/Rect2i;getY()I")) + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Rect2i;getY()I")) public int rso$renderSliderBoundsGetY(Rect2i instance) { return this.dim.getCenterY() - 5; } diff --git a/src/main/java/me/flashyreese/mods/reeses_sodium_options/util/StringUtils.java b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/util/StringUtils.java similarity index 95% rename from src/main/java/me/flashyreese/mods/reeses_sodium_options/util/StringUtils.java rename to common/src/main/java/me/flashyreese/mods/reeses_sodium_options/util/StringUtils.java index 4ce66051..662ff716 100644 --- a/src/main/java/me/flashyreese/mods/reeses_sodium_options/util/StringUtils.java +++ b/common/src/main/java/me/flashyreese/mods/reeses_sodium_options/util/StringUtils.java @@ -1,7 +1,7 @@ package me.flashyreese.mods.reeses_sodium_options.util; -import me.jellysquid.mods.sodium.client.gui.options.Option; -import me.jellysquid.mods.sodium.client.gui.options.OptionPage; +import net.caffeinemc.mods.sodium.client.gui.options.Option; +import net.caffeinemc.mods.sodium.client.gui.options.OptionPage; import java.util.ArrayList; import java.util.List; diff --git a/src/main/resources/assets/reeses-sodium-options/lang/be_by.json b/common/src/main/resources/assets/reeses-sodium-options/lang/be_by.json similarity index 100% rename from src/main/resources/assets/reeses-sodium-options/lang/be_by.json rename to common/src/main/resources/assets/reeses-sodium-options/lang/be_by.json diff --git a/src/main/resources/assets/reeses-sodium-options/lang/en_us.json b/common/src/main/resources/assets/reeses-sodium-options/lang/en_us.json similarity index 100% rename from src/main/resources/assets/reeses-sodium-options/lang/en_us.json rename to common/src/main/resources/assets/reeses-sodium-options/lang/en_us.json diff --git a/src/main/resources/assets/reeses-sodium-options/lang/es_mx.json b/common/src/main/resources/assets/reeses-sodium-options/lang/es_mx.json similarity index 100% rename from src/main/resources/assets/reeses-sodium-options/lang/es_mx.json rename to common/src/main/resources/assets/reeses-sodium-options/lang/es_mx.json diff --git a/src/main/resources/assets/reeses-sodium-options/lang/it_it.json b/common/src/main/resources/assets/reeses-sodium-options/lang/it_it.json similarity index 100% rename from src/main/resources/assets/reeses-sodium-options/lang/it_it.json rename to common/src/main/resources/assets/reeses-sodium-options/lang/it_it.json diff --git a/src/main/resources/assets/reeses-sodium-options/lang/pl_pl.json b/common/src/main/resources/assets/reeses-sodium-options/lang/pl_pl.json similarity index 100% rename from src/main/resources/assets/reeses-sodium-options/lang/pl_pl.json rename to common/src/main/resources/assets/reeses-sodium-options/lang/pl_pl.json diff --git a/src/main/resources/assets/reeses-sodium-options/lang/pt_br.json b/common/src/main/resources/assets/reeses-sodium-options/lang/pt_br.json similarity index 100% rename from src/main/resources/assets/reeses-sodium-options/lang/pt_br.json rename to common/src/main/resources/assets/reeses-sodium-options/lang/pt_br.json diff --git a/src/main/resources/assets/reeses-sodium-options/lang/ru_ru.json b/common/src/main/resources/assets/reeses-sodium-options/lang/ru_ru.json similarity index 100% rename from src/main/resources/assets/reeses-sodium-options/lang/ru_ru.json rename to common/src/main/resources/assets/reeses-sodium-options/lang/ru_ru.json diff --git a/src/main/resources/assets/reeses-sodium-options/lang/vi_vn.json b/common/src/main/resources/assets/reeses-sodium-options/lang/vi_vn.json similarity index 100% rename from src/main/resources/assets/reeses-sodium-options/lang/vi_vn.json rename to common/src/main/resources/assets/reeses-sodium-options/lang/vi_vn.json diff --git a/src/main/resources/assets/reeses-sodium-options/lang/zh_cn.json b/common/src/main/resources/assets/reeses-sodium-options/lang/zh_cn.json similarity index 100% rename from src/main/resources/assets/reeses-sodium-options/lang/zh_cn.json rename to common/src/main/resources/assets/reeses-sodium-options/lang/zh_cn.json diff --git a/src/main/resources/assets/reeses-sodium-options/lang/zh_tw.json b/common/src/main/resources/assets/reeses-sodium-options/lang/zh_tw.json similarity index 100% rename from src/main/resources/assets/reeses-sodium-options/lang/zh_tw.json rename to common/src/main/resources/assets/reeses-sodium-options/lang/zh_tw.json diff --git a/src/main/resources/reeses-sodium-options.mixins.json b/common/src/main/resources/reeses-sodium-options.mixins.json similarity index 100% rename from src/main/resources/reeses-sodium-options.mixins.json rename to common/src/main/resources/reeses-sodium-options.mixins.json diff --git a/src/main/resources/assets/reeses-sodium-options/icon.png b/common/src/main/resources/rso-icon.png similarity index 100% rename from src/main/resources/assets/reeses-sodium-options/icon.png rename to common/src/main/resources/rso-icon.png diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts new file mode 100644 index 00000000..7ea3aad9 --- /dev/null +++ b/fabric/build.gradle.kts @@ -0,0 +1,96 @@ +plugins { + java + idea + `maven-publish` + id("fabric-loom") version("1.6.5") +} + +val MINECRAFT_VERSION: String by rootProject.extra +val FABRIC_LOADER_VERSION: String by rootProject.extra +val FABRIC_API_VERSION: String by rootProject.extra +val MOD_VERSION: String by rootProject.extra + + +base { + archivesName.set("reeses-sodium-options-fabric-${MINECRAFT_VERSION}") +} + +dependencies { + minecraft("com.mojang:minecraft:${MINECRAFT_VERSION}") + mappings(loom.officialMojangMappings()) + modImplementation("net.fabricmc:fabric-loader:$FABRIC_LOADER_VERSION") + + modImplementation(group = "net.caffeinemc.mods", name = "common", version = "0.6.0-snapshot+mc1.20.4-local") + modImplementation(group = "net.caffeinemc.mods", name = "sodium-fabric-1.20.4", version = "0.6.0-snapshot+mc1.20.4-local") + compileOnly(project(":common")) + modImplementation("net.fabricmc.fabric-api:fabric-api:0.96.11+1.20.4") +} + +loom { + @Suppress("UnstableApiUsage") + mixin { defaultRefmapName.set("sodium.refmap.json") } + + runs { + named("client") { + client() + configName = "Fabric Client" + ideConfigGenerated(true) + runDir("run") + } + named("server") { + server() + configName = "Fabric Server" + ideConfigGenerated(true) + runDir("run") + } + } +} + +tasks { + withType { + source(project(":common").sourceSets.main.get().allSource) + } + + javadoc { source(project(":common").sourceSets.main.get().allJava) } + + processResources { + from(project(":common").sourceSets.main.get().resources) { + exclude("sodium.accesswidener") + } + + inputs.property("version", project.version) + + filesMatching("fabric.mod.json") { + expand(mapOf("version" to project.version)) + } + } +} + +publishing { + publications { + register("mavenJava", MavenPublication::class) { + artifactId = base.archivesName.get() + from(components["java"]) + } + } + + repositories { + maven { + name = "FlashyReeseReleases" + url = uri("https://maven.flashyreese.me/releases") + credentials { + username = System.getenv("MAVEN_USERNAME") + password = System.getenv("MAVEN_PASSWORD") + } + } + maven { + name = "FlashyReeseSnapshots" + url = uri("https://maven.flashyreese.me/snapshots") + credentials { + username = System.getenv("MAVEN_USERNAME") + password = System.getenv("MAVEN_PASSWORD") + } + } + maven("file://${System.getenv("local_maven")}") + } +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json similarity index 78% rename from src/main/resources/fabric.mod.json rename to fabric/src/main/resources/fabric.mod.json index d8cf39fe..55f483b5 100644 --- a/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -12,7 +12,7 @@ "issues": "https://github.com/FlashyReese/reeses-sodium-options/issues", "sources": "https://github.com/FlashyReese/reeses-sodium-options.git" }, - "icon": "assets/reeses-sodium-options/icon.png", + "icon": "rso-icon.png", "license": "MIT", "environment": "client", "mixins": [ @@ -32,17 +32,5 @@ "modmenu.modrinth": "https://modrinth.com/mod/reeses-sodium-options" } } - }, - "depends": { - "minecraft": ">=1.20.2", - "sodium": "*" - }, - "breaks": { - "iris": "<1.1.4", - "sodium-extra": "<0.5.3", - "sodium": "<0.5.8" - }, - "recommends": { - "sodium-extra": ">=0.4.2" } } diff --git a/gradle.properties b/gradle.properties index e0e70d24..d7fa8faa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,20 +1,2 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs=-Xmx1G -# Fabric Properties -# check these on https://modmuss50.me/fabric.html - minecraft_version=1.20.4 - yarn_mappings=1.20.4+build.3 - loader_version=0.15.6 -# Mod Properties - version_type=release - revision=1 - mod_version=1.7.2 - maven_group=me.flashyreese.mods - archives_base_name=reeses_sodium_options - -# Dependency - sodium_version=mc1.20.4-0.5.8 - iris_version=1.20.4-1.6.15 - -#Fabric api - fabric_version=0.95.1+1.20.4 +org.gradle.jvmargs=-Xmx2G diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1af9e093..b82aa23a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/neoforge/build.gradle.kts b/neoforge/build.gradle.kts new file mode 100644 index 00000000..e99a42c7 --- /dev/null +++ b/neoforge/build.gradle.kts @@ -0,0 +1,81 @@ +plugins { + id("idea") + id("maven-publish") + id("net.neoforged.gradle.userdev") version "7.0.81" + id("java-library") +} +base { + archivesName = "reeses-sodium-options-neoforge-1.20.4" +} + +val MINECRAFT_VERSION: String by rootProject.extra +val MOD_VERSION: String by rootProject.extra + +runs { + configureEach { + modSource(project.sourceSets.main.get()) + } + create("client") { + dependencies { + runtime("net.caffeinemc.mods:sodium-common-1.20.4:0.6.0-snapshot+mc1.20.4-local") + } + } + + create("data") { + programArguments.addAll("--mod", "reeses-sodium-options", "--all", "--output", file("src/generated/resources/").getAbsolutePath(), "--existing", file("src/main/resources/").getAbsolutePath()) + } +} + +dependencies { + implementation("net.neoforged:neoforge:20.4.219") + compileOnly(project(":common")) + implementation(group = "net.caffeinemc.mods", name = "sodium-common-1.20.4", version = "0.6.0-snapshot+mc1.20.4-local") + //implementation("net.caffeinemc.mods:sodium-neoforge-1.20.4:0.6.0-snapshot+mc1.20.4-local") +} + +// NeoGradle compiles the game, but we don't want to add our common code to the game's code +val notNeoTask: (Task) -> Boolean = { it: Task -> !it.name.startsWith("neo") && !it.name.startsWith("compileService") } + +tasks.withType().matching(notNeoTask).configureEach { + source(project(":common").sourceSets.main.get().allSource) +} + +tasks.withType().matching(notNeoTask).configureEach { + source(project(":common").sourceSets.main.get().allJava) +} + +tasks.withType().matching(notNeoTask).configureEach { + from(project(":common").sourceSets.main.get().resources) +} + +java.toolchain.languageVersion = JavaLanguageVersion.of(17) + +publishing { + publications { + register("mavenJava", MavenPublication::class) { + artifactId = base.archivesName.get() + from(components["java"]) + } + } + repositories { + maven { + name = "FlashyReeseReleases" + url = uri("https://maven.flashyreese.me/releases") + credentials { + username = System.getenv("MAVEN_USERNAME") + password = System.getenv("MAVEN_PASSWORD") + } + } + maven { + name = "FlashyReeseSnapshots" + url = uri("https://maven.flashyreese.me/snapshots") + credentials { + username = System.getenv("MAVEN_USERNAME") + password = System.getenv("MAVEN_PASSWORD") + } + } + maven { + url = uri("file://" + System.getenv("local_maven")) + } + } +} \ No newline at end of file diff --git a/neoforge/gradle.properties b/neoforge/gradle.properties new file mode 100644 index 00000000..2e6ed767 --- /dev/null +++ b/neoforge/gradle.properties @@ -0,0 +1 @@ +loom.platform = neoforge diff --git a/neoforge/src/main/java/me/flashyreese/mods/reeses_sodium_options/neoforge/ReesesSodiumOptionsMod.java b/neoforge/src/main/java/me/flashyreese/mods/reeses_sodium_options/neoforge/ReesesSodiumOptionsMod.java new file mode 100644 index 00000000..07bf0096 --- /dev/null +++ b/neoforge/src/main/java/me/flashyreese/mods/reeses_sodium_options/neoforge/ReesesSodiumOptionsMod.java @@ -0,0 +1,12 @@ +package me.flashyreese.mods.reeses_sodium_options.neoforge; + +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.common.Mod; + +@Mod("reeses_sodium_options") +public class ReesesSodiumOptionsMod { + public ReesesSodiumOptionsMod(IEventBus bus) { + // This class needs to exist for NeoForge to load the mod :> + System.out.println("Hello it's me, Reese!"); + } +} diff --git a/neoforge/src/main/resources/META-INF/mods.toml b/neoforge/src/main/resources/META-INF/mods.toml new file mode 100644 index 00000000..911b4fb5 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,27 @@ +modLoader = "javafml" +loaderVersion = "*" +license = "MIT" + +[[mods]] +modId = "reeses_sodium_options" + +version = "${version}" +displayName = "Reese's Sodium Options" + +logoFile="rso-icon.png" #optional + +authors="FlashyReese" +# A multi-line description for your mod. This has no minimum length, but it *is* required! +description = ''' +Replaces Sodium's Options Screen +''' + +[[dependencies.reeses-sodium-options]] +modId="minecraft" +type="required" +versionRange="[1.20.4,1.21)" +ordering="NONE" +side="CLIENT" + +[[mixins]] +config = "reeses-sodium-options.mixins.json" \ No newline at end of file diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index c4bb92c7..00000000 --- a/settings.gradle +++ /dev/null @@ -1,9 +0,0 @@ -pluginManagement { - repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - gradlePluginPortal() - } -} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..1cfc1d38 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,14 @@ +rootProject.name = "reeses-sodium-options" + +pluginManagement { + repositories { + maven { url = uri("https://maven.fabricmc.net/") } + maven { url = uri("https://files.minecraftforge.net/maven/") } + maven { url = uri("https://maven.neoforged.net/releases/") } + gradlePluginPortal() + } +} + +include("common") +include("fabric") +include("neoforge") \ No newline at end of file