mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-27 21:22:57 +00:00
Create Ability Hud Editor and Remove Ability Wheel.
This commit is contained in:
1 parent
8f76e007e4
commit
fc8e2e9e7f
32 files changed
+3057
-40
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class AbilityHotbarData {
|
||||
public static final String CHAIN_PREFIX = "chain:";
|
||||
public static final int TOTAL_SLOTS = 12;
|
||||
|
||||
public int slot = -1;
|
||||
public String abilityKey = "";
|
||||
|
||||
public AbilityHotbarData() {
|
||||
}
|
||||
|
||||
public AbilityHotbarData(int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public boolean isChainKey() {
|
||||
return abilityKey != null && abilityKey.startsWith(CHAIN_PREFIX);
|
||||
}
|
||||
|
||||
public String getResolveKey() {
|
||||
if (isChainKey()) return abilityKey.substring(CHAIN_PREFIX.length());
|
||||
return abilityKey;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("slot", slot);
|
||||
tag.setString("abilityKey", abilityKey != null ? abilityKey : "");
|
||||
compound.setTag("AbilityHotbar" + slot, tag);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
abilityKey = compound.getString("abilityKey");
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
abilityKey = "";
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return abilityKey == null || abilityKey.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -364,6 +364,12 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
// Regular ability activation
|
||||
Ability ability = (Ability) action;
|
||||
|
||||
// Toggle abilities cycle state instead of executing
|
||||
if (ability.isToggleable()) {
|
||||
toggleAbility(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check universal cooldown (abilities can optionally ignore it)
|
||||
if (!ability.isIgnoreCooldown() && isOnCooldown()) return false;
|
||||
|
||||
@@ -460,7 +466,7 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
|
||||
public void setSelectedIndex(int index) {
|
||||
if (index >= 0 && index < unlockedAbilities.size()) {
|
||||
if (index == -1 || (index >= 0 && index < unlockedAbilities.size())) {
|
||||
this.selectedIndex = index;
|
||||
syncToClient();
|
||||
}
|
||||
@@ -935,8 +941,9 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any unlocked ability keys that can no longer be resolved.
|
||||
* Called during load to clean up references to deleted abilities.
|
||||
* Remove any unlocked ability keys that can no longer be resolved or
|
||||
* are no longer allowed for players (e.g. NPC-only abilities).
|
||||
* Called during load to clean up references to deleted/restricted abilities.
|
||||
* Supports both regular ability keys and "chain:" prefixed chained ability keys.
|
||||
*/
|
||||
private void validateUnlockedAbilities() {
|
||||
@@ -949,6 +956,9 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
if (resolved == null) {
|
||||
it.remove();
|
||||
LogWriter.info("Removed invalid ability reference from player data: " + key);
|
||||
} else if (!resolved.getAllowedBy().allowsPlayer()) {
|
||||
it.remove();
|
||||
LogWriter.info("Removed non-player ability from player data: " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.ability.AbilityHotbarSyncPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class PlayerAbilityHotbarData {
|
||||
public AbilityHotbarData[] slots = new AbilityHotbarData[AbilityHotbarData.TOTAL_SLOTS];
|
||||
|
||||
public PlayerAbilityHotbarData() {
|
||||
for (int i = 0; i < slots.length; i++) {
|
||||
slots[i] = new AbilityHotbarData(i);
|
||||
}
|
||||
}
|
||||
|
||||
public AbilityHotbarData getSlot(int index) {
|
||||
if (index < 0 || index >= slots.length) return null;
|
||||
return slots[index];
|
||||
}
|
||||
|
||||
public void setSlot(int index, String abilityKey) {
|
||||
if (index < 0 || index >= slots.length) return;
|
||||
slots[index].abilityKey = abilityKey != null ? abilityKey : "";
|
||||
}
|
||||
|
||||
public void clearSlot(int index) {
|
||||
if (index < 0 || index >= slots.length) return;
|
||||
slots[index].reset();
|
||||
}
|
||||
|
||||
public boolean hasAnyAbilities() {
|
||||
for (AbilityHotbarData slot : slots) {
|
||||
if (!slot.isEmpty()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
for (int i = 0; i < slots.length; i++) {
|
||||
slots[i].writeToNBT(compound);
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
for (int i = 0; i < slots.length; i++) {
|
||||
NBTTagCompound slotTag = compound.getCompoundTag("AbilityHotbar" + i);
|
||||
slots[i].readFromNBT(slotTag);
|
||||
}
|
||||
validateSlots();
|
||||
}
|
||||
|
||||
public void validateSlots() {
|
||||
if (AbilityController.Instance == null) return;
|
||||
for (AbilityHotbarData slot : slots) {
|
||||
if (slot.isEmpty()) continue;
|
||||
boolean valid;
|
||||
if (slot.isChainKey()) {
|
||||
valid = AbilityController.Instance.canResolveChainedAbility(slot.getResolveKey());
|
||||
} else {
|
||||
valid = AbilityController.Instance.canResolveAbility(slot.abilityKey);
|
||||
// Also check that resolved ability allows player usage
|
||||
if (valid) {
|
||||
Ability ability = AbilityController.Instance.resolveAbility(slot.abilityKey);
|
||||
if (ability != null && !ability.getAllowedBy().allowsPlayer()) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
slot.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void syncToClient(EntityPlayer player) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
AbilityHotbarSyncPacket.sendToPlayer((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public PlayerTradeData tradeData = new PlayerTradeData(this);
|
||||
|
||||
public PlayerAbilityData abilityData = new PlayerAbilityData(this);
|
||||
public PlayerAbilityHotbarData hotbarData = new PlayerAbilityHotbarData();
|
||||
public ActionManager actionManager = new ActionManager();
|
||||
public PlayerDataScript scriptData;
|
||||
|
||||
@@ -119,6 +120,9 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
|
||||
// Sync player ability data to client
|
||||
abilityData.syncToClient();
|
||||
|
||||
// Sync hotbar data to client
|
||||
hotbarData.syncToClient(player);
|
||||
}
|
||||
|
||||
public void onLogout() {
|
||||
@@ -151,6 +155,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
magicData.readToNBT(data);
|
||||
tradeData.readFromNBT(data);
|
||||
abilityData.readFromNBT(data);
|
||||
hotbarData.readFromNBT(data);
|
||||
|
||||
if (player != null) {
|
||||
playername = player.getCommandSenderName();
|
||||
@@ -195,6 +200,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
magicData.writeToNBT(compound);
|
||||
tradeData.writeToNBT(compound);
|
||||
abilityData.writeToNBT(compound);
|
||||
hotbarData.writeToNBT(compound);
|
||||
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
|
||||
Reference in new issue
Block a user