Implement mutual exclusives
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package net.fretux.skillengine.skilltree;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AbilityNode {
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final Component title;
|
||||
private final Component description;
|
||||
private final float x, y;
|
||||
private final List<ResourceLocation> links;
|
||||
private final List<ResourceLocation> tags;
|
||||
private final ResourceLocation icon;
|
||||
private final int cooldown;
|
||||
|
||||
public AbilityNode(ResourceLocation id,
|
||||
Component title,
|
||||
Component description,
|
||||
float x, float y,
|
||||
List<ResourceLocation> links,
|
||||
List<ResourceLocation> tags,
|
||||
ResourceLocation icon,
|
||||
int cooldown) {
|
||||
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.links = List.copyOf(links);
|
||||
this.tags = List.copyOf(tags);
|
||||
this.icon = icon;
|
||||
this.cooldown = cooldown;
|
||||
}
|
||||
|
||||
public ResourceLocation getId() { return id; }
|
||||
public Component getTitle() { return title; }
|
||||
public Component getDescription() { return description; }
|
||||
public float getX() { return x; }
|
||||
public float getY() { return y; }
|
||||
public List<ResourceLocation> getLinks() { return links; }
|
||||
public List<ResourceLocation> getTags() { return tags; }
|
||||
public ResourceLocation getIcon() { return icon; }
|
||||
public int getCooldown() { return cooldown; }
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package net.fretux.skillengine.skilltree;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
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 AbilityNodeLoader extends SimpleJsonResourceReloadListener {
|
||||
|
||||
private static final Gson GSON = new GsonBuilder().create();
|
||||
|
||||
public AbilityNodeLoader() {
|
||||
super(GSON, "abilitynodes");
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onAddReloadListeners(AddReloadListenerEvent event) {
|
||||
event.addListener(new AbilityNodeLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void apply(Map<ResourceLocation, JsonElement> jsons,
|
||||
ResourceManager resourceManager,
|
||||
ProfilerFiller profiler) {
|
||||
|
||||
SkillEngine.LOGGER.info("Loading ability nodes...");
|
||||
|
||||
AbilityNodeRegistry.clear();
|
||||
|
||||
jsons.forEach((id, json) -> {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
|
||||
Component title = Component.literal(obj.get("title").getAsString());
|
||||
Component description = Component.literal(obj.get("description").getAsString());
|
||||
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 icon = new ResourceLocation(obj.get("icon").getAsString());
|
||||
|
||||
int cooldown = obj.has("cooldown") ? obj.get("cooldown").getAsInt() : 0;
|
||||
|
||||
AbilityNode node = new AbilityNode(id, title, description, x, y, links, tags, icon, cooldown);
|
||||
AbilityNodeRegistry.put(node);
|
||||
});
|
||||
|
||||
SkillEngine.LOGGER.info("Loaded {} active ability nodes", AbilityNodeRegistry.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 AbilityNodeRegistry {
|
||||
|
||||
private static final Map<ResourceLocation, AbilityNode> ABILITIES = new LinkedHashMap<>();
|
||||
|
||||
public static void clear() {
|
||||
ABILITIES.clear();
|
||||
}
|
||||
|
||||
public static void put(AbilityNode node) {
|
||||
ABILITIES.put(node.getId(), node);
|
||||
}
|
||||
|
||||
public static AbilityNode get(ResourceLocation id) {
|
||||
return ABILITIES.get(id);
|
||||
}
|
||||
|
||||
public static Collection<AbilityNode> all() {
|
||||
return ABILITIES.values();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user