From b4ff05a67ace9e77b084dd45453151444d8b4a61 Mon Sep 17 00:00:00 2001 From: faluhub Date: Mon, 6 May 2024 22:43:32 +0200 Subject: [PATCH] stuff --- gradle.properties | 2 +- .../CustomCategoryResourceManager.java | 2 +- .../core/category/PracticeCategory.java | 20 +++++++++++-------- .../core/category/utils/InventoryUtils.java | 13 ++++++++++-- .../gui/screen/CategoryPreferencesScreen.java | 8 ++++---- .../gui/screen/EditInventoryScreen.java | 2 +- .../gui/screen/InventoryOptionsScreen.java | 15 +++++++++----- .../screen/SettingsTypeSelectionScreen.java | 2 +- .../gui/screen/SplitSettingsScreen.java | 2 +- .../gui/screen/StandardSettingsScreen.java | 2 +- .../gui/widget/ThumbnailButtonWidget.java | 2 +- .../gui/screen/CreateWorldScreenMixin.java | 2 +- .../mixin/gui/screen/GameMenuScreenMixin.java | 3 +-- .../mixin/world/PlayerManagerMixin.java | 11 ++++++++-- .../assets/peepopractice/lang/en_us.json | 1 + 15 files changed, 56 insertions(+), 31 deletions(-) diff --git a/gradle.properties b/gradle.properties index 91a7670..4791c01 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=1.16.1+build.21 loader_version=0.15.7 # Mod Properties -mod_version=2.2-pre3 +mod_version=2.2-pre4 maven_group=me.falu archives_base_name=peepopractice diff --git a/src/main/java/me/falu/peepopractice/core/category/CustomCategoryResourceManager.java b/src/main/java/me/falu/peepopractice/core/category/CustomCategoryResourceManager.java index 4d7f82a..c8aa1d7 100644 --- a/src/main/java/me/falu/peepopractice/core/category/CustomCategoryResourceManager.java +++ b/src/main/java/me/falu/peepopractice/core/category/CustomCategoryResourceManager.java @@ -266,7 +266,7 @@ public static void register() throws InvalidCategorySyntaxException { } } CUSTOM_CATEGORIES.add(category); - categories.append(category.getName(false)).append(", "); + categories.append(category.getSimpleName()).append(", "); } } PeepoPractice.log(categories); diff --git a/src/main/java/me/falu/peepopractice/core/category/PracticeCategory.java b/src/main/java/me/falu/peepopractice/core/category/PracticeCategory.java index 0b1f87d..8a5786e 100644 --- a/src/main/java/me/falu/peepopractice/core/category/PracticeCategory.java +++ b/src/main/java/me/falu/peepopractice/core/category/PracticeCategory.java @@ -13,7 +13,6 @@ import me.falu.peepopractice.core.category.utils.InventoryUtils; import me.falu.peepopractice.core.exception.NotInitializedException; import me.falu.peepopractice.core.writer.PracticeWriter; -import net.minecraft.client.resource.language.I18n; import net.minecraft.server.world.ServerWorld; import net.minecraft.text.LiteralText; import net.minecraft.text.MutableText; @@ -180,16 +179,21 @@ public void removeCustomValue(String key) { } } - public String getTranslatedName() { - return I18n.translate("peepopractice.categories." + this.id); + public String getSimpleName() { + return this.getTranslatedName().getString(); } - public String getName(boolean showPb) { - StringBuilder text = new StringBuilder((this.isFillerCategory() ? Formatting.ITALIC : "") + this.getTranslatedName() + (showPb || this.isFillerCategory() ? Formatting.RESET : "")); + public Text getTranslatedName() { + return new TranslatableText("peepopractice.categories." + this.id); + } + + public Text getName(boolean showPb) { + MutableText text = this.getTranslatedName().copy().formatted(this.isFillerCategory() ? Formatting.ITALIC : Formatting.RESET); if (showPb) { + text.append(" "); text.append(this.getPbText()); } - return text.toString(); + return text; } public Text getPbText() { @@ -227,7 +231,7 @@ public boolean isAA() { } public boolean hasConfiguredInventory() { - if (this.canHaveEmptyInventory) { + if (this.canHaveEmptyInventory || CategoryPreferences.RANDOM_INVENTORY.getBoolValue(this)) { return true; } PracticeWriter writer = PracticeWriter.INVENTORY_WRITER; @@ -235,7 +239,7 @@ public boolean hasConfiguredInventory() { if (!config.has(this.getId())) { return false; } - int selected = InventoryUtils.getSelectedInventory(); + int selected = InventoryUtils.getSelectedInventory(this); JsonArray profiles = config.getAsJsonArray(this.getId()); if (profiles.size() <= selected) { return false; diff --git a/src/main/java/me/falu/peepopractice/core/category/utils/InventoryUtils.java b/src/main/java/me/falu/peepopractice/core/category/utils/InventoryUtils.java index 991347b..d618050 100644 --- a/src/main/java/me/falu/peepopractice/core/category/utils/InventoryUtils.java +++ b/src/main/java/me/falu/peepopractice/core/category/utils/InventoryUtils.java @@ -28,8 +28,17 @@ public class InventoryUtils { public static boolean BOOK_OPEN; public static boolean FILTERING_CRAFTABLE; - public static int getSelectedInventory() { - return CategoryPreferences.SELECTED_INVENTORY.getValue().ordinal(); + public static int getSelectedInventory(PracticeCategory category) { + return CategoryPreferences.SELECTED_INVENTORY.getValue(category).ordinal(); + } + + public static int randomInventory(PracticeCategory category) { + JsonObject config = PracticeWriter.INVENTORY_WRITER.get(); + JsonElement profilesElement = config.get(category.getId()); + if (profilesElement.isJsonArray()) { + return new Random().nextInt(profilesElement.getAsJsonArray().size()); + } + return 0; } public static void putItems(Inventory inventory, PracticeCategory category, int profileIndex) { diff --git a/src/main/java/me/falu/peepopractice/gui/screen/CategoryPreferencesScreen.java b/src/main/java/me/falu/peepopractice/gui/screen/CategoryPreferencesScreen.java index 258ff3c..6ab1d46 100644 --- a/src/main/java/me/falu/peepopractice/gui/screen/CategoryPreferencesScreen.java +++ b/src/main/java/me/falu/peepopractice/gui/screen/CategoryPreferencesScreen.java @@ -17,15 +17,15 @@ public class CategoryPreferencesScreen extends Screen { private final PracticeCategory category; public CategoryPreferencesScreen(Screen parent, PracticeCategory category) { - super(new TranslatableText("peepopractice.title.category_preferences", category.getName(false))); + super(new TranslatableText("peepopractice.title.category_preferences", category.getSimpleName())); this.parent = parent; this.category = category; } public static Text getFormattedText(PracticeCategory category, CategoryPreference preference) { - return new LiteralText("" + Formatting.BOLD) - .append(preference.getLabel().copy()) - .append(":\n" + Formatting.RESET) + return new LiteralText(Formatting.BOLD.toString()) + .append(preference.getLabel().copy().append(":\n").formatted(Formatting.BOLD)) + .append(Formatting.RESET.toString()) .append(preference.getValueLabel(category, true)); } diff --git a/src/main/java/me/falu/peepopractice/gui/screen/EditInventoryScreen.java b/src/main/java/me/falu/peepopractice/gui/screen/EditInventoryScreen.java index 36f4077..7b1dd37 100644 --- a/src/main/java/me/falu/peepopractice/gui/screen/EditInventoryScreen.java +++ b/src/main/java/me/falu/peepopractice/gui/screen/EditInventoryScreen.java @@ -80,7 +80,7 @@ public class EditInventoryScreen extends PlayerlessHandledScreen { private boolean lastClickOutsideBounds; private EditInventoryScreen(Screen parent, PracticeCategory category, int selectedProfile) { - super(new PlayerlessCreativeScreenHandler(), PeepoPractice.PLAYERLESS_INVENTORY, new TranslatableText("peepopractice.title.edit_inventory", category.getName(false))); + super(new PlayerlessCreativeScreenHandler(), PeepoPractice.PLAYERLESS_INVENTORY, new TranslatableText("peepopractice.title.edit_inventory", category.getSimpleName())); this.backgroundHeight = 136; this.backgroundWidth = 195; diff --git a/src/main/java/me/falu/peepopractice/gui/screen/InventoryOptionsScreen.java b/src/main/java/me/falu/peepopractice/gui/screen/InventoryOptionsScreen.java index fef9989..bf9fc12 100644 --- a/src/main/java/me/falu/peepopractice/gui/screen/InventoryOptionsScreen.java +++ b/src/main/java/me/falu/peepopractice/gui/screen/InventoryOptionsScreen.java @@ -5,9 +5,9 @@ import com.mojang.blaze3d.systems.RenderSystem; import lombok.RequiredArgsConstructor; import me.falu.peepopractice.PeepoPractice; +import me.falu.peepopractice.core.category.PracticeCategory; import me.falu.peepopractice.core.category.preferences.CategoryPreferences; import me.falu.peepopractice.core.category.preferences.PreferenceTypes; -import me.falu.peepopractice.core.category.PracticeCategory; import me.falu.peepopractice.core.category.utils.InventoryUtils; import me.falu.peepopractice.core.playerless.PlayerlessInventory; import me.falu.peepopractice.core.writer.PracticeWriter; @@ -29,6 +29,7 @@ public class InventoryOptionsScreen extends Screen { private static final Identifier EGG_TEXTURE = new Identifier("textures/item/egg.png"); + private static final Identifier BREWING_STAND_TEXTURE = new Identifier("textures/item/brewing_stand.png"); private static final Identifier WIDGETS = new Identifier("textures/gui/widgets.png"); private final Screen parent; private final PracticeCategory category; @@ -36,7 +37,7 @@ public class InventoryOptionsScreen extends Screen { private final List hotbarPositions; public InventoryOptionsScreen(Screen parent, PracticeCategory category) { - super(new TranslatableText("peepopractice.title.inventory_options", category.getName(false))); + super(new TranslatableText("peepopractice.title.inventory_options", category.getSimpleName())); this.parent = parent; this.category = category; this.namePositions = new ArrayList<>(); @@ -62,7 +63,8 @@ protected void init() { int x = (this.width - rowWidth) / 2; int y = this.height - containerHeight + paddingY * i + rowButtonSize * i; boolean isCorrectBound = profiles.size() >= i; - boolean isSelected = i == InventoryUtils.getSelectedInventory(); + boolean isRandomInventory = CategoryPreferences.RANDOM_INVENTORY.getBoolValue(this.category); + boolean isSelected = i == InventoryUtils.getSelectedInventory(this.category) && !isRandomInventory; int finalI = i; ButtonWidget editButton = this.addButton(new LimitlessButtonWidget(x, y, rowButtonSize, rowButtonSize, new LiteralText("Edit"), b -> { if (this.client != null) { @@ -80,7 +82,7 @@ protected void init() { this.client.openScreen(new InventoryOptionsScreen(this.parent, this.category)); } })); - selectButton.active = !isSelected && isCorrectBound; + selectButton.active = !isSelected && isCorrectBound && !isRandomInventory; } int otherButtonWidth = (this.width - rowWidth) / 2 - paddingX * 2; this.addButton( @@ -115,7 +117,7 @@ protected void init() { this.addButton( new LimitlessButtonWidget( null, - EGG_TEXTURE, + BREWING_STAND_TEXTURE, null, scrambleButton.x, scrambleButton.y + scrambleButton.getHeight(), @@ -125,6 +127,9 @@ protected void init() { b -> { CategoryPreferences.RANDOM_INVENTORY.advanceValue(this.category); b.setMessage(CategoryPreferencesScreen.getFormattedText(this.category, CategoryPreferences.RANDOM_INVENTORY)); + if (this.client != null) { + this.client.openScreen(new InventoryOptionsScreen(this.parent, this.category)); + } } ) ); diff --git a/src/main/java/me/falu/peepopractice/gui/screen/SettingsTypeSelectionScreen.java b/src/main/java/me/falu/peepopractice/gui/screen/SettingsTypeSelectionScreen.java index 5b175ab..6bd3ac0 100644 --- a/src/main/java/me/falu/peepopractice/gui/screen/SettingsTypeSelectionScreen.java +++ b/src/main/java/me/falu/peepopractice/gui/screen/SettingsTypeSelectionScreen.java @@ -42,7 +42,7 @@ public String getReason() { private final PracticeCategory category; public SettingsTypeSelectionScreen(Screen parent, PracticeCategory category) { - super(new TranslatableText("peepopractice.title.settings_type_selection", category.getName(false))); + super(new TranslatableText("peepopractice.title.settings_type_selection", category.getSimpleName())); this.parent = parent; this.category = category; } diff --git a/src/main/java/me/falu/peepopractice/gui/screen/SplitSettingsScreen.java b/src/main/java/me/falu/peepopractice/gui/screen/SplitSettingsScreen.java index f439ee6..d2e9e61 100644 --- a/src/main/java/me/falu/peepopractice/gui/screen/SplitSettingsScreen.java +++ b/src/main/java/me/falu/peepopractice/gui/screen/SplitSettingsScreen.java @@ -21,7 +21,7 @@ public class SplitSettingsScreen extends Screen { private final PracticeCategory category; public SplitSettingsScreen(Screen parent, PracticeCategory category) { - super(new TranslatableText("peepopractice.title.split_settings", category.getName(false))); + super(new TranslatableText("peepopractice.title.split_settings", category.getSimpleName())); this.parent = parent; this.category = category; } diff --git a/src/main/java/me/falu/peepopractice/gui/screen/StandardSettingsScreen.java b/src/main/java/me/falu/peepopractice/gui/screen/StandardSettingsScreen.java index e80e0bc..a47e6aa 100644 --- a/src/main/java/me/falu/peepopractice/gui/screen/StandardSettingsScreen.java +++ b/src/main/java/me/falu/peepopractice/gui/screen/StandardSettingsScreen.java @@ -32,7 +32,7 @@ public class StandardSettingsScreen extends Screen { private TextFieldWidget pieChartDirectoryField; public StandardSettingsScreen(Screen parent, PracticeCategory category) { - super(new TranslatableText("peepopractice.title.standard_settings", category.getName(false))); + super(new TranslatableText("peepopractice.title.standard_settings", category.getSimpleName())); this.parent = parent; PeepoPractice.CONFIGURING_CATEGORY = category; } diff --git a/src/main/java/me/falu/peepopractice/gui/widget/ThumbnailButtonWidget.java b/src/main/java/me/falu/peepopractice/gui/widget/ThumbnailButtonWidget.java index 14a0b4d..5609af7 100644 --- a/src/main/java/me/falu/peepopractice/gui/widget/ThumbnailButtonWidget.java +++ b/src/main/java/me/falu/peepopractice/gui/widget/ThumbnailButtonWidget.java @@ -61,7 +61,7 @@ public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float del drawTexture(matrices, this.configButton.x + 2, this.configButton.y + 2, 0.0F, 0.0F, 16, 16, 16, 16); fill(matrices, this.x, this.y + this.height, this.x + this.width, this.y + this.height - this.height / 2 + 5, BackgroundHelper.ColorMixer.getArgb(150, 0, 0, 0)); - this.drawCenteredString( + this.drawCenteredText( matrices, client.textRenderer, this.category.getName(false), diff --git a/src/main/java/me/falu/peepopractice/mixin/gui/screen/CreateWorldScreenMixin.java b/src/main/java/me/falu/peepopractice/mixin/gui/screen/CreateWorldScreenMixin.java index c16de54..c5fa51e 100644 --- a/src/main/java/me/falu/peepopractice/mixin/gui/screen/CreateWorldScreenMixin.java +++ b/src/main/java/me/falu/peepopractice/mixin/gui/screen/CreateWorldScreenMixin.java @@ -46,7 +46,7 @@ protected CreateWorldScreenMixin(Text title) { if (!category.equals(PracticeCategoriesAny.EMPTY)) { this.field_24289 = this.field_24290 = category.hasWorldProperties() ? category.getWorldProperties().getStartDifficulty() : Difficulty.EASY; this.cheatsEnabled = this.tweakedCheats = true; - this.levelName = category.getTranslatedName(); + this.levelName = category.getTranslatedName().getString(); } } diff --git a/src/main/java/me/falu/peepopractice/mixin/gui/screen/GameMenuScreenMixin.java b/src/main/java/me/falu/peepopractice/mixin/gui/screen/GameMenuScreenMixin.java index 9023bd6..560df0b 100644 --- a/src/main/java/me/falu/peepopractice/mixin/gui/screen/GameMenuScreenMixin.java +++ b/src/main/java/me/falu/peepopractice/mixin/gui/screen/GameMenuScreenMixin.java @@ -17,7 +17,6 @@ import net.minecraft.client.gui.widget.AbstractButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import net.minecraft.text.TranslatableText; import org.spongepowered.asm.mixin.Mixin; @@ -152,7 +151,7 @@ public abstract class GameMenuScreenMixin extends ScreenMixin { if (this.renderTitle) { RenderSystem.pushMatrix(); RenderSystem.scalef(2.0F, 2.0F, 2.0F); - this.drawCenteredText(matrices, this.textRenderer, new LiteralText(PeepoPractice.CATEGORY.getName(true)), this.width / 2 / 2, 6, 0xFFFFFF); + this.drawCenteredText(matrices, this.textRenderer, PeepoPractice.CATEGORY.getName(true), this.width / 2 / 2, 6, 0xFFFFFF); RenderSystem.popMatrix(); } } diff --git a/src/main/java/me/falu/peepopractice/mixin/world/PlayerManagerMixin.java b/src/main/java/me/falu/peepopractice/mixin/world/PlayerManagerMixin.java index eb6fa61..0297bbd 100644 --- a/src/main/java/me/falu/peepopractice/mixin/world/PlayerManagerMixin.java +++ b/src/main/java/me/falu/peepopractice/mixin/world/PlayerManagerMixin.java @@ -57,8 +57,15 @@ public abstract class PlayerManagerMixin { player.inventory.setStack(i, InventoryUtils.PREVIOUS_INVENTORY.get(i).copy()); } } else { - PeepoPractice.log("Using configured inventory."); - InventoryUtils.putItems(player.inventory, PeepoPractice.CATEGORY, InventoryUtils.getSelectedInventory()); + int inventory; + if (CategoryPreferences.RANDOM_INVENTORY.getBoolValue()) { + PeepoPractice.log("Using random inventory."); + inventory = InventoryUtils.randomInventory(PeepoPractice.CATEGORY); + } else { + PeepoPractice.log("Using configured inventory."); + inventory = InventoryUtils.getSelectedInventory(PeepoPractice.CATEGORY); + } + InventoryUtils.putItems(player.inventory, PeepoPractice.CATEGORY, inventory); if (CategoryPreferences.SCRAMBLE_INVENTORY.getBoolValue()) { PeepoPractice.log("Scrambling inventory."); List taken = new ArrayList<>(); diff --git a/src/main/resources/assets/peepopractice/lang/en_us.json b/src/main/resources/assets/peepopractice/lang/en_us.json index 1d99ef7..bfe7b6d 100644 --- a/src/main/resources/assets/peepopractice/lang/en_us.json +++ b/src/main/resources/assets/peepopractice/lang/en_us.json @@ -52,6 +52,7 @@ "peepopractice.global_options.change_window_title.info": "If enabled, the text '(Practice)' will be appended to the game's window title.", "peepopractice.global_options.give_saturation.info": "If enabled, you'll get 10 saturation when you spawn in.", "peepopractice.preferences.scramble_inventory": "Scramble", + "peepopractice.preferences.random_inventory": "Random", "peepopractice.preferences.compare_type": "Split Comparison", "peepopractice.preferences.compare_type.info": "Which type of time the split is compared against.", "peepopractice.preferences.pace_timer_show_type": "Show Pace Timer",