diff options
Diffstat (limited to 'src/main/java/dev/mayaqq/ygasi/gui')
-rw-r--r-- | src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java | 33 | ||||
-rw-r--r-- | src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java | 12 | ||||
-rw-r--r-- | src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java | 14 | ||||
-rw-r--r-- | src/main/java/dev/mayaqq/ygasi/gui/SkillGui.java | 25 | ||||
-rw-r--r-- | src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java | 11 |
5 files changed, 59 insertions, 36 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java index ac19478..535d37e 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java @@ -1,5 +1,7 @@ package dev.mayaqq.ygasi.gui; +import dev.mayaqq.ygasi.util.GetAdvancementProgress; +import dev.mayaqq.ygasi.util.GrantAdvancementCriterion; import eu.pb4.sgui.api.elements.*; import eu.pb4.sgui.api.gui.SimpleGui; @@ -7,24 +9,22 @@ import net.minecraft.item.ItemStack; 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.stat.Stats; import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import java.util.UUID; - import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS; import dev.mayaqq.ygasi.registry.ConfigRegistry; -import dev.mayaqq.ygasi.registry.PlayerDataRegistry; +import net.minecraft.util.Identifier; public class BranchGui { public static void gui(ServerPlayerEntity player) { try { - UUID playerUUID = player.getUuid(); - PlayerDataRegistry.load(playerUUID); - SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false) {}; + SkillGui gui = new SkillGui(ScreenHandlerType.GENERIC_9X3, player, false) {}; gui.setTitle(Text.of("§3Skill Points: " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)))); @@ -47,11 +47,11 @@ public class BranchGui { .setItem(Items.BARRIER) .setName(Text.literal("Close") .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.DARK_RED))) - .setCallback((index, clickType, actionType) -> gui.close()) + .setCallback((index, clickType, actionType) -> close(player)) ); //branch items - if (PlayerDataRegistry.PLAYERDATA.branches.get("mercenary") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("mercenary")) { + if (!GetAdvancementProgress.get(player, "mercenary")) { gui.setSlot(11, new GuiElementBuilder() .setItem(Items.IRON_SWORD) .hideFlag(ItemStack.TooltipSection.MODIFIERS) @@ -71,7 +71,7 @@ public class BranchGui { ); } - if (PlayerDataRegistry.PLAYERDATA.branches.get("wizardry") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("wizardry")) { + if (!GetAdvancementProgress.get(player, "wizardry")) { gui.setSlot(13, new GuiElementBuilder() .setItem(Items.BLAZE_ROD) .addLoreLine(Text.literal("Cost: " + ConfigRegistry.CONFIG.branchCost).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_GRAY))) @@ -89,7 +89,7 @@ public class BranchGui { ); } - if (PlayerDataRegistry.PLAYERDATA.branches.get("druidry") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("druidry")) { + if (!GetAdvancementProgress.get(player, "druidry")) { gui.setSlot(15, new GuiElementBuilder() .setItem(Items.OAK_SAPLING) .addLoreLine(Text.literal("Cost: " + ConfigRegistry.CONFIG.branchCost).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_GRAY))) @@ -106,6 +106,8 @@ public class BranchGui { .setCallback((index, clickType, actionType) -> DruidryGui.gui(player)) ); } + GrantAdvancementCriterion.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/root"), "opened_skill_menu"); + gui.open(); } catch (Exception e) { e.printStackTrace(); @@ -115,14 +117,15 @@ public class BranchGui { 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); - PlayerDataRegistry.PLAYERDATA.branches.put(branch, true); - PlayerDataRegistry.save(player.getUuid()); player.closeHandledScreen(); if (branch.equals("mercenary")) { + GrantAdvancementCriterion.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/mercenary"), "unlocked_mercenary"); MercenaryGui.gui(player); } else if (branch.equals("wizardry")) { + GrantAdvancementCriterion.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/wizardry"), "unlocked_wizardry"); WizardryGui.gui(player); } else if (branch.equals("druidry")) { + GrantAdvancementCriterion.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/druidry"), "unlocked_druidry"); DruidryGui.gui(player); } @@ -131,4 +134,8 @@ public class BranchGui { player.closeHandledScreen(); } } -} + public static void close(ServerPlayerEntity player) { + player.playSound(SoundEvents.ITEM_BOOK_PAGE_TURN, SoundCategory.PLAYERS, 1.0F, 1.0F); + player.closeHandledScreen(); + } +}
\ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java index 4054ead..2b865f2 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java @@ -1,28 +1,26 @@ package dev.mayaqq.ygasi.gui; -import dev.mayaqq.ygasi.registry.PlayerDataRegistry; +import dev.mayaqq.ygasi.util.GetAdvancementProgress; import eu.pb4.sgui.api.elements.GuiElementBuilder; 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.stat.Stats; import net.minecraft.text.Text; -import java.util.UUID; - import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS; public class DruidryGui { public static void gui(ServerPlayerEntity player) { try { - UUID playerUUID = player.getUuid(); - PlayerDataRegistry.load(playerUUID); - if (PlayerDataRegistry.PLAYERDATA.branches.get("druidry") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("druidry")) { + if (!GetAdvancementProgress.get(player, "druidry")) { player.sendMessage(Text.of("§cYou have not unlocked this branch yet!"), false); BranchGui.gui(player); } else { - SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false) {}; + SkillGui gui = new SkillGui(ScreenHandlerType.GENERIC_9X6, player, false) {}; gui.setTitle(Text.of( "§a§lDruidry " + "§3Skill Points: " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)))); diff --git a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java index 5c95eb2..c3e89b1 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java @@ -1,28 +1,26 @@ package dev.mayaqq.ygasi.gui; -import dev.mayaqq.ygasi.registry.PlayerDataRegistry; +import dev.mayaqq.ygasi.util.GetAdvancementProgress; import eu.pb4.sgui.api.elements.GuiElementBuilder; 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.stat.Stats; import net.minecraft.text.Text; -import java.util.UUID; - import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS; public class MercenaryGui { public static void gui(ServerPlayerEntity player) { try { - UUID playerUUID = player.getUuid(); - PlayerDataRegistry.load(playerUUID); - if (PlayerDataRegistry.PLAYERDATA.branches.get("mercenary") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("mercenary")) { + if (!GetAdvancementProgress.get(player, "mercenary")) { player.sendMessage(Text.of("§cYou have not unlocked this branch yet!"), false); BranchGui.gui(player); } else { - SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false) {}; + SkillGui gui = new SkillGui(ScreenHandlerType.GENERIC_9X6, player, false) {}; gui.setTitle(Text.of( "§c§lMercenary " + "§3Skill Points: " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)))); @@ -38,4 +36,4 @@ public class MercenaryGui { e.printStackTrace(); } } -} +}
\ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/gui/SkillGui.java b/src/main/java/dev/mayaqq/ygasi/gui/SkillGui.java new file mode 100644 index 0000000..d12375d --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/gui/SkillGui.java @@ -0,0 +1,25 @@ +package dev.mayaqq.ygasi.gui; + +import eu.pb4.sgui.api.gui.SimpleGui; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvents; + +public class SkillGui extends SimpleGui { + public SkillGui(ScreenHandlerType<?> type, ServerPlayerEntity player, boolean manipulatePlayerSlots) { + super(type, player, manipulatePlayerSlots); + } + + @Override + public void onOpen() { + this.player.playSound(SoundEvents.ITEM_BOOK_PAGE_TURN, SoundCategory.PLAYERS, 1.0F, 1.0F); + super.onOpen(); + } + + @Override + public void onClose() { + player.playSound(SoundEvents.ITEM_BOOK_PAGE_TURN, SoundCategory.PLAYERS, 1.0F, 1.0F); + super.onClose(); + } +}
\ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java index c48b0c1..f5ae47f 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java @@ -1,28 +1,23 @@ package dev.mayaqq.ygasi.gui; -import dev.mayaqq.ygasi.registry.PlayerDataRegistry; +import dev.mayaqq.ygasi.util.GetAdvancementProgress; import eu.pb4.sgui.api.elements.GuiElementBuilder; -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.stat.Stats; import net.minecraft.text.Text; -import java.util.UUID; - import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS; public class WizardryGui { public static void gui(ServerPlayerEntity player) { try { - UUID playerUUID = player.getUuid(); - PlayerDataRegistry.load(playerUUID); - if (PlayerDataRegistry.PLAYERDATA.branches.get("wizardry") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("wizardry")) { + if (!GetAdvancementProgress.get(player, "wizardry")) { player.sendMessage(Text.of("§cYou have not unlocked this branch yet!"), false); BranchGui.gui(player); } else { - SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X6, player, false) {}; + SkillGui gui = new SkillGui(ScreenHandlerType.GENERIC_9X6, player, false) {}; gui.setTitle(Text.of( "§5§lWizardry " + "§3Skill Points: " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)))); |