fix more bugs
This commit is contained in:
+1
-1
@@ -48,7 +48,7 @@ mod_name=Fretux's Skill Engine
|
|||||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||||
mod_license=All Rights Reserved
|
mod_license=All Rights Reserved
|
||||||
# The mod version. See https://semver.org/
|
# The mod version. See https://semver.org/
|
||||||
mod_version=1.1.1
|
mod_version=1.1.2
|
||||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||||
# This should match the base package used for the mod sources.
|
# This should match the base package used for the mod sources.
|
||||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
|
|||||||
@@ -10,22 +10,29 @@ import java.util.function.Supplier;
|
|||||||
public class ClientboundNodeUnlockedPacket {
|
public class ClientboundNodeUnlockedPacket {
|
||||||
|
|
||||||
private final ResourceLocation id;
|
private final ResourceLocation id;
|
||||||
|
private final int newSkillPoints;
|
||||||
|
|
||||||
public ClientboundNodeUnlockedPacket(ResourceLocation id) {
|
public ClientboundNodeUnlockedPacket(ResourceLocation id, int newSkillPoints) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.newSkillPoints = newSkillPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void encode(ClientboundNodeUnlockedPacket msg, FriendlyByteBuf buf) {
|
public static void encode(ClientboundNodeUnlockedPacket msg, FriendlyByteBuf buf) {
|
||||||
buf.writeResourceLocation(msg.id);
|
buf.writeResourceLocation(msg.id);
|
||||||
|
buf.writeInt(msg.newSkillPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClientboundNodeUnlockedPacket decode(FriendlyByteBuf buf) {
|
public static ClientboundNodeUnlockedPacket decode(FriendlyByteBuf buf) {
|
||||||
return new ClientboundNodeUnlockedPacket(buf.readResourceLocation());
|
ResourceLocation id = buf.readResourceLocation();
|
||||||
|
int points = buf.readInt();
|
||||||
|
return new ClientboundNodeUnlockedPacket(id, points);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handle(ClientboundNodeUnlockedPacket msg, Supplier<NetworkEvent.Context> ctx) {
|
public static void handle(ClientboundNodeUnlockedPacket msg, Supplier<NetworkEvent.Context> ctx) {
|
||||||
ctx.get().enqueueWork(() -> {
|
ctx.get().enqueueWork(() -> {
|
||||||
|
// Update client-side unlocked set and points immediately so UI can reflect changes this frame
|
||||||
SkilltreeClientState.unlockNode(msg.id);
|
SkilltreeClientState.unlockNode(msg.id);
|
||||||
|
SkilltreeClientState.setCurrentSkillPoints(msg.newSkillPoints);
|
||||||
});
|
});
|
||||||
ctx.get().setPacketHandled(true);
|
ctx.get().setPacketHandled(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,9 +49,10 @@ public class ServerboundUnlockNodePacket {
|
|||||||
data.unlockNode(node);
|
data.unlockNode(node);
|
||||||
SkillEngine.LOGGER.info("Node {} unlocked for {}", msg.nodeId, player.getGameProfile().getName());
|
SkillEngine.LOGGER.info("Node {} unlocked for {}", msg.nodeId, player.getGameProfile().getName());
|
||||||
|
|
||||||
|
// Send client an immediate update about the unlocked node and the new remaining points
|
||||||
PacketHandler.CHANNEL.send(
|
PacketHandler.CHANNEL.send(
|
||||||
PacketDistributor.PLAYER.with(() -> player),
|
PacketDistributor.PLAYER.with(() -> player),
|
||||||
new ClientboundNodeUnlockedPacket(node.getId())
|
new ClientboundNodeUnlockedPacket(node.getId(), data.getSkillPoints())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
SkillEngine.LOGGER.info("Cannot unlock node {} for {} (canUnlock=false)",
|
SkillEngine.LOGGER.info("Cannot unlock node {} for {} (canUnlock=false)",
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ public class SkillNodeLoader extends SimpleJsonResourceReloadListener {
|
|||||||
SkillNodeRegistry.clear();
|
SkillNodeRegistry.clear();
|
||||||
jsons.forEach((id, element) -> {
|
jsons.forEach((id, element) -> {
|
||||||
JsonObject obj = element.getAsJsonObject();
|
JsonObject obj = element.getAsJsonObject();
|
||||||
|
ResourceLocation nodeId = obj.has("id")
|
||||||
|
? new ResourceLocation(obj.get("id").getAsString())
|
||||||
|
: id;
|
||||||
String title = obj.get("title").getAsString();
|
String title = obj.get("title").getAsString();
|
||||||
String description = obj.get("description").getAsString();
|
String description = obj.get("description").getAsString();
|
||||||
int cost = obj.get("cost").getAsInt();
|
int cost = obj.get("cost").getAsInt();
|
||||||
@@ -59,7 +62,7 @@ public class SkillNodeLoader extends SimpleJsonResourceReloadListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SkillNode node = new SkillNode(
|
SkillNode node = new SkillNode(
|
||||||
id,
|
nodeId,
|
||||||
Component.literal(title),
|
Component.literal(title),
|
||||||
Component.literal(description),
|
Component.literal(description),
|
||||||
cost,
|
cost,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"id": "skillengine:welcome",
|
||||||
"title": "Welcome to Ascend",
|
"title": "Welcome to Ascend",
|
||||||
"description": "This is your first skill node.\nClick Unlock to test the system.",
|
"description": "This is your first skill node.\nClick Unlock to test the system.",
|
||||||
"cost": 0,
|
"cost": 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user