Port to 1.16.5

This commit is contained in:
axolotlmaid 2024-05-12 12:14:29 +01:00
parent b34de740f0
commit ae35603bf7
5 changed files with 83 additions and 83 deletions

View file

@ -1,13 +1,14 @@
package com.axolotlmaid.optionsprofiles.gui; package com.axolotlmaid.optionsprofiles.gui;
import com.axolotlmaid.optionsprofiles.profiles.Profiles; import com.axolotlmaid.optionsprofiles.profiles.Profiles;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
public class EditProfileScreen extends Screen { public class EditProfileScreen extends Screen {
private final Screen lastScreen; private final Screen lastScreen;
@ -16,40 +17,41 @@ public class EditProfileScreen extends Screen {
private EditBox profileNameEdit; private EditBox profileNameEdit;
public EditProfileScreen(Screen screen, Component profileName) { 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.lastScreen = screen;
this.profileName = profileName; this.profileName = profileName;
} }
protected void init() { 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.profileNameEdit.setValue(profileName.getString());
this.addWidget(this.profileNameEdit); this.addWidget(this.profileNameEdit);
this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.overwrite-options"), (button) -> { this.addButton(new Button(this.width / 2 - 50, 145, 100, 20, new TranslatableComponent("gui.optionsprofiles.overwrite-options"), (button -> {
new Profiles().writeOptionsFilesIntoProfile(profileName.getString()); Profiles.writeOptionsFilesIntoProfile(profileName.getString());
this.minecraft.setScreen(this.lastScreen); 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) -> { this.addButton(new Button(this.width / 2 - 50, 166, 100, 20, new TranslatableComponent("gui.optionsprofiles.rename-profile"), (button -> {
new Profiles().renameProfile(profileName.getString(), this.profileNameEdit.getValue()); Profiles.renameProfile(profileName.getString(), this.profileNameEdit.getValue());
this.minecraft.setScreen(new EditProfileScreen(lastScreen, Component.literal(this.profileNameEdit.getValue()))); this.minecraft.setScreen(new EditProfileScreen(lastScreen, Component.nullToEmpty(this.profileNameEdit.getValue())));
}).size(100, 20).pos(this.width / 2 - 50, this.height - 65).build()); })));
this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.delete-profile").withStyle(ChatFormatting.RED), (button) -> { this.addButton(new Button(5, this.height - 25, 100, 20, new TranslatableComponent("gui.optionsprofiles.delete-profile").withStyle(ChatFormatting.RED), (button -> {
new Profiles().deleteProfile(profileName.getString()); Profiles.deleteProfile(profileName.getString());
this.minecraft.setScreen(this.lastScreen); 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); 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) { public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) {
super.render(guiGraphics, mouseX, mouseY, delta); this.renderBackground(poseStack);
this.profileNameEdit.render(guiGraphics, mouseX, mouseY, delta); this.profileNameEdit.render(poseStack, mouseX, mouseY, delta);
guiGraphics.drawCenteredString(this.font, this.title, this.width / 2, 8, 16777215); drawCenteredString(poseStack, 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); drawCenteredString(poseStack, this.font, new TranslatableComponent("gui.optionsprofiles.profile-name-text"), this.width / 2, 100, 16777215);
super.render(poseStack, mouseX, mouseY, delta);
} }
} }

View file

