Complete Ability Hud System + Added-Per-Ability Cooldown System to be Reflected in Hud and Hud GUI

This commit is contained in:
Kam committed 2026-02-20 03:47:12 -05:00
1 parent 877fe2b275
commit 44118ec770
13 files changed
+467 -47

No files matched your search

@@ -109,6 +109,10 @@ public abstract class Ability implements IAbility, IAbilityAction {
// Cooldown override
protected boolean ignoreCooldown = false;
// Per-ability cooldown: if true, this ability has its own independent cooldown
// instead of sharing the global cooldown with other abilities
protected boolean perAbilityCooldown = false;
// ═══════════════════════════════════════════════════════════════════
// BUILT-IN (set in constructor via configureAsBuiltIn, NOT persisted)
// ═══════════════════════════════════════════════════════════════════
@@ -603,8 +607,10 @@ public abstract class Ability implements IAbility, IAbilityAction {
FieldDef.boolField("ability.syncWindup", this::isSyncWindupWithAnimation, this::setSyncWindupWithAnimation)
.hover("ability.hover.sync")
).tab("General").visibleWhen(() -> hasWindUpAnimation() && isSyncWindupWithAnimation()));
defs.add(FieldDef.intField("ability.cooldownTicks", this::getCooldownTicks, this::setCooldownTicks)
.tab("General").range(0, 10000));
defs.add(FieldDef.row(
FieldDef.intField("ability.cooldownTicks", this::getCooldownTicks, this::setCooldownTicks).range(0, 10000),
FieldDef.boolField("ability.perAbilityCooldown", this::isPerAbilityCooldown, this::setPerAbilityCooldown)
).tab("General"));
defs.add(FieldDef.section("ability.section.movement").tab("General"));
defs.add(FieldDef.stringEnumField("ability.lockMovement", LockMovementType.getDisplayKeys(),
() -> this.getLockMovement().getDisplayKey(),
@@ -1282,6 +1288,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
nbt.setTag("customData", (NBTTagCompound) customData.copy());
nbt.setInteger("allowedBy", allowedBy.ordinal());
nbt.setBoolean("ignoreCooldown", ignoreCooldown);
nbt.setBoolean("perAbilityCooldown", perAbilityCooldown);
// Toggle
nbt.setInteger("toggleStates", toggleStates);
@@ -1363,6 +1370,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
customData = nbt.getCompoundTag("customData");
allowedBy = UserType.fromOrdinal(nbt.getInteger("allowedBy"));
ignoreCooldown = nbt.getBoolean("ignoreCooldown");
perAbilityCooldown = nbt.getBoolean("perAbilityCooldown");
// Toggle
toggleStates = nbt.getInteger("toggleStates");
@@ -1951,6 +1959,14 @@ public abstract class Ability implements IAbility, IAbilityAction {
this.ignoreCooldown = ignoreCooldown;
}
public boolean isPerAbilityCooldown() {
return perAbilityCooldown;
}
public void setPerAbilityCooldown(boolean perAbilityCooldown) {
this.perAbilityCooldown = perAbilityCooldown;
}
public boolean isToggleable() {
return toggleStates > 0;
}
@@ -26,6 +26,7 @@ import kamkeel.npcs.network.packets.data.SoundManagementPacket;
import kamkeel.npcs.network.packets.data.SwingPlayerArmPacket;
import kamkeel.npcs.network.packets.data.UpdateAnimationsPacket;
import kamkeel.npcs.network.packets.data.VillagerListPacket;
import kamkeel.npcs.network.packets.data.ability.AbilityCooldownSyncPacket;
import kamkeel.npcs.network.packets.data.ability.AbilityHotbarSyncPacket;
import kamkeel.npcs.network.packets.data.ability.PlayerAbilityStatePacket;
import kamkeel.npcs.network.packets.data.ability.PlayerAbilitySyncPacket;
@@ -603,6 +604,7 @@ public class PacketHandler {
DATA_PACKET.registerPacket(new PlayerAbilitySyncPacket());
DATA_PACKET.registerPacket(new PlayerAbilityStatePacket());
DATA_PACKET.registerPacket(new AbilityHotbarSyncPacket());
DATA_PACKET.registerPacket(new AbilityCooldownSyncPacket());
}
public void registerPlayerPackets() {
@@ -65,6 +65,7 @@ public enum EnumDataPacket {
PLAYER_ABILITY_SYNC,
PLAYER_ABILITY_STATE,
ABILITY_HOTBAR_SYNC,
ABILITY_COOLDOWN_SYNC,
// Auction System
AUCTION_DATA,
@@ -0,0 +1,109 @@
package kamkeel.npcs.network.packets.data.ability;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.AbstractPacket;
import kamkeel.npcs.network.PacketChannel;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.enums.EnumDataPacket;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.data.PlayerData;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* Lightweight packet that syncs cooldown state (global + per-ability) to the client.
* Sent when cooldowns are rolled, reset, or on login.
*/
public final class AbilityCooldownSyncPacket extends AbstractPacket {
public static final String packetName = "Data|AbilityCooldownSync";
private long globalCooldownEndTime;
private int globalCooldownDuration;
private HashMap<String, Long> perAbilityCooldownEndTimes;
private HashMap<String, Integer> perAbilityCooldownDurations;
public AbilityCooldownSyncPacket() {
}
public AbilityCooldownSyncPacket(long globalEndTime, int globalDuration,
HashMap<String, Long> perEndTimes,
HashMap<String, Integer> perDurations) {
this.globalCooldownEndTime = globalEndTime;
this.globalCooldownDuration = globalDuration;
this.perAbilityCooldownEndTimes = perEndTimes;
this.perAbilityCooldownDurations = perDurations;
}
@Override
public Enum getType() {
return EnumDataPacket.ABILITY_COOLDOWN_SYNC;
}
@Override
public PacketChannel getChannel() {
return PacketHandler.DATA_PACKET;
}
@Override
public void sendData(ByteBuf out) throws IOException {
out.writeLong(globalCooldownEndTime);
out.writeInt(globalCooldownDuration);
// Write per-ability cooldowns
int count = perAbilityCooldownEndTimes != null ? perAbilityCooldownEndTimes.size() : 0;
out.writeInt(count);
if (count > 0) {
for (Map.Entry<String, Long> entry : perAbilityCooldownEndTimes.entrySet()) {
ByteBufUtils.writeUTF8String(out, entry.getKey());
out.writeLong(entry.getValue());
Integer dur = perAbilityCooldownDurations.get(entry.getKey());
out.writeInt(dur != null ? dur : 0);
}
}
}
@SideOnly(Side.CLIENT)
@Override
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
long globalEndTime = in.readLong();
int globalDuration = in.readInt();
int count = in.readInt();
HashMap<String, Long> perEndTimes = new HashMap<>();
HashMap<String, Integer> perDurations = new HashMap<>();
for (int i = 0; i < count; i++) {
String key = ByteBufUtils.readUTF8String(in);
long endTime = in.readLong();
int duration = in.readInt();
perEndTimes.put(key, endTime);
perDurations.put(key, duration);
}
PlayerData data = PlayerData.get(player);
if (data != null && data.abilityData != null) {
data.abilityData.applyCooldownSync(globalEndTime, globalDuration, perEndTimes, perDurations);
}
}
/**
* Send the player's current cooldown state to their client.
*/
public static void sendToPlayer(EntityPlayerMP player) {
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
if (data == null || data.abilityData == null) return;
PacketHandler.Instance.sendToPlayer(new AbilityCooldownSyncPacket(
data.abilityData.getCooldownEndTime(),
data.abilityData.getGlobalCooldownDurationValue(),
data.abilityData.getPerAbilityCooldownEndTimes(),
data.abilityData.getPerAbilityCooldownDurations()
), player);
}
}