mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 19:59:56 +00:00
Ability Push
This commit is contained in:
1 parent
3e85557984
commit
166c8aa228
66 files changed
+10780
-42
No files matched your search
@@ -68,6 +68,7 @@ import noppes.npcs.controllers.SpawnController;
|
||||
import noppes.npcs.controllers.TagController;
|
||||
import noppes.npcs.controllers.TransportController;
|
||||
import noppes.npcs.enchants.EnchantInterface;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import noppes.npcs.entity.EntityChairMount;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityMagicProjectile;
|
||||
@@ -268,6 +269,8 @@ public class CustomNpcs {
|
||||
new SpawnController();
|
||||
new LinkedNpcController();
|
||||
new AnimationController();
|
||||
new AbilityController();
|
||||
AbilityController.Instance.load();
|
||||
|
||||
LinkedItemController.getInstance().load();
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@ public class CustomNpcsPermissions {
|
||||
public static final Permission NPC_ADVANCED_TRANSPORT = new Permission("customnpcs.npc.advanced.transport");
|
||||
public static final Permission NPC_ADVANCED_TRANSFORM = new Permission("customnpcs.npc.advanced.transform");
|
||||
public static final Permission NPC_ADVANCED_LINKED = new Permission("customnpcs.npc.advanced.linked");
|
||||
public static final Permission NPC_ADVANCED_MAGIC = new Permission("customnpcs.npc.advanced.linked");
|
||||
public static final Permission NPC_ADVANCED_MAGIC = new Permission("customnpcs.npc.advanced.magic");
|
||||
public static final Permission NPC_ADVANCED_ABILITIES = new Permission("customnpcs.npc.advanced.abilities");
|
||||
public static final Permission NPC_ADVANCED_TAGS = new Permission("customnpcs.npc.advanced.tags");
|
||||
|
||||
public static final Permission GLOBAL_REMOTE = new Permission("customnpcs.global.remote");
|
||||
|
||||
@@ -0,0 +1,725 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.packets.data.ability.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.TelegraphSpawnPacket;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.AbilityEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Manages NPC abilities - storage, selection, execution, and cooldowns.
|
||||
* Follows the DataStats/DataAI pattern for NPC data management.
|
||||
*/
|
||||
public class DataAbilities {
|
||||
|
||||
private final EntityNPCInterface npc;
|
||||
private final Random random = new Random();
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CONFIGURATION (saved to NBT)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/** List of abilities this NPC can use */
|
||||
private List<Ability> abilities = new ArrayList<>();
|
||||
|
||||
/** Whether the ability system is enabled for this NPC */
|
||||
public boolean enabled = false;
|
||||
|
||||
/** Minimum ticks between ability selections (global cooldown) */
|
||||
public int globalCooldown = 20;
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// RUNTIME STATE (not saved)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/** Currently executing ability (null if none) */
|
||||
private transient Ability currentAbility;
|
||||
|
||||
/** Per-ability cooldown timers (ability ID -> world time when cooldown ends) */
|
||||
private transient Map<String, Long> cooldowns = new HashMap<>();
|
||||
|
||||
/** Ticks until next ability can be selected (global cooldown timer) */
|
||||
private transient int globalCooldownTimer = 0;
|
||||
|
||||
/** Last target used for ability execution */
|
||||
private transient EntityLivingBase lastTarget;
|
||||
|
||||
/** Recent hit timestamps for hit count condition */
|
||||
private transient List<Long> recentHitTimes = new ArrayList<>();
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CONSTRUCTOR
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public DataAbilities(EntityNPCInterface npc) {
|
||||
this.npc = npc;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// TICK - Called from EntityNPCInterface.onLivingUpdate()
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Main tick method - handles ability execution and cooldown management.
|
||||
* Should be called every tick from onLivingUpdate().
|
||||
*/
|
||||
public void tick() {
|
||||
if (!enabled || npc.worldObj.isRemote || npc.isKilled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Tick global cooldown
|
||||
if (globalCooldownTimer > 0) {
|
||||
globalCooldownTimer--;
|
||||
}
|
||||
|
||||
// Tick current ability if executing
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
tickCurrentAbility();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tick the currently executing ability.
|
||||
*/
|
||||
private void tickCurrentAbility() {
|
||||
EntityLivingBase target = lastTarget != null ? lastTarget : npc.getAttackTarget();
|
||||
AbilityPhase oldPhase = currentAbility.getPhase();
|
||||
|
||||
// Tick advances time and possibly changes phase
|
||||
boolean phaseChanged = currentAbility.tick();
|
||||
|
||||
// Fire tick event for scripts
|
||||
fireTickEvent(currentAbility, target);
|
||||
|
||||
// Handle phase-specific logic
|
||||
switch (currentAbility.getPhase()) {
|
||||
case WINDUP:
|
||||
currentAbility.onWindUpTick(npc, target, npc.worldObj, currentAbility.getCurrentTick());
|
||||
break;
|
||||
|
||||
case ACTIVE:
|
||||
if (phaseChanged && oldPhase == AbilityPhase.WINDUP) {
|
||||
// Just entered ACTIVE phase - lock telegraph position if it was following
|
||||
// This commits the ability to its current target position
|
||||
TelegraphInstance telegraph = currentAbility.getTelegraphInstance();
|
||||
if (telegraph != null) {
|
||||
telegraph.lockPosition();
|
||||
}
|
||||
|
||||
// Remove telegraph - it has served its purpose
|
||||
removeTelegraph(currentAbility);
|
||||
|
||||
// Play active sound and animation
|
||||
playAbilitySound(currentAbility.getActiveSound());
|
||||
playAbilityAnimation(currentAbility.getActiveAnimationId());
|
||||
|
||||
// Fire execute event (cancelable)
|
||||
AbilityEvent.ExecuteEvent executeEvent = new AbilityEvent.ExecuteEvent(
|
||||
npc.wrappedNPC, currentAbility, target);
|
||||
if (NpcAPI.EVENT_BUS.post(executeEvent)) {
|
||||
// Event was cancelled - skip execution but continue to recovery
|
||||
return;
|
||||
}
|
||||
|
||||
// Call onExecute
|
||||
currentAbility.onExecute(npc, target, npc.worldObj);
|
||||
}
|
||||
currentAbility.onActiveTick(npc, target, npc.worldObj, currentAbility.getCurrentTick());
|
||||
break;
|
||||
|
||||
case RECOVERY:
|
||||
// Recovery phase - just wait
|
||||
break;
|
||||
|
||||
case IDLE:
|
||||
// Ability completed
|
||||
currentAbility.onComplete(npc, target);
|
||||
|
||||
// Fire complete event
|
||||
AbilityEvent.CompleteEvent completeEvent = new AbilityEvent.CompleteEvent(
|
||||
npc.wrappedNPC, currentAbility, target);
|
||||
NpcAPI.EVENT_BUS.post(completeEvent);
|
||||
|
||||
onAbilityComplete();
|
||||
break;
|
||||
}
|
||||
|
||||
// Clear AI pathfinding if ability is controlling movement
|
||||
// But DON'T zero motion - let the ability set it if needed
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
if (isAbilityControllingMovement()) {
|
||||
// Clear navigator so AI doesn't fight with ability movement
|
||||
npc.getNavigator().clearPathEntity();
|
||||
|
||||
// Only zero motion if lockMovement is true AND ability doesn't have its own movement
|
||||
// This allows stationary abilities to freeze the NPC, while movement abilities can set their own motion
|
||||
if (currentAbility.isLockMovement() && !currentAbility.hasAbilityMovement()) {
|
||||
npc.motionX = 0;
|
||||
npc.motionZ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an ability completes.
|
||||
*/
|
||||
private void onAbilityComplete() {
|
||||
if (currentAbility != null) {
|
||||
// Stop any ability animation
|
||||
stopAbilityAnimation();
|
||||
|
||||
// Start per-ability cooldown
|
||||
startCooldown(currentAbility);
|
||||
currentAbility = null;
|
||||
lastTarget = null;
|
||||
|
||||
// Start global cooldown
|
||||
globalCooldownTimer = globalCooldown;
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// ABILITY SELECTION - Called from CombatHandler
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Try to select and start an ability for the given target.
|
||||
* Called by CombatHandler when NPC is in combat and ready for an ability.
|
||||
*
|
||||
* @param target The combat target
|
||||
* @return true if an ability was started
|
||||
*/
|
||||
public boolean trySelectAndStart(EntityLivingBase target) {
|
||||
if (!canSelectAbility()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Ability selected = selectAbility(target);
|
||||
if (selected == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return startAbility(selected, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an ability can be selected right now.
|
||||
*/
|
||||
public boolean canSelectAbility() {
|
||||
if (!enabled || abilities.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
return false;
|
||||
}
|
||||
if (globalCooldownTimer > 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select an ability using weighted random from eligible abilities.
|
||||
*/
|
||||
private Ability selectAbility(EntityLivingBase target) {
|
||||
List<Ability> eligible = new ArrayList<>();
|
||||
int totalWeight = 0;
|
||||
|
||||
for (Ability ability : abilities) {
|
||||
if (isAbilityEligible(ability, target)) {
|
||||
eligible.add(ability);
|
||||
totalWeight += ability.getWeight();
|
||||
}
|
||||
}
|
||||
|
||||
if (eligible.isEmpty() || totalWeight <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Weighted random selection
|
||||
int roll = random.nextInt(totalWeight);
|
||||
int cumulative = 0;
|
||||
for (Ability ability : eligible) {
|
||||
cumulative += ability.getWeight();
|
||||
if (roll < cumulative) {
|
||||
return ability;
|
||||
}
|
||||
}
|
||||
|
||||
return eligible.get(eligible.size() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a specific ability is eligible for use.
|
||||
*/
|
||||
private boolean isAbilityEligible(Ability ability, EntityLivingBase target) {
|
||||
// Check enabled
|
||||
if (!ability.isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check cooldown
|
||||
if (isOnCooldown(ability)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if already executing
|
||||
if (ability.isExecuting()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check range
|
||||
if (target != null) {
|
||||
float distance = npc.getDistanceToEntity(target);
|
||||
if (distance < ability.getMinRange() || distance > ability.getMaxRange()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check conditions
|
||||
if (!ability.checkConditions(npc, target)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start executing an ability.
|
||||
*/
|
||||
private boolean startAbility(Ability ability, EntityLivingBase target) {
|
||||
// Fire start event (cancelable)
|
||||
AbilityEvent.StartEvent startEvent = new AbilityEvent.StartEvent(
|
||||
npc.wrappedNPC, ability, target);
|
||||
if (NpcAPI.EVENT_BUS.post(startEvent)) {
|
||||
// Event was cancelled - don't start the ability
|
||||
return false;
|
||||
}
|
||||
|
||||
currentAbility = ability;
|
||||
lastTarget = target;
|
||||
ability.start(target);
|
||||
|
||||
// Spawn telegraph and send to clients
|
||||
spawnTelegraph(ability, target);
|
||||
|
||||
// Play wind up sound if configured
|
||||
playAbilitySound(ability.getWindUpSound());
|
||||
|
||||
// Play wind up animation if configured
|
||||
playAbilityAnimation(ability.getWindUpAnimationId());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Play a sound at the NPC's location.
|
||||
*/
|
||||
private void playAbilitySound(String sound) {
|
||||
if (sound != null && !sound.isEmpty()) {
|
||||
npc.worldObj.playSoundAtEntity(npc, sound, 1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Play an animation on the NPC by ID.
|
||||
*/
|
||||
private void playAbilityAnimation(int animationId) {
|
||||
if (animationId < 0) return;
|
||||
if (AnimationController.Instance == null) return;
|
||||
|
||||
Animation animation = AnimationController.Instance.animations.get(animationId);
|
||||
if (animation != null) {
|
||||
npc.display.animationData.setEnabled(true);
|
||||
npc.display.animationData.setAnimation(animation);
|
||||
npc.display.animationData.updateClient();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop any currently playing ability animation.
|
||||
*/
|
||||
private void stopAbilityAnimation() {
|
||||
npc.display.animationData.setAnimation(null);
|
||||
npc.display.animationData.updateClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn and send telegraph for an ability.
|
||||
*/
|
||||
private void spawnTelegraph(Ability ability, EntityLivingBase target) {
|
||||
TelegraphInstance telegraph = ability.createTelegraph(npc, target);
|
||||
if (telegraph != null) {
|
||||
ability.setTelegraphInstance(telegraph);
|
||||
// Send to all nearby players
|
||||
TelegraphSpawnPacket.sendToTracking(telegraph, npc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove telegraph when ability ends or is interrupted.
|
||||
*/
|
||||
private void removeTelegraph(Ability ability) {
|
||||
TelegraphInstance telegraph = ability.getTelegraphInstance();
|
||||
if (telegraph != null) {
|
||||
TelegraphRemovePacket.sendToTracking(telegraph.getInstanceId(), npc);
|
||||
ability.setTelegraphInstance(null);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// COOLDOWN MANAGEMENT
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Check if an ability is on cooldown.
|
||||
*/
|
||||
public boolean isOnCooldown(Ability ability) {
|
||||
Long endTime = cooldowns.get(ability.getId());
|
||||
if (endTime == null) {
|
||||
return false;
|
||||
}
|
||||
return npc.worldObj.getTotalWorldTime() < endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start cooldown for an ability.
|
||||
*/
|
||||
private void startCooldown(Ability ability) {
|
||||
long endTime = npc.worldObj.getTotalWorldTime() + ability.getCooldownTicks();
|
||||
cooldowns.put(ability.getId(), endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset cooldown for a specific ability.
|
||||
*/
|
||||
public void resetCooldown(String abilityId) {
|
||||
cooldowns.remove(abilityId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all cooldowns.
|
||||
*/
|
||||
public void resetAllCooldowns() {
|
||||
cooldowns.clear();
|
||||
globalCooldownTimer = 0;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// INTERRUPTION - Called from CombatHandler on damage
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Handle damage taken - may interrupt current ability.
|
||||
*
|
||||
* @param source The damage source
|
||||
* @param amount The damage amount
|
||||
* @return true if ability was interrupted
|
||||
*/
|
||||
public boolean onDamage(DamageSource source, float amount) {
|
||||
// Track hit for hit count condition
|
||||
recordHit();
|
||||
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (currentAbility.canInterrupt(amount)) {
|
||||
interruptCurrentAbility(source, amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a hit for the hit count condition.
|
||||
*/
|
||||
private void recordHit() {
|
||||
recentHitTimes.add(npc.worldObj.getTotalWorldTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of hits received within the specified tick window.
|
||||
*
|
||||
* @param withinTicks The time window in ticks
|
||||
* @return Number of hits in that window
|
||||
*/
|
||||
public int getRecentHitCount(int withinTicks) {
|
||||
long currentTime = npc.worldObj.getTotalWorldTime();
|
||||
long cutoff = currentTime - withinTicks;
|
||||
|
||||
// Clean up old entries and count
|
||||
int count = 0;
|
||||
recentHitTimes.removeIf(time -> time < cutoff);
|
||||
for (Long time : recentHitTimes) {
|
||||
if (time >= cutoff) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupt the currently executing ability.
|
||||
*/
|
||||
public void interruptCurrentAbility(DamageSource source, float damage) {
|
||||
if (currentAbility != null) {
|
||||
// Remove telegraph early
|
||||
removeTelegraph(currentAbility);
|
||||
|
||||
// Stop any ability animation
|
||||
stopAbilityAnimation();
|
||||
|
||||
// Fire interrupt event
|
||||
AbilityEvent.InterruptEvent interruptEvent = new AbilityEvent.InterruptEvent(
|
||||
npc.wrappedNPC, currentAbility, lastTarget, source, damage);
|
||||
NpcAPI.EVENT_BUS.post(interruptEvent);
|
||||
|
||||
currentAbility.onInterrupt(npc, source, damage);
|
||||
currentAbility.interrupt();
|
||||
currentAbility = null;
|
||||
lastTarget = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force stop the current ability (no interrupt event).
|
||||
*/
|
||||
public void stopCurrentAbility() {
|
||||
if (currentAbility != null) {
|
||||
removeTelegraph(currentAbility);
|
||||
stopAbilityAnimation();
|
||||
currentAbility.interrupt();
|
||||
currentAbility = null;
|
||||
lastTarget = null;
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SCRIPT EVENTS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Fire the ability tick event for scripts.
|
||||
*/
|
||||
private void fireTickEvent(Ability ability, EntityLivingBase target) {
|
||||
AbilityEvent.TickEvent event = new AbilityEvent.TickEvent(
|
||||
npc.wrappedNPC, ability, target,
|
||||
ability.getPhase().ordinal(), ability.getCurrentTick());
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire an ability hit event. Called by abilities when they hit an entity.
|
||||
* Returns null if the event was cancelled, otherwise returns the (possibly modified) event.
|
||||
*
|
||||
* @param ability The ability doing the hit
|
||||
* @param target The original target of the ability
|
||||
* @param hitEntity The entity being hit
|
||||
* @param damage The damage amount
|
||||
* @param knockback The horizontal knockback
|
||||
* @param knockbackUp The vertical knockback
|
||||
* @return The event (with possibly modified values), or null if cancelled
|
||||
*/
|
||||
public AbilityEvent.HitEvent fireHitEvent(Ability ability, EntityLivingBase target,
|
||||
EntityLivingBase hitEntity, float damage,
|
||||
float knockback, float knockbackUp) {
|
||||
AbilityEvent.HitEvent event = new AbilityEvent.HitEvent(
|
||||
npc.wrappedNPC, ability, target, hitEntity, damage, knockback, knockbackUp);
|
||||
if (NpcAPI.EVENT_BUS.post(event)) {
|
||||
return null; // Cancelled
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the NPC this DataAbilities belongs to.
|
||||
*/
|
||||
public EntityNPCInterface getNpc() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// RESET - Called on NPC death/respawn
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Reset all runtime state (cooldowns, current ability).
|
||||
* Called when NPC respawns or combat ends.
|
||||
*/
|
||||
public void reset() {
|
||||
stopCurrentAbility();
|
||||
resetAllCooldowns();
|
||||
|
||||
// Reset execution state on all abilities
|
||||
for (Ability ability : abilities) {
|
||||
ability.reset();
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// ABILITY LIST MANAGEMENT
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public List<Ability> getAbilities() {
|
||||
return abilities;
|
||||
}
|
||||
|
||||
public void addAbility(Ability ability) {
|
||||
abilities.add(ability);
|
||||
}
|
||||
|
||||
public void removeAbility(int index) {
|
||||
if (index >= 0 && index < abilities.size()) {
|
||||
abilities.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAbility(String id) {
|
||||
abilities.removeIf(a -> a.getId().equals(id));
|
||||
}
|
||||
|
||||
public Ability getAbility(String id) {
|
||||
for (Ability ability : abilities) {
|
||||
if (ability.getId().equals(id)) {
|
||||
return ability;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clearAbilities() {
|
||||
abilities.clear();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return abilities.isEmpty();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// STATE QUERIES
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Check if NPC is currently executing an ability.
|
||||
*/
|
||||
public boolean isExecutingAbility() {
|
||||
return currentAbility != null && currentAbility.isExecuting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently executing ability.
|
||||
*/
|
||||
public Ability getCurrentAbility() {
|
||||
return currentAbility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if ability is controlling NPC movement (AI pathfinding should be blocked).
|
||||
* Called by AI tasks to determine if they should try to path.
|
||||
*
|
||||
* Rules:
|
||||
* - WINDUP phase: Block AI if lockMovement is true
|
||||
* - ACTIVE phase: Block AI if lockMovement OR hasAbilityMovement is true
|
||||
* - RECOVERY phase: Block AI if lockMovement is true
|
||||
*/
|
||||
public boolean isAbilityControllingMovement() {
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AbilityPhase phase = currentAbility.getPhase();
|
||||
|
||||
switch (phase) {
|
||||
case WINDUP:
|
||||
// During windup, only block if lockMovement is set
|
||||
// This allows NPC to keep chasing while winding up if lockMovement=false
|
||||
return currentAbility.isLockMovement();
|
||||
|
||||
case ACTIVE:
|
||||
// During active phase, block if either:
|
||||
// - lockMovement is true (stationary ability)
|
||||
// - hasAbilityMovement is true (ability is moving the NPC itself)
|
||||
return currentAbility.isLockMovement() || currentAbility.hasAbilityMovement();
|
||||
|
||||
case RECOVERY:
|
||||
// During recovery, block if lockMovement is set
|
||||
return currentAbility.isLockMovement();
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if NPC movement should be blocked due to ability execution.
|
||||
* @deprecated Use isAbilityControllingMovement() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isMovementBlocked() {
|
||||
return isAbilityControllingMovement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if NPC should skip normal attacks during ability execution.
|
||||
*/
|
||||
public boolean shouldBlockAttack() {
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) {
|
||||
return false;
|
||||
}
|
||||
AbilityPhase phase = currentAbility.getPhase();
|
||||
return phase == AbilityPhase.WINDUP || phase == AbilityPhase.ACTIVE;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// NBT SERIALIZATION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setBoolean("AbilitiesEnabled", enabled);
|
||||
compound.setInteger("AbilityGlobalCooldown", globalCooldown);
|
||||
|
||||
NBTTagList abilityList = new NBTTagList();
|
||||
for (Ability ability : abilities) {
|
||||
abilityList.appendTag(ability.writeNBT());
|
||||
}
|
||||
compound.setTag("Abilities", abilityList);
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
enabled = compound.getBoolean("AbilitiesEnabled");
|
||||
globalCooldown = compound.hasKey("AbilityGlobalCooldown") ?
|
||||
compound.getInteger("AbilityGlobalCooldown") : 20;
|
||||
|
||||
abilities.clear();
|
||||
NBTTagList abilityList = compound.getTagList("Abilities", 10);
|
||||
for (int i = 0; i < abilityList.tagCount(); i++) {
|
||||
NBTTagCompound abilityNBT = abilityList.getCompoundTagAt(i);
|
||||
Ability ability = AbilityController.Instance.fromNBT(abilityNBT);
|
||||
if (ability != null) {
|
||||
abilities.add(ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -763,6 +763,18 @@ public class NoppesUtilServer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendAbilityTypesInfo(EntityPlayerMP player) {
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
kamkeel.npcs.controllers.data.ability.AbilityController controller = kamkeel.npcs.controllers.data.ability.AbilityController.Instance;
|
||||
if (controller != null) {
|
||||
int index = 0;
|
||||
for (String typeId : controller.getTypes()) {
|
||||
map.put(typeId, index++);
|
||||
}
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.ABILITY_TYPES);
|
||||
}
|
||||
|
||||
public static DialogOption setNpcDialog(int slot, int dialogId, EntityPlayer player) throws IOException {
|
||||
return setNpcDialog(slot, dialogId, getEditingNpc(player));
|
||||
}
|
||||
|
||||
@@ -42,8 +42,14 @@ public class CombatHandler {
|
||||
return;
|
||||
}
|
||||
combatResetTimer = 0;
|
||||
}
|
||||
|
||||
// Try to select and start an ability if not currently executing one
|
||||
// Ability ticking is handled by DataAbilities in onLivingUpdate
|
||||
EntityLivingBase target = npc.getAttackTarget();
|
||||
if (target != null && npc.abilities.enabled && !npc.abilities.isExecutingAbility()) {
|
||||
npc.abilities.trySelectAndStart(target);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldCombatContinue() {
|
||||
if (npc.getAttackTarget() == null)
|
||||
@@ -72,6 +78,9 @@ public class CombatHandler {
|
||||
}
|
||||
aggressors.put(el, f + damageAmount);
|
||||
}
|
||||
|
||||
// Check for ability interruption
|
||||
npc.abilities.onDamage(source, damageAmount);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
@@ -86,6 +95,9 @@ public class CombatHandler {
|
||||
aggressors.clear();
|
||||
recentDamages.clear();
|
||||
npc.setBoolFlag(false, 4);
|
||||
|
||||
// Reset ability state when combat ends
|
||||
npc.abilities.reset();
|
||||
}
|
||||
|
||||
public boolean checkTarget() {
|
||||
@@ -148,4 +160,26 @@ public class CombatHandler {
|
||||
}
|
||||
return newThreat > currentThreat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if NPC is currently executing an ability.
|
||||
* Used by AI tasks to avoid conflicting with ability execution.
|
||||
*/
|
||||
public boolean isExecutingAbility() {
|
||||
return npc.abilities.isExecutingAbility();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if NPC movement should be blocked due to ability execution.
|
||||
*/
|
||||
public boolean isMovementBlocked() {
|
||||
return npc.abilities.isMovementBlocked();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if NPC should skip normal attacks during ability execution.
|
||||
*/
|
||||
public boolean shouldBlockAttack() {
|
||||
return npc.abilities.shouldBlockAttack();
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,11 @@ public class EntityAIAttackTarget extends EntityAIBase {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't start pathfinding if ability is controlling movement
|
||||
if (this.npc.abilities.isAbilityControllingMovement()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
double var2 = this.npc.getDistanceSq(entitylivingbase.posX, entitylivingbase.boundingBox.minY, entitylivingbase.posZ);
|
||||
double var3 = this.npc.ais.distanceToMelee * this.npc.ais.distanceToMelee;
|
||||
|
||||
@@ -115,13 +120,18 @@ public class EntityAIAttackTarget extends EntityAIBase {
|
||||
public void updateTask() {
|
||||
this.npc.getLookHelper().setLookPositionWithEntity(this.entityTarget, 30.0F, 30.0F);
|
||||
|
||||
|
||||
if (!navOverride && --this.field_75445_i <= 0) {
|
||||
// Skip pathfinding updates if ability is controlling movement
|
||||
if (!navOverride && !this.npc.abilities.isAbilityControllingMovement() && --this.field_75445_i <= 0) {
|
||||
this.field_75445_i = 4 + this.npc.getRNG().nextInt(7);
|
||||
this.npc.getNavigator().tryMoveToEntityLiving(this.entityTarget, 1.3f);
|
||||
}
|
||||
this.attackTick = Math.max(this.attackTick - 1, 0);
|
||||
|
||||
// Skip attacks if ability is blocking them
|
||||
if (this.npc.abilities.shouldBlockAttack()) {
|
||||
return;
|
||||
}
|
||||
|
||||
double distance = this.npc.getDistanceSq(this.entityTarget.posX, this.entityTarget.boundingBox.minY, this.entityTarget.posZ);
|
||||
double range = npc.stats.attackRange * npc.stats.attackRange + entityTarget.width;
|
||||
double minRange = this.npc.width * 2.0F * this.npc.width * 2.0F + entityTarget.width;
|
||||
|
||||
@@ -18,6 +18,11 @@ public class EntityAILeapAtTargetNpc extends EntityAIBase {
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
// Don't leap if ability is controlling movement
|
||||
if (this.npc.abilities.isAbilityControllingMovement()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.leapTarget = this.npc.getAttackTarget();
|
||||
if (this.leapTarget == null) {
|
||||
return false;
|
||||
|
||||
@@ -17,6 +17,11 @@ public class EntityAIPounceTarget extends EntityAIBase {
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
// Don't pounce if ability is controlling movement
|
||||
if (this.npc.abilities.isAbilityControllingMovement()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.npc.onGround)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ public class EntityAISprintToTarget extends EntityAIBase {
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
// Don't sprint if ability is controlling movement
|
||||
if (this.npc.abilities.isAbilityControllingMovement()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityLivingBase runTarget = this.npc.getAttackTarget();
|
||||
|
||||
if (runTarget == null || this.npc.getNavigator().noPath()) {
|
||||
|
||||
@@ -136,6 +136,8 @@ import noppes.npcs.client.renderer.RenderNpcCrystal;
|
||||
import noppes.npcs.client.renderer.RenderNpcDragon;
|
||||
import noppes.npcs.client.renderer.RenderNpcSlime;
|
||||
import noppes.npcs.client.renderer.RenderProjectile;
|
||||
import kamkeel.npcs.client.renderer.TelegraphRenderer;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphManager;
|
||||
import noppes.npcs.client.renderer.blocks.BlockBannerRenderer;
|
||||
import noppes.npcs.client.renderer.blocks.BlockBarrelRenderer;
|
||||
import noppes.npcs.client.renderer.blocks.BlockBeamRenderer;
|
||||
@@ -306,6 +308,10 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
|
||||
|
||||
// Telegraph rendering system
|
||||
TelegraphManager.initClient();
|
||||
MinecraftForge.EVENT_BUS.register(new TelegraphRenderer());
|
||||
|
||||
if (ConfigClient.InventoryGuiEnabled) {
|
||||
MinecraftForge.EVENT_BUS.register(new TabRegistry());
|
||||
if (TabRegistry.getTabList().isEmpty()) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.world.World;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.client.controllers.MusicController;
|
||||
import noppes.npcs.client.controllers.ScriptSoundController;
|
||||
import kamkeel.npcs.controllers.data.ability.telegraph.TelegraphManager;
|
||||
import noppes.npcs.client.gui.hud.ClientHudManager;
|
||||
import noppes.npcs.client.gui.hud.CompassHudComponent;
|
||||
import noppes.npcs.client.gui.hud.EnumHudComponent;
|
||||
@@ -109,6 +110,11 @@ public class ClientTickHandler {
|
||||
|
||||
MusicController.Instance.onUpdate();
|
||||
ScriptSoundController.Instance.onUpdate();
|
||||
|
||||
// Tick telegraph manager for ability warnings
|
||||
if (TelegraphManager.ClientInstance != null) {
|
||||
TelegraphManager.ClientInstance.tick(mc.theWorld);
|
||||
}
|
||||
if (Minecraft.getMinecraft().thePlayer != null && (prevWidth != mc.displayWidth || prevHeight != mc.displayHeight)) {
|
||||
prevWidth = mc.displayWidth;
|
||||
prevHeight = mc.displayHeight;
|
||||
|
||||
@@ -0,0 +1,463 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.AbilitiesGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcSavePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.constants.EnumScrollData;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* GUI for managing NPC abilities.
|
||||
* Shows list of assigned abilities with add/remove/edit controls.
|
||||
*/
|
||||
public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, ICustomScrollListener, IGuiData, ITextfieldListener, ISubGuiListener, IAbilityConfigCallback {
|
||||
|
||||
private GuiCustomScroll availableTypesScroll;
|
||||
private GuiCustomScroll npcAbilitiesScroll;
|
||||
|
||||
// All available ability types (typeId -> index)
|
||||
private final HashMap<String, Integer> allAbilityTypes = new HashMap<>();
|
||||
|
||||
// NPC's current abilities
|
||||
private final List<Ability> npcAbilities = new ArrayList<>();
|
||||
|
||||
// Settings
|
||||
private boolean abilitiesEnabled = false;
|
||||
private int globalCooldown = 20;
|
||||
|
||||
private String search = "";
|
||||
private int selectedAbilityIndex = -1;
|
||||
|
||||
public GuiNPCAbilities(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
PacketClient.sendClient(new AbilitiesGetAllPacket());
|
||||
PacketClient.sendClient(new AbilitiesNpcGetPacket());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 10;
|
||||
|
||||
// Enabled checkbox
|
||||
addLabel(new GuiNpcLabel(100, "gui.enabled", guiLeft + 5, y + 5));
|
||||
addButton(new GuiNpcButton(100, guiLeft + 55, y, 50, 20, new String[]{"gui.no", "gui.yes"}, abilitiesEnabled ? 1 : 0));
|
||||
|
||||
// Global cooldown (spaced out since combat only is removed)
|
||||
addLabel(new GuiNpcLabel(101, "ability.globalCooldown", guiLeft + 140, y + 5));
|
||||
GuiNpcTextField cooldownField = new GuiNpcTextField(101, this, fontRendererObj, guiLeft + 230, y, 50, 20, String.valueOf(globalCooldown));
|
||||
cooldownField.setIntegersOnly();
|
||||
cooldownField.setMinMaxDefault(0, 10000, 20);
|
||||
addTextField(cooldownField);
|
||||
|
||||
y += 28;
|
||||
|
||||
// Left scroll: available ability types
|
||||
addLabel(new GuiNpcLabel(1, "ability.availableTypes", guiLeft + 5, y));
|
||||
if (availableTypesScroll == null) {
|
||||
availableTypesScroll = new GuiCustomScroll(this, 0);
|
||||
availableTypesScroll.setSize(140, 130);
|
||||
}
|
||||
availableTypesScroll.guiLeft = guiLeft + 5;
|
||||
availableTypesScroll.guiTop = y + 12;
|
||||
availableTypesScroll.setList(getFilteredTypeList());
|
||||
addScroll(availableTypesScroll);
|
||||
|
||||
// Search bar for types
|
||||
addTextField(new GuiNpcTextField(4, this, fontRendererObj, guiLeft + 5, y + 145, 140, 18, search));
|
||||
|
||||
// Right scroll: NPC's abilities (widened to use available space)
|
||||
addLabel(new GuiNpcLabel(2, "ability.npcAbilities", guiLeft + 210, y));
|
||||
if (npcAbilitiesScroll == null) {
|
||||
npcAbilitiesScroll = new GuiCustomScroll(this, 1);
|
||||
npcAbilitiesScroll.setSize(160, 130);
|
||||
} else {
|
||||
npcAbilitiesScroll.setSize(160, 130);
|
||||
}
|
||||
npcAbilitiesScroll.guiLeft = guiLeft + 210;
|
||||
npcAbilitiesScroll.guiTop = y + 12;
|
||||
updateNpcAbilitiesList();
|
||||
addScroll(npcAbilitiesScroll);
|
||||
|
||||
// Center buttons: Add/Remove
|
||||
int centerX = guiLeft + 158;
|
||||
addButton(new GuiNpcButton(70, centerX, y + 40, 40, 20, ">>>")); // Add
|
||||
addButton(new GuiNpcButton(71, centerX, y + 62, 40, 20, "<<<")); // Remove
|
||||
|
||||
// Load button (under the add/remove arrows)
|
||||
addButton(new GuiNpcButton(75, centerX, y + 90, 40, 20, "gui.load"));
|
||||
|
||||
// Right side buttons: Edit and Up/Down carrots with Save button
|
||||
addButton(new GuiNpcButton(72, guiLeft + 210, y + 145, 55, 20, "gui.edit"));
|
||||
getButton(72).setEnabled(selectedAbilityIndex >= 0);
|
||||
|
||||
// Up/Down carrot buttons
|
||||
addButton(new GuiNpcButton(73, guiLeft + 270, y + 145, 20, 20, "<"));
|
||||
addButton(new GuiNpcButton(74, guiLeft + 292, y + 145, 20, 20, ">"));
|
||||
getButton(73).setEnabled(selectedAbilityIndex > 0);
|
||||
getButton(74).setEnabled(selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size() - 1);
|
||||
|
||||
// Save button (to the right of carrots, only enabled when ability is selected)
|
||||
addButton(new GuiNpcButton(76, guiLeft + 320, y + 145, 50, 20, "gui.save"));
|
||||
getButton(76).setEnabled(selectedAbilityIndex >= 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
|
||||
// Enabled toggle
|
||||
if (id == 100) {
|
||||
abilitiesEnabled = ((GuiNpcButton) guibutton).getValue() == 1;
|
||||
save();
|
||||
return;
|
||||
}
|
||||
|
||||
// Add ability
|
||||
if (id == 70) {
|
||||
if (availableTypesScroll.hasSelected()) {
|
||||
String displayName = availableTypesScroll.getSelected();
|
||||
String typeId = getTypeIdFromDisplayName(displayName);
|
||||
Ability newAbility = AbilityController.Instance.create(typeId);
|
||||
if (newAbility != null) {
|
||||
newAbility.setId("ability_" + System.currentTimeMillis());
|
||||
// Don't set custom name - let it default to type name
|
||||
npcAbilities.add(newAbility);
|
||||
// Auto-select the newly added ability
|
||||
selectedAbilityIndex = npcAbilities.size() - 1;
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
initGui();
|
||||
save();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove ability
|
||||
if (id == 71) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
npcAbilities.remove(selectedAbilityIndex);
|
||||
selectedAbilityIndex = -1;
|
||||
updateNpcAbilitiesList();
|
||||
initGui();
|
||||
save();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Edit ability
|
||||
if (id == 72) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
setSubGui(new SubGuiAbilityConfig(npcAbilities.get(selectedAbilityIndex), this));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Move up (carrot left = earlier in list)
|
||||
if (id == 73) {
|
||||
if (selectedAbilityIndex > 0) {
|
||||
Ability temp = npcAbilities.get(selectedAbilityIndex);
|
||||
npcAbilities.set(selectedAbilityIndex, npcAbilities.get(selectedAbilityIndex - 1));
|
||||
npcAbilities.set(selectedAbilityIndex - 1, temp);
|
||||
selectedAbilityIndex--;
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
initGui();
|
||||
save();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Move down (carrot right = later in list)
|
||||
if (id == 74) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size() - 1) {
|
||||
Ability temp = npcAbilities.get(selectedAbilityIndex);
|
||||
npcAbilities.set(selectedAbilityIndex, npcAbilities.get(selectedAbilityIndex + 1));
|
||||
npcAbilities.set(selectedAbilityIndex + 1, temp);
|
||||
selectedAbilityIndex++;
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
initGui();
|
||||
save();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Load ability (opens load dialog to add ability directly to NPC)
|
||||
if (id == 75) {
|
||||
setSubGui(new SubGuiAbilityLoad(this));
|
||||
return;
|
||||
}
|
||||
|
||||
// Save selected ability
|
||||
if (id == 76) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
Ability abilityToSave = npcAbilities.get(selectedAbilityIndex);
|
||||
if (abilityToSave.getName() == null || abilityToSave.getName().isEmpty()) {
|
||||
// Need a name to save - open edit dialog first
|
||||
setSubGui(new SubGuiAbilityConfig(abilityToSave, this));
|
||||
} else {
|
||||
setSubGui(new SubGuiAbilitySaveConfirm(abilityToSave));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||
if (type == EnumScrollData.ABILITY_TYPES) {
|
||||
allAbilityTypes.clear();
|
||||
allAbilityTypes.putAll(data);
|
||||
if (availableTypesScroll != null) {
|
||||
availableTypesScroll.setList(getFilteredTypeList());
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
abilitiesEnabled = compound.getBoolean("AbilitiesEnabled");
|
||||
globalCooldown = compound.hasKey("AbilityGlobalCooldown") ? compound.getInteger("AbilityGlobalCooldown") : 20;
|
||||
|
||||
npcAbilities.clear();
|
||||
NBTTagList abilityList = compound.getTagList("Abilities", 10);
|
||||
for (int i = 0; i < abilityList.tagCount(); i++) {
|
||||
NBTTagCompound abilityNBT = abilityList.getCompoundTagAt(i);
|
||||
Ability ability = AbilityController.Instance.fromNBT(abilityNBT);
|
||||
if (ability != null) {
|
||||
npcAbilities.add(ability);
|
||||
}
|
||||
}
|
||||
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int i, int j, int k) {
|
||||
super.mouseClicked(i, j, k);
|
||||
if (k == 0 && availableTypesScroll != null) {
|
||||
availableTypesScroll.mouseClicked(i, j, k);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
if (getTextField(4) != null && getTextField(4).isFocused()) {
|
||||
if (search.equals(getTextField(4).getText()))
|
||||
return;
|
||||
search = getTextField(4).getText().toLowerCase();
|
||||
availableTypesScroll.setList(getFilteredTypeList());
|
||||
availableTypesScroll.resetScroll();
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getFilteredTypeList() {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String typeId : allAbilityTypes.keySet()) {
|
||||
String displayName = getDisplayName(typeId);
|
||||
if (search.isEmpty() || typeId.toLowerCase().contains(search) || displayName.toLowerCase().contains(search)) {
|
||||
list.add(displayName);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the typeId from a display name shown in the available types list.
|
||||
*/
|
||||
private String getTypeIdFromDisplayName(String displayName) {
|
||||
for (String typeId : allAbilityTypes.keySet()) {
|
||||
if (getDisplayName(typeId).equals(displayName)) {
|
||||
return typeId;
|
||||
}
|
||||
}
|
||||
return displayName;
|
||||
}
|
||||
|
||||
private void updateNpcAbilitiesList() {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (int i = 0; i < npcAbilities.size(); i++) {
|
||||
list.add(getAbilityListEntry(i));
|
||||
}
|
||||
if (npcAbilitiesScroll != null) {
|
||||
npcAbilitiesScroll.setList(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the display entry for an ability in the list.
|
||||
* Format: "[●] 1. Custom Name (Type)" or "[●] 1. Type" if no custom name
|
||||
* Circle is green (§a) for enabled, red (§c) for disabled
|
||||
*/
|
||||
private String getAbilityListEntry(int index) {
|
||||
Ability ability = npcAbilities.get(index);
|
||||
String typeName = getDisplayName(ability.getTypeId());
|
||||
String customName = ability.getName();
|
||||
|
||||
// Color prefix: green circle for enabled, red for disabled
|
||||
String colorPrefix = ability.isEnabled() ? "\u00A7a\u25CF\u00A7r " : "\u00A7c\u25CF\u00A7r ";
|
||||
|
||||
if (customName != null && !customName.isEmpty() && !customName.equals(typeName)) {
|
||||
return colorPrefix + (index + 1) + ". " + customName + " (" + typeName + ")";
|
||||
}
|
||||
return colorPrefix + (index + 1) + ". " + typeName;
|
||||
}
|
||||
|
||||
private void selectAbilityByIndex(int index) {
|
||||
if (index >= 0 && index < npcAbilities.size()) {
|
||||
String entry = getAbilityListEntry(index);
|
||||
if (npcAbilitiesScroll != null) {
|
||||
npcAbilitiesScroll.setSelected(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the localized display name for an ability type.
|
||||
* Uses lang key "ability.type.cnpc_slam" for "cnpc:slam"
|
||||
*/
|
||||
private String getDisplayName(String typeId) {
|
||||
// Convert "cnpc:slam" to lang key "ability.type.cnpc_slam"
|
||||
String langKey = "ability.type." + typeId.replace(":", "_");
|
||||
String translated = I18n.format(langKey);
|
||||
|
||||
// If translation exists and is different from key, use it
|
||||
if (!translated.equals(langKey)) {
|
||||
return translated;
|
||||
}
|
||||
|
||||
// Fallback: Convert "cnpc:slam" to "Slam"
|
||||
if (typeId.contains(":")) {
|
||||
String name = typeId.substring(typeId.indexOf(":") + 1);
|
||||
name = name.replace("_", " ");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String word : name.split(" ")) {
|
||||
if (word.length() > 0) {
|
||||
sb.append(Character.toUpperCase(word.charAt(0)));
|
||||
if (word.length() > 1) {
|
||||
sb.append(word.substring(1));
|
||||
}
|
||||
sb.append(" ");
|
||||
}
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
return typeId;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setBoolean("AbilitiesEnabled", abilitiesEnabled);
|
||||
compound.setInteger("AbilityGlobalCooldown", globalCooldown);
|
||||
|
||||
NBTTagList abilityList = new NBTTagList();
|
||||
for (Ability ability : npcAbilities) {
|
||||
abilityList.appendTag(ability.writeNBT());
|
||||
}
|
||||
compound.setTag("Abilities", abilityList);
|
||||
|
||||
PacketClient.sendClient(new AbilitiesNpcSavePacket(compound));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from SubGuiAbilityLoad when a saved ability is loaded.
|
||||
* Adds the ability to the NPC's ability list.
|
||||
*/
|
||||
public void loadAbility(Ability loadedAbility) {
|
||||
if (loadedAbility != null) {
|
||||
loadedAbility.setId("ability_" + System.currentTimeMillis());
|
||||
npcAbilities.add(loadedAbility);
|
||||
// Auto-select the newly added ability
|
||||
selectedAbilityIndex = npcAbilities.size() - 1;
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
initGui();
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(String selected) {
|
||||
if (availableTypesScroll != null) {
|
||||
availableTypesScroll.setSelected(selected);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll == npcAbilitiesScroll) {
|
||||
String selected = npcAbilitiesScroll.getSelected();
|
||||
if (selected != null) {
|
||||
// Parse index from "[●] 1. Name" format - strip color codes first
|
||||
String stripped = selected.replaceAll("\u00A7.", "").trim();
|
||||
// Now format is "● 1. Name" - find the number after the circle
|
||||
int dotIndex = stripped.indexOf(".");
|
||||
if (dotIndex > 0) {
|
||||
try {
|
||||
// Extract just the number portion (skip "● " prefix)
|
||||
String numPart = stripped.substring(0, dotIndex).replaceAll("[^0-9]", "");
|
||||
selectedAbilityIndex = Integer.parseInt(numPart) - 1;
|
||||
} catch (NumberFormatException e) {
|
||||
selectedAbilityIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (scroll == npcAbilitiesScroll && selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
setSubGui(new SubGuiAbilityConfig(npcAbilities.get(selectedAbilityIndex), this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textField) {
|
||||
if (textField.id == 101) {
|
||||
globalCooldown = textField.getInteger();
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiAbilityConfig) {
|
||||
// Ability was saved in the SubGui, refresh list
|
||||
updateNpcAbilitiesList();
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from SubGuiAbilityConfig when ability is saved.
|
||||
*/
|
||||
public void onAbilitySaved(Ability ability) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcAbilities.size()) {
|
||||
npcAbilities.set(selectedAbilityIndex, ability);
|
||||
updateNpcAbilitiesList();
|
||||
save();
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,55 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
/**
|
||||
* Confirmation dialog for deleting an ability preset.
|
||||
*/
|
||||
public class SubGuiAbilityDeleteConfirm extends SubGuiInterface {
|
||||
|
||||
private final String abilityName;
|
||||
private final SubGuiAbilityLoad loadGui;
|
||||
|
||||
public SubGuiAbilityDeleteConfirm(String abilityName, SubGuiAbilityLoad loadGui) {
|
||||
this.abilityName = abilityName;
|
||||
this.loadGui = loadGui;
|
||||
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
ySize = 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 10;
|
||||
|
||||
addLabel(new GuiNpcLabel(0, "ability.delete.confirm", guiLeft + 10, y));
|
||||
y += 12;
|
||||
addLabel(new GuiNpcLabel(1, "'" + abilityName + "'?", guiLeft + 10, y));
|
||||
|
||||
y += 30;
|
||||
|
||||
addButton(new GuiNpcButton(0, guiLeft + 30, y, 60, 20, "gui.yes"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 110, y, 60, 20, "gui.no"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
|
||||
if (id == 0) {
|
||||
// Delete the ability
|
||||
AbilityController.Instance.deleteAbility(abilityName);
|
||||
loadGui.onAbilityDeleted(abilityName);
|
||||
close();
|
||||
} else if (id == 1) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Dialog for loading a saved ability preset.
|
||||
* Can be opened from SubGuiAbilityConfig (to load into editing ability)
|
||||
* or from GuiNPCAbilities (to add ability directly to NPC).
|
||||
*/
|
||||
public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollListener {
|
||||
|
||||
private final SubGuiAbilityConfig parentConfig;
|
||||
private final GuiNPCAbilities parentAbilities;
|
||||
private String selectedName = null;
|
||||
private List<String> abilityNames = new ArrayList<>();
|
||||
|
||||
public SubGuiAbilityLoad(SubGuiAbilityConfig parentConfig) {
|
||||
this.parentConfig = parentConfig;
|
||||
this.parentAbilities = null;
|
||||
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
ySize = 180;
|
||||
}
|
||||
|
||||
public SubGuiAbilityLoad(GuiNPCAbilities parentAbilities) {
|
||||
this.parentConfig = null;
|
||||
this.parentAbilities = parentAbilities;
|
||||
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
ySize = 180;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
// Load ability names
|
||||
Set<String> names = AbilityController.Instance.getSavedAbilityNames();
|
||||
abilityNames = new ArrayList<>(names);
|
||||
|
||||
int y = guiTop + 5;
|
||||
|
||||
addLabel(new GuiNpcLabel(0, "ability.load.select", guiLeft + 10, y));
|
||||
y += 14;
|
||||
|
||||
// Scroll list of saved abilities
|
||||
GuiCustomScroll scroll = new GuiCustomScroll(this, 0);
|
||||
scroll.setSize(200, 110);
|
||||
scroll.guiLeft = guiLeft + 10;
|
||||
scroll.guiTop = y;
|
||||
scroll.setUnsortedList(abilityNames);
|
||||
if (selectedName != null && abilityNames.contains(selectedName)) {
|
||||
scroll.setSelected(selectedName);
|
||||
}
|
||||
addScroll(scroll);
|
||||
|
||||
y += 115;
|
||||
|
||||
// Buttons
|
||||
addButton(new GuiNpcButton(0, guiLeft + 10, y, 60, 20, "gui.load"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 80, y, 60, 20, "gui.delete"));
|
||||
addButton(new GuiNpcButton(2, guiLeft + 150, y, 60, 20, "gui.cancel"));
|
||||
|
||||
// Disable load/delete if nothing selected
|
||||
getButton(0).setEnabled(selectedName != null && !selectedName.isEmpty());
|
||||
getButton(1).setEnabled(selectedName != null && !selectedName.isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
|
||||
if (id == 0 && selectedName != null) {
|
||||
// Load the selected ability
|
||||
Ability loaded = AbilityController.Instance.getSavedAbility(selectedName);
|
||||
if (loaded != null) {
|
||||
if (parentConfig != null) {
|
||||
parentConfig.loadAbility(loaded);
|
||||
} else if (parentAbilities != null) {
|
||||
parentAbilities.loadAbility(loaded);
|
||||
}
|
||||
}
|
||||
close();
|
||||
} else if (id == 1 && selectedName != null) {
|
||||
// Delete confirmation
|
||||
setSubGui(new SubGuiAbilityDeleteConfirm(selectedName, this));
|
||||
} else if (id == 2) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
|
||||
if (scroll.id == 0) {
|
||||
selectedName = scroll.getSelected();
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (scroll.id == 0 && selection != null && !selection.isEmpty()) {
|
||||
// Double-click to load immediately
|
||||
Ability loaded = AbilityController.Instance.getSavedAbility(selection);
|
||||
if (loaded != null) {
|
||||
if (parentConfig != null) {
|
||||
parentConfig.loadAbility(loaded);
|
||||
} else if (parentAbilities != null) {
|
||||
parentAbilities.loadAbility(loaded);
|
||||
}
|
||||
}
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after an ability is deleted to refresh the list.
|
||||
*/
|
||||
public void onAbilityDeleted(String name) {
|
||||
if (name.equals(selectedName)) {
|
||||
selectedName = null;
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
/**
|
||||
* Confirmation dialog for saving an ability preset.
|
||||
*/
|
||||
public class SubGuiAbilitySaveConfirm extends SubGuiInterface {
|
||||
|
||||
private final Ability ability;
|
||||
private final boolean exists;
|
||||
|
||||
public SubGuiAbilitySaveConfirm(Ability ability) {
|
||||
this.ability = ability;
|
||||
this.exists = AbilityController.Instance.hasSavedAbility(ability.getName());
|
||||
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
ySize = 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 10;
|
||||
|
||||
if (exists) {
|
||||
addLabel(new GuiNpcLabel(0, "ability.save.overwrite", guiLeft + 10, y));
|
||||
y += 12;
|
||||
addLabel(new GuiNpcLabel(1, "'" + ability.getName() + "'?", guiLeft + 10, y));
|
||||
} else {
|
||||
addLabel(new GuiNpcLabel(0, "ability.save.confirm", guiLeft + 10, y));
|
||||
y += 12;
|
||||
addLabel(new GuiNpcLabel(1, "'" + ability.getName() + "'?", guiLeft + 10, y));
|
||||
}
|
||||
|
||||
y += 30;
|
||||
|
||||
addButton(new GuiNpcButton(0, guiLeft + 30, y, 60, 20, "gui.yes"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 110, y, 60, 20, "gui.no"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
|
||||
if (id == 0) {
|
||||
// Save the ability
|
||||
AbilityController.Instance.saveAbility(ability);
|
||||
close();
|
||||
} else if (id == 1) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package noppes.npcs.client.gui.global;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityDeleteConfirm;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityLoad;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Global GUI for managing saved ability presets.
|
||||
* Allows viewing, editing, and deleting saved abilities.
|
||||
*/
|
||||
public class GuiNpcManageAbilities extends GuiNPCInterface2 implements ICustomScrollListener, ISubGuiListener, IAbilityConfigCallback {
|
||||
|
||||
private GuiCustomScroll scroll;
|
||||
private String selectedName = null;
|
||||
private List<String> abilityNames = new ArrayList<>();
|
||||
private String search = "";
|
||||
|
||||
public GuiNpcManageAbilities(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
loadAbilityNames();
|
||||
}
|
||||
|
||||
private void loadAbilityNames() {
|
||||
Set<String> names = AbilityController.Instance.getSavedAbilityNames();
|
||||
abilityNames = new ArrayList<>(names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 10;
|
||||
|
||||
// Title label
|
||||
addLabel(new GuiNpcLabel(0, "ability.manager.title", guiLeft + 10, y));
|
||||
y += 20;
|
||||
|
||||
// Scroll list of saved abilities
|
||||
if (scroll == null) {
|
||||
scroll = new GuiCustomScroll(this, 0);
|
||||
}
|
||||
scroll.setSize(xSize - 90, 160);
|
||||
scroll.guiLeft = guiLeft + 10;
|
||||
scroll.guiTop = y;
|
||||
scroll.setUnsortedList(getFilteredList());
|
||||
if (selectedName != null && abilityNames.contains(selectedName)) {
|
||||
scroll.setSelected(selectedName);
|
||||
}
|
||||
addScroll(scroll);
|
||||
|
||||
// Search bar
|
||||
addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 10, y + 163, xSize - 90, 18, search));
|
||||
|
||||
// Right side buttons
|
||||
int btnX = guiLeft + xSize - 70;
|
||||
addButton(new GuiNpcButton(1, btnX, y, 60, 20, "gui.edit"));
|
||||
addButton(new GuiNpcButton(2, btnX, y + 25, 60, 20, "gui.delete"));
|
||||
addButton(new GuiNpcButton(3, btnX, y + 60, 60, 20, "selectServer.refresh"));
|
||||
|
||||
// Enable/disable buttons based on selection
|
||||
getButton(1).setEnabled(selectedName != null && !selectedName.isEmpty());
|
||||
getButton(2).setEnabled(selectedName != null && !selectedName.isEmpty());
|
||||
}
|
||||
|
||||
private List<String> getFilteredList() {
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<>(abilityNames);
|
||||
}
|
||||
List<String> filtered = new ArrayList<>();
|
||||
for (String name : abilityNames) {
|
||||
if (name.toLowerCase().contains(search.toLowerCase())) {
|
||||
filtered.add(name);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
|
||||
if (id == 1 && selectedName != null) {
|
||||
// Edit
|
||||
Ability ability = AbilityController.Instance.getSavedAbility(selectedName);
|
||||
if (ability != null) {
|
||||
setSubGui(new SubGuiAbilityConfig(ability, this));
|
||||
}
|
||||
} else if (id == 2 && selectedName != null) {
|
||||
// Delete
|
||||
setSubGui(new SubGuiAbilityDeleteConfirm(selectedName, null));
|
||||
} else if (id == 3) {
|
||||
// Refresh
|
||||
AbilityController.Instance.load();
|
||||
loadAbilityNames();
|
||||
selectedName = null;
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
|
||||
if (scroll.id == 0) {
|
||||
selectedName = scroll.getSelected();
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (scroll.id == 0 && selection != null && !selection.isEmpty()) {
|
||||
// Double-click to edit
|
||||
Ability ability = AbilityController.Instance.getSavedAbility(selection);
|
||||
if (ability != null) {
|
||||
setSubGui(new SubGuiAbilityConfig(ability, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
if (getTextField(1) != null && getTextField(1).isFocused()) {
|
||||
if (!search.equals(getTextField(1).getText())) {
|
||||
search = getTextField(1).getText();
|
||||
scroll.setUnsortedList(getFilteredList());
|
||||
scroll.resetScroll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
// Refresh list after any sub gui closes
|
||||
loadAbilityNames();
|
||||
if (subgui instanceof SubGuiAbilityDeleteConfirm) {
|
||||
// After delete, clear selection if it was deleted
|
||||
if (selectedName != null && !abilityNames.contains(selectedName)) {
|
||||
selectedName = null;
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAbilitySaved(Ability ability) {
|
||||
// Save the edited ability
|
||||
AbilityController.Instance.saveAbility(ability);
|
||||
loadAbilityNames();
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Nothing to save - abilities are saved individually
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
|
||||
private GuiNpcSquareButton tagButton;
|
||||
private GuiNpcSquareButton effectsButton;
|
||||
private GuiNpcSquareButton magicsButton;
|
||||
private GuiNpcSquareButton abilitiesButton;
|
||||
|
||||
public GuiNPCGlobalMainMenu(EntityNPCInterface npc) {
|
||||
super(npc, 5);
|
||||
@@ -94,6 +95,8 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
|
||||
registerButton(magicsButton = new GuiNpcSquareButton(20, 0, 0, 20, "global.magic", 0xFF333333));
|
||||
magicsButton.setIconPos(24, 24, 48, 56).setIconTexture(specialIcons);
|
||||
|
||||
registerButton(abilitiesButton = new GuiNpcSquareButton(21, 0, 0, 20, "global.abilities", 0xFF333333));
|
||||
abilitiesButton.setIconPos(24, 24, 72, 56).setIconTexture(specialIcons); // Placeholder icon position
|
||||
|
||||
// Layout composite buttons optimally.
|
||||
layoutButtons();
|
||||
@@ -236,6 +239,9 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
|
||||
if (id == 19) {
|
||||
NoppesUtil.requestOpenGUI(EnumGuiType.ManageEffects);
|
||||
}
|
||||
if (id == 21) {
|
||||
NoppesUtil.openGUI(player, new noppes.npcs.client.gui.global.GuiNpcManageAbilities(npc));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@ import noppes.npcs.client.gui.advanced.GuiNPCAdvancedLinkedNpc;
|
||||
import noppes.npcs.client.gui.advanced.GuiNPCDialogNpcOptions;
|
||||
import noppes.npcs.client.gui.advanced.GuiNPCFactionSetup;
|
||||
import noppes.npcs.client.gui.advanced.GuiNPCLinesMenu;
|
||||
import noppes.npcs.client.gui.advanced.GuiNPCAbilities;
|
||||
import noppes.npcs.client.gui.advanced.GuiNPCMagic;
|
||||
import noppes.npcs.client.gui.advanced.GuiNPCMarks;
|
||||
import noppes.npcs.client.gui.advanced.GuiNPCNightSetup;
|
||||
@@ -69,6 +70,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData {
|
||||
this.addButton(new GuiNpcButton(15, guiLeft + 208, y, 190, 20, "advanced.marks"));
|
||||
|
||||
this.addButton(new GuiNpcButton(16, guiLeft + 15, y += 22, 190, 20, "menu.magics"));
|
||||
this.addButton(new GuiNpcButton(17, guiLeft + 208, y, 190, 20, "menu.abilities"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,6 +132,10 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData {
|
||||
save();
|
||||
NoppesUtil.openGUI(player, new GuiNPCMagic(npc));
|
||||
}
|
||||
if (button.id == 17) {
|
||||
save();
|
||||
NoppesUtil.openGUI(player, new GuiNPCAbilities(npc));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.script;
|
||||
import kamkeel.npcs.network.packets.request.script.EventScriptPacket;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.data.DataScript;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
@@ -15,23 +16,30 @@ public class GuiNPCEventScripts extends GuiScriptInterface {
|
||||
|
||||
public GuiNPCEventScripts(EntityNPCInterface npc) {
|
||||
this.hookList = new ArrayList<>();
|
||||
hookList.add("init");
|
||||
hookList.add("tick");
|
||||
hookList.add("interact");
|
||||
hookList.add("dialog");
|
||||
hookList.add("damaged");
|
||||
hookList.add("killed");
|
||||
hookList.add("meleeAttack");
|
||||
hookList.add("meleeSwing");
|
||||
hookList.add("rangedLaunched");
|
||||
hookList.add("target");
|
||||
hookList.add("collide");
|
||||
hookList.add("kills");
|
||||
hookList.add("dialogClose");
|
||||
hookList.add("timer");
|
||||
hookList.add("targetLost");
|
||||
hookList.add("projectileTick");
|
||||
hookList.add("projectileImpact");
|
||||
hookList.add(EnumScriptType.INIT.function);
|
||||
hookList.add(EnumScriptType.TICK.function);
|
||||
hookList.add(EnumScriptType.INTERACT.function);
|
||||
hookList.add(EnumScriptType.DIALOG.function);
|
||||
hookList.add(EnumScriptType.DAMAGED.function);
|
||||
hookList.add(EnumScriptType.KILLED.function);
|
||||
hookList.add(EnumScriptType.ATTACK_MELEE.function);
|
||||
hookList.add(EnumScriptType.ATTACK_SWING.function);
|
||||
hookList.add(EnumScriptType.RANGED_LAUNCHED.function);
|
||||
hookList.add(EnumScriptType.TARGET.function);
|
||||
hookList.add(EnumScriptType.COLLIDE.function);
|
||||
hookList.add(EnumScriptType.KILLS.function);
|
||||
hookList.add(EnumScriptType.DIALOG_CLOSE.function);
|
||||
hookList.add(EnumScriptType.TIMER.function);
|
||||
hookList.add(EnumScriptType.TARGET_LOST.function);
|
||||
hookList.add(EnumScriptType.PROJECTILE_TICK.function);
|
||||
hookList.add(EnumScriptType.PROJECTILE_IMPACT.function);
|
||||
// Ability hooks
|
||||
hookList.add(EnumScriptType.ABILITY_START.function);
|
||||
hookList.add(EnumScriptType.ABILITY_EXECUTE.function);
|
||||
hookList.add(EnumScriptType.ABILITY_INTERRUPT.function);
|
||||
hookList.add(EnumScriptType.ABILITY_COMPLETE.function);
|
||||
hookList.add(EnumScriptType.ABILITY_HIT.function);
|
||||
hookList.add(EnumScriptType.ABILITY_TICK.function);
|
||||
|
||||
this.script = new DataScript(npc);
|
||||
this.handler = this.script;
|
||||
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.script;
|
||||
import kamkeel.npcs.network.packets.request.script.GlobalNPCScriptPacket;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.data.GlobalNPCDataScript;
|
||||
|
||||
@@ -12,23 +13,30 @@ public class GuiScriptAllNPCs extends GuiScriptInterface {
|
||||
private final GlobalNPCDataScript script = new GlobalNPCDataScript(null);
|
||||
|
||||
public GuiScriptAllNPCs() {
|
||||
hookList.add("init");
|
||||
hookList.add("tick");
|
||||
hookList.add("interact");
|
||||
hookList.add("dialog");
|
||||
hookList.add("damaged");
|
||||
hookList.add("killed");
|
||||
hookList.add("meleeAttack");
|
||||
hookList.add("meleeSwing");
|
||||
hookList.add("rangedLaunched");
|
||||
hookList.add("target");
|
||||
hookList.add("collide");
|
||||
hookList.add("kills");
|
||||
hookList.add("dialogClose");
|
||||
hookList.add("timer");
|
||||
hookList.add("targetLost");
|
||||
hookList.add("projectileTick");
|
||||
hookList.add("projectileImpact");
|
||||
hookList.add(EnumScriptType.INIT.function);
|
||||
hookList.add(EnumScriptType.TICK.function);
|
||||
hookList.add(EnumScriptType.INTERACT.function);
|
||||
hookList.add(EnumScriptType.DIALOG.function);
|
||||
hookList.add(EnumScriptType.DAMAGED.function);
|
||||
hookList.add(EnumScriptType.KILLED.function);
|
||||
hookList.add(EnumScriptType.ATTACK_MELEE.function);
|
||||
hookList.add(EnumScriptType.ATTACK_SWING.function);
|
||||
hookList.add(EnumScriptType.RANGED_LAUNCHED.function);
|
||||
hookList.add(EnumScriptType.TARGET.function);
|
||||
hookList.add(EnumScriptType.COLLIDE.function);
|
||||
hookList.add(EnumScriptType.KILLS.function);
|
||||
hookList.add(EnumScriptType.DIALOG_CLOSE.function);
|
||||
hookList.add(EnumScriptType.TIMER.function);
|
||||
hookList.add(EnumScriptType.TARGET_LOST.function);
|
||||
hookList.add(EnumScriptType.PROJECTILE_TICK.function);
|
||||
hookList.add(EnumScriptType.PROJECTILE_IMPACT.function);
|
||||
// Ability hooks
|
||||
hookList.add(EnumScriptType.ABILITY_START.function);
|
||||
hookList.add(EnumScriptType.ABILITY_EXECUTE.function);
|
||||
hookList.add(EnumScriptType.ABILITY_INTERRUPT.function);
|
||||
hookList.add(EnumScriptType.ABILITY_COMPLETE.function);
|
||||
hookList.add(EnumScriptType.ABILITY_HIT.function);
|
||||
hookList.add(EnumScriptType.ABILITY_TICK.function);
|
||||
|
||||
this.handler = this.script;
|
||||
GlobalNPCScriptPacket.Get();
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
package noppes.npcs.client.gui.select;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationsGetPacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.IScrollData;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.constants.EnumScrollData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Animation selection dialog for choosing global animations.
|
||||
* Requests animation data from the server via packets.
|
||||
*/
|
||||
public class GuiAnimationSelection extends SubGuiInterface implements ICustomScrollListener, IScrollData {
|
||||
|
||||
private GuiCustomScroll scrollAnimations;
|
||||
private HashMap<String, Integer> animationData = new HashMap<String, Integer>();
|
||||
|
||||
private int initialAnimationId;
|
||||
public int selectedAnimationId = -1;
|
||||
private String selectedName = null;
|
||||
|
||||
private String search = "";
|
||||
|
||||
public GuiAnimationSelection(int animationId) {
|
||||
drawDefaultBackground = false;
|
||||
title = "";
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
ySize = 226;
|
||||
|
||||
this.initialAnimationId = animationId;
|
||||
this.selectedAnimationId = animationId;
|
||||
|
||||
// Request animation data from server
|
||||
PacketClient.sendClient(new AnimationsGetPacket());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
this.addLabel(new GuiNpcLabel(0, "gui.animations", guiLeft + 8, guiTop + 4));
|
||||
|
||||
this.addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + ySize - 35, 50, 20, "gui.clear"));
|
||||
this.addButton(new GuiNpcButton(2, guiLeft + xSize - 56, guiTop + ySize - 35, 50, 20, "gui.done"));
|
||||
this.addButton(new GuiNpcButton(3, guiLeft + xSize - 108, guiTop + ySize - 35, 50, 20, "gui.cancel"));
|
||||
|
||||
if (scrollAnimations == null) {
|
||||
scrollAnimations = new GuiCustomScroll(this, 0, 0);
|
||||
scrollAnimations.setSize(212, 163);
|
||||
}
|
||||
scrollAnimations.setList(getSearchList());
|
||||
if (selectedName != null) {
|
||||
scrollAnimations.setSelected(selectedName);
|
||||
}
|
||||
scrollAnimations.guiLeft = guiLeft + 4;
|
||||
scrollAnimations.guiTop = guiTop + 14;
|
||||
this.addScroll(scrollAnimations);
|
||||
|
||||
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 4, guiTop + 179, 212, 20, search));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||
this.animationData = data;
|
||||
|
||||
// Find the name for our initial animation ID
|
||||
if (initialAnimationId >= 0) {
|
||||
for (String name : data.keySet()) {
|
||||
if (data.get(name) == initialAnimationId) {
|
||||
selectedName = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollAnimations != null) {
|
||||
scrollAnimations.setList(getSearchList());
|
||||
if (selectedName != null) {
|
||||
scrollAnimations.setSelected(selectedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(String selected) {
|
||||
this.selectedName = selected;
|
||||
if (scrollAnimations != null) {
|
||||
scrollAnimations.setSelected(selected);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
if (getTextField(55) != null) {
|
||||
if (getTextField(55).isFocused()) {
|
||||
if (search.equals(getTextField(55).getText()))
|
||||
return;
|
||||
search = getTextField(55).getText().toLowerCase();
|
||||
scrollAnimations.resetScroll();
|
||||
scrollAnimations.setList(getSearchList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getSearchList() {
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<String>(animationData.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (String name : animationData.keySet()) {
|
||||
if (name.toLowerCase().contains(search))
|
||||
list.add(name);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll.id == 0) {
|
||||
String selected = scrollAnimations.getSelected();
|
||||
if (selected != null && animationData.containsKey(selected)) {
|
||||
selectedName = selected;
|
||||
selectedAnimationId = animationData.get(selected);
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (selectedAnimationId < 0)
|
||||
return;
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
if (id == 1) {
|
||||
// Clear selection
|
||||
selectedName = null;
|
||||
selectedAnimationId = -1;
|
||||
close();
|
||||
}
|
||||
if (id == 2) {
|
||||
// Done - keep selection
|
||||
close();
|
||||
}
|
||||
if (id == 3) {
|
||||
// Cancel - restore initial value
|
||||
selectedAnimationId = initialAnimationId;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the selected animation (for display purposes).
|
||||
*/
|
||||
public String getSelectedName() {
|
||||
return selectedName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
|
||||
/**
|
||||
* Callback interface for SubGuiAbilityConfig.
|
||||
* Implemented by GUIs that open the ability config dialog.
|
||||
*/
|
||||
public interface IAbilityConfigCallback {
|
||||
/**
|
||||
* Called when an ability has been edited and saved.
|
||||
* @param ability The edited ability
|
||||
*/
|
||||
void onAbilitySaved(Ability ability);
|
||||
}
|
||||
@@ -63,5 +63,6 @@ public enum EnumGuiType {
|
||||
ScriptItem,
|
||||
ScriptBlock,
|
||||
Paintbrush,
|
||||
MagicBook;
|
||||
MagicBook,
|
||||
ManageAbilities;
|
||||
}
|
||||
@@ -114,7 +114,14 @@ public enum EnumScriptType {
|
||||
PROFILE("profile"),
|
||||
PROFILE_CHANGE("profileChange"),
|
||||
PROFILE_REMOVE("profileRemove"),
|
||||
PROFILE_CREATE("profileCreate");
|
||||
PROFILE_CREATE("profileCreate"),
|
||||
|
||||
ABILITY_START("abilityStart"),
|
||||
ABILITY_EXECUTE("abilityExecute"),
|
||||
ABILITY_INTERRUPT("abilityInterrupt"),
|
||||
ABILITY_COMPLETE("abilityComplete"),
|
||||
ABILITY_HIT("abilityHit"),
|
||||
ABILITY_TICK("abilityTick");
|
||||
|
||||
public String function;
|
||||
|
||||
|
||||
@@ -5,5 +5,6 @@ public enum EnumScrollData {
|
||||
MAGIC,
|
||||
MAGIC_CYCLES,
|
||||
DIALOG_GROUP,
|
||||
QUEST_GROUP
|
||||
QUEST_GROUP,
|
||||
ABILITY_TYPES
|
||||
}
|
||||
@@ -73,6 +73,7 @@ import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.event.ServerChatEvent;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.DataAbilities;
|
||||
import noppes.npcs.DataAI;
|
||||
import noppes.npcs.DataAdvanced;
|
||||
import noppes.npcs.DataDisplay;
|
||||
@@ -183,6 +184,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
public DataScript script;
|
||||
public DataTransform transform;
|
||||
public DataTimers timers;
|
||||
public DataAbilities abilities;
|
||||
|
||||
public CombatHandler combatHandler = new CombatHandler(this);
|
||||
public ActionManager actionManager = new ActionManager();
|
||||
@@ -271,6 +273,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
transform = new DataTransform(this);
|
||||
script = new DataScript(this);
|
||||
timers = new DataTimers(this);
|
||||
abilities = new DataAbilities(this);
|
||||
this.getAttributeMap().registerAttribute(SharedMonsterAttributes.attackDamage);
|
||||
|
||||
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(stats.maxHealth);
|
||||
@@ -460,6 +463,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
onCollide();
|
||||
|
||||
actionManager.tick();
|
||||
abilities.tick();
|
||||
}
|
||||
|
||||
if (wasKilled != isKilled() && wasKilled) {
|
||||
@@ -1179,6 +1183,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
script.readEventsFromNBT(compound);
|
||||
timers.readFromNBT(compound);
|
||||
advanced.readToNBT(compound);
|
||||
abilities.readFromNBT(compound);
|
||||
if (advanced.role != EnumRoleType.None && roleInterface != null)
|
||||
roleInterface.readFromNBT(compound);
|
||||
if (advanced.job != EnumJobType.None && jobInterface != null)
|
||||
@@ -1211,6 +1216,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
script.writeEventsToNBT(compound);
|
||||
timers.writeToNBT(compound);
|
||||
advanced.writeToNBT(compound);
|
||||
abilities.writeToNBT(compound);
|
||||
if (advanced.role != EnumRoleType.None && roleInterface != null)
|
||||
roleInterface.writeToNBT(compound);
|
||||
if (advanced.job != EnumJobType.None && jobInterface != null)
|
||||
|
||||
@@ -60,6 +60,7 @@ import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.gui.ICustomGui;
|
||||
import noppes.npcs.api.handler.IActionManager;
|
||||
import noppes.npcs.api.handler.IAbilityHandler;
|
||||
import noppes.npcs.api.handler.IAnimationHandler;
|
||||
import noppes.npcs.api.handler.IAttributeHandler;
|
||||
import noppes.npcs.api.handler.ICloneHandler;
|
||||
@@ -83,6 +84,7 @@ import noppes.npcs.compat.PixelmonHelper;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.constants.EnumAnimationPart;
|
||||
import noppes.npcs.containers.ContainerNpcInterface;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.ChunkController;
|
||||
import noppes.npcs.controllers.CustomEffectController;
|
||||
@@ -356,6 +358,12 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
return AnimationController.Instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbilityHandler getAbilities() {
|
||||
this.checkWorld();
|
||||
return AbilityController.Instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAllBiomeNames() {
|
||||
List<String> biomes = new ArrayList<>();
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
package noppes.npcs.scripted.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.api.IDamageSource;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||
import noppes.npcs.api.event.IAbilityEvent;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
/**
|
||||
* Events fired during NPC ability execution lifecycle.
|
||||
*/
|
||||
public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
protected final Ability ability;
|
||||
protected final IEntityLivingBase target;
|
||||
|
||||
public AbilityEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
|
||||
super(npc);
|
||||
this.ability = ability;
|
||||
this.target = target != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(target) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility getAbility() {
|
||||
return ability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "abilityEvent";
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when an ability starts executing (enters WINDUP phase).
|
||||
*/
|
||||
@Cancelable
|
||||
public static class StartEvent extends AbilityEvent implements IAbilityEvent.StartEvent {
|
||||
public StartEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
|
||||
super(npc, ability, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_START.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when an ability enters the ACTIVE phase and performs its effect.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ExecuteEvent extends AbilityEvent implements IAbilityEvent.ExecuteEvent {
|
||||
public ExecuteEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
|
||||
super(npc, ability, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_EXECUTE.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when an ability is interrupted by damage.
|
||||
*/
|
||||
public static class InterruptEvent extends AbilityEvent implements IAbilityEvent.InterruptEvent {
|
||||
private final IDamageSource damageSource;
|
||||
private final float damage;
|
||||
|
||||
public InterruptEvent(ICustomNpc npc, Ability ability, EntityLivingBase target, DamageSource source, float damage) {
|
||||
super(npc, ability, target);
|
||||
this.damageSource = NpcAPI.Instance().getIDamageSource(source);
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDamageSource getDamageSource() {
|
||||
return damageSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_INTERRUPT.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when an ability completes its full execution cycle.
|
||||
*/
|
||||
public static class CompleteEvent extends AbilityEvent implements IAbilityEvent.CompleteEvent {
|
||||
public CompleteEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
|
||||
super(npc, ability, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_COMPLETE.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when an ability hits an entity with damage.
|
||||
* This is a cancelable event - canceling prevents the damage from being applied.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class HitEvent extends AbilityEvent implements IAbilityEvent.HitEvent {
|
||||
private final IEntityLivingBase hitEntity;
|
||||
private float damage;
|
||||
private float knockback;
|
||||
private float knockbackUp;
|
||||
|
||||
public HitEvent(ICustomNpc npc, Ability ability, EntityLivingBase target,
|
||||
EntityLivingBase hitEntity, float damage, float knockback, float knockbackUp) {
|
||||
super(npc, ability, target);
|
||||
this.hitEntity = hitEntity != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(hitEntity) : null;
|
||||
this.damage = damage;
|
||||
this.knockback = knockback;
|
||||
this.knockbackUp = knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getHitEntity() {
|
||||
return hitEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(float damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockback() {
|
||||
return knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockback(float knockback) {
|
||||
this.knockback = knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockbackUp() {
|
||||
return knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockbackUp(float knockbackUp) {
|
||||
this.knockbackUp = knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_HIT.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired every tick while an ability is executing.
|
||||
* Provides information about the current phase and tick.
|
||||
*/
|
||||
public static class TickEvent extends AbilityEvent implements IAbilityEvent.TickEvent {
|
||||
private final int abilityPhase;
|
||||
private final int tick;
|
||||
|
||||
public TickEvent(ICustomNpc npc, Ability ability, EntityLivingBase target, int phase, int tick) {
|
||||
super(npc, ability, target);
|
||||
this.abilityPhase = phase;
|
||||
this.tick = tick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAbilityPhase() {
|
||||
return abilityPhase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTick() {
|
||||
return tick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_TICK.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user