@ -2,14 +2,14 @@ package com.axolotlmaid.optionsprofiles.gui;
import com.axolotlmaid.optionsprofiles.profiles.Profiles; import com.axolotlmaid.optionsprofiles.profiles.Profiles;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font; 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.Button;
import net.minecraft.client.gui.components.ContainerObjectSelectionList; import net.minecraft.client.gui.components.ContainerObjectSelectionList;
import net.minecraft.client.gui.components.events.GuiEventListener; 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.Component;
import net.minecraft.network.chat.TranslatableComponent;
import java.nio.file.DirectoryStream; import java.nio.file.DirectoryStream;
import java.nio.file.Files; import java.nio.file.Files;
@ -22,7 +22,7 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Entr
final ProfilesScreen profilesScreen; final ProfilesScreen profilesScreen;
public ProfilesList(ProfilesScreen profilesScreen, Minecraft minecraft) { public ProfilesList(ProfilesScreen profilesScreen, Minecraft minecraft) {
super(minecraft, profilesScreen.width + 45, profilesScreen.height - 52, 20, 20); super(minecraft, profilesScreen.width + 45, profilesScreen.height, 20, profilesScreen.height - 32, 20);
this.profilesScreen = profilesScreen; this.profilesScreen = profilesScreen;
refreshEntries(); refreshEntries();
@ -35,7 +35,7 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Entr
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(profilesDirectory)) { try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(profilesDirectory)) {
for (Path profile : directoryStream) { 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) { } catch (Exception e) {
System.out.println("An error occurred when listing profiles."); System.out.println("An error occurred when listing profiles.");
@ -59,12 +59,12 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Entr
ProfileEntry(Component profileName) { ProfileEntry(Component profileName) {
this.profileName = 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)); 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) -> { this.loadButton = new Button(0, 0, 75, 20, new TranslatableComponent("gui.optionsprofiles.load-profile"), (button) -> {
new Profiles().loadProfile(profileName.getString()); Profiles.loadProfile(profileName.getString());
minecraft.options.load(); minecraft.options.load();
minecraft.options.loadSelectedResourcePacks(minecraft.getResourcePackRepository()); minecraft.options.loadSelectedResourcePacks(minecraft.getResourcePackRepository());
@ -73,35 +73,35 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Entr
minecraft.options.save(); minecraft.options.save();
button.active = false; button.active = false;
}).size(75, 20).createNarration((supplier) -> 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; Font fontRenderer = ProfilesList.this.minecraft.font;
int textY = y + entryHeight / 2; int textY = y + entryHeight / 2;
Objects.requireNonNull(ProfilesList.this.minecraft.font); 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.x = x + 115;
this.editButton.setY(y); this.editButton.y = y;
this.editButton.render(guiGraphics, mouseX, mouseY, tickDelta); this.editButton.render(poseStack, mouseX, mouseY, tickDelta);
this.loadButton.setX(x + 190); this.loadButton.x = x + 190;
this.loadButton.setY(y); this.loadButton.y = y;
this.loadButton.render(guiGraphics, mouseX, mouseY, tickDelta); this.loadButton.render(poseStack, mouseX, mouseY, tickDelta);
} }
public List<? extends GuiEventListener> children() { public List<? extends GuiEventListener> children() {
return ImmutableList.of(this.editButton, this.loadButton); return ImmutableList.of(this.editButton, this.loadButton);
} }
public List<? extends NarratableEntry> narratables() { // public List<? extends NarratableEntry> narratables() {
return ImmutableList.of(this.editButton, this.loadButton); // return ImmutableList.of(this.editButton, this.loadButton);
} // }
} }
public abstract static class Entry extends ContainerObjectSelectionList.Entry<ProfilesList.Entry> { public abstract static class Entry extends ContainerObjectSelectionList.Entry<ProfilesList.Entry> {

View file

@ -1,18 +1,18 @@
package com.axolotlmaid.optionsprofiles.gui; package com.axolotlmaid.optionsprofiles.gui;
import com.axolotlmaid.optionsprofiles.profiles.Profiles; 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.components.Button;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent;
public class ProfilesScreen extends Screen { public class ProfilesScreen extends Screen {
private final Screen lastScreen; private final Screen lastScreen;
private ProfilesList profilesList; private ProfilesList profilesList;
public ProfilesScreen(Screen screen) { public ProfilesScreen(Screen screen) {
super(Component.translatable("gui.optionsprofiles.profiles-menu")); super(new TranslatableComponent("gui.optionsprofiles.profiles-menu"));
this.lastScreen = screen; this.lastScreen = screen;
} }
@ -21,19 +21,19 @@ public class ProfilesScreen extends Screen {
this.addWidget(this.profilesList); this.addWidget(this.profilesList);
// buttons // buttons
this.addRenderableWidget(Button.builder(Component.translatable("gui.optionsprofiles.save-current-options"), (button) -> { this.addButton(new Button(this.width / 2 - 155, this.height - 29, 150, 20, new TranslatableComponent("gui.optionsprofiles.save-current-options"), (button -> {
new Profiles().createProfile(); Profiles.createProfile();
this.profilesList.refreshEntries(); 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); 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) { public void render(PoseStack poseStack, int mouseX, int mouseY, float delta) {
super.render(guiGraphics, mouseX, mouseY, delta); this.profilesList.render(poseStack, mouseX, mouseY, delta);
this.profilesList.render(guiGraphics, mouseX, mouseY, delta); drawCenteredString(poseStack, this.font, this.title, this.width / 2, 8, 16777215);
guiGraphics.drawCenteredString(this.font, this.title, this.width / 2, 8, 16777215); super.render(poseStack, mouseX, mouseY, delta);
} }
} }

View file

@ -5,6 +5,7 @@ import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.OptionsScreen; import net.minecraft.client.gui.screens.OptionsScreen;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@ -18,8 +19,8 @@ public class MixinOptionsScreen extends Screen {
@Inject(at = @At("HEAD"), method = "init") @Inject(at = @At("HEAD"), method = "init")
private void init(CallbackInfo info) { 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)); this.minecraft.setScreen(new ProfilesScreen(this));
}).width(100).pos(5, 5).build()); })));
} }
} }

