From cfa25b292e5e13ceb23aff6790a29254cfa812f0 Mon Sep 17 00:00:00 2001 From: tvoklov Date: Thu, 30 Nov 2023 03:04:20 +0400 Subject: [PATCH] fabric 1.18.2 port --- common/build.gradle | 2 +- .../gui/EditProfileScreen.java | 53 ++++++++++--------- .../optionsprofiles/gui/ProfilesList.java | 48 ++++++++--------- .../optionsprofiles/gui/ProfilesScreen.java | 25 ++++----- .../mixin/MixinOptionsScreen.java | 5 +- .../optionsprofiles/profiles/Profiles.java | 12 ++--- .../profiles/SodiumConfigLoader.java | 1 - fabric/src/main/resources/fabric.mod.json | 4 +- .../resources/optionsprofiles.mixins.json | 5 +- forge/src/main/resources/META-INF/mods.toml | 6 +-- gradle.properties | 10 ++-- 11 files changed, 85 insertions(+), 86 deletions(-) diff --git a/common/build.gradle b/common/build.gradle index 3772f38..744ed58 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -28,7 +28,7 @@ dependencies { modApi "dev.architectury:architectury:${rootProject.architectury_version}" // sodium - modImplementation "maven.modrinth:sodium:mc1.20.1-0.5.3" + modImplementation "maven.modrinth:sodium:mc1.18.2-0.4.1" } publishing { diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/EditProfileScreen.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/EditProfileScreen.java index 92c1f67..c8241fa 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/EditProfileScreen.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/EditProfileScreen.java @@ -1,55 +1,56 @@ package com.axolotlmaid.optionsprofiles.gui; import com.axolotlmaid.optionsprofiles.profiles.Profiles; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.ChatFormatting; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.*; public class EditProfileScreen extends Screen { private final Screen lastScreen; - private final Component profileName; + private final String profileName; private EditBox profileNameEdit; - public EditProfileScreen(Screen screen, Component profileName) { - super(Component.literal(Component.translatable("gui.optionsprofiles.editing-profile-title").getString() + profileName.getString())); + public EditProfileScreen(Screen screen, String profileName) { + super(new TextComponent(new TranslatableComponent("gui.optionsprofiles.editing-profile-title").getString() + profileName)); this.lastScreen = screen; this.profileName = profileName; } protected void init() { - this.profileNameEdit = new EditBox(this.font, this.width / 2 - 102, this.height - 130, 204, 20, Component.empty()); - this.profileNameEdit.setValue(profileName.getString()); - this.addWidget(this.profileNameEdit); + this.profileNameEdit = new EditBox(this.font, this.width / 2 - 102, this.height - 130, 204, 20, new TextComponent(Component.EMPTY.getString())); + this.profileNameEdit.setValue(profileName); + this.addRenderableWidget(this.profileNameEdit); - this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.overwrite-options"), (button) -> { - new Profiles().writeOptionsFilesIntoProfile(profileName.getString()); + this.addRenderableWidget(new Button(this.width / 2 - 50, this.height - 85, 100, 20, new TranslatableComponent("gui.optionsprofiles.overwrite-options"), (button) -> { + Profiles.writeOptionsFilesIntoProfile(profileName); this.minecraft.setScreen(this.lastScreen); - }).size(100, 20).pos(this.width / 2 - 50, this.height - 85).build()); + })); - this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.rename-profile"), (button) -> { - new Profiles().renameProfile(profileName.getString(), this.profileNameEdit.getValue()); - this.minecraft.setScreen(new EditProfileScreen(lastScreen, Component.literal(this.profileNameEdit.getValue()))); - }).size(100, 20).pos(this.width / 2 - 50, this.height - 65).build()); + this.addRenderableWidget(new Button(this.width / 2 - 50, this.height - 65, 100, 20, new TranslatableComponent("gui.optionsprofiles.rename-profile"), (button) -> { + Profiles.renameProfile(profileName, this.profileNameEdit.getValue()); + this.minecraft.setScreen(new EditProfileScreen(lastScreen, this.profileNameEdit.getValue())); + })); - this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.delete-profile").withStyle(ChatFormatting.RED), (button) -> { - new Profiles().deleteProfile(profileName.getString()); + this.addRenderableWidget(new Button(5, this.height - 25, 100, 20, new TranslatableComponent("gui.optionsprofiles.delete-profile").withStyle(ChatFormatting.RED), (button) -> { + Profiles.deleteProfile(profileName); this.minecraft.setScreen(this.lastScreen); - }).size(100, 20).pos(5, this.height - 25).build()); + })); - this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> { + this.addRenderableWidget(new Button(this.width / 2 - 50, this.height - 40, 100, 20, CommonComponents.GUI_DONE, (button) -> { this.minecraft.setScreen(this.lastScreen); - }).size(100, 20).pos(this.width / 2 - 50, this.height - 40).build()); + })); } - public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { - super.render(guiGraphics, mouseX, mouseY, delta); - this.profileNameEdit.render(guiGraphics, mouseX, mouseY, delta); - guiGraphics.drawCenteredString(this.font, this.title, this.width / 2, 8, 16777215); - guiGraphics.drawCenteredString(this.font, Component.translatable("gui.optionsprofiles.profile-name-text"), this.width / 2, this.height - 145, 16777215); + public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) { + renderBackground(poseStack); +// this.profileNameEdit.render(poseStack, mouseX, mouseY, delta); + GuiComponent.drawCenteredString(poseStack, this.font, this.title, this.width / 2, 8, 16777215); + GuiComponent.drawCenteredString(poseStack, this.font, new TranslatableComponent("gui.optionsprofiles.profile-name-text"), this.width / 2, this.height - 145, 16777215); + super.render(poseStack, mouseX, mouseY, delta); } } \ No newline at end of file diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesList.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesList.java index a77c1a1..463f0fe 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesList.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesList.java @@ -2,14 +2,17 @@ package com.axolotlmaid.optionsprofiles.gui; import com.axolotlmaid.optionsprofiles.profiles.Profiles; import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.ContainerObjectSelectionList; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -18,7 +21,7 @@ import java.nio.file.Paths; import java.util.List; import java.util.Objects; -public class ProfilesList extends ContainerObjectSelectionList { +public class ProfilesList extends ContainerObjectSelectionList { final ProfilesScreen profilesScreen; public ProfilesList(ProfilesScreen profilesScreen, Minecraft minecraft) { @@ -35,7 +38,7 @@ public class ProfilesList extends ContainerObjectSelectionList directoryStream = Files.newDirectoryStream(profilesDirectory)) { for (Path profile : directoryStream) { - this.addEntry(new ProfilesList.ProfileEntry(Component.literal(profile.getFileName().toString()))); + this.addEntry(new ProfilesList.ProfileEntry(profile.getFileName().toString())); } } catch (Exception e) { System.out.println("An error occurred when listing profiles."); @@ -51,20 +54,20 @@ public class ProfilesList extends ContainerObjectSelectionList { + private final String profileName; private final Button editButton; private final Button loadButton; - ProfileEntry(Component profileName) { + ProfileEntry(String profileName) { this.profileName = profileName; - this.editButton = Button.builder(Component.translatable("gui.optionsprofiles.edit-profile"), (button) -> { + this.editButton = new Button(0, 0, 75, 20, new TranslatableComponent("gui.optionsprofiles.edit-profile"), (button) -> { minecraft.setScreen(new EditProfileScreen(profilesScreen, profileName)); - }).size(75, 20).createNarration((supplier) -> Component.translatable("gui.optionsprofiles.edit-profile")).build(); + }); - this.loadButton = Button.builder(Component.translatable("gui.optionsprofiles.load-profile"), (button) -> { - new Profiles().loadProfile(profileName.getString()); + this.loadButton = new Button(0, 0, 75, 20, new TranslatableComponent("gui.optionsprofiles.load-profile"), (button) -> { + Profiles.loadProfile(profileName); minecraft.options.load(); minecraft.options.loadSelectedResourcePacks(minecraft.getResourcePackRepository()); @@ -73,26 +76,27 @@ public class ProfilesList extends ContainerObjectSelectionList Component.translatable("gui.optionsprofiles.load-profile")).build(); + }); - this.loadButton.active = !new Profiles().isProfileLoaded(profileName.getString()); + this.loadButton.active = !Profiles.isProfileLoaded(profileName); } - public void render(GuiGraphics guiGraphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + @Override + public void render(PoseStack poseStack, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { Font fontRenderer = ProfilesList.this.minecraft.font; int textY = y + entryHeight / 2; Objects.requireNonNull(ProfilesList.this.minecraft.font); - guiGraphics.drawString(fontRenderer, this.profileName, x - 50, textY - 9 / 2, 16777215, false); + GuiComponent.drawString(poseStack, fontRenderer, this.profileName, x - 50, textY - 9 / 2, 16777215); - this.editButton.setX(x + 115); - this.editButton.setY(y); - this.editButton.render(guiGraphics, mouseX, mouseY, tickDelta); + this.editButton.x = x + 115; + this.editButton.y = y; + this.editButton.render(poseStack, mouseX, mouseY, tickDelta); - this.loadButton.setX(x + 190); - this.loadButton.setY(y); - this.loadButton.render(guiGraphics, mouseX, mouseY, tickDelta); + this.loadButton.x = x + 190; + this.loadButton.y = y; + this.loadButton.render(poseStack, mouseX, mouseY, tickDelta); } public List children() { @@ -104,8 +108,4 @@ public class ProfilesList extends ContainerObjectSelectionList { - public Entry() { - } - } } \ No newline at end of file diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesScreen.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesScreen.java index c5960df..2bfb655 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesScreen.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/ProfilesScreen.java @@ -1,18 +1,19 @@ package com.axolotlmaid.optionsprofiles.gui; import com.axolotlmaid.optionsprofiles.profiles.Profiles; -import net.minecraft.client.gui.GuiGraphics; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.gui.GuiComponent; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; public class ProfilesScreen extends Screen { private final Screen lastScreen; private ProfilesList profilesList; public ProfilesScreen(Screen screen) { - super(Component.translatable("gui.optionsprofiles.profiles-menu")); + super(new TranslatableComponent("gui.optionsprofiles.profiles-menu")); this.lastScreen = screen; } @@ -21,19 +22,19 @@ public class ProfilesScreen extends Screen { this.addWidget(this.profilesList); // buttons - this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.save-current-options"), (button) -> { - new Profiles().createProfile(); + this.addRenderableWidget(new Button(this.width / 2 - 155, this.height - 29, 150, 20, new TranslatableComponent("gui.optionsprofiles.save-current-options"), (button) -> { + Profiles.createProfile(); this.profilesList.refreshEntries(); - }).size(150, 20).pos(this.width / 2 - 155, this.height - 29).build()); + })); - this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> { + this.addRenderableWidget(new Button(this.width / 2 + 5, this.height - 29, 150, 20, CommonComponents.GUI_DONE, (button) -> { this.minecraft.setScreen(this.lastScreen); - }).size(150, 20).pos(this.width / 2 + 5, this.height - 29).build()); + })); } - public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { - super.render(guiGraphics, mouseX, mouseY, delta); - this.profilesList.render(guiGraphics, mouseX, mouseY, delta); - guiGraphics.drawCenteredString(this.font, this.title, this.width / 2, 8, 16777215); + public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) { + this.profilesList.render(poseStack, mouseX, mouseY, delta); + GuiComponent.drawCenteredString(poseStack, this.font, this.title, this.width / 2, 8, 16777215); + super.render(poseStack, mouseX, mouseY, delta); } } \ No newline at end of file diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/mixin/MixinOptionsScreen.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/mixin/MixinOptionsScreen.java index 22a807a..6527b81 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/mixin/MixinOptionsScreen.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/mixin/MixinOptionsScreen.java @@ -5,6 +5,7 @@ import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.OptionsScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -18,8 +19,8 @@ public class MixinOptionsScreen extends Screen { @Inject(at = @At("HEAD"), method = "init") private void init(CallbackInfo info) { - this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.profiles-menu"), (button) -> { + this.addRenderableWidget(new Button(5, 5, 100, 20, new TranslatableComponent("gui.optionsprofiles.profiles-menu"), (button) -> { this.minecraft.setScreen(new ProfilesScreen(this)); - }).width(100).pos(5, 5).build()); + })); } } \ No newline at end of file diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/Profiles.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/Profiles.java index 9c438a1..1348b7a 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/Profiles.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/Profiles.java @@ -13,7 +13,7 @@ import java.util.List; import java.util.stream.Stream; public class Profiles { - public void createProfile() { + public static void createProfile() { String profileName = "Profile 1"; Path profile = Paths.get("options-profiles/" + profileName); @@ -38,7 +38,7 @@ public class Profiles { } } - public void writeOptionsFilesIntoProfile(String profileName) { + public static void writeOptionsFilesIntoProfile(String profileName) { Path profile = Paths.get("options-profiles/" + profileName); // options.txt @@ -90,7 +90,7 @@ public class Profiles { } } - public boolean isProfileLoaded(String profileName) { + public static boolean isProfileLoaded(String profileName) { Path profile = Paths.get("options-profiles/" + profileName); Path options = Paths.get("options.txt"); @@ -122,7 +122,7 @@ public class Profiles { return false; } - public void loadProfile(String profileName) { + public static void loadProfile(String profileName) { Path profile = Paths.get("options-profiles/" + profileName); // options.txt @@ -158,7 +158,7 @@ public class Profiles { } } - public void renameProfile(String profileName, String newProfileName) { + public static void renameProfile(String profileName, String newProfileName) { Path profile = Paths.get("options-profiles/" + profileName); Path newProfile = Paths.get("options-profiles/" + newProfileName); @@ -179,7 +179,7 @@ public class Profiles { } } - public void deleteProfile(String profileName) { + public static void deleteProfile(String profileName) { Path profile = Paths.get("options-profiles/" + profileName); try (Stream files = Files.walk(profile)) { diff --git a/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/SodiumConfigLoader.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/SodiumConfigLoader.java index bd1d974..1d31401 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/SodiumConfigLoader.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/SodiumConfigLoader.java @@ -36,7 +36,6 @@ public class SodiumConfigLoader { SodiumClientMod.options().performance.useEntityCulling = configData.performance.use_entity_culling; SodiumClientMod.options().performance.useFogOcclusion = configData.performance.use_fog_occlusion; SodiumClientMod.options().performance.useBlockFaceCulling = configData.performance.use_block_face_culling; - SodiumClientMod.options().performance.useNoErrorGLContext = configData.performance.use_no_error_g_l_context; SodiumClientMod.options().notifications.hideDonationButton = configData.notifications.hide_donation_button; diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 14d5207..604eb9c 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -26,7 +26,7 @@ ], "depends": { "fabric": "*", - "minecraft": ">=1.20.1", - "architectury": ">=9.1.12" + "minecraft": ">=1.18.2", + "architectury": ">=4.11.90" } } \ No newline at end of file diff --git a/fabric/src/main/resources/optionsprofiles.mixins.json b/fabric/src/main/resources/optionsprofiles.mixins.json index b6eaa9d..9d4e801 100644 --- a/fabric/src/main/resources/optionsprofiles.mixins.json +++ b/fabric/src/main/resources/optionsprofiles.mixins.json @@ -1,10 +1,7 @@ { "required": true, - "package": "com.axolotlmaid.optionsprofiles.mixin.fabric", + "package": "com.axolotlmaid.optionsprofiles.mixin", "compatibilityLevel": "JAVA_17", - "minVersion": "0.8", - "client": [ - ], "mixins": [ ], "injectors": { diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml index c0964c7..43edd7d 100644 --- a/forge/src/main/resources/META-INF/mods.toml +++ b/forge/src/main/resources/META-INF/mods.toml @@ -16,20 +16,20 @@ logoFile = "icon.png" [[dependencies.examplemod]] modId = "forge" mandatory = true -versionRange = "[47,)" +versionRange = "[40,)" ordering = "NONE" side = "BOTH" [[dependencies.examplemod]] modId = "minecraft" mandatory = true -versionRange = "[1.20.1,)" +versionRange = "[1.18.2,)" ordering = "NONE" side = "BOTH" [[dependencies.examplemod]] modId = "architectury" mandatory = true -versionRange = "[9.1.12,)" +versionRange = "[4.11.93,)" ordering = "AFTER" side = "BOTH" \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index c4522d8..f8fdce3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs=-Xmx6G -minecraft_version=1.20.2 +minecraft_version=1.18.2 enabled_platforms=fabric,forge archives_base_name=optionsprofiles @@ -15,9 +15,9 @@ maven_group=com.axolotlmaid.optionsprofiles #forge_version=1.20.1-47.2.1 -architectury_version=10.0.9 +architectury_version=4.11.90 -fabric_loader_version=0.14.24 -fabric_api_version=0.90.7+1.20.2 +fabric_loader_version=0.14.22 +fabric_api_version=0.77.0+1.18.2 -forge_version=1.20.2-48.0.39 \ No newline at end of file +forge_version=1.18.2-40.2.0 \ No newline at end of file