Implement all required compat with Ascend
This commit is contained in:
@@ -1,17 +1,32 @@
|
||||
package net.fretux.skillengine.skilltree;
|
||||
|
||||
import net.fretux.ascend.player.PlayerStatsProvider;
|
||||
import net.fretux.skillengine.capability.PlayerSkillData;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SkillLogic {
|
||||
|
||||
public static boolean canUnlock(PlayerSkillData data, SkillNode node) {
|
||||
public static boolean canUnlock(PlayerSkillData data, Player player, SkillNode node) {
|
||||
if (data.isUnlocked(node.getId())) return false;
|
||||
if (data.getSkillPoints() < node.getCost()) return false;
|
||||
if (node.isRoot()) return true;
|
||||
if (!meetsAscendPrerequisites(player, node)) return false;
|
||||
for (ResourceLocation neighborId : node.getLinks()) {
|
||||
if (data.isUnlocked(neighborId)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static boolean meetsAscendPrerequisites(Player player, SkillNode node) {
|
||||
return player.getCapability(PlayerStatsProvider.PLAYER_STATS).map(stats -> {
|
||||
for (Map.Entry<String, Integer> req : node.getPrereqAttributes().entrySet()) {
|
||||
int current = stats.getAttributeLevel(req.getKey());
|
||||
if (current < req.getValue()) return false;
|
||||
}
|
||||
return true;
|
||||
}).orElse(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SkillNode {
|
||||
|
||||
@@ -15,6 +16,8 @@ public class SkillNode {
|
||||
private final float y;
|
||||
private final List<ResourceLocation> links;
|
||||
private final List<ResourceLocation> tags;
|
||||
private final ResourceLocation icons;
|
||||
private final Map<String, Integer> prereqAttributes;
|
||||
|
||||
public SkillNode(ResourceLocation id,
|
||||
Component title,
|
||||
@@ -22,7 +25,9 @@ public class SkillNode {
|
||||
int cost,
|
||||
float x, float y,
|
||||
List<ResourceLocation> links,
|
||||
List<ResourceLocation> tags) {
|
||||
List<ResourceLocation> tags,
|
||||
ResourceLocation icons,
|
||||
Map<String, Integer> prereqAttributes) {
|
||||
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
@@ -32,18 +37,51 @@ public class SkillNode {
|
||||
this.y = y;
|
||||
this.links = List.copyOf(links);
|
||||
this.tags = List.copyOf(tags);
|
||||
this.icons = icons;
|
||||
this.prereqAttributes = Map.copyOf(prereqAttributes);
|
||||
}
|
||||
|
||||
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 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 ResourceLocation getIcons() {
|
||||
return icons;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getPrereqAttributes() {
|
||||
return prereqAttributes;
|
||||
}
|
||||
|
||||
public boolean isRoot() {
|
||||
return links.isEmpty(); // or a dedicated flag if you want later
|
||||
return links.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -33,29 +34,30 @@ public class SkillNodeLoader extends SimpleJsonResourceReloadListener {
|
||||
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())));
|
||||
|
||||
ResourceLocation icons = new ResourceLocation(obj.get("icons").getAsString());
|
||||
Map<String, Integer> prereqAttributes = new HashMap<>();
|
||||
if (obj.has("prerequisites")) {
|
||||
JsonObject prereqObj = obj.getAsJsonObject("prerequisites");
|
||||
for (Map.Entry<String, JsonElement> entry : prereqObj.entrySet()) {
|
||||
prereqAttributes.put(entry.getKey(), entry.getValue().getAsInt());
|
||||
}
|
||||
}
|
||||
SkillNode node = new SkillNode(
|
||||
id,
|
||||
Component.literal(title),
|
||||
@@ -63,11 +65,12 @@ public class SkillNodeLoader extends SimpleJsonResourceReloadListener {
|
||||
cost,
|
||||
x, y,
|
||||
links,
|
||||
tags
|
||||
tags,
|
||||
icons,
|
||||
prereqAttributes
|
||||
);
|
||||
SkillNodeRegistry.put(node);
|
||||
});
|
||||
|
||||
SkillEngine.LOGGER.info("Loaded {} skill nodes", SkillNodeRegistry.all().size());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user