aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaximusbarcz <maxim.baranek@gmail.com>2022-12-19 20:05:03 +0100
committerMaximusbarcz <maxim.baranek@gmail.com>2022-12-19 20:05:03 +0100
commit3f4b8a506d46a3fc558d6941a31af1b69b4cede7 (patch)
treefa4f52bd2fdc7c39275781c7d4b46923260a4b5e /src
parent0a587147d29dc0bc0fd5aeb98a67e3d76719b0d9 (diff)
downloadygasi-3f4b8a506d46a3fc558d6941a31af1b69b4cede7.tar.gz
ygasi-3f4b8a506d46a3fc558d6941a31af1b69b4cede7.tar.bz2
ygasi-3f4b8a506d46a3fc558d6941a31af1b69b4cede7.zip
Im so done lmfao... anyway finally made PlayerDataSaving work so thats amazing, also finished the Branch choosing gui, I think I can finally work on other stuff now.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/dev/mayaqq/ygasi/CreatePlayerData.java54
-rw-r--r--src/main/java/dev/mayaqq/ygasi/Ygasi.java (renamed from src/main/java/dev/mayaqq/ygasi/ygasi.java)5
-rw-r--r--src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java124
-rw-r--r--src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java1
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java40
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java6
-rw-r--r--src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java52
-rw-r--r--src/main/resources/fabric.mod.json2
-rw-r--r--src/main/resources/ygasi.mixins.json2
9 files changed, 213 insertions, 73 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/CreatePlayerData.java b/src/main/java/dev/mayaqq/ygasi/CreatePlayerData.java
deleted file mode 100644
index 0444060..0000000
--- a/src/main/java/dev/mayaqq/ygasi/CreatePlayerData.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package dev.mayaqq.ygasi;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import net.fabricmc.loader.api.FabricLoader;
-
-import java.io.*;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-public class CreatePlayerData {
- public static UUID playerId;
- private static File serverDatFile = new File(FabricLoader.getInstance().getConfigDir().toFile() + "/ygasi","serverDat.json");
- public static ServerData SERVERDATA = new ServerData();
- private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
-
- public static void load() {
- if (!serverDatFile.exists()) {
- try {
- serverDatFile.createNewFile();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- } else {
- try {
- SERVERDATA = gson.fromJson(new FileReader(serverDatFile), ServerData.class);
- } catch (FileNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
- }
- public static void createPlayerData(UUID player) throws IOException {
- try {
- playerId = player;
- Map<UUID, Map<Integer, Map<String, Integer>>> uuidMap = new HashMap<>();
- Map<Integer, Map<String, Integer>> tree = new HashMap<>();
- Map<String, Integer> skills = new HashMap<>();
- skills.put("0", 0);
- for (int i = 1; i < 4; i++) {
-
- }
- var Writer = new FileWriter(serverDatFile);
- Writer.write(gson.toJson(SERVERDATA));
- Writer.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- public static class ServerData {
- UUID player = null;
- public ServerData() {}
- }
-}
diff --git a/src/main/java/dev/mayaqq/ygasi/ygasi.java b/src/main/java/dev/mayaqq/ygasi/Ygasi.java
index d0ab984..78d4c6c 100644
--- a/src/main/java/dev/mayaqq/ygasi/ygasi.java
+++ b/src/main/java/dev/mayaqq/ygasi/Ygasi.java
@@ -7,9 +7,7 @@ import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-
-public class ygasi implements ModInitializer {
+public class Ygasi implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("ygasi");
@Override
@@ -17,7 +15,6 @@ public class ygasi implements ModInitializer {
StatRegistry.skillRegister();
CommandRegistry.RegisterCommands();
ConfigRegistry.load();
- CreatePlayerData.load();
LOGGER.info("You've got a skill issue!");
}
}
diff --git a/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java
new file mode 100644
index 0000000..7039eff
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/gui/BranchGui.java
@@ -0,0 +1,124 @@
+package dev.mayaqq.ygasi.gui;
+
+import dev.mayaqq.ygasi.registry.ConfigRegistry;
+import dev.mayaqq.ygasi.registry.PlayerDataRegistry;
+import eu.pb4.sgui.api.elements.*;
+import eu.pb4.sgui.api.gui.SimpleGui;
+import net.minecraft.item.ItemStack;
+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.Style;
+import net.minecraft.text.Text;
+import net.minecraft.util.Formatting;
+
+import java.util.UUID;
+
+import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
+
+public class BranchGui {
+ public static void gui(ServerPlayerEntity player) {
+ UUID playerUUID = player.getUuid();
+ PlayerDataRegistry.load(playerUUID);
+ try {
+ SimpleGui gui = new SimpleGui(ScreenHandlerType.GENERIC_9X3, player, false) {};
+
+ gui.setTitle(Text.of("§3Skill Points: " + player.getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(SKILL_POINTS))));
+
+ //background items
+ for (int x = 0; x <= 17; x++) {
+ gui.setSlot(x, new GuiElementBuilder()
+ .setItem(Items.GRAY_STAINED_GLASS_PANE)
+ .setName(Text.of(" "))
+ );
+ }
+ for (int x = 18; x <= 26; x++) {
+ gui.setSlot(x, new GuiElementBuilder()
+ .setItem(Items.RED_STAINED_GLASS_PANE)
+ .setName(Text.of(" "))
+ );
+ }
+
+ //close button
+ gui.setSlot(22, new GuiElementBuilder()
+ .setItem(Items.BARRIER)
+ .setName(Text.literal("Close")
+ .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.DARK_RED)))
+ .setCallback((index, clickType, actionType) -> gui.close())
+ );
+
+ //branch items
+ if (PlayerDataRegistry.PLAYERDATA.branches.get("mercenary") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("mercenary")) {
+ gui.setSlot(11, new GuiElementBuilder()
+ .setItem(Items.IRON_SWORD)
+ .hideFlag(ItemStack.TooltipSection.MODIFIERS)
+ .addLoreLine(Text.literal("Cost: " + ConfigRegistry.CONFIG.branchCost).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_GRAY)))
+ .setName(Text.literal("Mercenary")
+ .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED)))
+ .setCallback((index, clickType, actionType) -> save(player, "mercenary", "§cMercenary"))
+ );
+ } else {
+ gui.setSlot(11, new GuiElementBuilder()
+ .setItem(Items.IRON_SWORD)
+ .hideFlag(ItemStack.TooltipSection.MODIFIERS)
+ .glow()
+ .setName(Text.literal("Mercenary")
+ .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED)))
+ .setCallback((index, clickType, actionType) -> gui.close())
+ );
+ }
+
+ if (PlayerDataRegistry.PLAYERDATA.branches.get("wizardry") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("wizardry")) {
+ gui.setSlot(13, new GuiElementBuilder()
+ .setItem(Items.BLAZE_ROD)
+ .addLoreLine(Text.literal("Cost: " + ConfigRegistry.CONFIG.branchCost).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_GRAY)))
+ .setName(Text.literal("Wizardry")
+ .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.DARK_PURPLE)))
+ .setCallback((index, clickType, actionType) -> save(player, "wizardry", "§5Wizardry"))
+ );
+ } else {
+ gui.setSlot(13, new GuiElementBuilder()
+ .setItem(Items.BLAZE_ROD)
+ .glow()
+ .setName(Text.literal("Wizardry")
+ .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.DARK_PURPLE)))
+ .setCallback((index, clickType, actionType) -> gui.close())
+ );
+ }
+
+ if (PlayerDataRegistry.PLAYERDATA.branches.get("druidry") == null || !PlayerDataRegistry.PLAYERDATA.branches.get("druidry")) {
+ gui.setSlot(15, new GuiElementBuilder()
+ .setItem(Items.OAK_SAPLING)
+ .addLoreLine(Text.literal("Cost: " + ConfigRegistry.CONFIG.branchCost).setStyle(Style.EMPTY.withFormatting(Formatting.DARK_GRAY)))
+ .setName(Text.literal("Druidry")
+ .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.GREEN)))
+ .setCallback((index, clickType, actionType) -> save(player, "druidry", "§aDruidry"))
+ );
+ } else {
+ gui.setSlot(15, new GuiElementBuilder()
+ .setItem(Items.OAK_SAPLING)
+ .glow()
+ .setName(Text.literal("Druidry")
+ .setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.GREEN)))
+ .setCallback((index, clickType, actionType) -> gui.close())
+ );
+ }
+ gui.open();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ public static void save(ServerPlayerEntity player, String branch, String branchName) {
+ 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();
+ } else {
+ player.sendMessage(Text.literal("You don't have enough skill points to unlock this branch!").setStyle(Style.EMPTY.withBold(true).withFormatting(Formatting.RED)), false);
+ player.closeHandledScreen();
+ }
+ }
+}
diff --git a/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java b/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
index 444ecb8..0f56908 100644
--- a/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
+++ b/src/main/java/dev/mayaqq/ygasi/mixin/AdvancementRewardsMixin.java
@@ -12,7 +12,6 @@ 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.ygasi.LOGGER;
@Mixin(AdvancementRewards.class)
public class AdvancementRewardsMixin {
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
index 2d29443..93ccbbd 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/CommandRegistry.java
@@ -1,16 +1,16 @@
package dev.mayaqq.ygasi.registry;
import com.mojang.brigadier.arguments.IntegerArgumentType;
-import dev.mayaqq.ygasi.CreatePlayerData;
+import com.mojang.brigadier.context.CommandContext;
+import dev.mayaqq.ygasi.gui.BranchGui;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.CommandManager;
+import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.stat.Stats;
import net.minecraft.text.Text;
-import java.io.IOException;
-
import static dev.mayaqq.ygasi.registry.StatRegistry.SKILL_POINTS;
import static net.minecraft.server.command.CommandManager.literal;
@@ -18,14 +18,32 @@ public class CommandRegistry {
public static void RegisterCommands() {
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("skilltree")
.executes(context -> {
- try {
- CreatePlayerData.createPlayerData(context.getSource().getPlayerOrThrow().getUuid());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- context.getSource().sendMessage(Text.literal("§aSkillData Registered!"));
+ ServerPlayerEntity player = context.getSource().getPlayer();
+ BranchGui.gui(player);
return 1;
- })));
+ })
+ .then(literal("Mercenary")
+ .executes(context -> {
+ ServerPlayerEntity player = context.getSource().getPlayer();
+ BranchGui.gui(player);
+ return 1;
+ })
+ )
+ .then(literal("Wizardry")
+ .executes(context -> {
+ ServerPlayerEntity player = context.getSource().getPlayer();
+ BranchGui.gui(player);
+ return 1;
+ })
+ )
+ .then(literal("Druidry")
+ .executes(context -> {
+ ServerPlayerEntity player = context.getSource().getPlayer();
+ BranchGui.gui(player);
+ return 1;
+ })
+ )
+ ));
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(literal("ygasi")
.requires(source -> source.hasPermissionLevel(4))
.then(literal("reset")
@@ -54,4 +72,4 @@ public class CommandRegistry {
})))
));
}
-}
+} \ No newline at end of file
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
index b34af4b..9e5c075 100644
--- a/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
+++ b/src/main/java/dev/mayaqq/ygasi/registry/ConfigRegistry.java
@@ -15,6 +15,7 @@ public class ConfigRegistry {
public static Config CONFIG = new Config();
static File modConfFolder = new File(FabricLoader.getInstance().getConfigDir().toFile(),"ygasi");
+ private static final File serverDatFile = new File(FabricLoader.getInstance().getConfigDir().toFile() + "/ygasi/players");
private static File configFile = new File(modConfFolder,"config.json");
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
@@ -23,7 +24,9 @@ public class ConfigRegistry {
if (!modConfFolder.exists()) {
modConfFolder.mkdir();
}
-
+ if (!serverDatFile.exists()) {
+ serverDatFile.mkdir();
+ }
if (!configFile.exists()) {
try {
configFile.createNewFile();
@@ -50,6 +53,7 @@ public class ConfigRegistry {
public static class Config {
//the thing to write in the config file
public int pointsRewarded = 1;
+ public int branchCost = 16;
public Config() {}
}
}
diff --git a/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java b/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java
new file mode 100644
index 0000000..620ee89
--- /dev/null
+++ b/src/main/java/dev/mayaqq/ygasi/registry/PlayerDataRegistry.java
@@ -0,0 +1,52 @@
+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();
+ private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+
+ public static void load(UUID uuid) {
+ File playerDatFile = new File(FabricLoader.getInstance().getConfigDir().toFile() + "/ygasi/players/" + uuid + ".json");
+ if (!playerDatFile.exists()) {
+ try {
+ playerDatFile.createNewFile();
+ save(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().getConfigDir().toFile() + "/ygasi/players/" + uuid + ".json");
+ var writer = new FileWriter(playerDatFile);
+ writer.write(gson.toJson(PLAYERDATA));
+ writer.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static class PlayerData {
+ @SerializedName("branches")
+ public Map<String, Boolean> branches = new HashMap<>();
+ @SerializedName("skills")
+ public Map<String, Integer> skills = new HashMap<>();
+ public PlayerData() {}
+ }
+} \ No newline at end of file
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index 1ec8757..3d70f3b 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -19,7 +19,7 @@
"environment": "*",
"entrypoints": {
"main": [
- "dev.mayaqq.ygasi.ygasi"
+ "dev.mayaqq.ygasi.Ygasi"
]
},
"mixins": [
diff --git a/src/main/resources/ygasi.mixins.json b/src/main/resources/ygasi.mixins.json
index aeb9daf..f82afc7 100644
--- a/src/main/resources/ygasi.mixins.json
+++ b/src/main/resources/ygasi.mixins.json
@@ -13,4 +13,4 @@
"injectors": {
"defaultRequire": 1
}
-}
+} \ No newline at end of file