aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java19
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java2
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/ExtraGui.java2
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java12
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java61
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java2
-rw-r--r--src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java2
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java5
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java1
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/StatRegistry.java1
-rw-r--r--src/main/java/dev/mayaqq/ygasi/util/YgasiUtils.java23
11 files changed, 117 insertions, 13 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java
index a9ccb71..9dcfd39 100644
--- a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java
+++ b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java
@@ -13,6 +13,7 @@ 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;
@@ -49,7 +50,7 @@ public class BranchGui {
}
//branch items
- if (!YgasiUtils.getAdvancementProgress(player, "mercenary")) {
+ if (!YgasiUtils.getAdvancementProgress(player, "minecraft", "ygasi/mercenary")) {
gui.setSlot(11, new GuiElementBuilder()
.setItem(Items.DIAMOND_SWORD)
.setCustomModelData(1)
@@ -70,7 +71,7 @@ public class BranchGui {
);
}
- if (!YgasiUtils.getAdvancementProgress(player, "wizardry")) {
+ 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)))
@@ -88,7 +89,7 @@ public class BranchGui {
);
}
- if (!YgasiUtils.getAdvancementProgress(player, "druidry")) {
+ 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)))
@@ -106,7 +107,7 @@ public class BranchGui {
);
}
- if (!YgasiUtils.getAdvancementProgress(player, "extra")) {
+ 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)))
@@ -130,6 +131,12 @@ public class BranchGui {
.setName(Text.literal("Info").formatted(Formatting.GOLD).formatted(Formatting.BOLD))
.setCallback((index, clickType, actionType) -> infoMessage(player))
);
+ //reset item
+ gui.setSlot(8, new GuiElementBuilder()
+ .setItem(Items.BARRIER)
+ .setName(Text.literal("Reset").formatted(Formatting.RED).formatted(Formatting.BOLD))
+ .setCallback((index, clickType, actionType) -> ResetGui.gui(player))
+ );
YgasiUtils.grantAdvancementCriterion(player, new Identifier("minecraft", "ygasi/root"), "opened_skill_menu");
@@ -165,13 +172,13 @@ public class BranchGui {
}
} else {
- player.sendMessage(Text.translatable("gui.ygasi.no.skill").setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED)), false);
+ player.sendMessage(Text.translatable("gui.ygasi.branch.no.skill").setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED)), false);
player.closeHandledScreen();
}
}
}
public static void infoMessage(ServerPlayerEntity player) {
player.closeHandledScreen();
- player.sendMessage(Text.translatable("gui.ygasi.info.main"), false);
+ 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/DruidryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java
index dc5e5e7..748f9b3 100644
--- a/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java
+++ b/src/main/java/dev/mayaqq/ygasi/gui/DruidryGui.java
@@ -13,7 +13,7 @@ import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
public class DruidryGui {
public static void gui(ServerPlayerEntity player) {
try {
- if (!YgasiUtils.getAdvancementProgress(player, "druidry")) {
+ if (!YgasiUtils.getAdvancementProgress(player, "minecraft", "ygasi/druidry")) {
player.sendMessage(Text.of("§cYou have not unlocked this branch yet!"), false);
BranchGui.gui(player);
} else {
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/ExtraGui.java b/src/main/java/dev/mayaqq/ygasi/gui/ExtraGui.java
index 98ca697..04cfc98 100644
--- a/src/main/java/dev/mayaqq/ygasi/gui/ExtraGui.java
+++ b/src/main/java/dev/mayaqq/ygasi/gui/ExtraGui.java
@@ -13,7 +13,7 @@ import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
public class ExtraGui {
public static void gui(ServerPlayerEntity player) {
try {
- if (!YgasiUtils.getAdvancementProgress(player, "extra")) {
+ if (!YgasiUtils.getAdvancementProgress(player, "minecraft", "ygasi/extra")) {
player.sendMessage(Text.of("§cYou have not unlocked this branch yet!"), false);
BranchGui.gui(player);
} else {
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java
index 79cc08d..ac722b6 100644
--- a/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java
+++ b/src/main/java/dev/mayaqq/ygasi/gui/MercenaryGui.java
@@ -1,5 +1,6 @@
package dev.mayaqq.ygasi.gui;
+import dev.mayaqq.ygasi.registry.ConfigRegistry;
import dev.mayaqq.ygasi.util.YgasiUtils;
import eu.pb4.sgui.api.elements.GuiElementBuilder;
import net.minecraft.item.Items;
@@ -13,7 +14,7 @@ import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
public class MercenaryGui {
public static void gui(ServerPlayerEntity player) {
try {
- if (!YgasiUtils.getAdvancementProgress(player, "mercenary")) {
+ if (!YgasiUtils.getAdvancementProgress(player, "minecraft", "ygasi/mercenary")) {
player.sendMessage(Text.of("§cYou have not unlocked this branch yet!"), false);
BranchGui.gui(player);
} else {
@@ -35,6 +36,15 @@ public class MercenaryGui {
.addLoreLine(Text.of("§3Skill Points: " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS))))
);
+ if (!YgasiUtils.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".replace("%cost%", ConfigRegistry.CONFIG.offence1Cost + "")))
+ );
+ }
+
gui.open();
}
} catch (Exception e) {
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java b/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java
new file mode 100644
index 0000000..95c8206
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/gui/ResetGui.java
@@ -0,0 +1,61 @@
+package dev.mayaqq.ygasi.gui;
+
+import dev.mayaqq.ygasi.util.YgasiUtils;
+import eu.pb4.sgui.api.elements.GuiElementBuilder;
+import net.minecraft.advancement.Advancement;
+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 static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
+import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS_TOTAL;
+
+public class ResetGui {
+ public static void gui(ServerPlayerEntity player) {
+
+ SkillGui gui = new SkillGui(ScreenHandlerType.GENERIC_9X3, player, false) {};
+
+ //background items
+ for (int x = 0; x <= 26; x++) {
+ gui.setSlot(x, new GuiElementBuilder()
+ .setItem(Items.GRAY_STAINED_GLASS_PANE)
+ .setName(Text.of(" "))
+ );
+ }
+
+ gui.setSlot(12, new GuiElementBuilder()
+ .setItem(Items.GREEN_CONCRETE)
+ .setName(Text.translatable("gui.ygasi.reset.confirm"))
+ .addLoreLine(Text.translatable("gui.ygasi.reset.confirm.lore"))
+ .setCallback((index, clickType, actionType) -> reset(player))
+ );
+
+ gui.setSlot(14, new GuiElementBuilder()
+ .setItem(Items.RED_CONCRETE)
+ .setName(Text.translatable("gui.ygasi.reset.deny"))
+ .addLoreLine(Text.translatable("gui.ygasi.reset.deny.lore"))
+ .setCallback((index, clickType, actionType) -> BranchGui.gui(player))
+ );
+
+ gui.open();
+ }
+ 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();
+ YgasiUtils.revokeAllAdvancements(player, "minecraft", "ygasi/");
+ player.sendMessage(Text.translatable("gui.ygasi.branch.reset.main"), 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.branch.reset.no.xp"), false);
+ player.closeHandledScreen();
+ }
+ }
+} \ 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 d049e5a..499f911 100644
--- a/src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java
+++ b/src/main/java/dev/mayaqq/ygasi/gui/WizardryGui.java
@@ -13,7 +13,7 @@ import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
public class WizardryGui {
public static void gui(ServerPlayerEntity player) {
try {
- if (!YgasiUtils.getAdvancementProgress(player, "wizardry")) {
+ if (!YgasiUtils.getAdvancementProgress(player, "minecraft", "ygasi/wizardry")) {
player.sendMessage(Text.of("§cYou have not unlocked this branch yet!"), false);
BranchGui.gui(player);
} else {
diff --git a/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java b/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
index 58e8353..b4ff5f3 100644
--- a/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
+++ b/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
@@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
+import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS_TOTAL;
@Mixin(AdvancementRewards.class)
@@ -24,6 +25,7 @@ public class AdvancementRewardsMixin {
private void apply(ServerPlayerEntity player, CallbackInfo ci) {
if (recipes.length == 0 && experience != 1) {
player.increaseStat(SKILL_POINTS, ConfigRegistry.CONFIG.pointsRewarded);
+ player.increaseStat(SKILL_POINTS_TOTAL, ConfigRegistry.CONFIG.pointsRewarded);
} else if (experience == 1) {
player.addExperience(-1);
}
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
index 1da9830..aa03f96 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
@@ -18,6 +18,7 @@ import net.minecraft.text.Text;
import java.io.File;
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;
public class CommandRegistry {
@@ -57,6 +58,7 @@ public class CommandRegistry {
.executes(context -> {
ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "target");
player.resetStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS));
+ player.resetStat(Stats.CUSTOM.getOrCreateStat(StatRegistry.SKILL_POINTS_TOTAL));
context.getSource().sendMessage(Text.literal("§aSkill Points reset to 0 for " + player.getEntityName() + "."));
return 1;
})))
@@ -66,6 +68,7 @@ public class CommandRegistry {
.executes(context -> {
ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "target");
player.increaseStat(SKILL_POINTS, IntegerArgumentType.getInteger(context, "amount"));
+ player.increaseStat(SKILL_POINTS_TOTAL, IntegerArgumentType.getInteger(context, "amount"));
context.getSource().sendMessage(Text.literal("§aSkill Points increased by " + IntegerArgumentType.getInteger(context, "amount") + " for " + player.getEntityName() + "."));
return 1;
}))))
@@ -73,7 +76,7 @@ public class CommandRegistry {
.then(CommandManager.argument("target", EntityArgumentType.player())
.executes(context -> {
ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "target");
- context.getSource().sendMessage(Text.literal("§a" + player.getEntityName() + " has " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) + " Unspent Skill Points."));
+ context.getSource().sendMessage(Text.literal("§a" + player.getEntityName() + " has " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)) + " Unspent Skill Points and " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS_TOTAL)) + " Total Skill Points."));
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 658f044..0b5cfa5 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
@@ -51,6 +51,7 @@ public class ConfigRegistry {
public int pointsRewarded = 1;
public int branchCost = 16;
public Boolean enableSkillBook = true;
+ public int offence1Cost = 3;
public Config() {}
}
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/StatRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/StatRegistry.java
index 5d6d165..4dbdbd3 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/StatRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/StatRegistry.java
@@ -7,6 +7,7 @@ import net.minecraft.util.Identifier;
public class StatRegistry {
public static Identifier SKILL_POINTS = PolymerStat.registerStat("skill_points", StatFormatter.DEFAULT);
+ public static Identifier SKILL_POINTS_TOTAL = PolymerStat.registerStat("skill_points_total", StatFormatter.DEFAULT);
public static void skillRegister() {}
}
diff --git a/src/main/java/dev/mayaqq/ygasi/util/YgasiUtils.java b/src/main/java/dev/mayaqq/ygasi/util/YgasiUtils.java
index ba3cfc8..1c3b267 100644
--- a/src/main/java/dev/mayaqq/ygasi/util/YgasiUtils.java
+++ b/src/main/java/dev/mayaqq/ygasi/util/YgasiUtils.java
@@ -27,7 +27,26 @@ public class YgasiUtils {
}
}
- public static boolean getAdvancementProgress(ServerPlayerEntity player, String advancement) {
- return player.getAdvancementTracker().getProgress(player.getServer().getAdvancementLoader().get(new Identifier("minecraft", "ygasi/" + advancement))).isDone();
+ public static void revokeAllAdvancements(ServerPlayerEntity player, String namespace ,String path) {
+ if (player.getServer() == null) {
+ return;
+ }
+ ServerAdvancementLoader sal = player.getServer().getAdvancementLoader();
+ PlayerAdvancementTracker tracker = player.getAdvancementTracker();
+
+ for (Advancement advancement : sal.getAdvancements()) {
+ if (advancement.getId().getNamespace().equals(namespace) && advancement.getId().getPath().startsWith(path)) {
+ for (String criterion : advancement.getCriteria().keySet()) {
+ tracker.revokeCriterion(advancement, criterion);
+ }
+ }
+ }
+ }
+
+ public static boolean getAdvancementProgress(ServerPlayerEntity player, String namespace, String path) {
+ if (player.getServer() == null) {
+ return false;
+ }
+ return player.getAdvancementTracker().getProgress(player.getServer().getAdvancementLoader().get(new Identifier(namespace, path))).isDone();
}
} \ No newline at end of file