diff options
author | Maximusbarcz <maxim.baranek@gmail.com> | 2022-12-23 22:31:38 +0100 |
---|---|---|
committer | Maximusbarcz <maxim.baranek@gmail.com> | 2022-12-23 22:31:38 +0100 |
commit | f7ca47ba8132addd94928aa8615448c47a6b3d7b (patch) | |
tree | a46151060500ffba77630e64817a4bfb842268e0 /src/main/java/dev/mayaqq | |
parent | e5bc4dae41d2d3e04440a4fe02793d4084427437 (diff) | |
download | ygasi-f7ca47ba8132addd94928aa8615448c47a6b3d7b.tar.gz ygasi-f7ca47ba8132addd94928aa8615448c47a6b3d7b.tar.bz2 ygasi-f7ca47ba8132addd94928aa8615448c47a6b3d7b.zip |
Enormous amounts of trolling :tomfoolery:, not only that I fixed basically everything and switched the entire system to advancements, it now also has a cool custom book that you can open and stuff! Only issue I'm currently facing is that you get a skill point when you get the advancement for opening the gui and clicking stuff... right not that big of an issue but when I add 2 billion advancements its gonna hurt a bit. Love, Mayaqq
Diffstat (limited to 'src/main/java/dev/mayaqq')
17 files changed, 283 insertions, 126 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/Ygasi.java b/src/main/java/dev/mayaqq/ygasi/Ygasi.java index 78d4c6c..ebfec85 100644 --- a/src/main/java/dev/mayaqq/ygasi/Ygasi.java +++ b/src/main/java/dev/mayaqq/ygasi/Ygasi.java @@ -1,20 +1,47 @@ package dev.mayaqq.ygasi; +import dev.mayaqq.ygasi.items.SkillBookItem; import dev.mayaqq.ygasi.registry.CommandRegistry; import dev.mayaqq.ygasi.registry.ConfigRegistry; import dev.mayaqq.ygasi.registry.StatRegistry; +import eu.pb4.polymer.api.resourcepack.PolymerModelData; +import eu.pb4.polymer.api.resourcepack.PolymerRPUtils; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; +import net.fabricmc.fabric.impl.resource.loader.ModResourcePackUtil; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Ygasi implements ModInitializer { public static final Logger LOGGER = LoggerFactory.getLogger("ygasi"); + public static final SkillBookItem SKILL_BOOK = new SkillBookItem(new Item.Settings().group(ItemGroup.MISC).maxCount(1), Items.BOOK); + @Override public void onInitialize() { StatRegistry.skillRegister(); CommandRegistry.RegisterCommands(); ConfigRegistry.load(); LOGGER.info("You've got a skill issue!"); + + PolymerRPUtils.addAssetSource("ygasi"); + PolymerModelData modelData = PolymerRPUtils.requestModel(Items.BOOK, new Identifier("ygasi", "item/skill_book")); + + Registry.register(Registry.ITEM, "ygasi:skill_book", SKILL_BOOK); + + if (ConfigRegistry.CONFIG.enableSkillBook) { + ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { + if (!handler.player.getScoreboardTags().contains("ygasi:skill_book_unlocked")) { + handler.player.addScoreboardTag("ygasi:skill_book_unlocked"); + handler.player.getInventory().offerOrDrop(new ItemStack(SKILL_BOOK)); + } + }); + } } -} +}
\ No newline at end of file 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)))); diff --git a/src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java b/src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java new file mode 100644 index 0000000..ce4143f --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/items/SkillBookItem.java @@ -0,0 +1,52 @@ +package dev.mayaqq.ygasi.items; + +import dev.mayaqq.ygasi.gui.BranchGui; +import eu.pb4.polymer.api.item.PolymerItemUtils; +import eu.pb4.polymer.api.item.SimplePolymerItem; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.enchantment.Enchantments; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.Hand; + +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.TypedActionResult; +import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public class SkillBookItem extends SimplePolymerItem { + + public SkillBookItem(Settings settings, Item polymerItem) { + super(settings, polymerItem); + } + + @Override + public ItemStack getPolymerItemStack(ItemStack itemStack, ServerPlayerEntity player) { + ItemStack out = PolymerItemUtils.createItemStack(itemStack, player); + out.addEnchantment(Enchantments.LURE, 0); + out.setCustomName(Text.translatable("item.ygasi.skill_book").formatted(Formatting.GOLD).formatted(Formatting.BOLD)); + return out; + } + + @Override + public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) { + ServerPlayerEntity player = (ServerPlayerEntity) playerEntity; + BranchGui.gui(player); + return TypedActionResult.success(playerEntity.getStackInHand(hand)); + } + + @Override + public int getPolymerCustomModelData(ItemStack itemStack, @Nullable ServerPlayerEntity player) { + return 1; + } + + @Override + public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) { + tooltip.add(Text.translatable("item.ygasi.skill_book.tooltip").formatted(Formatting.GRAY)); + } +}
\ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java b/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java index 0f56908..a2c1330 100644 --- a/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java +++ b/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java @@ -1,7 +1,11 @@ package dev.mayaqq.ygasi.mixin; import dev.mayaqq.ygasi.registry.ConfigRegistry; +import net.minecraft.advancement.Advancement; +import net.minecraft.advancement.AdvancementDisplay; +import net.minecraft.advancement.AdvancementFrame; import net.minecraft.advancement.AdvancementRewards; +import net.minecraft.server.ServerAdvancementLoader; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; import org.spongepowered.asm.mixin.Final; @@ -13,11 +17,12 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS; + @Mixin(AdvancementRewards.class) public class AdvancementRewardsMixin { @Shadow @Final private Identifier[] recipes; - @Inject(method = "apply",at = @At("HEAD")) + @Inject(method = "apply", at = @At("HEAD")) private void inject(ServerPlayerEntity player, CallbackInfo ci) { if (recipes.length == 0) { player.increaseStat(SKILL_POINTS, ConfigRegistry.CONFIG.pointsRewarded); diff --git a/src/main/java/dev/mayaqq/ygasi/registry/AdvancementRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/AdvancementRegistry.java deleted file mode 100644 index 09aa2c5..0000000 --- a/src/main/java/dev/mayaqq/ygasi/registry/AdvancementRegistry.java +++ /dev/null @@ -1,4 +0,0 @@ -package dev.mayaqq.ygasi.registry; - -public class AdvancementRegistry { -} diff --git a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java index 62d8dea..1da9830 100644 --- a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java +++ b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java @@ -57,10 +57,7 @@ public class CommandRegistry { .executes(context -> { ServerPlayerEntity player = EntityArgumentType.getPlayer(context, "target"); player.resetStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS)); - File playerData = new File(FabricLoader.getInstance().getGameDir().toFile() + "/ygasi/" + player.getUuid() + ".json"); - playerData.delete(); - PlayerDataRegistry.load(player.getUuid()); - context.getSource().sendMessage(Text.literal("§aSkill Points reset to 0 and all skill data deleted for " + player.getEntityName() + ".")); + context.getSource().sendMessage(Text.literal("§aSkill Points reset to 0 for " + player.getEntityName() + ".")); return 1; }))) .then(literal("add") diff --git a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java index f6e0c82..658f044 100644 --- a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java +++ b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java @@ -50,6 +50,8 @@ public class ConfigRegistry { //the thing to write in the config file public int pointsRewarded = 1; public int branchCost = 16; + public Boolean enableSkillBook = true; + public Config() {} } } diff --git a/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java deleted file mode 100644 index d3fd387..0000000 --- a/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java +++ /dev/null @@ -1,78 +0,0 @@ -package dev.mayaqq.ygasi.registry; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.annotations.SerializedName; -import net.fabricmc.loader.api.FabricLoader; - -import java.io.*; -import java.util.*; - -public class PlayerDataRegistry { - public static PlayerData PLAYERDATA = new PlayerData(); - public static EmptyPlayerData EMPTYPLAYERDATA = new EmptyPlayerData(); - private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - - - public static void load(UUID uuid) { - //this isnt working :sob: - File playerDataFolder = new File(FabricLoader.getInstance().getGameDir().toFile(), "ygasi"); - File playerDatFile = new File(FabricLoader.getInstance().getGameDir().toFile() + "/ygasi/" + uuid + ".json"); - if (!playerDataFolder.exists()) { - playerDataFolder.mkdir(); - } - if (!playerDatFile.exists()) { - try { - playerDatFile.createNewFile(); - saveEmpty(uuid); - } catch (IOException e) { - throw new RuntimeException(e); - } - } else { - try { - PLAYERDATA = gson.fromJson(new FileReader(playerDatFile), PlayerData.class); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } - } - } - - public static void save(UUID uuid) { - try { - File playerDatFile = new File(FabricLoader.getInstance().getGameDir().toFile() + "/ygasi/" + uuid + ".json"); - var writer = new FileWriter(playerDatFile); - writer.write(gson.toJson(PLAYERDATA)); - writer.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - public static void saveEmpty(UUID uuid) { - try { - File playerDatFile = new File(FabricLoader.getInstance().getGameDir().toFile() + "/ygasi/" + uuid + ".json"); - var writer = new FileWriter(playerDatFile); - writer.write(gson.toJson(EMPTYPLAYERDATA)); - writer.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static class PlayerData { - @SerializedName("branches") - public static Map<String, Boolean> branches = new HashMap<>(); - @SerializedName("skills") - public static Map<String, Integer> skills = new HashMap<>(); - - public PlayerData() {} - } - - public static class EmptyPlayerData { - @SerializedName("branches") - public static Map<String, Boolean> branches = new HashMap<>(); - @SerializedName("skills") - public static Map<String, Integer> skills = new HashMap<>(); - - public EmptyPlayerData() {} - } -}
\ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/registry/advancements/Advancements.java b/src/main/java/dev/mayaqq/ygasi/registry/advancements/Advancements.java new file mode 100644 index 0000000..ac33abe --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/registry/advancements/Advancements.java @@ -0,0 +1,76 @@ +package dev.mayaqq.ygasi.registry.advancements; + +import de.dafuqs.revelationary.advancement_criteria.AdvancementGottenCriterion; +import net.minecraft.advancement.Advancement; +import net.minecraft.advancement.AdvancementFrame; +import net.minecraft.advancement.criterion.ImpossibleCriterion; +import net.minecraft.item.Items; +import net.minecraft.predicate.entity.EntityPredicate; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +import java.util.function.Consumer; + +public class Advancements implements Consumer<Consumer<Advancement>> { + + @Override + public void accept(Consumer<Advancement> consumer) { + Advancement rootAdvancement = Advancement.Builder.create() + .display( + Items.DIAMOND, // The display icon + Text.literal("You've got a skill issue!"), // The title + Text.literal("The journey begins here!"), // 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, // Announce to chat + false // Hidden in the advancement tab + ) + // The first string used in criterion is the name referenced by other advancements when they want to have 'requirements' + .criterion("opened_skill_menu", new ImpossibleCriterion.Conditions()) + .build(consumer, "ygasi" + "/root"); + + Advancement mercenary = Advancement.Builder.create().parent(rootAdvancement) + .display( + Items.IRON_SWORD, + Text.literal("Mercenary"), + Text.literal("Unlock the mercenary branch!"), + null, + AdvancementFrame.GOAL, + false, + false, + false + ) + .criterion("unlocked_mercenary", new ImpossibleCriterion.Conditions()) + .criterion("gotten_previous", new AdvancementGottenCriterion.Conditions(EntityPredicate.Extended.EMPTY, rootAdvancement.getId())) + .build(consumer, "ygasi" + "/mercenary"); + Advancement wizardry = Advancement.Builder.create().parent(rootAdvancement) + .display( + Items.BLAZE_ROD, + Text.literal("Wizardry"), + Text.literal("Unlock the wizardry branch!"), + null, + AdvancementFrame.GOAL, + false, + false, + false + ) + .criterion("unlocked_wizardry", new ImpossibleCriterion.Conditions()) + .criterion("gotten_previous", new AdvancementGottenCriterion.Conditions(EntityPredicate.Extended.EMPTY, rootAdvancement.getId())) + .build(consumer, "ygasi" + "/wizardry"); + Advancement druidry = Advancement.Builder.create().parent(rootAdvancement) + .display( + Items.OAK_SAPLING, + Text.literal("Druidry"), + Text.literal("Unlock the druidry branch!"), + null, + AdvancementFrame.GOAL, + false, + false, + false + ) + .criterion("unlocked_druidry", new ImpossibleCriterion.Conditions()) + .criterion("gotten_previous", new AdvancementGottenCriterion.Conditions(EntityPredicate.Extended.EMPTY, rootAdvancement.getId())) + .build(consumer, "ygasi" + "/druidry"); + } +}
\ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/registry/advancements/dataGen/AdvancementProvider.java b/src/main/java/dev/mayaqq/ygasi/registry/advancements/dataGen/AdvancementProvider.java new file mode 100644 index 0000000..a9b1a64 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/registry/advancements/dataGen/AdvancementProvider.java @@ -0,0 +1,18 @@ +package dev.mayaqq.ygasi.registry.advancements.dataGen; + +import dev.mayaqq.ygasi.registry.advancements.Advancements; +import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; +import net.fabricmc.fabric.api.datagen.v1.provider.FabricAdvancementProvider; +import net.minecraft.advancement.Advancement; + +import java.util.function.Consumer; + +public class AdvancementProvider extends FabricAdvancementProvider { + protected AdvancementProvider(FabricDataGenerator dataGenerator) { + super(dataGenerator); + } + @Override + public void generateAdvancement(Consumer<Advancement> consumer) { + new Advancements().accept(consumer); + } +} diff --git a/src/main/java/dev/mayaqq/ygasi/registry/DataGenRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/advancements/dataGen/DataGenRegistry.java index a060c42..9bba67d 100644 --- a/src/main/java/dev/mayaqq/ygasi/registry/DataGenRegistry.java +++ b/src/main/java/dev/mayaqq/ygasi/registry/advancements/dataGen/DataGenRegistry.java @@ -1,4 +1,4 @@ -package dev.mayaqq.ygasi.registry; +package dev.mayaqq.ygasi.registry.advancements.dataGen; import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint; import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; @@ -6,6 +6,6 @@ import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator; public class DataGenRegistry implements DataGeneratorEntrypoint { @Override public void onInitializeDataGenerator(FabricDataGenerator dataGenerator) { - + dataGenerator.addProvider(AdvancementProvider::new); } } diff --git a/src/main/java/dev/mayaqq/ygasi/util/GetAdvancementProgress.java b/src/main/java/dev/mayaqq/ygasi/util/GetAdvancementProgress.java new file mode 100644 index 0000000..9b4d4a8 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/util/GetAdvancementProgress.java @@ -0,0 +1,10 @@ +package dev.mayaqq.ygasi.util; + +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; + +public class GetAdvancementProgress { + public static boolean get(ServerPlayerEntity player, String advancement) { + return player.getAdvancementTracker().getProgress(player.getServer().getAdvancementLoader().get(new Identifier("minecraft", "ygasi/" + advancement))).isDone(); + } +} diff --git a/src/main/java/dev/mayaqq/ygasi/util/GrantAdvancementCriterion.java b/src/main/java/dev/mayaqq/ygasi/util/GrantAdvancementCriterion.java new file mode 100644 index 0000000..c141c06 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/util/GrantAdvancementCriterion.java @@ -0,0 +1,29 @@ +package dev.mayaqq.ygasi.util; + +import net.minecraft.advancement.Advancement; +import net.minecraft.advancement.PlayerAdvancementTracker; +import net.minecraft.server.ServerAdvancementLoader; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Identifier; +import org.jetbrains.annotations.NotNull; + +import static dev.mayaqq.ygasi.Ygasi.LOGGER; + +public class GrantAdvancementCriterion { + public static void grantAdvancementCriterion(@NotNull ServerPlayerEntity serverPlayerEntity, Identifier advancementIdentifier, String criterion) { + if (serverPlayerEntity.getServer() == null) { + return; + } + ServerAdvancementLoader sal = serverPlayerEntity.getServer().getAdvancementLoader(); + PlayerAdvancementTracker tracker = serverPlayerEntity.getAdvancementTracker(); + + Advancement advancement = sal.get(advancementIdentifier); + if (advancement == null) { + LOGGER.error("Trying to grant a criterion \"" + criterion + "\" for an advancement that does not exist: " + advancementIdentifier); + } else { + if (!tracker.getProgress(advancement).isDone()) { + tracker.grantCriterion(advancement, criterion); + } + } + } +} |