diff options
Diffstat (limited to 'src/main/java/dev/mayaqq')
6 files changed, 66 insertions, 17 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java b/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java index 52b3047..97cd225 100644 --- a/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java +++ b/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java @@ -1,10 +1,8 @@ package dev.mayaqq.ygasi.events; import dev.mayaqq.ygasi.registry.ConfigRegistry; -import dev.mayaqq.ygasi.util.AdvUtils; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; import static dev.mayaqq.ygasi.registry.ItemRegistry.SKILL_BOOK; @@ -15,7 +13,6 @@ public class PlayerConnectEvent { if (!handler.player.getScoreboardTags().contains("skill_book_unlocked") && ConfigRegistry.CONFIG.enableSkillBook) { handler.player.addScoreboardTag("skill_book_unlocked"); handler.player.getInventory().offerOrDrop(new ItemStack(SKILL_BOOK)); - AdvUtils.grantAdvancementCriterion(handler.player, new Identifier("ygasi", "recipes/minecraft_ygasi/skill_book"), "opened_skill_menu"); } }); } diff --git a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java index 4180771..8c1fa4b 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java @@ -74,6 +74,18 @@ public class BranchGui { ); } + for (int i = 13; i <=15; i += 2) { + gui.setSlot(i, new GuiElementBuilder() + .setItem(Items.BARRIER) + .setName(Text.translatable("gui.ygasi.branch.wip").formatted(Formatting.RED)) + ); + } + gui.setSlot(26, new GuiElementBuilder() + .setItem(Items.BARRIER) + .setName(Text.translatable("gui.ygasi.branch.wip").formatted(Formatting.RED)) + ); + + /* //wizardry gui button if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/wizardry")) { gui.setSlot(13, new GuiElementBuilder() @@ -124,6 +136,7 @@ public class BranchGui { .setCallback((index, clickType, actionType) -> ExtraGui.gui(player)) ); } + */ //info item button gui.setSlot(18, new GuiElementBuilder() @@ -136,7 +149,7 @@ public class BranchGui { ); //reset item button gui.setSlot(8, new GuiElementBuilder() - .setItem(Items.BARRIER) + .setItem(Items.TNT) .setName(Text.translatable("gui.ygasi.branch.reset.title")) .addLoreLine(Text.translatable("gui.ygasi.branch.reset.lore")) .addLoreLine(Text.translatable("gui.ygasi.branch.reset.lore2")) @@ -189,6 +202,7 @@ public class BranchGui { Class<?> guiClass = BRANCH_TO_GUI.get(branch); if (hasMercenary || hasWizadry || hasDrudiry) { player.sendMessage(Text.translatable("gui.ygasi.branch.no.unlock"), true); + player.playSound(SoundEvents.BLOCK_ANVIL_BREAK, SoundCategory.PLAYERS, 1.0F, 1.0F); player.closeHandledScreen(); } else { AdvUtils.grantAdvancementCriterion(player, advancementId, advancementCriterion); @@ -204,6 +218,7 @@ public class BranchGui { //if the player doesn't have enough skill points } else { player.sendMessage(Text.translatable("gui.ygasi.branch.no.skill"), true); + player.playSound(SoundEvents.BLOCK_ANVIL_BREAK, SoundCategory.PLAYERS, 1.0F, 1.0F); player.closeHandledScreen(); } } diff --git a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java index 87a0c85..cdbb989 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java @@ -10,8 +10,6 @@ import net.minecraft.item.Item; 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 net.minecraft.util.Formatting; diff --git a/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java b/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java index 6d8e538..c74280f 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java @@ -1,7 +1,6 @@ package dev.mayaqq.ygasi.gui; -import dev.mayaqq.ygasi.abilities.mercenary.Offence1; -import dev.mayaqq.ygasi.abilities.mercenary.Offence2; +import dev.mayaqq.ygasi.abilities.mercenary.*; import dev.mayaqq.ygasi.gui.common.SkillGui; import dev.mayaqq.ygasi.registry.ConfigRegistry; import dev.mayaqq.ygasi.util.AdvUtils; @@ -14,6 +13,9 @@ import net.minecraft.sound.SoundEvents; import net.minecraft.stat.Stats; import net.minecraft.text.Text; +import java.util.Arrays; + +import static dev.mayaqq.ygasi.Ygasi.LOGGER; import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS; import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS_TOTAL; @@ -62,12 +64,26 @@ public class ResetGui { //check if player experience level is greater than 10 //revoke the abilities first if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/mercenary")) { - Offence1.revoke(player); - Offence2.revoke(player); + AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/mercenary"); + String[] subBranches = {"mercenary.Offence", "mercenary.Ninja", "mercenary.Defence"}; + resetBranch(subBranches, player); } - AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/"); player.sendMessage(Text.translatable("gui.ygasi.reset.success"), true); player.getStatHandler().setStat(player, Stats.CUSTOM.getOrCreateStat(SKILL_POINTS), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS_TOTAL))); + } + private static void resetBranch (String[] subBranches, ServerPlayerEntity player) { + for (String subBranch : subBranches) { + for (int i = 1; i < 4; i++) { + String branch = subBranch + i; + try { + Class<?> branchClass = Class.forName("dev.mayaqq.ygasi.abilities." + branch); + branchClass.getMethod("revoke", ServerPlayerEntity.class).invoke(null, player); + + } catch (Exception e) { + LOGGER.error(Arrays.toString(e.getStackTrace())); + } + } + } } }
\ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/gui/common/GuiCommon.java b/src/main/java/dev/mayaqq/ygasi/gui/common/GuiCommon.java index c6946b4..3f54ee6 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/common/GuiCommon.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/common/GuiCommon.java @@ -1,6 +1,7 @@ package dev.mayaqq.ygasi.gui.common; import dev.mayaqq.ygasi.gui.BranchGui; +import dev.mayaqq.ygasi.util.AdvUtils; import eu.pb4.sgui.api.elements.GuiElementBuilder; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -39,6 +40,7 @@ public class GuiCommon { } } public static void setSkillSlot(SkillGui gui, ServerPlayerEntity player, int itemIndex, Item item, String nameKey, int cost, Class<?> skillClass, Class<?> guiClass) { + String advName = nameKey.split("\\.")[3]; gui.setSlot(itemIndex, new GuiElementBuilder() .setItem(item) .hideFlag(ItemStack.TooltipSection.MODIFIERS) @@ -48,11 +50,15 @@ public class GuiCommon { .setCallback((index, clickType, actionType) -> { if (player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) >= cost) { try { - skillClass.getMethod("give", ServerPlayerEntity.class).invoke(null, player); - player.getStatHandler().setStat(player, Stats.CUSTOM.getOrCreateStat(SKILL_POINTS), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) - cost); - guiClass.getMethod("gui", ServerPlayerEntity.class).invoke(null, player); - player.playSound(SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.PLAYERS, 1.0F, 1.0F); - + if (AdvUtils.hasBeforeAdvancements(player, "minecraft", "ygasi/"+ advName)) { + skillClass.getMethod("give", ServerPlayerEntity.class).invoke(null, player); + player.getStatHandler().setStat(player, Stats.CUSTOM.getOrCreateStat(SKILL_POINTS), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) - cost); + guiClass.getMethod("gui", ServerPlayerEntity.class).invoke(null, player); + player.playSound(SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.PLAYERS, 1.0F, 1.0F); + } else { + player.playSound(SoundEvents.BLOCK_ANVIL_BREAK, SoundCategory.PLAYERS, 1.0F, 1.0F); + player.sendMessage(Text.translatable("gui.ygasi.branches.no.previous"), true); + } } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/main/java/dev/mayaqq/ygasi/util/AdvUtils.java b/src/main/java/dev/mayaqq/ygasi/util/AdvUtils.java index b2227fe..708ed36 100644 --- a/src/main/java/dev/mayaqq/ygasi/util/AdvUtils.java +++ b/src/main/java/dev/mayaqq/ygasi/util/AdvUtils.java @@ -26,7 +26,7 @@ public class AdvUtils { } } - public static void revokeAllAdvancements(ServerPlayerEntity player, String namespace ,String path) { + public static void revokeAllAdvancements(ServerPlayerEntity player, String namespace, String path) { if (player.getServer() == null) { return; } @@ -48,4 +48,21 @@ public class AdvUtils { } return player.getAdvancementTracker().getProgress(player.getServer().getAdvancementLoader().get(new Identifier(namespace, path))).isDone(); } + + public static boolean hasBeforeAdvancements(ServerPlayerEntity player, String namespace, String path) { + int level = Integer.parseInt(path.substring(path.length() - 1)); + if (player.getServer() == null) { + return false; + } + for (int i = 1; i < level; i++) { + try { + if (!getAdvancementProgress(player, namespace, path.substring(0, path.length() - 1) + i)) { + return false; + } + } catch (Exception e) { + return false; + } + } + return true; + } }
\ No newline at end of file |