Initial commit

This commit is contained in:
2025-11-24 23:10:25 +01:00
commit 6f06da5f31
41 changed files with 3443 additions and 0 deletions
@@ -0,0 +1,73 @@
package net.fretux.skillengine.skilltree;
import com.google.gson.*;
import net.fretux.skillengine.SkillEngine;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraftforge.event.AddReloadListenerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Mod.EventBusSubscriber(modid = SkillEngine.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class SkillNodeLoader extends SimpleJsonResourceReloadListener {
private static final Gson GSON = new GsonBuilder().create();
public SkillNodeLoader() {
super(GSON, "skillnodes");
}
@SubscribeEvent
public static void onAddReloadListeners(AddReloadListenerEvent event) {
event.addListener(new SkillNodeLoader());
}
@Override
protected void apply(Map<ResourceLocation, JsonElement> jsons,
ResourceManager resourceManager,
ProfilerFiller profiler) {
SkillEngine.LOGGER.info("Loading skill nodes...");
SkillNodeRegistry.clear();
jsons.forEach((id, element) -> {
JsonObject obj = element.getAsJsonObject();
String title = obj.get("title").getAsString();
String description = obj.get("description").getAsString();
int cost = obj.get("cost").getAsInt();
JsonObject pos = obj.getAsJsonObject("position");
float x = pos.get("x").getAsFloat();
float y = pos.get("y").getAsFloat();
List<ResourceLocation> links = new ArrayList<>();
obj.getAsJsonArray("links").forEach(e ->
links.add(new ResourceLocation(e.getAsString())));
List<ResourceLocation> tags = new ArrayList<>();
obj.getAsJsonArray("tags").forEach(e ->
tags.add(new ResourceLocation(e.getAsString())));
SkillNode node = new SkillNode(
id,
Component.literal(title),
Component.literal(description),
cost,
x, y,
links,
tags
);
SkillNodeRegistry.put(node);
});
SkillEngine.LOGGER.info("Loaded {} skill nodes", SkillNodeRegistry.all().size());
}
}