From ae35603bf706b359fe60a2c3fe536220333c516a Mon Sep 17 00:00:00 2001 From: axolotlmaid <124442837+axolotlmaid@users.noreply.github.com> Date: Sun, 12 May 2024 12:14:29 +0100 Subject: [PATCH] Port to 1.16.5 --- .../gui/EditProfileScreen.java | 42 ++++++++------- .../optionsprofiles/gui/ProfilesList.java | 42 +++++++-------- .../optionsprofiles/gui/ProfilesScreen.java | 24 ++++----- .../mixin/MixinOptionsScreen.java | 5 +- .../profiles/SodiumConfigLoader.java | 53 +++++++++---------- 5 files changed, 83 insertions(+), 83 deletions(-) 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..1bc14d4 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/EditProfileScreen.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/gui/EditProfileScreen.java @@ -1,13 +1,14 @@ 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.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.TranslatableComponent; public class EditProfileScreen extends Screen { private final Screen lastScreen; @@ -16,40 +17,41 @@ public class EditProfileScreen extends Screen { private EditBox profileNameEdit; public EditProfileScreen(Screen screen, Component profileName) { - super(Component.literal(Component.translatable("gui.optionsprofiles.editing-profile-title").getString() + profileName.getString())); + super(Component.nullToEmpty(new TranslatableComponent("gui.optionsprofiles.editing-profile-title").getString() + profileName.getString())); 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 = new EditBox(this.font, this.width / 2 - 100, 116, 200, 20, new TranslatableComponent("gui.optionsprofiles.profile-name-text")); this.profileNameEdit.setValue(profileName.getString()); this.addWidget(this.profileNameEdit); - this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.overwrite-options"), (button) -> { - new Profiles().writeOptionsFilesIntoProfile(profileName.getString()); + this.addButton(new Button(this.width / 2 - 50, 145, 100, 20, new TranslatableComponent("gui.optionsprofiles.overwrite-options"), (button -> { + Profiles.writeOptionsFilesIntoProfile(profileName.getString()); 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.addButton(new Button(this.width / 2 - 50, 166, 100, 20, new TranslatableComponent("gui.optionsprofiles.rename-profile"), (button -> { + Profiles.renameProfile(profileName.getString(), this.profileNameEdit.getValue()); + this.minecraft.setScreen(new EditProfileScreen(lastScreen, Component.nullToEmpty(this.profileNameEdit.getValue()))); + }))); - this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.delete-profile").withStyle(ChatFormatting.RED), (button) -> { - new Profiles().deleteProfile(profileName.getString()); + this.addButton(new Button(5, this.height - 25, 100, 20, new TranslatableComponent("gui.optionsprofiles.delete-profile").withStyle(ChatFormatting.RED), (button -> { + Profiles.deleteProfile(profileName.getString()); this.minecraft.setScreen(this.lastScreen); - }).size(100, 20).pos(5, this.height - 25).build()); + }))); - this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, (button) -> { + this.addButton(new Button(this.width / 2 - 75, this.height - 40, 150, 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) { + this.renderBackground(poseStack); + this.profileNameEdit.render(poseStack, mouseX, mouseY, delta); + drawCenteredString(poseStack, this.font, this.title, this.width / 2, 8, 16777215); + drawCenteredString(poseStack, this.font, new TranslatableComponent("gui.optionsprofiles.profile-name-text"), this.width / 2, 100, 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 468713a..e4de5c0 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,14 @@ 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.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.TranslatableComponent; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -22,7 +22,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(Component.nullToEmpty(profile.getFileName().toString()))); } } catch (Exception e) { System.out.println("An error occurred when listing profiles."); @@ -59,12 +59,12 @@ public class ProfilesList extends ContainerObjectSelectionList { + 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.getString()); minecraft.options.load(); minecraft.options.loadSelectedResourcePacks(minecraft.getResourcePackRepository()); @@ -73,35 +73,35 @@ 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.getString()); } - public void render(GuiGraphics guiGraphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + 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); + 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() { return ImmutableList.of(this.editButton, this.loadButton); } - public List narratables() { - return ImmutableList.of(this.editButton, this.loadButton); - } +// public List narratables() { +// return ImmutableList.of(this.editButton, this.loadButton); +// } } public abstract static class Entry extends ContainerObjectSelectionList.Entry { 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..1e34dd1 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,18 @@ 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.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 +21,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.addButton(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.addButton(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); + 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..d33271d 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.addButton(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/SodiumConfigLoader.java b/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/SodiumConfigLoader.java index 1d660d0..556d7c4 100644 --- a/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/SodiumConfigLoader.java +++ b/common/src/main/java/com/axolotlmaid/optionsprofiles/profiles/SodiumConfigLoader.java @@ -22,27 +22,27 @@ public class SodiumConfigLoader { } private static void apply(ConfigData configData) { + SodiumClientMod.options().notifications.hideDonationButton = configData.notifications.hide_donation_button; + + SodiumClientMod.options().quality.cloudQuality = SodiumGameOptions.GraphicsQuality.valueOf(configData.quality.cloud_quality); SodiumClientMod.options().quality.weatherQuality = SodiumGameOptions.GraphicsQuality.valueOf(configData.quality.weather_quality); - SodiumClientMod.options().quality.leavesQuality = SodiumGameOptions.GraphicsQuality.valueOf(configData.quality.leaves_quality); SodiumClientMod.options().quality.enableVignette = configData.quality.enable_vignette; + SodiumClientMod.options().quality.enableClouds = configData.quality.enable_clouds; + SodiumClientMod.options().quality.smoothLighting = SodiumGameOptions.LightingQuality.valueOf(configData.quality.smooth_lighting); - SodiumClientMod.options().advanced.enableMemoryTracing = configData.advanced.enable_memory_tracing; - SodiumClientMod.options().advanced.useAdvancedStagingBuffers = configData.advanced.use_advanced_staging_buffers; - SodiumClientMod.options().advanced.cpuRenderAheadLimit = configData.advanced.cpu_render_ahead_limit; - - SodiumClientMod.options().performance.chunkBuilderThreads = configData.performance.chunk_builder_threads; - SodiumClientMod.options().performance.alwaysDeferChunkUpdates = configData.performance.always_defer_chunk_updates_v2; - SodiumClientMod.options().performance.animateOnlyVisibleTextures = configData.performance.animate_only_visible_textures; - 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.hasClearedDonationButton = configData.notifications.has_cleared_donation_button; - SodiumClientMod.options().notifications.hasSeenDonationPrompt = configData.notifications.has_seen_donation_prompt; + SodiumClientMod.options().advanced.useVertexArrayObjects = configData.advanced.use_vertex_array_objects; + SodiumClientMod.options().advanced.useChunkMultidraw = configData.advanced.use_advanced_staging_buffers; + SodiumClientMod.options().advanced.animateOnlyVisibleTextures = configData.advanced.animate_only_visible_textures; + SodiumClientMod.options().advanced.useEntityCulling = configData.advanced.use_entity_culling; + SodiumClientMod.options().advanced.useParticleCulling = configData.advanced.use_particle_culling; + SodiumClientMod.options().advanced.useFogOcclusion = configData.advanced.use_fog_occlusion; + SodiumClientMod.options().advanced.useCompactVertexFormat = configData.advanced.use_compact_vertex_format; + SodiumClientMod.options().advanced.useBlockFaceCulling = configData.advanced.use_block_face_culling; + SodiumClientMod.options().advanced.allowDirectMemoryAccess = configData.advanced.allow_direct_memory_access; + SodiumClientMod.options().advanced.ignoreDriverBlacklist = configData.advanced.ignore_driver_blacklist; try { - SodiumGameOptions.writeToDisk(SodiumClientMod.options()); + SodiumClientMod.options().writeChanges(); } catch (IOException e) { e.printStackTrace(); } @@ -51,34 +51,31 @@ public class SodiumConfigLoader { public static class ConfigData { public Quality quality; public Advanced advanced; - public Performance performance; public Notifications notifications; public static class Quality { + public String cloud_quality; public String weather_quality; - public String leaves_quality; public boolean enable_vignette; + public boolean enable_clouds; + public String smooth_lighting; } public static class Advanced { - public boolean enable_memory_tracing; + public boolean use_vertex_array_objects; public boolean use_advanced_staging_buffers; - public int cpu_render_ahead_limit; - } - - public static class Performance { - public int chunk_builder_threads; - public boolean always_defer_chunk_updates_v2; public boolean animate_only_visible_textures; public boolean use_entity_culling; + public boolean use_particle_culling; public boolean use_fog_occlusion; + public boolean use_compact_vertex_format; public boolean use_block_face_culling; - public boolean use_no_error_g_l_context; + public boolean allow_direct_memory_access; + public boolean ignore_driver_blacklist; } public static class Notifications { - public boolean has_cleared_donation_button; - public boolean has_seen_donation_prompt; + public boolean hide_donation_button; } } } \ No newline at end of file