mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 16:59:43 +00:00
- Add Script Tab to Abilities - Add Custom Ability - Add Icon Support for Abilities / Default Icon Support - Remove Icon Tab and throw it into Effects with allowed Override - Removed Deprecated API Sources
177 lines
4.6 KiB
Java
177 lines
4.6 KiB
Java
package noppes.npcs.scripted.wrapper;
|
|
|
|
import kamkeel.npcs.controllers.AbilityController;
|
|
import kamkeel.npcs.controllers.data.ability.Ability;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import noppes.npcs.api.ability.IAbility;
|
|
import noppes.npcs.api.ability.IPlayerAbilityData;
|
|
import noppes.npcs.controllers.data.PlayerAbilityData;
|
|
import noppes.npcs.controllers.data.PlayerData;
|
|
|
|
/**
|
|
* Script wrapper for PlayerAbilityData providing API access to player abilities.
|
|
*/
|
|
public class ScriptPlayerAbilityData implements IPlayerAbilityData {
|
|
|
|
private final PlayerAbilityData data;
|
|
private final PlayerData playerData;
|
|
|
|
public ScriptPlayerAbilityData(PlayerData playerData) {
|
|
this.playerData = playerData;
|
|
this.data = playerData.abilityData;
|
|
}
|
|
|
|
@Override
|
|
public String[] getUnlockedAbilities() {
|
|
return data.getUnlockedAbilities();
|
|
}
|
|
|
|
@Override
|
|
public void unlockAbility(String key) {
|
|
// Validate ability exists and allows players (peek avoids deep copy)
|
|
Ability ability = AbilityController.Instance.peekAbility(key);
|
|
if (ability == null) {
|
|
return; // Ability doesn't exist
|
|
}
|
|
if (!ability.getAllowedBy().allowsPlayer()) {
|
|
return; // Ability is NPC-only
|
|
}
|
|
// Use canonical key (registry key for built-in, UUID for custom)
|
|
String canonicalKey = ability.getId() != null ? ability.getId() : key;
|
|
data.unlockAbility(canonicalKey);
|
|
}
|
|
|
|
@Override
|
|
public void lockAbility(String key) {
|
|
String canonicalKey = resolveCanonicalKey(key);
|
|
data.lockAbility(canonicalKey);
|
|
}
|
|
|
|
@Override
|
|
public boolean hasUnlockedAbility(String key) {
|
|
String canonicalKey = resolveCanonicalKey(key);
|
|
return data.hasUnlockedAbility(canonicalKey);
|
|
}
|
|
|
|
@Override
|
|
public int getSelectedIndex() {
|
|
return data.getSelectedIndex();
|
|
}
|
|
|
|
@Override
|
|
public void setSelectedIndex(int index) {
|
|
data.setSelectedIndex(index);
|
|
}
|
|
|
|
@Override
|
|
public String getSelectedAbilityKey() {
|
|
return data.getSelectedAbilityKey();
|
|
}
|
|
|
|
@Override
|
|
public void selectNext() {
|
|
data.selectNext();
|
|
}
|
|
|
|
@Override
|
|
public void selectPrevious() {
|
|
data.selectPrevious();
|
|
}
|
|
|
|
@Override
|
|
public boolean isExecutingAbility() {
|
|
return data.isExecutingAbility();
|
|
}
|
|
|
|
@Override
|
|
public IAbility getCurrentAbility() {
|
|
Ability a = data.getCurrentAbility();
|
|
return a != null ? a.deepCopy() : null;
|
|
}
|
|
|
|
@Override
|
|
public void interruptCurrentAbility() {
|
|
data.interruptCurrentAbility();
|
|
}
|
|
|
|
@Override
|
|
public void completeCurrentAbility() {
|
|
data.completeCurrentAbility();
|
|
}
|
|
|
|
@Override
|
|
public boolean isOnCooldown() {
|
|
return data.isOnCooldown();
|
|
}
|
|
|
|
@Override
|
|
public boolean isOnCooldown(String key) {
|
|
EntityPlayer player = playerData.player;
|
|
if (player == null) return false;
|
|
return data.isOnCooldown(key, player);
|
|
}
|
|
|
|
@Override
|
|
public void resetCooldown() {
|
|
data.resetCooldown();
|
|
}
|
|
|
|
@Override
|
|
public void resetCooldown(String key) {
|
|
data.resetCooldown(key);
|
|
}
|
|
|
|
@Override
|
|
public void resetAllCooldowns() {
|
|
data.resetAllCooldowns();
|
|
}
|
|
|
|
@Override
|
|
public boolean activateAbility() {
|
|
EntityPlayer player = playerData.player;
|
|
if (player == null) return false;
|
|
return data.activateAbility(player);
|
|
}
|
|
|
|
@Override
|
|
public boolean activateAbility(String key) {
|
|
EntityPlayer player = playerData.player;
|
|
if (player == null) return false;
|
|
return data.activateAbility(player, key);
|
|
}
|
|
|
|
// Toggle system
|
|
|
|
@Override
|
|
public int toggleAbility(String key) {
|
|
return data.toggleAbility(key);
|
|
}
|
|
|
|
@Override
|
|
public int getToggleState(String key) {
|
|
return data.getToggleState(key);
|
|
}
|
|
|
|
@Override
|
|
public void setToggleState(String key, int state) {
|
|
data.setToggleState(key, state);
|
|
}
|
|
|
|
@Override
|
|
public boolean isAbilityToggled(String key) {
|
|
return data.isAbilityToggled(key);
|
|
}
|
|
|
|
/**
|
|
* Resolve a user-provided key to the canonical storage key.
|
|
* Uses the same resolution as unlockAbility: registry key for built-in, UUID for custom.
|
|
*/
|
|
private String resolveCanonicalKey(String key) {
|
|
Ability ability = AbilityController.Instance.peekAbility(key);
|
|
if (ability != null && ability.getId() != null) {
|
|
return ability.getId();
|
|
}
|
|
return key;
|
|
}
|
|
}
|