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,17 @@
package net.fretux.skillengine.skilltree;
import net.fretux.skillengine.capability.PlayerSkillData;
import net.minecraft.resources.ResourceLocation;
public class SkillLogic {
public static boolean canUnlock(PlayerSkillData data, SkillNode node) {
if (data.isUnlocked(node.getId())) return false;
if (data.getSkillPoints() < node.getCost()) return false;
if (node.isRoot()) return true;
for (ResourceLocation neighborId : node.getLinks()) {
if (data.isUnlocked(neighborId)) return true;
}
return false;
}
}
@@ -0,0 +1,49 @@
package net.fretux.skillengine.skilltree;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import java.util.List;
public class SkillNode {
private final ResourceLocation id;
private final Component title;
private final Component description;
private final int cost;
private final float x;
private final float y;
private final List<ResourceLocation> links;
private final List<ResourceLocation> tags;
public SkillNode(ResourceLocation id,
Component title,
Component description,
int cost,
float x, float y,
List<ResourceLocation> links,
List<ResourceLocation> tags) {
this.id = id;
this.title = title;
this.description = description;
this.cost = cost;
this.x = x;
this.y = y;
this.links = List.copyOf(links);
this.tags = List.copyOf(tags);
}
public ResourceLocation getId() { return id; }
public Component getTitle() { return title; }
public Component getDescription() { return description; }
public int getCost() { return cost; }
public float getX() { return x; }
public float getY() { return y; }
public List<ResourceLocation> getLinks() { return links; }
public List<ResourceLocation> getTags() { return tags; }
public boolean isRoot() {
return links.isEmpty(); // or a dedicated flag if you want later
}
}
@@ -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());
}
}
@@ -0,0 +1,28 @@
package net.fretux.skillengine.skilltree;
import net.minecraft.resources.ResourceLocation;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
public class SkillNodeRegistry {
private static final Map<ResourceLocation, SkillNode> NODES = new LinkedHashMap<>();
public static void clear() {
NODES.clear();
}
public static void put(SkillNode node) {
NODES.put(node.getId(), node);
}
public static SkillNode get(ResourceLocation id) {
return NODES.get(id);
}
public static Collection<SkillNode> all() {
return NODES.values();
}
}