Remove json, implement mutual exclusives, adjustments & fix bugs

This commit is contained in:
2025-12-05 18:41:32 +01:00
parent bb8bc7b479
commit 9ce984a54a
18 changed files with 48 additions and 96 deletions
@@ -23,12 +23,6 @@ public class PlayerSkillData {
public boolean isUnlocked(ResourceLocation nodeId) { public boolean isUnlocked(ResourceLocation nodeId) {
return unlockedNodes.contains(nodeId); return unlockedNodes.contains(nodeId);
} }
public boolean hasTag(ResourceLocation tag) {
return activeTags.contains(tag);
}
public Set<ResourceLocation> getActiveTags() {
return activeTags;
}
private final ResourceLocation[] abilitySlots = new ResourceLocation[3]; private final ResourceLocation[] abilitySlots = new ResourceLocation[3];
@@ -57,10 +51,10 @@ public class PlayerSkillData {
} }
tag.put("Tags", tagList); tag.put("Tags", tagList);
ListTag abilityList = new ListTag(); ListTag abilityList = new ListTag();
for (int i = 0; i < abilitySlots.length; i++) { for (ResourceLocation abilitySlot : abilitySlots) {
CompoundTag t = new CompoundTag(); CompoundTag t = new CompoundTag();
if (abilitySlots[i] != null) { if (abilitySlot != null) {
t.putString("Id", abilitySlots[i].toString()); t.putString("Id", abilitySlot.toString());
} else { } else {
t.putString("Id", ""); t.putString("Id", "");
} }
@@ -130,9 +124,12 @@ public class PlayerSkillData {
} }
public void bindAbility(int slot, ResourceLocation abilityId) { public void bindAbility(int slot, ResourceLocation abilityId) {
bindHelperFunc(slot, abilityId, abilitySlots);
}
public static void bindHelperFunc(int slot, ResourceLocation abilityId, ResourceLocation[] abilitySlots) {
int index = slot - 1; int index = slot - 1;
if (index < 0 || index >= abilitySlots.length) return; if (index < 0 || index >= abilitySlots.length) return;
// Ensure the same ability is not present in multiple slots
if (abilityId != null) { if (abilityId != null) {
for (int i = 0; i < abilitySlots.length; i++) { for (int i = 0; i < abilitySlots.length; i++) {
if (abilityId.equals(abilitySlots[i])) { if (abilityId.equals(abilitySlots[i])) {
@@ -143,12 +140,6 @@ public class PlayerSkillData {
abilitySlots[index] = abilityId; abilitySlots[index] = abilityId;
} }
public ResourceLocation getAbilityInSlot(int slot) {
int index = slot - 1;
if (index < 0 || index >= abilitySlots.length) return null;
return abilitySlots[index];
}
public ResourceLocation[] getAbilitySlots() { public ResourceLocation[] getAbilitySlots() {
return abilitySlots.clone(); return abilitySlots.clone();
} }
@@ -9,9 +9,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class PlayerSkillProvider implements ICapabilityProvider, ICapabilitySerializable<CompoundTag> { public class PlayerSkillProvider implements ICapabilityProvider, ICapabilitySerializable<CompoundTag> {
public static final ResourceLocation ID = new ResourceLocation("skillengine", "player_skill_data"); public static final ResourceLocation ID = new ResourceLocation("skillengine", "player_skill_data");
private final PlayerSkillData backend = new PlayerSkillData(); private final PlayerSkillData backend = new PlayerSkillData();
private final LazyOptional<PlayerSkillData> optional = LazyOptional.of(() -> backend); private final LazyOptional<PlayerSkillData> optional = LazyOptional.of(() -> backend);
@@ -19,7 +19,7 @@ public class SkillEngineCapabilities {
@SubscribeEvent @SubscribeEvent
public static void onAttachCapabilities(AttachCapabilitiesEvent<Entity> event) { public static void onAttachCapabilities(AttachCapabilitiesEvent<Entity> event) {
if (event.getObject() instanceof Player player) { if (event.getObject() instanceof Player) {
SkillEngine.LOGGER.info("Attaching PlayerSkillData capability"); SkillEngine.LOGGER.info("Attaching PlayerSkillData capability");
event.addCapability( event.addCapability(
new ResourceLocation(SkillEngine.MODID, "player_skill_data"), new ResourceLocation(SkillEngine.MODID, "player_skill_data"),
@@ -10,6 +10,7 @@ import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
public class AbilityBindingScreen extends Screen { public class AbilityBindingScreen extends Screen {
@@ -74,7 +75,7 @@ public class AbilityBindingScreen extends Screen {
} }
@Override @Override
public void render(GuiGraphics gfx, int mouseX, int mouseY, float partialTick) { public void render(@NotNull GuiGraphics gfx, int mouseX, int mouseY, float partialTick) {
this.renderBackground(gfx); this.renderBackground(gfx);
int x = (width - PANEL_WIDTH) / 2; int x = (width - PANEL_WIDTH) / 2;
int y = (height - PANEL_HEIGHT) / 2; int y = (height - PANEL_HEIGHT) / 2;
@@ -10,19 +10,17 @@ import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class AbilitySelectScreen extends Screen { public class AbilitySelectScreen extends Screen {
private final Screen parent; private final Screen parent;
private final int slot; // 1..3 private final int slot;
private final List<AbilityNode> unlockedAbilities = new ArrayList<>(); private final List<AbilityNode> unlockedAbilities = new ArrayList<>();
private int page = 0; private int page = 0;
private static final int PAGE_SIZE = 8; private static final int PAGE_SIZE = 8;
private static final int PANEL_WIDTH = 260; private static final int PANEL_WIDTH = 260;
private static final int PANEL_HEIGHT = 220; private static final int PANEL_HEIGHT = 220;
@@ -54,7 +52,6 @@ public class AbilitySelectScreen extends Screen {
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
AbilityNode node = unlockedAbilities.get(i); AbilityNode node = unlockedAbilities.get(i);
String label = node.getTitle().getString(); String label = node.getTitle().getString();
// Disable if already in this slot to avoid redundant bind
boolean alreadyInThisSlot = SkilltreeClientState.getSlotOfAbility(node.getId()) == slot; boolean alreadyInThisSlot = SkilltreeClientState.getSlotOfAbility(node.getId()) == slot;
Button btn = Button.builder(Component.literal(label), b -> select(node)) Button btn = Button.builder(Component.literal(label), b -> select(node))
.pos(x + 15, rowY) .pos(x + 15, rowY)
@@ -67,7 +64,6 @@ public class AbilitySelectScreen extends Screen {
addRenderableWidget(btn); addRenderableWidget(btn);
rowY += 24; rowY += 24;
} }
// paging controls
if (page > 0) { if (page > 0) {
addRenderableWidget(Button.builder(Component.literal("< Prev"), b -> { addRenderableWidget(Button.builder(Component.literal("< Prev"), b -> {
page--; page--;
@@ -86,7 +82,6 @@ public class AbilitySelectScreen extends Screen {
private void select(AbilityNode node) { private void select(AbilityNode node) {
ResourceLocation id = node.getId(); ResourceLocation id = node.getId();
// optimistic client update, then send to server
SkilltreeClientState.bindAbilityLocal(slot, id); SkilltreeClientState.bindAbilityLocal(slot, id);
PacketHandler.CHANNEL.sendToServer(new ServerboundBindAbilityPacket(id, slot)); PacketHandler.CHANNEL.sendToServer(new ServerboundBindAbilityPacket(id, slot));
back(); back();
@@ -107,7 +102,7 @@ public class AbilitySelectScreen extends Screen {
} }
@Override @Override
public void render(GuiGraphics gfx, int mouseX, int mouseY, float partialTick) { public void render(@NotNull GuiGraphics gfx, int mouseX, int mouseY, float partialTick) {
this.renderBackground(gfx); this.renderBackground(gfx);
int x = (width - PANEL_WIDTH) / 2; int x = (width - PANEL_WIDTH) / 2;
int y = (height - PANEL_HEIGHT) / 2; int y = (height - PANEL_HEIGHT) / 2;
@@ -8,6 +8,7 @@ import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
public class AbilitySlotsScreen extends Screen { public class AbilitySlotsScreen extends Screen {
private static final int PANEL_WIDTH = 260; private static final int PANEL_WIDTH = 260;
@@ -24,7 +25,6 @@ public class AbilitySlotsScreen extends Screen {
int buttonW = 80; int buttonW = 80;
int buttonH = 20; int buttonH = 20;
int buttonX = x + PANEL_WIDTH - buttonW - 15; int buttonX = x + PANEL_WIDTH - buttonW - 15;
// Y slot = 1 // Y slot = 1
addRenderableWidget(Button.builder(Component.literal("Rebind"), b -> openSelect(1)) addRenderableWidget(Button.builder(Component.literal("Rebind"), b -> openSelect(1))
.pos(buttonX, rowY).size(buttonW, buttonH).build()); .pos(buttonX, rowY).size(buttonW, buttonH).build());
@@ -34,7 +34,6 @@ public class AbilitySlotsScreen extends Screen {
// C slot = 3 // C slot = 3
addRenderableWidget(Button.builder(Component.literal("Rebind"), b -> openSelect(3)) addRenderableWidget(Button.builder(Component.literal("Rebind"), b -> openSelect(3))
.pos(buttonX, rowY + 70).size(buttonW, buttonH).build()); .pos(buttonX, rowY + 70).size(buttonW, buttonH).build());
addRenderableWidget(Button.builder(Component.literal("Close"), b -> onClose()) addRenderableWidget(Button.builder(Component.literal("Close"), b -> onClose())
.pos(x + PANEL_WIDTH - 70, y + PANEL_HEIGHT - 28).size(60, 20).build()); .pos(x + PANEL_WIDTH - 70, y + PANEL_HEIGHT - 28).size(60, 20).build());
} }
@@ -54,20 +53,17 @@ public class AbilitySlotsScreen extends Screen {
} }
@Override @Override
public void render(GuiGraphics gfx, int mouseX, int mouseY, float partialTick) { public void render(@NotNull GuiGraphics gfx, int mouseX, int mouseY, float partialTick) {
this.renderBackground(gfx); this.renderBackground(gfx);
int x = (width - PANEL_WIDTH) / 2; int x = (width - PANEL_WIDTH) / 2;
int y = (height - PANEL_HEIGHT) / 2; int y = (height - PANEL_HEIGHT) / 2;
gfx.fill(0, 0, width, height, 0xAA000000); gfx.fill(0, 0, width, height, 0xAA000000);
gfx.fill(x, y, x + PANEL_WIDTH, y + PANEL_HEIGHT, 0xFF222222); gfx.fill(x, y, x + PANEL_WIDTH, y + PANEL_HEIGHT, 0xFF222222);
gfx.drawCenteredString(font, Component.literal("Ability Slots"), x + PANEL_WIDTH / 2, y + 12, 0xFFFFFF); gfx.drawCenteredString(font, Component.literal("Ability Slots"), x + PANEL_WIDTH / 2, y + 12, 0xFFFFFF);
int rowY = y + 40; int rowY = y + 40;
drawSlotRow(gfx, x + 15, rowY, 1, "Y"); drawSlotRow(gfx, x + 15, rowY, 1, "Y");
drawSlotRow(gfx, x + 15, rowY + 35, 2, "X"); drawSlotRow(gfx, x + 15, rowY + 35, 2, "X");
drawSlotRow(gfx, x + 15, rowY + 70, 3, "C"); drawSlotRow(gfx, x + 15, rowY + 70, 3, "C");
super.render(gfx, mouseX, mouseY, partialTick); super.render(gfx, mouseX, mouseY, partialTick);
} }
@@ -11,6 +11,7 @@ import net.minecraftforge.fml.common.Mod;
modid = SkillEngine.MODID, modid = SkillEngine.MODID,
value = Dist.CLIENT value = Dist.CLIENT
) )
public class ClientEvents { public class ClientEvents {
@SubscribeEvent @SubscribeEvent
public static void onKeyInput(InputEvent.Key event) { public static void onKeyInput(InputEvent.Key event) {
@@ -1,6 +1,7 @@
package net.fretux.skillengine.client; package net.fretux.skillengine.client;
import net.fretux.skillengine.SkillEngine; import net.fretux.skillengine.SkillEngine;
import net.fretux.skillengine.capability.PlayerSkillData;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.toasts.SystemToast; import net.minecraft.client.gui.components.toasts.SystemToast;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
@@ -65,14 +66,7 @@ public class SkilltreeClientState {
} }
public static void bindAbilityLocal(int slot, ResourceLocation abilityId) { public static void bindAbilityLocal(int slot, ResourceLocation abilityId) {
int index = slot - 1; PlayerSkillData.bindHelperFunc(slot, abilityId, abilitySlots);
if (index < 0 || index >= abilitySlots.length) return;
if (abilityId != null) {
for (int i = 0; i < abilitySlots.length; i++) {
if (abilityId.equals(abilitySlots[i])) abilitySlots[i] = null;
}
}
abilitySlots[index] = abilityId;
} }
public static void setAbilitySlots(ResourceLocation[] slots) { public static void setAbilitySlots(ResourceLocation[] slots) {
@@ -17,33 +17,23 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText; import net.minecraft.network.chat.FormattedText;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class SkilltreeScreen extends Screen { public class SkilltreeScreen extends Screen {
private static final int NODE_RADIUS = 12; private static final int NODE_RADIUS = 12;
private static final int ABILITY_RADIUS = 12; private static final int ABILITY_RADIUS = 12;
private static final int OVERLAY_WIDTH = 240; private static final int OVERLAY_WIDTH = 240;
private static final int OVERLAY_HEIGHT = 180; private static final int OVERLAY_HEIGHT = 180;
private static final int OVERLAY_CONTENT_HEIGHT = 160; private static final int OVERLAY_CONTENT_HEIGHT = 160;
private static final float ZOOM_STEP = 0.1f; private static final float ZOOM_STEP = 0.1f;
private static final float LINE_THICKNESS = 2.0f; private static final float LINE_THICKNESS = 2.0f;
private float zoom = 1.0f; private float zoom = 1.0f;
private final float minZoom = 0.5f;
private final float maxZoom = 2.0f;
private double panX = 0; private double panX = 0;
private double panY = 0; private double panY = 0;
private boolean dragging = false; private boolean dragging = false;
private double lastMouseX;
private double lastMouseY;
private SkillNode hoveredNode = null; private SkillNode hoveredNode = null;
private SkillNode selectedNode = null; private SkillNode selectedNode = null;
private AbilityNode hoveredAbility = null; private AbilityNode hoveredAbility = null;
@@ -60,7 +50,9 @@ public class SkilltreeScreen extends Screen {
@Override @Override
public boolean mouseScrolled(double mouseX, double mouseY, double delta) { public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
zoom += delta * ZOOM_STEP; zoom += (float) (delta * ZOOM_STEP);
float minZoom = 0.5f;
float maxZoom = 2.0f;
zoom = Mth.clamp(zoom, minZoom, maxZoom); zoom = Mth.clamp(zoom, minZoom, maxZoom);
return true; return true;
} }
@@ -74,6 +66,7 @@ public class SkilltreeScreen extends Screen {
SkillNode clickedNode = findNodeAt(mouseX, mouseY); SkillNode clickedNode = findNodeAt(mouseX, mouseY);
if (clickedNode != null) { if (clickedNode != null) {
if (isLockedByExclusivity(clickedNode)) { if (isLockedByExclusivity(clickedNode)) {
assert Minecraft.getInstance().player != null;
Minecraft.getInstance().player.playSound( Minecraft.getInstance().player.playSound(
net.minecraft.sounds.SoundEvents.VILLAGER_NO, 1f, 1f net.minecraft.sounds.SoundEvents.VILLAGER_NO, 1f, 1f
); );
@@ -97,8 +90,6 @@ public class SkilltreeScreen extends Screen {
return true; return true;
} }
dragging = true; dragging = true;
lastMouseX = mouseX;
lastMouseY = mouseY;
} }
return super.mouseClicked(mouseX, mouseY, button); return super.mouseClicked(mouseX, mouseY, button);
} }
@@ -125,7 +116,7 @@ public class SkilltreeScreen extends Screen {
} }
@Override @Override
public void render(GuiGraphics gfx, int mouseX, int mouseY, float partialTicks) { public void render(@NotNull GuiGraphics gfx, int mouseX, int mouseY, float partialTicks) {
this.renderBackground(gfx); this.renderBackground(gfx);
renderSkillPointHeader(gfx); renderSkillPointHeader(gfx);
hoveredNode = findNodeAt(mouseX, mouseY); hoveredNode = findNodeAt(mouseX, mouseY);
@@ -244,6 +235,7 @@ public class SkilltreeScreen extends Screen {
if (!node.getPrereqAttributes().isEmpty()) { if (!node.getPrereqAttributes().isEmpty()) {
tooltip.add(Component.literal("Requirements:") tooltip.add(Component.literal("Requirements:")
.withStyle(ChatFormatting.GOLD)); .withStyle(ChatFormatting.GOLD));
assert Minecraft.getInstance().player != null;
Minecraft.getInstance().player.getCapability(PlayerStatsProvider.PLAYER_STATS) Minecraft.getInstance().player.getCapability(PlayerStatsProvider.PLAYER_STATS)
.ifPresent(stats -> node.getPrereqAttributes().forEach((attr, required) -> { .ifPresent(stats -> node.getPrereqAttributes().forEach((attr, required) -> {
int current = stats.getAttributeLevel(attr); int current = stats.getAttributeLevel(attr);
@@ -287,6 +279,7 @@ public class SkilltreeScreen extends Screen {
0xFFFFFF 0xFFFFFF
); );
textY[0] += 12; textY[0] += 12;
assert Minecraft.getInstance().player != null;
Minecraft.getInstance().player.getCapability(PlayerStatsProvider.PLAYER_STATS) Minecraft.getInstance().player.getCapability(PlayerStatsProvider.PLAYER_STATS)
.ifPresent(stats -> node.getPrereqAttributes().forEach((attr, required) -> { .ifPresent(stats -> node.getPrereqAttributes().forEach((attr, required) -> {
int current = stats.getAttributeLevel(attr); int current = stats.getAttributeLevel(attr);
@@ -14,17 +14,15 @@ import net.minecraftforge.network.PacketDistributor;
public class SkillEnginePlayerEvents { public class SkillEnginePlayerEvents {
private static void sync(ServerPlayer player) { private static void sync(ServerPlayer player) {
player.getCapability(SkillEngineCapabilities.PLAYER_SKILLS).ifPresent(data -> { player.getCapability(SkillEngineCapabilities.PLAYER_SKILLS).ifPresent(data -> PacketHandler.CHANNEL.send(
PacketHandler.CHANNEL.send( PacketDistributor.PLAYER.with(() -> player),
PacketDistributor.PLAYER.with(() -> player), new ClientboundSyncSkillsPacket(
new ClientboundSyncSkillsPacket( data.getUnlockedNodes(),
data.getUnlockedNodes(), data.getUnlockedAbilities(),
data.getUnlockedAbilities(), data.getSkillPoints(),
data.getSkillPoints(), data.getAbilitySlots()
data.getAbilitySlots() )
) ));
);
});
} }
@SubscribeEvent @SubscribeEvent
@@ -9,7 +9,6 @@ import net.fretux.skillengine.client.SkilltreeClientState;
import java.util.function.Supplier; import java.util.function.Supplier;
public class ClientboundNodeUnlockedPacket { public class ClientboundNodeUnlockedPacket {
private final ResourceLocation id; private final ResourceLocation id;
private final int newSkillPoints; private final int newSkillPoints;
@@ -13,7 +13,7 @@ public class PacketHandler {
private static final String PROTOCOL = "1"; private static final String PROTOCOL = "1";
public static final SimpleChannel CHANNEL = NetworkRegistry.ChannelBuilder public static final SimpleChannel CHANNEL = NetworkRegistry.ChannelBuilder
.named(new ResourceLocation(SkillEngine.MODID, "network")) .named(ResourceLocation.fromNamespaceAndPath(SkillEngine.MODID, "network"))
.clientAcceptedVersions(PROTOCOL::equals) .clientAcceptedVersions(PROTOCOL::equals)
.serverAcceptedVersions(PROTOCOL::equals) .serverAcceptedVersions(PROTOCOL::equals)
.networkProtocolVersion(() -> PROTOCOL) .networkProtocolVersion(() -> PROTOCOL)
@@ -2,7 +2,6 @@ package net.fretux.skillengine.network;
import net.fretux.skillengine.capability.SkillEngineCapabilities; import net.fretux.skillengine.capability.SkillEngineCapabilities;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.fretux.skillengine.network.PacketHandler;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.network.NetworkEvent; import net.minecraftforge.network.NetworkEvent;
@@ -36,7 +35,6 @@ public class ServerboundBindAbilityPacket {
player.getCapability(SkillEngineCapabilities.PLAYER_SKILLS).ifPresent(data -> player.getCapability(SkillEngineCapabilities.PLAYER_SKILLS).ifPresent(data ->
data.bindAbility(msg.slot, msg.abilityId) data.bindAbility(msg.slot, msg.abilityId)
); );
// Sync back to client so UI reflects updated bindings
PacketHandler.syncSkillsTo(player); PacketHandler.syncSkillsTo(player);
}); });
ctx.get().setPacketHandled(true); ctx.get().setPacketHandled(true);
@@ -12,13 +12,10 @@ import net.minecraftforge.network.PacketDistributor;
import java.util.function.Supplier; import java.util.function.Supplier;
public class ServerboundUnlockNodePacket { public class ServerboundUnlockNodePacket {
private final ResourceLocation nodeId; private final ResourceLocation nodeId;
public ServerboundUnlockNodePacket(ResourceLocation nodeId) { public ServerboundUnlockNodePacket(ResourceLocation nodeId) {
this.nodeId = nodeId; this.nodeId = nodeId;
} }
public static void encode(ServerboundUnlockNodePacket msg, FriendlyByteBuf buf) { public static void encode(ServerboundUnlockNodePacket msg, FriendlyByteBuf buf) {
buf.writeResourceLocation(msg.nodeId); buf.writeResourceLocation(msg.nodeId);
} }
@@ -73,7 +70,6 @@ public class ServerboundUnlockNodePacket {
} }
}); });
}); });
ctx.get().setPacketHandled(true); ctx.get().setPacketHandled(true);
} }
} }
@@ -13,6 +13,7 @@ import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraftforge.event.AddReloadListenerEvent; import net.minecraftforge.event.AddReloadListenerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -34,38 +35,28 @@ public class AbilityNodeLoader extends SimpleJsonResourceReloadListener {
@Override @Override
protected void apply(Map<ResourceLocation, JsonElement> jsons, protected void apply(Map<ResourceLocation, JsonElement> jsons,
ResourceManager resourceManager, @NotNull ResourceManager resourceManager,
ProfilerFiller profiler) { @NotNull ProfilerFiller profiler) {
SkillEngine.LOGGER.info("Loading ability nodes..."); SkillEngine.LOGGER.info("Loading ability nodes...");
AbilityNodeRegistry.clear(); AbilityNodeRegistry.clear();
jsons.forEach((id, json) -> { jsons.forEach((id, json) -> {
JsonObject obj = json.getAsJsonObject(); JsonObject obj = json.getAsJsonObject();
Component title = Component.literal(obj.get("title").getAsString()); Component title = Component.literal(obj.get("title").getAsString());
Component description = Component.literal(obj.get("description").getAsString()); Component description = Component.literal(obj.get("description").getAsString());
JsonObject pos = obj.getAsJsonObject("position"); JsonObject pos = obj.getAsJsonObject("position");
float x = pos.get("x").getAsFloat(); float x = pos.get("x").getAsFloat();
float y = pos.get("y").getAsFloat(); float y = pos.get("y").getAsFloat();
List<ResourceLocation> links = new ArrayList<>(); List<ResourceLocation> links = new ArrayList<>();
obj.getAsJsonArray("links").forEach(e -> obj.getAsJsonArray("links").forEach(e ->
links.add(new ResourceLocation(e.getAsString()))); links.add(new ResourceLocation(e.getAsString())));
List<ResourceLocation> tags = new ArrayList<>(); List<ResourceLocation> tags = new ArrayList<>();
obj.getAsJsonArray("tags").forEach(e -> obj.getAsJsonArray("tags").forEach(e ->
tags.add(new ResourceLocation(e.getAsString()))); tags.add(new ResourceLocation(e.getAsString())));
ResourceLocation icon = new ResourceLocation(obj.get("icon").getAsString()); ResourceLocation icon = new ResourceLocation(obj.get("icon").getAsString());
int cooldown = obj.has("cooldown") ? obj.get("cooldown").getAsInt() : 0; int cooldown = obj.has("cooldown") ? obj.get("cooldown").getAsInt() : 0;
AbilityNode node = new AbilityNode(id, title, description, x, y, links, tags, icon, cooldown); AbilityNode node = new AbilityNode(id, title, description, x, y, links, tags, icon, cooldown);
AbilityNodeRegistry.put(node); AbilityNodeRegistry.put(node);
}); });
SkillEngine.LOGGER.info("Loaded {} active ability nodes", AbilityNodeRegistry.all().size()); SkillEngine.LOGGER.info("Loaded {} active ability nodes", AbilityNodeRegistry.all().size());
} }
} }
@@ -7,21 +7,16 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
public class AbilityNodeRegistry { public class AbilityNodeRegistry {
private static final Map<ResourceLocation, AbilityNode> ABILITIES = new LinkedHashMap<>(); private static final Map<ResourceLocation, AbilityNode> ABILITIES = new LinkedHashMap<>();
public static void clear() { public static void clear() {
ABILITIES.clear(); ABILITIES.clear();
} }
public static void put(AbilityNode node) { public static void put(AbilityNode node) {
ABILITIES.put(node.getId(), node); ABILITIES.put(node.getId(), node);
} }
public static AbilityNode get(ResourceLocation id) { public static AbilityNode get(ResourceLocation id) {
return ABILITIES.get(id); return ABILITIES.get(id);
} }
public static Collection<AbilityNode> all() { public static Collection<AbilityNode> all() {
return ABILITIES.values(); return ABILITIES.values();
} }
@@ -10,6 +10,7 @@ import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraftforge.event.AddReloadListenerEvent; import net.minecraftforge.event.AddReloadListenerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@@ -32,8 +33,8 @@ public class SkillNodeLoader extends SimpleJsonResourceReloadListener {
@Override @Override
protected void apply(Map<ResourceLocation, JsonElement> jsons, protected void apply(Map<ResourceLocation, JsonElement> jsons,
ResourceManager resourceManager, @NotNull ResourceManager resourceManager,
ProfilerFiller profiler) { @NotNull ProfilerFiller profiler) {
SkillEngine.LOGGER.info("Loading skill nodes..."); SkillEngine.LOGGER.info("Loading skill nodes...");
SkillNodeRegistry.clear(); SkillNodeRegistry.clear();
jsons.forEach((id, element) -> { jsons.forEach((id, element) -> {
@@ -0,0 +1,5 @@
{
"key.skillengine.openskilltree": "Open Skilltree",
"key.skillengine.openabilities": "Open Ability Screen"
}