diff options
Diffstat (limited to 'src/main/java/dev')
23 files changed, 420 insertions, 118 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Defence1.java b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Defence1.java new file mode 100644 index 0000000..22ec265 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Defence1.java @@ -0,0 +1,18 @@ +package dev.mayaqq.ygasi.abilities.mercenary; + +import dev.mayaqq.ygasi.util.AdvUtils; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public class Defence1 { + public static void give(ServerPlayerEntity player) { + if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/defence1")) { + AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/defence1"), "unlocked_defence1"); + } + } + public static void revoke(ServerPlayerEntity player) { + if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/defence1")) { + AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/defence1"); + } + } +} diff --git a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Defence2.java b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Defence2.java new file mode 100644 index 0000000..3a47e89 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Defence2.java @@ -0,0 +1,18 @@ +package dev.mayaqq.ygasi.abilities.mercenary; + +import dev.mayaqq.ygasi.util.AdvUtils; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public class Defence2 { + public static void give(ServerPlayerEntity player) { + if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/defence2")) { + AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/defence2"), "unlocked_defence2"); + } + } + public static void revoke(ServerPlayerEntity player) { + if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/defence2")) { + AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/defence2"); + } + } +} diff --git a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Defence3.java b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Defence3.java new file mode 100644 index 0000000..39241aa --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Defence3.java @@ -0,0 +1,18 @@ +package dev.mayaqq.ygasi.abilities.mercenary; + +import dev.mayaqq.ygasi.util.AdvUtils; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public class Defence3 { + public static void give(ServerPlayerEntity player) { + if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/defence3")) { + AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/defence3"), "unlocked_defence3"); + } + } + public static void revoke(ServerPlayerEntity player) { + if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/defence3")) { + AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/defence3"); + } + } +} diff --git a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Ninja1.java b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Ninja1.java new file mode 100644 index 0000000..09ac5b2 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Ninja1.java @@ -0,0 +1,18 @@ +package dev.mayaqq.ygasi.abilities.mercenary; + +import dev.mayaqq.ygasi.util.AdvUtils; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public class Ninja1 { + public static void give(ServerPlayerEntity player) { + if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/ninja1")) { + AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/ninja1"), "unlocked_ninja1"); + } + } + public static void revoke(ServerPlayerEntity player) { + if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/ninja1")) { + AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/ninja1"); + } + } +} diff --git a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Ninja2.java b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Ninja2.java new file mode 100644 index 0000000..e673d83 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Ninja2.java @@ -0,0 +1,18 @@ +package dev.mayaqq.ygasi.abilities.mercenary; + +import dev.mayaqq.ygasi.util.AdvUtils; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public class Ninja2 { + public static void give(ServerPlayerEntity player) { + if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/ninja2")) { + AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/ninja2"), "unlocked_ninja2"); + } + } + public static void revoke(ServerPlayerEntity player) { + if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/ninja2")) { + AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/ninja2"); + } + } +} diff --git a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Ninja3.java b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Ninja3.java new file mode 100644 index 0000000..818da0f --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Ninja3.java @@ -0,0 +1,18 @@ +package dev.mayaqq.ygasi.abilities.mercenary; + +import dev.mayaqq.ygasi.util.AdvUtils; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public class Ninja3 { + public static void give(ServerPlayerEntity player) { + if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/ninja3")) { + AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/ninja3"), "unlocked_ninja3"); + } + } + public static void revoke(ServerPlayerEntity player) { + if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/ninja3")) { + AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/ninja3"); + } + } +} diff --git a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence1.java b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence1.java new file mode 100644 index 0000000..73b99e0 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence1.java @@ -0,0 +1,22 @@ +package dev.mayaqq.ygasi.abilities.mercenary; + +import dev.mayaqq.ygasi.registry.ConfigRegistry; +import dev.mayaqq.ygasi.util.AdvUtils; +import net.minecraft.entity.attribute.EntityAttributes; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public class Offence1 { + public static void give(ServerPlayerEntity player) { + if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence1")) { + player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).setBaseValue(player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).getBaseValue() + ConfigRegistry.CONFIG.offence1DefIncrease); + AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/offence1"), "unlocked_offence1"); + } + } + public static void revoke(ServerPlayerEntity player) { + if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence1")) { + player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).setBaseValue(player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).getBaseValue() - ConfigRegistry.CONFIG.offence1DefIncrease); + AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/offence1"); + } + } +}
\ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence2.java b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence2.java new file mode 100644 index 0000000..9b99592 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence2.java @@ -0,0 +1,18 @@ +package dev.mayaqq.ygasi.abilities.mercenary; + +import dev.mayaqq.ygasi.util.AdvUtils; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public class Offence2 { + public static void give(ServerPlayerEntity player) { + if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence2")) { + AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/offence2"), "unlocked_offence2"); + } + } + public static void revoke(ServerPlayerEntity player) { + if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence2")) { + AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/offence2"); + } + } +} diff --git a/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence3.java b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence3.java new file mode 100644 index 0000000..86efbc6 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/abilities/mercenary/Offence3.java @@ -0,0 +1,18 @@ +package dev.mayaqq.ygasi.abilities.mercenary; + +import dev.mayaqq.ygasi.util.AdvUtils; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public class Offence3 { + public static void give(ServerPlayerEntity player) { + if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence3")) { + AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/offence3"), "unlocked_offence3"); + } + } + public static void revoke(ServerPlayerEntity player) { + if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence3")) { + AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/offence3"); + } + } +} diff --git a/src/main/java/dev/mayaqq/ygasi/dataGen/advancements/YgasiAdvancements.java b/src/main/java/dev/mayaqq/ygasi/dataGen/advancements/YgasiAdvancements.java index 70fc642..e95ce6f 100644 --- a/src/main/java/dev/mayaqq/ygasi/dataGen/advancements/YgasiAdvancements.java +++ b/src/main/java/dev/mayaqq/ygasi/dataGen/advancements/YgasiAdvancements.java @@ -22,7 +22,7 @@ public class YgasiAdvancements implements Consumer<Consumer<Advancement>> { Text.translatable("advancements.ygasi.root.description"), // The description new Identifier("textures/block/sculk_catalyst_top.png"), // Background image used AdvancementFrame.CHALLENGE, // Options: TASK, CHALLENGE, GOAL - true, // Show toast top right + false, // Show toast top right false, // Announce to chat false // Hidden in the advancement tab ).criterion("opened_skill_menu", new ImpossibleCriterion.Conditions()).rewards(AdvancementRewards.Builder.experience(1)).build(consumer, "ygasi" + "/root"); diff --git a/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java b/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java index 34f5f46..52b3047 100644 --- a/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java +++ b/src/main/java/dev/mayaqq/ygasi/events/PlayerConnectEvent.java @@ -2,17 +2,16 @@ package dev.mayaqq.ygasi.events; import dev.mayaqq.ygasi.registry.ConfigRegistry; import dev.mayaqq.ygasi.util.AdvUtils; -import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; -import static dev.mayaqq.ygasi.Ygasi.LOGGER; import static dev.mayaqq.ygasi.registry.ItemRegistry.SKILL_BOOK; public class PlayerConnectEvent { public static void onPlayerConnect() { ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { + //if the player has not joined yet, they will get a skill book if the option is turned on 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)); diff --git a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java index eca0226..4180771 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java @@ -1,5 +1,6 @@ package dev.mayaqq.ygasi.gui; +import dev.mayaqq.ygasi.gui.common.SkillGui; import dev.mayaqq.ygasi.util.AdvUtils; import eu.pb4.sgui.api.elements.*; @@ -7,6 +8,8 @@ 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.Text; import net.minecraft.util.Formatting; @@ -16,13 +19,17 @@ import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS; import dev.mayaqq.ygasi.registry.ConfigRegistry; import net.minecraft.util.Identifier; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + public class BranchGui { public static void gui(ServerPlayerEntity player) { Text cost = Text.of("§3" + ConfigRegistry.CONFIG.branchCost); try { SkillGui gui = new SkillGui(ScreenHandlerType.GENERIC_9X3, player, false) {}; //the title of the gui - gui.setTitle(Text.translatable("gui.ygasi.branch.title", player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS))).formatted(Formatting.DARK_AQUA)); + gui.setTitle(Text.translatable("gui.ygasi.branch.title", Text.of("§3" + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS))))); //background items for (int x = 0; x <= 26; x++) { @@ -133,6 +140,7 @@ public class BranchGui { .setName(Text.translatable("gui.ygasi.branch.reset.title")) .addLoreLine(Text.translatable("gui.ygasi.branch.reset.lore")) .addLoreLine(Text.translatable("gui.ygasi.branch.reset.lore2")) + .addLoreLine(Text.translatable("gui.ygasi.branch.reset.lore3", Text.of("§8" + ConfigRegistry.CONFIG.resetCost))) .setCallback((index, clickType, actionType) -> ResetGui.gui(player)) ); @@ -162,51 +170,47 @@ public class BranchGui { } //the rest of the branches } else { - //same code as in extra if (player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) >= ConfigRegistry.CONFIG.branchCost) { //grant the player the advancement of the branch they unlocked - switch (branch) { - case "mercenary" -> { - if (hasWizadry || hasDrudiry) { - player.sendMessage(Text.translatable("gui.ygasi.branch.no.unlock"), true); - } else { - hasMercenary = true; - AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/mercenary"), "unlocked_mercenary"); - MercenaryGui.gui(player); - unlockSuccess(player, branchName); - } - } - case "wizardry" -> { - if (hasMercenary || hasDrudiry) { - player.sendMessage(Text.translatable("gui.ygasi.branch.no.unlock"), true); - } else { - hasWizadry = true; - AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/wizardry"), "unlocked_wizardry"); - WizardryGui.gui(player); - unlockSuccess(player, branchName); - } - } - case "druidry" -> { - if (hasMercenary || hasWizadry) { - player.sendMessage(Text.translatable("gui.ygasi.branch.no.unlock"), true); - } else { - hasDrudiry = true; - AdvUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/druidry"), "unlocked_druidry"); - DruidryGui.gui(player); - unlockSuccess(player, branchName); - } + final Map<String, Class<?>> BRANCH_TO_GUI = new HashMap<>() {{ + put("mercenary", MercenaryGui.class); + put("wizardry", WizardryGui.class); + put("druidry", DruidryGui.class); + }}; + + final Map<String, String> BRANCH_TO_ADVANCEMENT = new HashMap<>() {{ + put("mercenary", "unlocked_mercenary"); + put("wizardry", "unlocked_wizardry"); + put("druidry", "unlocked_druidry"); + }}; + + Identifier advancementId = new Identifier("minecraft", "ygasi/" + branch); + String advancementCriterion = BRANCH_TO_ADVANCEMENT.get(branch); + Class<?> guiClass = BRANCH_TO_GUI.get(branch); + if (hasMercenary || hasWizadry || hasDrudiry) { + player.sendMessage(Text.translatable("gui.ygasi.branch.no.unlock"), true); + player.closeHandledScreen(); + } else { + AdvUtils.grantAdvancementCriterion(player, advancementId, advancementCriterion); + unlockSuccess(player, branchName); + try { + Method guiMethod = guiClass.getMethod("gui", ServerPlayerEntity.class); + guiMethod.invoke(null, player); + } catch (Exception e) { + e.printStackTrace(); } } - player.closeHandledScreen(); + //if the player doesn't have enough skill points } else { - player.sendMessage(Text.translatable("gui.ygasi.branch.no.skill"), false); + player.sendMessage(Text.translatable("gui.ygasi.branch.no.skill"), true); player.closeHandledScreen(); } } } private static void unlockSuccess(ServerPlayerEntity player, String branchName) { - player.sendMessage(Text.translatable("gui.ygasi.branch.unlock", Text.translatable(branchName)), false); + player.playSound(SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.PLAYERS, 1.0F, 1.0F); + player.sendMessage(Text.translatable("gui.ygasi.branch.unlock", Text.translatable(branchName)), true); //remove the spent skill points player.getStatHandler().setStat(player, Stats.CUSTOM.getOrCreateStat(SKILL_POINTS), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) - ConfigRegistry.CONFIG.branchCost); } diff --git a/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java b/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java index 74c1c5e..21934a8 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java @@ -11,6 +11,8 @@ import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; import net.minecraft.text.Text; +import java.lang.reflect.Field; + import static dev.mayaqq.ygasi.Ygasi.click; public class ConfigGui { @@ -57,6 +59,15 @@ public class ConfigGui { ); gui.setSlot(3, new GuiElementBuilder() + .setItem(Items.RED_TERRACOTTA) + .setName(Text.translatable("config.ygasi.resetCost.title")) + .addLoreLine(Text.translatable("config.ygasi.current").append(Text.of(String.valueOf(ConfigRegistry.CONFIG.resetCost)))) + .setCallback((index, clickType, actionType) -> { + textInput(player, "resetCost"); + }) + ); + + gui.setSlot(4, 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)))) @@ -65,7 +76,7 @@ public class ConfigGui { }) ); - gui.setSlot(4, new GuiElementBuilder() + gui.setSlot(5, new GuiElementBuilder() .setItem(Items.STICK) .setCount(2) .setName(Text.translatable("config.ygasi.T2Cost.title")) @@ -75,7 +86,7 @@ public class ConfigGui { }) ); - gui.setSlot(5, new GuiElementBuilder() + gui.setSlot(6, new GuiElementBuilder() .setItem(Items.STICK) .setCount(3) .setName(Text.translatable("config.ygasi.T3Cost.title")) @@ -94,42 +105,12 @@ public class ConfigGui { 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"), true); - } - } - case "branchCost" -> { - try { - ConfigRegistry.CONFIG.branchCost = Integer.parseInt(this.getLine(0).getString()); - } catch (NumberFormatException e) { - player.sendMessage(Text.translatable("config.ygasi.invalid.number"), true); - } - } - case "T1Cost" -> { - try { - ConfigRegistry.CONFIG.T1Cost = Integer.parseInt(this.getLine(0).getString()); - } catch (NumberFormatException e) { - player.sendMessage(Text.translatable("config.ygasi.invalid.number"), true); - } - } - case "T2Cost" -> { - try { - ConfigRegistry.CONFIG.T2Cost = Integer.parseInt(this.getLine(0).getString()); - } catch (NumberFormatException e) { - player.sendMessage(Text.translatable("config.ygasi.invalid.number"), true); - } - } - case "T3Cost" -> { - try { - ConfigRegistry.CONFIG.T3Cost = Integer.parseInt(this.getLine(0).getString()); - } catch (NumberFormatException e) { - player.sendMessage(Text.translatable("config.ygasi.invalid.number"), true); - } - } + try { + Field field = ConfigRegistry.CONFIG.getClass().getDeclaredField(option); + field.setAccessible(true); + field.set(ConfigRegistry.CONFIG, Integer.parseInt(this.getLine(0).getString())); + } catch (Exception e) { + player.sendMessage(Text.translatable("config.ygasi.invalid.number"), true); } gui(player); } diff --git a/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java index 7c3e0fd..d9896ae 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java @@ -1,5 +1,6 @@ package dev.mayaqq.ygasi.gui; +import dev.mayaqq.ygasi.gui.common.SkillGui; import dev.mayaqq.ygasi.util.AdvUtils; import eu.pb4.sgui.api.elements.GuiElementBuilder; import net.minecraft.item.Items; diff --git a/src/main/java/dev/mayaqq/ygasi/gui/ExtraGui.java b/src/main/java/dev/mayaqq/ygasi/gui/ExtraGui.java index 89905d7..2715952 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/ExtraGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/ExtraGui.java @@ -1,5 +1,6 @@ package dev.mayaqq.ygasi.gui; +import dev.mayaqq.ygasi.gui.common.SkillGui; import dev.mayaqq.ygasi.util.AdvUtils; import eu.pb4.sgui.api.elements.GuiElementBuilder; import net.minecraft.item.Items; diff --git a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java index 9eb0122..c88d2de 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java @@ -1,49 +1,86 @@ package dev.mayaqq.ygasi.gui; +import dev.mayaqq.ygasi.abilities.mercenary.*; +import dev.mayaqq.ygasi.gui.common.GuiCommon; +import dev.mayaqq.ygasi.gui.common.SkillGui; +import dev.mayaqq.ygasi.registry.ConfigRegistry; import dev.mayaqq.ygasi.util.AdvUtils; import eu.pb4.sgui.api.elements.GuiElementBuilder; 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; import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS; public class MercenaryGui { public static void gui(ServerPlayerEntity player) { - String title = Text.translatable("gui.ygasi.branch.mercenary.title").getString() + " " + Text.translatable("gui.ygasi.branch.title", player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS))).formatted(Formatting.DARK_AQUA).getString(); + String title = Text.translatable("gui.ygasi.branch.mercenary.title").getString() + " " + Text.translatable("gui.ygasi.branch.title", Text.of("§3" + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)))).getString(); try { if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/mercenary")) { - player.sendMessage(Text.translatable("gui.ygasi.branches.fail"), false); + player.sendMessage(Text.translatable("gui.ygasi.branches.fail"), true); BranchGui.gui(player); } else { - SkillGui gui = new SkillGui(ScreenHandlerType.GENERIC_9X6, player, false) {}; + SkillGui gui = new SkillGui(ScreenHandlerType.GENERIC_9X6, player, false) { + @Override + public void onClose() { + super.onClose(); + BranchGui.gui(player); + } + }; gui.setTitle(Text.of(title)); //background items - for (int x = 0; x <= 53; x++) { - gui.setSlot(x, new GuiElementBuilder() - .setItem(Items.GRAY_STAINED_GLASS_PANE) - .setName(Text.of(" ")) - ); - } + GuiCommon.background(gui); - //skill items gui.setSlot(49, new GuiElementBuilder() .setItem(Items.DIAMOND_BLOCK) .setName(Text.of("§c§lMercenary Unlocked!")) .addLoreLine(Text.of("§3Skill Points: " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)))) ); - if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence1")) { - gui.setSlot(10, new GuiElementBuilder() - .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")) - ); + int[] positions = {38, 19, 1, 40, 22, 4, 42, 25, 7}; + String[] advancementNames = {"offence1", "offence2", "offence3", "ninja1", "ninja2", "ninja3", "defence1", "defence2", "defence3"}; + int t1cost = ConfigRegistry.CONFIG.T1Cost; + int t2cost = ConfigRegistry.CONFIG.T2Cost; + int t3cost = ConfigRegistry.CONFIG.T3Cost; + int[] costs = {t1cost, t2cost, t3cost, t1cost, t2cost, t3cost, t1cost, t2cost, t3cost}; + String[] nameKeys = { + "gui.ygasi.mercenary.offence1", "gui.ygasi.mercenary.offence2", "gui.ygasi.mercenary.offence3", + "gui.ygasi.mercenary.ninja1", "gui.ygasi.mercenary.ninja2", "gui.ygasi.mercenary.ninja3", + "gui.ygasi.mercenary.defence1", "gui.ygasi.mercenary.defence2", "gui.ygasi.mercenary.defence3" + }; + Class<?>[] classes = {Offence1.class, Offence2.class, Offence3.class, Ninja1.class, Ninja2.class, Ninja3.class, Defence1.class, Defence2.class, Defence3.class}; + for (int i = 0; i < positions.length; i++) { + int position = positions[i]; + String advancementName = advancementNames[i]; + String nameKey = nameKeys[i]; + if (!AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/" + advancementName)) { + if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence1") && (advancementName.startsWith("ninja") || advancementName.startsWith("defence"))) { + GuiCommon.setDoneItem(gui, position, Items.BARRIER, nameKey, false); + } else if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/ninja1") && (advancementName.startsWith("defence") || advancementName.startsWith("offence"))) { + GuiCommon.setDoneItem(gui, position, Items.BARRIER, nameKey, false); + } else if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/defence1") && (advancementName.startsWith("offence") || advancementName.startsWith("ninja"))) { + GuiCommon.setDoneItem(gui, position, Items.BARRIER, nameKey, false); + } else { + GuiCommon.setSkillSlot(gui, player, position, Items.IRON_SWORD, nameKey, costs[i], classes[i], MercenaryGui.class); + } + if (position - 9 >= 0) { + GuiCommon.filler(gui, position - 9, false); + } + } else { + GuiCommon.setDoneItem(gui, position, Items.IRON_SWORD, nameKey, true); + try { + if (position - 9 >= 0) { + GuiCommon.filler(gui, position - 9, true); + } + } catch (Exception e) { + return; + } + } } gui.open(); diff --git a/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java b/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java index c581e02..e7fb2ef 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java @@ -1,5 +1,9 @@ package dev.mayaqq.ygasi.gui; +import dev.mayaqq.ygasi.abilities.mercenary.Offence1; +import dev.mayaqq.ygasi.abilities.mercenary.Offence2; +import dev.mayaqq.ygasi.gui.common.SkillGui; +import dev.mayaqq.ygasi.registry.ConfigRegistry; import dev.mayaqq.ygasi.util.AdvUtils; import eu.pb4.sgui.api.elements.GuiElementBuilder; import net.minecraft.item.Items; @@ -30,7 +34,19 @@ public class ResetGui { .setItem(Items.GREEN_CONCRETE) .setName(Text.translatable("gui.ygasi.reset.confirm.title")) .addLoreLine(Text.translatable("gui.ygasi.reset.confirm.lore")) - .setCallback((index, clickType, actionType) -> reset(player)) + .setCallback((index, clickType, actionType) -> { + reset(player); + BranchGui.gui(player); + if (player.experienceLevel >= ConfigRegistry.CONFIG.resetCost) { + player.closeHandledScreen(); + player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 1.0F, 1.0F); + player.experienceLevel -= ConfigRegistry.CONFIG.resetCost; + + } else { + player.sendMessage(Text.translatable("gui.ygasi.reset.fail"), true); + player.closeHandledScreen(); + } + }) ); gui.setSlot(14, new GuiElementBuilder() @@ -44,17 +60,14 @@ public class ResetGui { } public static void reset(ServerPlayerEntity player) { //check if player experience level is greater than 10 - if (player.experienceLevel >= 10) { - player.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.PLAYERS, 1.0F, 1.0F); - player.experienceLevel -= 10; - player.closeHandledScreen(); - AdvUtils.revokeAllAdvancements(player, "minecraft", "ygasi/"); - player.sendMessage(Text.translatable("gui.ygasi.reset.success"), false); - player.getStatHandler().setStat(player, Stats.CUSTOM.getOrCreateStat(SKILL_POINTS), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS_TOTAL))); - BranchGui.gui(player); - } else { - player.sendMessage(Text.translatable("gui.ygasi.reset.fail"), false); - player.closeHandledScreen(); + //revoke the abilities first + if (AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/mercenary")) { + Offence1.revoke(player); + Offence2.revoke(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))); + } }
\ 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 347135f..672f829 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java @@ -1,5 +1,6 @@ package dev.mayaqq.ygasi.gui; +import dev.mayaqq.ygasi.gui.common.SkillGui; import dev.mayaqq.ygasi.util.AdvUtils; import eu.pb4.sgui.api.elements.GuiElementBuilder; import net.minecraft.item.Items; diff --git a/src/main/java/dev/mayaqq/ygasi/gui/common/GuiCommon.java b/src/main/java/dev/mayaqq/ygasi/gui/common/GuiCommon.java new file mode 100644 index 0000000..6c486a5 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/gui/common/GuiCommon.java @@ -0,0 +1,87 @@ +package dev.mayaqq.ygasi.gui.common; + +import dev.mayaqq.ygasi.gui.BranchGui; +import eu.pb4.sgui.api.elements.GuiElementBuilder; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +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 static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS; + +public class GuiCommon { + public static void setDoneItem(SkillGui gui, int index, Item item, String nameKey, Boolean glow) { + GuiElementBuilder builder = new GuiElementBuilder(); + builder.setItem(item); + builder.hideFlag(ItemStack.TooltipSection.MODIFIERS); + builder.setName(Text.translatable(nameKey)); + if (glow) { + builder.glow(); + } + builder.addLoreLine(Text.translatable(nameKey + ".lore")); + gui.setSlot(index, builder.build()); + } + public static void filler(SkillGui gui, int index, Boolean done) { + if (done) { + gui.setSlot(index, new GuiElementBuilder() + .setItem(Items.LIME_STAINED_GLASS_PANE) + .setName(Text.of(" ")) + ); + } else { + gui.setSlot(index, new GuiElementBuilder() + .setItem(Items.RED_STAINED_GLASS_PANE) + .setName(Text.of(" ")) + ); + } + } + public static void setSkillSlot(SkillGui gui, ServerPlayerEntity player, int itemIndex, Item item, String nameKey, int cost, Class<?> skillClass, Class<?> guiClass) { + gui.setSlot(itemIndex, new GuiElementBuilder() + .setItem(item) + .hideFlag(ItemStack.TooltipSection.MODIFIERS) + .setName(Text.translatable(nameKey)) + .addLoreLine(Text.translatable(nameKey + ".lore")) + .addLoreLine(Text.translatable("gui.ygasi.branches.lore.cost", Text.of("§8"+ cost))) + .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); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } else { + player.sendMessage(Text.translatable("gui.ygasi.branches.no.skill"), false); + } + } + )); + } + public static void background(SkillGui gui) { + for (int x = 0; x <= 53; x++) { + gui.setSlot(x, new GuiElementBuilder() + .setItem(Items.GRAY_STAINED_GLASS_PANE) + .setName(Text.of(" ")) + ); + } + + for (int i = 48; i <= 50; i++) { + gui.setSlot(i, new GuiElementBuilder() + .setItem(Items.LIME_STAINED_GLASS_PANE) + .setName(Text.of(" ")) + ); + } + gui.setSlot(45, new GuiElementBuilder() + .setItem(Items.ARROW) + .setName(Text.translatable("gui.ygasi.branches.back")) + .setCallback((index, clickType, actionType) -> { + BranchGui.gui(gui.getPlayer()); + }) + ); + } +} diff --git a/src/main/java/dev/mayaqq/ygasi/gui/SkillGui.java b/src/main/java/dev/mayaqq/ygasi/gui/common/SkillGui.java index f453379..87cc0c8 100644 --- a/src/main/java/dev/mayaqq/ygasi/gui/SkillGui.java +++ b/src/main/java/dev/mayaqq/ygasi/gui/common/SkillGui.java @@ -1,4 +1,4 @@ -package dev.mayaqq.ygasi.gui; +package dev.mayaqq.ygasi.gui.common; import eu.pb4.sgui.api.gui.SimpleGui; import net.minecraft.screen.ScreenHandlerType; diff --git a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java index 781ef4d..2b29a3c 100644 --- a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java +++ b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java @@ -1,5 +1,6 @@ package dev.mayaqq.ygasi.registry; +import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.context.CommandContext; import dev.mayaqq.ygasi.gui.*; @@ -15,6 +16,7 @@ import net.minecraft.util.Formatting; import java.io.File; +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; import static net.minecraft.server.command.CommandManager.literal; @@ -53,12 +55,19 @@ public class CommandRegistry { .requires(source -> source.hasPermissionLevel(4)) .then(literal("skillpoints") .then(literal("reset") - .then(CommandManager.argument("target", EntityArgumentType.player()) + .then(CommandManager.argument("targets", EntityArgumentType.players()) .executes(context -> { - ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "target"); - player.resetStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)); - player.resetStat(Stats.CUSTOM.getOrCreateStat(StatRegistry.SKILL_POINTS_TOTAL)); - player.sendMessage(Text.translatable("commands.ygasi.skillpoints.reset", player.getEntityName()).formatted(Formatting.GREEN)); + for (int i = 0; i <= EntityArgumentType.getPlayers(context, "targets").size(); i++) { + ServerPlayerEntity[] players = EntityArgumentType.getPlayers(context, "targets").toArray(new ServerPlayerEntity[0]); + ResetGui.reset(players[i]); + } + String players; + if (EntityArgumentType.getPlayers(context, "targets").size() == 1) { + players = EntityArgumentType.getPlayers(context, "targets").toArray()[0].toString(); + } else { + players = EntityArgumentType.getPlayers(context, "targets").size() + " players"; + } + context.getSource().sendMessage(Text.translatable("commands.ygasi.skillpoints.reset", players).formatted(Formatting.GREEN)); return 1; }))) .then(literal("add") @@ -69,14 +78,14 @@ public class CommandRegistry { ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "target"); player.increaseStat(SKILL_POINTS, amount); player.increaseStat(SKILL_POINTS_TOTAL, amount); - player.sendMessage(Text.translatable("commands.ygasi.skillpoints.add", amount, player.getName()).formatted(Formatting.GREEN)); + context.getSource().sendMessage(Text.translatable("commands.ygasi.skillpoints.add", amount, player.getName()).formatted(Formatting.GREEN)); return 1; })))) .then(literal("get") .then(CommandManager.argument("target", EntityArgumentType.player()) .executes(context -> { ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "target"); - player.sendMessage(Text.translatable("commands.ygasi.skillpoints.get", player.getEntityName(), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS_TOTAL))).formatted(Formatting.GREEN)); + context.getSource().sendMessage(Text.translatable("commands.ygasi.skillpoints.get", player.getEntityName(), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)), player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS_TOTAL))).formatted(Formatting.GREEN)); return 1; })))) .then(literal("config") diff --git a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java index 2c939b3..c48cd6e 100644 --- a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java +++ b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java @@ -11,7 +11,7 @@ public class ConfigRegistry { public static Config CONFIG = new Config(); static File modConfFolder = new File(FabricLoader.getInstance().getConfigDir().toFile(),"ygasi"); - private static File configFile = new File(modConfFolder,"config.json"); + private static final File configFile = new File(modConfFolder,"config.json"); private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); public static void load() { @@ -50,9 +50,11 @@ public class ConfigRegistry { public int pointsRewarded = 1; public int branchCost = 16; public Boolean enableSkillBook = true; + public int resetCost = 10; public int T1Cost = 5; public int T2Cost = 10; public int T3Cost = 15; + public int offence1DefIncrease = 3; public Config() {} } diff --git a/src/main/java/dev/mayaqq/ygasi/registry/ItemRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/ItemRegistry.java index 06f3196..145a063 100644 --- a/src/main/java/dev/mayaqq/ygasi/registry/ItemRegistry.java +++ b/src/main/java/dev/mayaqq/ygasi/registry/ItemRegistry.java @@ -13,8 +13,10 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; public class ItemRegistry { - public static final SkillBookItem SKILL_BOOK = new SkillBookItem(new Item.Settings().maxCount(1), Items.BOOK); + public static final SkillBookItem SKILL_BOOK = Registry.register(Registries.ITEM, new Identifier("ygasi", "skill_book"), new SkillBookItem(new Item.Settings().maxCount(1), Items.BOOK)); + public static void register() { + //Register item group PolymerItemGroupUtils.builder(new Identifier("ygasi", "ygasi")) .displayName(Text.translatable("creative.ygasi.group")) .icon(() -> new ItemStack(Items.BOOK)) @@ -22,9 +24,8 @@ public class ItemRegistry { entries.add(SKILL_BOOK); }) .build(); + //Register item model PolymerResourcePackUtils.addModAssets("ygasi"); PolymerModelData skillBookModelData = PolymerResourcePackUtils.requestModel(Items.BOOK, new Identifier("ygasi", "item/skill_book")); - - Registry.register(Registries.ITEM, new Identifier("ygasi", "skill_book"), SKILL_BOOK); } } |