aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/dev/mayaqq/ygasi/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/dev/mayaqq/ygasi/gui')
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java74
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/ConfigGui.java57
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java1
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/ExtraGui.java1
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java73
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java37
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java1
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/common/GuiCommon.java87
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/common/SkillGui.java (renamed from src/main/java/dev/mayaqq/ygasi/gui/SkillGui.java)2
9 files changed, 229 insertions, 104 deletions
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;