diff options
Diffstat (limited to 'src/main/java')
6 files changed, 207 insertions, 66 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java index 9dcfd39..71be174 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java @@ -8,12 +8,10 @@ import net.minecraft.item.Items; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.stat.Stats; -import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.util.Formatting; import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS; -import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS_TOTAL; import dev.mayaqq.ygasi.registry.ConfigRegistry; import net.minecraft.util.Identifier; @@ -25,7 +23,7 @@ public class BranchGui { try { SkillGui gui = new SkillGui(ScreenHandlerType.GENERIC_9X3, player, false) {}; - gui.setTitle(Text.of("§3Skill Points: " + skillPoints)); + gui.setTitle(Text.translatable("gui.ygasi.branch.title", skillPoints)); //background items for (int x = 0; x <= 26; x++) { @@ -55,18 +53,16 @@ public class BranchGui { .setItem(Items.DIAMOND_SWORD) .setCustomModelData(1) .hideFlag(ItemStack.TooltipSection.MODIFIERS) - .addLoreLine(Text.literal("Cost: " + ConfigRegistry.CONFIG.branchCost).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_GRAY))) - .setName(Text.literal("Mercenary") - .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED))) - .setCallback((index, clickType, actionType) -> save(player, "mercenary", "§cMercenary")) + .addLoreLine(Text.translatable("gui.ygasi.branch.cost", ConfigRegistry.CONFIG.branchCost)) + .setName(Text.translatable("gui.ygasi.branch.mercenary.title").formatted(Formatting.BOLD)) + .setCallback((index, clickType, actionType) -> save(player, "mercenary", "gui.ygasi.branch.mercenary.title")) ); } else { gui.setSlot(11, new GuiElementBuilder() .setItem(Items.DIAMOND_SWORD) .hideFlag(ItemStack.TooltipSection.MODIFIERS) .glow() - .setName(Text.literal("Mercenary") - .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED))) + .setName(Text.translatable("gui.ygasi.branch.mercenary.title").formatted(Formatting.BOLD)) .setCallback((index, clickType, actionType) -> MercenaryGui.gui(player)) ); } @@ -74,17 +70,15 @@ public class BranchGui { if (!YgasiUtils.getAdvancementProgress(player, "minecraft", "ygasi/wizardry")) { gui.setSlot(13, new GuiElementBuilder() .setItem(Items.BLAZE_ROD) - .addLoreLine(Text.literal("Cost: " + ConfigRegistry.CONFIG.branchCost).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_GRAY))) - .setName(Text.literal("Wizardry") - .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.DARK_PURPLE))) - .setCallback((index, clickType, actionType) -> save(player, "wizardry", "§5Wizardry")) + .addLoreLine(Text.translatable("gui.ygasi.branch.cost", ConfigRegistry.CONFIG.branchCost)) + .setName(Text.translatable("gui.ygasi.branch.wizardry.title").formatted(Formatting.BOLD)) + .setCallback((index, clickType, actionType) -> save(player, "wizardry", "gui.ygasi.branch.wizardry.title")) ); } else { gui.setSlot(13, new GuiElementBuilder() .setItem(Items.BLAZE_ROD) .glow() - .setName(Text.literal("Wizardry") - .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.DARK_PURPLE))) + .setName(Text.translatable("gui.ygasi.branch.wizardry.title").formatted(Formatting.BOLD)) .setCallback((index, clickType, actionType) -> WizardryGui.gui(player)) ); } @@ -92,17 +86,15 @@ public class BranchGui { if (!YgasiUtils.getAdvancementProgress(player, "minecraft", "ygasi/druidry")) { gui.setSlot(15, new GuiElementBuilder() .setItem(Items.OAK_SAPLING) - .addLoreLine(Text.literal("Cost: " + ConfigRegistry.CONFIG.branchCost).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_GRAY))) - .setName(Text.literal("Druidry") - .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.GREEN))) - .setCallback((index, clickType, actionType) -> save(player, "druidry", "§aDruidry")) + .addLoreLine(Text.translatable("gui.ygasi.branch.cost", ConfigRegistry.CONFIG.branchCost)) + .setName(Text.translatable("gui.ygasi.branch.druidry.title").formatted(Formatting.BOLD)) + .setCallback((index, clickType, actionType) -> save(player, "druidry", "gui.ygasi.branch.druidry.title")) ); } else { gui.setSlot(15, new GuiElementBuilder() .setItem(Items.OAK_SAPLING) .glow() - .setName(Text.literal("Druidry") - .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.GREEN))) + .setName(Text.translatable("gui.ygasi.branch.druidry.title").formatted(Formatting.BOLD)) .setCallback((index, clickType, actionType) -> DruidryGui.gui(player)) ); } @@ -110,17 +102,15 @@ public class BranchGui { if (!YgasiUtils.getAdvancementProgress(player, "minecraft", "ygasi/extra")) { gui.setSlot(26, new GuiElementBuilder() .setItem(Items.BOOK) - .addLoreLine(Text.literal("Cost: " + ConfigRegistry.CONFIG.branchCost / 2).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_GRAY))) - .setName(Text.literal("Extra") - .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.BLUE))) - .setCallback((index, clickType, actionType) -> save(player, "extra", "§9Extra Skills")) + .addLoreLine(Text.translatable("gui.ygasi.branch.cost", ConfigRegistry.CONFIG.branchCost / 2)) + .setName(Text.translatable("gui.ygasi.branch.extra.title").formatted(Formatting.BOLD)) + .setCallback((index, clickType, actionType) -> save(player, "extra", "gui.ygasi.branch.extra.title")) ); } else { gui.setSlot(26, new GuiElementBuilder() .setItem(Items.BOOK) .glow() - .setName(Text.literal("Extra Skills") - .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.BLUE))) + .setName(Text.translatable("gui.ygasi.branch.extra.title").formatted(Formatting.BOLD)) .setCallback((index, clickType, actionType) -> ExtraGui.gui(player)) ); } @@ -128,13 +118,18 @@ public class BranchGui { //info item gui.setSlot(18, new GuiElementBuilder() .setItem(Items.PAPER) - .setName(Text.literal("Info").formatted(Formatting.GOLD).formatted(Formatting.BOLD)) - .setCallback((index, clickType, actionType) -> infoMessage(player)) + .setName(Text.translatable("gui.ygasi.branch.info.title")) + .setCallback((index, clickType, actionType) -> { + player.closeHandledScreen(); + player.sendMessage(Text.translatable("gui.ygasi.branch.info.main"), false); + }) ); //reset item gui.setSlot(8, new GuiElementBuilder() .setItem(Items.BARRIER) - .setName(Text.literal("Reset").formatted(Formatting.RED).formatted(Formatting.BOLD)) + .setName(Text.translatable("gui.ygasi.branch.reset.title")) + .addLoreLine(Text.translatable("gui.ygasi.branch.reset.lore")) + .addLoreLine(Text.translatable("gui.ygasi.branch.reset.lore2")) .setCallback((index, clickType, actionType) -> ResetGui.gui(player)) ); @@ -150,35 +145,35 @@ public class BranchGui { if (player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) >= ConfigRegistry.CONFIG.branchCost / 2) { player.getStatHandler().setStat(player, Stats.CUSTOM.getOrCreateStat(SKILL_POINTS), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) - ConfigRegistry.CONFIG.branchCost / 2); YgasiUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/extra"), "unlocked_extra"); - player.sendMessage(Text.of("§aYou have unlocked the " + branchName + " branch!"), false); + player.sendMessage(Text.translatable("gui.ygasi.branch.unlock", Text.translatable(branchName)), false); ExtraGui.gui(player); } else { - player.sendMessage(Text.of("§cYou do not have enough skill points to unlock this branch!"), false); + player.sendMessage(Text.translatable("gui.ygasi.branch.no.skill"), false); } } else { if (player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) >= ConfigRegistry.CONFIG.branchCost) { player.getStatHandler().setStat(player, Stats.CUSTOM.getOrCreateStat(SKILL_POINTS), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) - ConfigRegistry.CONFIG.branchCost); - player.sendMessage(Text.of("You have selected the §a" + branchName + " §fbranch!"), false); + player.sendMessage(Text.translatable("gui.ygasi.branch.unlock", Text.translatable(branchName)), false); player.closeHandledScreen(); - if (branch.equals("mercenary")) { - YgasiUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/mercenary"), "unlocked_mercenary"); - MercenaryGui.gui(player); - } else if (branch.equals("wizardry")) { - YgasiUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/wizardry"), "unlocked_wizardry"); - WizardryGui.gui(player); - } else if (branch.equals("druidry")) { - YgasiUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/druidry"), "unlocked_druidry"); - DruidryGui.gui(player); + switch (branch) { + case "mercenary" -> { + YgasiUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/mercenary"), "unlocked_mercenary"); + MercenaryGui.gui(player); + } + case "wizardry" -> { + YgasiUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/wizardry"), "unlocked_wizardry"); + WizardryGui.gui(player); + } + case "druidry" -> { + YgasiUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/druidry"), "unlocked_druidry"); + DruidryGui.gui(player); + } } } else { - player.sendMessage(Text.translatable("gui.ygasi.branch.no.skill").setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED)), false); + player.sendMessage(Text.translatable("gui.ygasi.branch.no.skill"), false); player.closeHandledScreen(); } } } - public static void infoMessage(ServerPlayerEntity player) { - player.closeHandledScreen(); - player.sendMessage(Text.translatable("gui.ygasi.branch.info.main"), false); - } }
\ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java b/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java new file mode 100644 index 0000000..f847227 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java @@ -0,0 +1,146 @@ +package dev.mayaqq.ygasi.gui; + +import dev.mayaqq.ygasi.registry.ConfigRegistry; +import eu.pb4.sgui.api.elements.GuiElementBuilder; +import eu.pb4.sgui.api.gui.SignGui; +import eu.pb4.sgui.api.gui.SimpleGui; +import net.minecraft.item.Items; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; +import net.minecraft.text.Text; + +public class ConfigGui { + + public static void gui(ServerPlayerEntity player) { + SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false) { + @Override + public void onClose() { + ConfigRegistry.save(); + super.onClose(); + } + }; + + gui.setTitle(Text.translatable("config.ygasi.title")); + + gui.setSlot(0, new GuiElementBuilder() + .setItem(Items.ENDER_EYE) + .setName(Text.translatable("config.ygasi.pointsRewarded.title")) + .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.pointsRewarded)))) + .setCallback((index, clickType, actionType) -> { + textInput(player, "pointsRewarded"); + player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F); + }) + ); + + gui.setSlot(1, new GuiElementBuilder() + .setItem(Items.OAK_SAPLING) + .setName(Text.translatable("config.ygasi.branchCost.title")) + .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.branchCost)))) + .setCallback((index, clickType, actionType) -> { + textInput(player, "branchCost"); + player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F); + }) + ); + + gui.setSlot(2, new GuiElementBuilder() + .setItem(Items.BOOK) + .setName(Text.translatable("config.ygasi.enableSkillBook.title")) + .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.enableSkillBook)))) + .setCallback((index, clickType, actionType) -> { + ConfigRegistry.CONFIG.enableSkillBook = !ConfigRegistry.CONFIG.enableSkillBook; + gui.close(); + gui(player); + player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F); + }) + ); + + gui.setSlot(3, new GuiElementBuilder() + .setItem(Items.STICK) + .setName(Text.translatable("config.ygasi.T1Cost.title")) + .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.T1Cost)))) + .setCallback((index, clickType, actionType) -> { + textInput(player, "T1Cost"); + player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F); + }) + ); + + gui.setSlot(4, new GuiElementBuilder() + .setItem(Items.STICK) + .setCount(2) + .setName(Text.translatable("config.ygasi.T2Cost.title")) + .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.T2Cost)))) + .setCallback((index, clickType, actionType) -> { + textInput(player, "T2Cost"); + player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F); + }) + ); + + gui.setSlot(5, new GuiElementBuilder() + .setItem(Items.STICK) + .setCount(3) + .setName(Text.translatable("config.ygasi.T3Cost.title")) + .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.T3Cost)))) + .setCallback((index, clickType, actionType) -> { + textInput(player, "T3Cost"); + player.playSound(SoundEvents.UI_BUTTON_CLICK, SoundCategory.PLAYERS, 1.0F, 1.0F); + }) + ); + + gui.open(); + } + + + private static void textInput(ServerPlayerEntity player, String option) { + try { + SignGui gui = new SignGui(player) { + @Override + public void onClose() { + switch (option) { + case "pointsRewarded" -> { + try { + ConfigRegistry.CONFIG.pointsRewarded = Integer.parseInt(this.getLine(0).getString()); + } catch (NumberFormatException e) { + player.sendMessage(Text.translatable("config.ygasi.invalid.number"), false); + } + } + case "branchCost" -> { + try { + ConfigRegistry.CONFIG.branchCost = Integer.parseInt(this.getLine(0).getString()); + } catch (NumberFormatException e) { + player.sendMessage(Text.translatable("config.ygasi.invalid.number"), false); + } + } + case "T1Cost" -> { + try { + ConfigRegistry.CONFIG.T1Cost = Integer.parseInt(this.getLine(0).getString()); + } catch (NumberFormatException e) { + player.sendMessage(Text.translatable("config.ygasi.invalid.number"), false); + } + } + case "T2Cost" -> { + try { + ConfigRegistry.CONFIG.T2Cost = Integer.parseInt(this.getLine(0).getString()); + } catch (NumberFormatException e) { + player.sendMessage(Text.translatable("config.ygasi.invalid.number"), false); + } + } + case "T3Cost" -> { + try { + ConfigRegistry.CONFIG.T3Cost = Integer.parseInt(this.getLine(0).getString()); + } catch (NumberFormatException e) { + player.sendMessage(Text.translatable("config.ygasi.invalid.number"), false); + } + } + } + gui(player); + } + }; + gui.open(); + + } catch (Exception e) { + e.printStackTrace(); + } + } +}
\ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java index ac722b6..666c802 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java @@ -41,7 +41,7 @@ public class MercenaryGui { .setItem(Items.DIAMOND_SWORD) .setName(Text.translatable("gui.ygasi.mercenary.offence1")) .addLoreLine(Text.translatable("gui.ygasi.mercenary.offence1.lore")) - .addLoreLine(Text.translatable("gui.ygasi.mercenary.offence1.lore.cost".replace("%cost%", ConfigRegistry.CONFIG.offence1Cost + ""))) + .addLoreLine(Text.translatable("gui.ygasi.mercenary.offence1.lore.cost")) ); } diff --git a/src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java b/src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java index c96de2a..52f2c8d 100644 --- a/src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java +++ b/src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java @@ -27,9 +27,7 @@ public class SkillBookItem extends SimplePolymerItem { @Override public ItemStack getPolymerItemStack(ItemStack itemStack, ServerPlayerEntity player) { - ItemStack out = PolymerItemUtils.createItemStack(itemStack, player); - out.addEnchantment(Enchantments.LURE, 0); - return out; + return PolymerItemUtils.createItemStack(itemStack, player); } @Override diff --git a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java index aa03f96..e2aaa05 100644 --- a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java +++ b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java @@ -2,10 +2,7 @@ package dev.mayaqq.ygasi.registry; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.context.CommandContext; -import dev.mayaqq.ygasi.gui.BranchGui; -import dev.mayaqq.ygasi.gui.DruidryGui; -import dev.mayaqq.ygasi.gui.MercenaryGui; -import dev.mayaqq.ygasi.gui.WizardryGui; +import dev.mayaqq.ygasi.gui.*; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.command.argument.EntityArgumentType; @@ -80,6 +77,10 @@ public class CommandRegistry { return 1; }))) .then(literal("config") + .executes(context -> { + ConfigGui.gui(context.getSource().getPlayer()); + return 1; + }) .then(literal("reload") .executes(context -> { ConfigRegistry.load(); diff --git a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java index 0b5cfa5..2c939b3 100644 --- a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java +++ b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java @@ -5,10 +5,6 @@ import com.google.gson.GsonBuilder; import net.fabricmc.loader.api.FabricLoader; import java.io.*; -import java.nio.file.Files; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; public class ConfigRegistry { @@ -26,7 +22,7 @@ public class ConfigRegistry { if (!configFile.exists()) { try { configFile.createNewFile(); - saveConfig(); + save(); } catch (IOException e) { throw new RuntimeException(e); } @@ -39,11 +35,14 @@ public class ConfigRegistry { } } - public static void saveConfig() throws IOException { - //Write some info into the file under here - var writer = new FileWriter(configFile); - writer.write(gson.toJson(CONFIG)); - writer.close(); + public static void save() { + try { + FileWriter writer = new FileWriter(configFile); + gson.toJson(CONFIG, writer); + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } } public static class Config { @@ -51,7 +50,9 @@ public class ConfigRegistry { public int pointsRewarded = 1; public int branchCost = 16; public Boolean enableSkillBook = true; - public int offence1Cost = 3; + public int T1Cost = 5; + public int T2Cost = 10; + public int T3Cost = 15; public Config() {} } |