fabric 1.18.2 port

This commit is contained in:
tvoklov 2023-11-30 03:04:20 +04:00
parent 1cfcdcb83b
commit cfa25b292e
No known key found for this signature in database
GPG key ID: 512907C048B7122B
11 changed files with 85 additions and 86 deletions

View file

@ -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);
}
}

View file

@ -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<ProfilesList.Entry> {
public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.ProfileEntry> {
final ProfilesScreen profilesScreen;
public ProfilesList(ProfilesScreen profilesScreen, Minecraft minecraft) {
@ -35,7 +38,7 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Entr
try (DirectoryStream<Path> 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<ProfilesList.Entr
return super.getRowWidth() + 32;
}
public class ProfileEntry extends Entry {
private final Component profileName;
public class ProfileEntry extends ContainerObjectSelectionList.Entry<ProfilesList.ProfileEntry> {
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<ProfilesList.Entr
minecraft.options.save();
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);
}
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<? extends GuiEventListener> children() {
@ -104,8 +108,4 @@ public class ProfilesList extends ContainerObjectSelectionList<ProfilesList.Entr
}
}
public abstract static class Entry extends ContainerObjectSelectionList.Entry<ProfilesList.Entry> {
public Entry() {
}
}
}

View file

@ -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);
}
}

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.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());
}));
}
}

View file

@ -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<Path> files = Files.walk(profile)) {

View file

@ -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;