Skip to content

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
faluhub committed May 6, 2024
1 parent c81da5f commit b4ff05a
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 31 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -227,15 +231,15 @@ public boolean isAA() {
}

public boolean hasConfiguredInventory() {
if (this.canHaveEmptyInventory) {
if (this.canHaveEmptyInventory || CategoryPreferences.RANDOM_INVENTORY.getBoolValue(this)) {
return true;
}
PracticeWriter writer = PracticeWriter.INVENTORY_WRITER;
JsonObject config = writer.get();
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,14 +29,15 @@

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;
private final List<NamePositionData> namePositions;
private final List<HotbarPositionData> 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<>();
Expand All @@ -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) {
Expand All @@ -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(
Expand Down Expand Up @@ -115,7 +117,7 @@ protected void init() {
this.addButton(
new LimitlessButtonWidget(
null,
EGG_TEXTURE,
BREWING_STAND_TEXTURE,
null,
scrambleButton.x,
scrambleButton.y + scrambleButton.getHeight(),
Expand All @@ -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));
}
}
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> taken = new ArrayList<>();
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/peepopractice/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b4ff05a

Please sign in to comment.