View file

@ -22,27 +22,27 @@ public class SodiumConfigLoader {
} }
private static void apply(ConfigData configData) { 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.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.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.useVertexArrayObjects = configData.advanced.use_vertex_array_objects;
SodiumClientMod.options().advanced.useAdvancedStagingBuffers = configData.advanced.use_advanced_staging_buffers; SodiumClientMod.options().advanced.useChunkMultidraw = configData.advanced.use_advanced_staging_buffers;
SodiumClientMod.options().advanced.cpuRenderAheadLimit = configData.advanced.cpu_render_ahead_limit; SodiumClientMod.options().advanced.animateOnlyVisibleTextures = configData.advanced.animate_only_visible_textures;
SodiumClientMod.options().advanced.useEntityCulling = configData.advanced.use_entity_culling;
SodiumClientMod.options().performance.chunkBuilderThreads = configData.performance.chunk_builder_threads; SodiumClientMod.options().advanced.useParticleCulling = configData.advanced.use_particle_culling;
SodiumClientMod.options().performance.alwaysDeferChunkUpdates = configData.performance.always_defer_chunk_updates_v2; SodiumClientMod.options().advanced.useFogOcclusion = configData.advanced.use_fog_occlusion;
SodiumClientMod.options().performance.animateOnlyVisibleTextures = configData.performance.animate_only_visible_textures; SodiumClientMod.options().advanced.useCompactVertexFormat = configData.advanced.use_compact_vertex_format;
SodiumClientMod.options().performance.useEntityCulling = configData.performance.use_entity_culling; SodiumClientMod.options().advanced.useBlockFaceCulling = configData.advanced.use_block_face_culling;
SodiumClientMod.options().performance.useFogOcclusion = configData.performance.use_fog_occlusion; SodiumClientMod.options().advanced.allowDirectMemoryAccess = configData.advanced.allow_direct_memory_access;
SodiumClientMod.options().performance.useBlockFaceCulling = configData.performance.use_block_face_culling; SodiumClientMod.options().advanced.ignoreDriverBlacklist = configData.advanced.ignore_driver_blacklist;
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;
try { try {
SodiumGameOptions.writeToDisk(SodiumClientMod.options()); SodiumClientMod.options().writeChanges();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -51,34 +51,31 @@ public class SodiumConfigLoader {
public static class ConfigData { public static class ConfigData {
public Quality quality; public Quality quality;
public Advanced advanced; public Advanced advanced;
public Performance performance;
public Notifications notifications; public Notifications notifications;
public static class Quality { public static class Quality {
public String cloud_quality;
public String weather_quality; public String weather_quality;
public String leaves_quality;
public boolean enable_vignette; public boolean enable_vignette;
public boolean enable_clouds;
public String smooth_lighting;
} }
public static class Advanced { public static class Advanced {
public boolean enable_memory_tracing; public boolean use_vertex_array_objects;
public boolean use_advanced_staging_buffers; 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 animate_only_visible_textures;
public boolean use_entity_culling; public boolean use_entity_culling;
public boolean use_particle_culling;
public boolean use_fog_occlusion; public boolean use_fog_occlusion;
public boolean use_compact_vertex_format;
public boolean use_block_face_culling; 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 static class Notifications {
public boolean has_cleared_donation_button; public boolean hide_donation_button;
public boolean has_seen_donation_prompt;
} }
} }
} }