mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 08:02:20 +00:00
Merge branch 'dev' into syntax-highlighter-unified
This commit is contained in:
commit
df6beb4f15
207 files changed
+10330
-2705
No files matched your search
@@ -1,15 +1,23 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.ChainedAbilityEntry;
|
||||
import kamkeel.npcs.controllers.data.ability.ToggleEntry;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Shared base class for NPC and Player ability data management.
|
||||
@@ -28,73 +36,119 @@ public abstract class AbstractDataAbilities {
|
||||
// SHARED RUNTIME STATE (not saved to NBT)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/** Currently executing ability (null if none) */
|
||||
/**
|
||||
* Currently executing ability (null if none)
|
||||
*/
|
||||
protected Ability currentAbility;
|
||||
|
||||
/** World time when cooldown ends */
|
||||
/**
|
||||
* World time when cooldown ends
|
||||
*/
|
||||
protected long cooldownEndTime = 0;
|
||||
|
||||
/** Rotation lock state */
|
||||
/**
|
||||
* Rotation lock state
|
||||
*/
|
||||
protected boolean rotationLocked = false;
|
||||
protected float lockedYaw = 0;
|
||||
protected float lockedPitch = 0;
|
||||
|
||||
/** Position lock state */
|
||||
/**
|
||||
* Position lock state
|
||||
*/
|
||||
protected boolean positionLocked = false;
|
||||
protected double lockedPosX = 0;
|
||||
protected double lockedPosY = 0;
|
||||
protected double lockedPosZ = 0;
|
||||
|
||||
/**
|
||||
* Chained ability execution state
|
||||
*/
|
||||
protected ChainedAbility currentChain;
|
||||
protected int chainEntryIndex = -1;
|
||||
protected int chainDelayRemaining = -1;
|
||||
|
||||
/**
|
||||
* Set when interrupt already rolled cooldown (prevents double cooldown on NPC dazed completion).
|
||||
*/
|
||||
protected boolean interruptCooldownRolled = false;
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// ABSTRACT METHODS - Subclasses must implement
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/** Get the entity this ability data belongs to (NPC or Player). */
|
||||
/**
|
||||
* Get the entity this ability data belongs to (NPC or Player).
|
||||
*/
|
||||
protected abstract EntityLivingBase getEntity();
|
||||
|
||||
/** Get the current target for ability execution. */
|
||||
/**
|
||||
* Get the current target for ability execution.
|
||||
*/
|
||||
protected abstract EntityLivingBase getTarget();
|
||||
|
||||
/** Get the current world time. */
|
||||
/**
|
||||
* Get the current world time.
|
||||
*/
|
||||
protected abstract long getWorldTime();
|
||||
|
||||
// -- Event Firing --
|
||||
|
||||
/** Fire tick event. Implementation differs between NPC (NpcAPI) and Player (ScriptController). */
|
||||
/**
|
||||
* Fire tick event. Implementation differs between NPC (NpcAPI) and Player (ScriptController).
|
||||
*/
|
||||
protected abstract void fireTickEvent(Ability ability, EntityLivingBase target);
|
||||
|
||||
/** Fire execute event. Returns true if cancelled. */
|
||||
/**
|
||||
* Fire execute event. Returns true if cancelled.
|
||||
*/
|
||||
protected abstract boolean fireExecuteEvent(Ability ability, EntityLivingBase target);
|
||||
|
||||
/** Fire complete event. */
|
||||
/**
|
||||
* Fire complete event.
|
||||
*/
|
||||
protected abstract void fireCompleteEvent(Ability ability, EntityLivingBase target);
|
||||
|
||||
/** Fire interrupt event. */
|
||||
/**
|
||||
* Fire interrupt event.
|
||||
*/
|
||||
protected abstract void fireInterruptEvent(Ability ability, EntityLivingBase target,
|
||||
DamageSource source, float damage);
|
||||
|
||||
// -- Telegraph --
|
||||
|
||||
/** Spawn telegraphs for an ability. */
|
||||
/**
|
||||
* Spawn telegraphs for an ability.
|
||||
*/
|
||||
protected abstract void spawnTelegraph(Ability ability, EntityLivingBase target);
|
||||
|
||||
/** Remove telegraphs for an ability. */
|
||||
/**
|
||||
* Remove telegraphs for an ability.
|
||||
*/
|
||||
protected abstract void removeTelegraph(Ability ability);
|
||||
|
||||
// -- Animation/Sound Data Access --
|
||||
|
||||
/** Set animation data on the entity. */
|
||||
/**
|
||||
* Set animation data on the entity.
|
||||
*/
|
||||
protected abstract void setAnimationData(Animation animation);
|
||||
|
||||
/** Clear animation data on the entity. */
|
||||
/**
|
||||
* Clear animation data on the entity.
|
||||
*/
|
||||
protected abstract void clearAnimationData();
|
||||
|
||||
/** Play a sound at the entity's location. */
|
||||
/**
|
||||
* Play a sound at the entity's location.
|
||||
*/
|
||||
protected abstract void playAbilitySound(String sound);
|
||||
|
||||
// -- Rotation (subclass handles extra fields and application) --
|
||||
|
||||
/** Capture rotation values for locking. NPC captures 4 fields, Player captures 2. */
|
||||
/**
|
||||
* Capture rotation values for locking. NPC captures 4 fields, Player captures 2.
|
||||
*/
|
||||
protected abstract void captureLockedRotation();
|
||||
|
||||
// -- Completion --
|
||||
@@ -105,20 +159,44 @@ public abstract class AbstractDataAbilities {
|
||||
*/
|
||||
protected abstract void rollCooldown(Ability ability);
|
||||
|
||||
/** Additional completion logic (NPC clears lastTarget, Player clears key/target and syncs). */
|
||||
/**
|
||||
* Additional completion logic (NPC clears lastTarget, Player clears key/target and syncs).
|
||||
*/
|
||||
protected abstract void onAbilityComplete();
|
||||
|
||||
/**
|
||||
* Roll cooldown after a chained ability completes.
|
||||
* NPC: random(min, max) + chain.cooldownTicks. Player: chain.cooldownTicks only.
|
||||
*/
|
||||
protected abstract void rollChainCooldown(ChainedAbility chain);
|
||||
|
||||
|
||||
// -- Hooks (optional overrides) --
|
||||
|
||||
/** Called before onExecute in ACTIVE phase. NPC uses this for faceTarget/hitScan. */
|
||||
protected void onPreExecute(Ability ability, EntityLivingBase target) {}
|
||||
/**
|
||||
* Called before onExecute in ACTIVE phase. NPC uses this for faceTarget/hitScan.
|
||||
*/
|
||||
protected void onPreExecute(Ability ability, EntityLivingBase target) {
|
||||
}
|
||||
|
||||
/** Called after the phase switch. NPC uses this for hit scan updates and movement control. */
|
||||
protected void onPostPhaseTick(Ability ability, EntityLivingBase target) {}
|
||||
/**
|
||||
* Called after the phase switch. NPC uses this for hit scan updates and movement control.
|
||||
*/
|
||||
protected void onPostPhaseTick(Ability ability, EntityLivingBase target) {
|
||||
}
|
||||
|
||||
/** Additional lock releases in BURST_DELAY. NPC releases hitScan. */
|
||||
protected void onBurstDelayReleaseLocks() {}
|
||||
/**
|
||||
* Additional lock releases in BURST_DELAY. NPC releases hitScan.
|
||||
*/
|
||||
protected void onBurstDelayReleaseLocks() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for retargeting during chain execution when target dies. NPC overrides, Player returns null.
|
||||
*/
|
||||
protected EntityLivingBase retargetForChain() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SHARED ANIMATION METHODS
|
||||
@@ -158,36 +236,287 @@ public abstract class AbstractDataAbilities {
|
||||
// STATE QUERIES
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/** Check if an ability is currently executing. */
|
||||
/**
|
||||
* Check if an ability is currently executing.
|
||||
*/
|
||||
public boolean isExecutingAbility() {
|
||||
return currentAbility != null && currentAbility.isExecuting();
|
||||
}
|
||||
|
||||
/** Get the currently executing ability. */
|
||||
/**
|
||||
* Get the currently executing ability.
|
||||
*/
|
||||
public Ability getCurrentAbility() {
|
||||
return currentAbility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a chained ability is currently executing.
|
||||
*/
|
||||
public boolean isExecutingChain() {
|
||||
return currentChain != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently executing chained ability.
|
||||
*/
|
||||
public ChainedAbility getCurrentChain() {
|
||||
return currentChain;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// TOGGLE STATE (active toggles, independent of currentAbility)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Currently active toggles. Key = ability key, Value = toggle entry with state and tick counter.
|
||||
*/
|
||||
protected Map<String, ToggleEntry> activeToggles = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* Cycle a toggle ability to its next state.
|
||||
* Off(0) -> State 1 -> State 2 -> ... -> State N -> Off(0)
|
||||
*
|
||||
* @param key The ability key (e.g., "npcdbc:ki_fist")
|
||||
* @return The new state (0 = off, 1+ = active state number)
|
||||
*/
|
||||
public int toggleAbility(String key) {
|
||||
ToggleEntry existing = activeToggles.get(key);
|
||||
if (existing != null) {
|
||||
int currentState = existing.getState();
|
||||
int maxStates = existing.getAbility().getToggleStates();
|
||||
if (currentState < maxStates) {
|
||||
return cycleToggleState(key, existing, currentState, currentState + 1);
|
||||
} else {
|
||||
deactivateToggle(key);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return activateToggle(key, 1) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current toggle state for an ability.
|
||||
* @return 0 if not active, 1+ for active state
|
||||
*/
|
||||
public int getToggleState(String key) {
|
||||
ToggleEntry entry = activeToggles.get(key);
|
||||
return entry != null ? entry.getState() : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a toggle to a specific state. 0 = deactivate, 1+ = specific state.
|
||||
*/
|
||||
public void setToggleState(String key, int state) {
|
||||
if (state <= 0) {
|
||||
if (activeToggles.containsKey(key)) {
|
||||
deactivateToggle(key);
|
||||
}
|
||||
return;
|
||||
}
|
||||
ToggleEntry existing = activeToggles.get(key);
|
||||
if (existing != null) {
|
||||
int currentState = existing.getState();
|
||||
if (currentState != state) {
|
||||
cycleToggleState(key, existing, currentState, state);
|
||||
}
|
||||
} else {
|
||||
activateToggle(key, state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a toggle ability is currently active (any state > 0).
|
||||
*/
|
||||
public boolean isAbilityToggled(String key) {
|
||||
return activeToggles.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active toggle keys.
|
||||
*/
|
||||
public Set<String> getActiveToggleKeys() {
|
||||
return new LinkedHashSet<>(activeToggles.keySet());
|
||||
}
|
||||
|
||||
private boolean activateToggle(String key, int state) {
|
||||
Ability ability = AbilityController.Instance != null
|
||||
? AbilityController.Instance.resolveAbility(key) : null;
|
||||
if (ability == null || !ability.isToggleable()) return false;
|
||||
if (state < 1 || state > ability.getToggleStates()) state = 1;
|
||||
|
||||
if (fireToggleEvent(ability, 0, state)) return false;
|
||||
|
||||
ToggleEntry entry = new ToggleEntry(ability, state);
|
||||
activeToggles.put(key, entry);
|
||||
ability.onToggleOn(getEntity());
|
||||
ability.onToggleStateChanged(getEntity(), 0, state);
|
||||
onToggleStateChanged(key, true, state);
|
||||
return true;
|
||||
}
|
||||
|
||||
private int cycleToggleState(String key, ToggleEntry entry, int oldState, int newState) {
|
||||
Ability ability = entry.getAbility();
|
||||
if (newState < 1 || newState > ability.getToggleStates()) return oldState;
|
||||
|
||||
if (fireToggleEvent(ability, oldState, newState)) return oldState;
|
||||
|
||||
entry.setState(newState);
|
||||
ability.onToggleStateChanged(getEntity(), oldState, newState);
|
||||
onToggleStateChanged(key, true, newState);
|
||||
return newState;
|
||||
}
|
||||
|
||||
private void deactivateToggle(String key) {
|
||||
ToggleEntry entry = activeToggles.get(key);
|
||||
if (entry == null) return;
|
||||
int oldState = entry.getState();
|
||||
|
||||
if (fireToggleEvent(entry.getAbility(), oldState, 0)) return;
|
||||
|
||||
activeToggles.remove(key);
|
||||
entry.getAbility().onToggleOff(getEntity());
|
||||
entry.getAbility().onToggleStateChanged(getEntity(), oldState, 0);
|
||||
onToggleStateChanged(key, false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tick all active toggles. Call from tick() each game tick.
|
||||
* Toggles with hasActiveToggle=true get their onToggleTick() called.
|
||||
* If onToggleTick returns false, the toggle is auto-deactivated.
|
||||
* Every 10 ticks, fires a toggle update event for ALL active toggles.
|
||||
*/
|
||||
protected void tickActiveToggles() {
|
||||
if (activeToggles.isEmpty()) return;
|
||||
|
||||
EntityLivingBase entity = getEntity();
|
||||
List<String> toRemove = null;
|
||||
|
||||
for (Map.Entry<String, ToggleEntry> mapEntry : activeToggles.entrySet()) {
|
||||
ToggleEntry entry = mapEntry.getValue();
|
||||
entry.incrementTick();
|
||||
|
||||
if (entry.getAbility().hasActiveToggle()) {
|
||||
if (!entry.getAbility().onToggleTick(entity, entry.getTickCount(), entry.getState())) {
|
||||
if (toRemove == null) toRemove = new ArrayList<>();
|
||||
toRemove.add(mapEntry.getKey());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.getTickCount() % 10 == 0) {
|
||||
boolean enabled = fireToggleUpdateEvent(entry.getAbility(), entry.getTickCount(), entry.getState());
|
||||
if (!enabled) {
|
||||
if (toRemove == null) toRemove = new ArrayList<>();
|
||||
toRemove.add(mapEntry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toRemove != null) {
|
||||
for (String key : toRemove) {
|
||||
ToggleEntry entry = activeToggles.remove(key);
|
||||
if (entry != null) {
|
||||
int oldState = entry.getState();
|
||||
entry.getAbility().onToggleOff(entity);
|
||||
entry.getAbility().onToggleStateChanged(entity, oldState, 0);
|
||||
onToggleStateChanged(key, false, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for subclass to react to toggle state changes (sync packets, script events).
|
||||
*/
|
||||
protected void onToggleStateChanged(String key, boolean active, int state) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire a toggle event before state change.
|
||||
* @param oldState Previous state (0 = off)
|
||||
* @param newState Target state (0 = off)
|
||||
* @return true if the event was canceled
|
||||
*/
|
||||
protected boolean fireToggleEvent(Ability ability, int oldState, int newState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire a toggle update event every 10 ticks.
|
||||
* @return true if the toggle should remain active, false to force-deactivate
|
||||
*/
|
||||
protected boolean fireToggleUpdateEvent(Ability ability, int tick, int state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all active toggles (e.g., on death/reset).
|
||||
* Calls onToggleOff and onToggleStateChanged for each active toggle.
|
||||
*/
|
||||
protected void clearActiveToggles() {
|
||||
if (activeToggles.isEmpty()) return;
|
||||
EntityLivingBase entity = getEntity();
|
||||
for (Map.Entry<String, ToggleEntry> mapEntry : activeToggles.entrySet()) {
|
||||
ToggleEntry entry = mapEntry.getValue();
|
||||
entry.getAbility().onToggleOff(entity);
|
||||
entry.getAbility().onToggleStateChanged(entity, entry.getState(), 0);
|
||||
}
|
||||
activeToggles.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a toggle entry directly without calling onToggleOn.
|
||||
* Used for client-side sync and NBT restoration.
|
||||
* @param key The ability key
|
||||
* @param state The toggle state (0 = remove, 1+ = set at state)
|
||||
*/
|
||||
public void setToggleEntryDirect(String key, int state) {
|
||||
if (state > 0) {
|
||||
Ability ability = AbilityController.Instance != null
|
||||
? AbilityController.Instance.resolveAbility(key) : null;
|
||||
if (ability != null && ability.isToggleable()) {
|
||||
activeToggles.put(key, new ToggleEntry(ability, state));
|
||||
}
|
||||
} else {
|
||||
activeToggles.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// COOLDOWN MANAGEMENT
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/** Check if on cooldown. */
|
||||
/**
|
||||
* Check if on cooldown.
|
||||
*/
|
||||
public boolean isOnCooldown() {
|
||||
return getWorldTime() < cooldownEndTime;
|
||||
}
|
||||
|
||||
/** Get remaining cooldown ticks. */
|
||||
/**
|
||||
* Get remaining cooldown ticks.
|
||||
*/
|
||||
public long getRemainingCooldown() {
|
||||
long remaining = cooldownEndTime - getWorldTime();
|
||||
return remaining > 0 ? remaining : 0;
|
||||
}
|
||||
|
||||
/** Reset cooldown (allow immediate ability use). */
|
||||
/**
|
||||
* Reset cooldown (allow immediate ability use).
|
||||
*/
|
||||
public void resetCooldown() {
|
||||
cooldownEndTime = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cooldown end time directly.
|
||||
*/
|
||||
public void setCooldownEndTime(long endTime) {
|
||||
cooldownEndTime = endTime;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// POSITION LOCKING
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -212,8 +541,11 @@ public abstract class AbstractDataAbilities {
|
||||
onPositionLockChanged(false);
|
||||
}
|
||||
|
||||
/** Hook for subclass to react to position lock state changes (e.g., NPC sets data watcher flag). */
|
||||
protected void onPositionLockChanged(boolean locked) {}
|
||||
/**
|
||||
* Hook for subclass to react to position lock state changes (e.g., NPC sets data watcher flag).
|
||||
*/
|
||||
protected void onPositionLockChanged(boolean locked) {
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// ROTATION LOCKING
|
||||
@@ -227,8 +559,11 @@ public abstract class AbstractDataAbilities {
|
||||
onRotationLockChanged(false);
|
||||
}
|
||||
|
||||
/** Hook for subclass to react to rotation lock state changes (e.g., NPC sets flag, clears hitScan). */
|
||||
protected void onRotationLockChanged(boolean locked) {}
|
||||
/**
|
||||
* Hook for subclass to react to rotation lock state changes (e.g., NPC sets flag, clears hitScan).
|
||||
*/
|
||||
protected void onRotationLockChanged(boolean locked) {
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CORE TICK - Phase transition logic shared between NPC and Player
|
||||
@@ -242,6 +577,24 @@ public abstract class AbstractDataAbilities {
|
||||
* Subclass-specific behavior is injected via abstract methods and hooks.
|
||||
*/
|
||||
protected void tickCurrentAbility() {
|
||||
// Handle chain delay between entries
|
||||
if (chainDelayRemaining > 0) {
|
||||
chainDelayRemaining--;
|
||||
if (chainDelayRemaining <= 0) {
|
||||
EntityLivingBase chainTarget = getTarget();
|
||||
// Check if target is dead and retarget
|
||||
if (currentChain != null && chainTarget != null && chainTarget.isDead) {
|
||||
chainTarget = retargetForChain();
|
||||
if (chainTarget == null) {
|
||||
completeChain();
|
||||
return;
|
||||
}
|
||||
}
|
||||
startChainEntry(chainTarget);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
EntityLivingBase entity = getEntity();
|
||||
EntityLivingBase target = getTarget();
|
||||
AbilityPhase oldPhase = currentAbility.getPhase();
|
||||
@@ -254,7 +607,7 @@ public abstract class AbstractDataAbilities {
|
||||
|
||||
// Fire extender tick hook (e.g., per-tick resource drain)
|
||||
if (!AbilityController.Instance.fireOnAbilityTick(currentAbility, entity, target,
|
||||
currentAbility.getPhase(), currentAbility.getCurrentTick())) {
|
||||
currentAbility.getPhase(), currentAbility.getCurrentTick())) {
|
||||
interruptCurrentAbility(null, 0);
|
||||
return;
|
||||
}
|
||||
@@ -318,7 +671,10 @@ public abstract class AbstractDataAbilities {
|
||||
|
||||
// Fire execute event (cancelable)
|
||||
if (fireExecuteEvent(currentAbility, target)) {
|
||||
return; // Cancelled
|
||||
// Script cancelled — abort cleanly instead of leaving stuck in ACTIVE
|
||||
currentAbility.interrupt();
|
||||
handleAbilityCompletion(target);
|
||||
return;
|
||||
}
|
||||
|
||||
// Call onExecute
|
||||
@@ -339,8 +695,10 @@ public abstract class AbstractDataAbilities {
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto-complete for burst overlap mode
|
||||
// Auto-complete for burst overlap mode only.
|
||||
// Non-overlap waits for all entities to die naturally (via allDead check in onActiveTick).
|
||||
if (currentAbility.isBurstEnabled()
|
||||
&& currentAbility.isBurstOverlap()
|
||||
&& currentAbility.getBurstIndex() < currentAbility.getBurstAmount()
|
||||
&& currentAbility.getPhase() == AbilityPhase.ACTIVE
|
||||
&& currentAbility.isReadyForBurstCompletion(currentAbility.getCurrentTick())) {
|
||||
@@ -381,6 +739,7 @@ public abstract class AbstractDataAbilities {
|
||||
|
||||
/**
|
||||
* Handle ability completion. Called when ability phase becomes IDLE.
|
||||
* If a chain is active, advances to the next entry instead of completing.
|
||||
*/
|
||||
protected void handleAbilityCompletion(EntityLivingBase target) {
|
||||
if (currentAbility == null) return;
|
||||
@@ -400,10 +759,42 @@ public abstract class AbstractDataAbilities {
|
||||
// Release locks
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
|
||||
// Subclass-specific completion (cooldown, cleanup, sync)
|
||||
rollCooldown(currentAbility);
|
||||
stopAbilityAnimation();
|
||||
|
||||
// Chain mode: advance to next entry instead of completing
|
||||
if (currentChain != null) {
|
||||
// AFTER semantics: delay from the CURRENT (just-completed) entry
|
||||
ChainedAbilityEntry completedEntry = currentChain.getEntries().get(chainEntryIndex);
|
||||
int delay = completedEntry.getDelayTicks();
|
||||
|
||||
chainEntryIndex++;
|
||||
if (chainEntryIndex < currentChain.getEntries().size()) {
|
||||
// Check if target died and retarget
|
||||
if (target != null && target.isDead) {
|
||||
target = retargetForChain();
|
||||
if (target == null) {
|
||||
completeChain();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Enforce minimum 1-tick delay between chain entries
|
||||
chainDelayRemaining = Math.max(1, delay);
|
||||
currentAbility = null;
|
||||
return;
|
||||
}
|
||||
// All entries complete
|
||||
completeChain();
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal (non-chain) completion
|
||||
if (interruptCooldownRolled) {
|
||||
// Cooldown was already rolled during interrupt (e.g., chain interrupted, NPC ticked through DAZED)
|
||||
interruptCooldownRolled = false;
|
||||
} else {
|
||||
rollCooldown(currentAbility);
|
||||
}
|
||||
onAbilityComplete();
|
||||
}
|
||||
|
||||
@@ -421,7 +812,10 @@ public abstract class AbstractDataAbilities {
|
||||
|
||||
// Fire execute event (cancelable)
|
||||
if (fireExecuteEvent(ability, target)) {
|
||||
return; // Cancelled
|
||||
// Script cancelled — abort cleanly instead of leaving stuck in ACTIVE
|
||||
ability.interrupt();
|
||||
handleAbilityCompletion(target);
|
||||
return;
|
||||
}
|
||||
|
||||
// Call onExecute
|
||||
@@ -465,6 +859,15 @@ public abstract class AbstractDataAbilities {
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
|
||||
// If chain was active, roll chain cooldown and clear chain state
|
||||
if (currentChain != null) {
|
||||
rollChainCooldown(currentChain);
|
||||
interruptCooldownRolled = true;
|
||||
currentChain = null;
|
||||
chainEntryIndex = -1;
|
||||
chainDelayRemaining = -1;
|
||||
}
|
||||
|
||||
// Let subclass handle cleanup
|
||||
onInterruptComplete();
|
||||
}
|
||||
@@ -474,5 +877,107 @@ public abstract class AbstractDataAbilities {
|
||||
* Hook called after interrupt completes. Subclass handles clearing state and syncing.
|
||||
* NPC: keeps currentAbility (ticks through DAZED). Player: clears immediately.
|
||||
*/
|
||||
protected void onInterruptComplete() {}
|
||||
protected void onInterruptComplete() {
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CHAINED ABILITY EXECUTION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Start executing a chained ability. Sets up chain state and starts the first entry.
|
||||
*
|
||||
* @param chain The chained ability to execute (should be a deep copy)
|
||||
* @param target The initial target
|
||||
* @return true if the chain was started
|
||||
*/
|
||||
protected boolean startChain(ChainedAbility chain, EntityLivingBase target) {
|
||||
if (chain == null || chain.getEntries().isEmpty()) return false;
|
||||
|
||||
currentChain = chain;
|
||||
chainEntryIndex = 0;
|
||||
chainDelayRemaining = -1;
|
||||
|
||||
// AFTER semantics: no delay before first entry (delay applies after each entry completes)
|
||||
return startChainEntry(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the current chain entry's ability.
|
||||
*/
|
||||
protected boolean startChainEntry(EntityLivingBase target) {
|
||||
if (currentChain == null || chainEntryIndex < 0 || chainEntryIndex >= currentChain.getEntries().size()) {
|
||||
completeChain();
|
||||
return false;
|
||||
}
|
||||
|
||||
ChainedAbilityEntry entry = currentChain.getEntries().get(chainEntryIndex);
|
||||
Ability ability = entry.resolve();
|
||||
if (ability == null) {
|
||||
// Broken reference - complete chain
|
||||
completeChain();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate the resolved ability's UserType matches the chain's allowed context.
|
||||
// The chain's own UserType was already checked at selection time, but individual
|
||||
// abilities may have stricter restrictions (e.g., PLAYER_ONLY in an NPC chain).
|
||||
if (!ability.getAllowedBy().allowsNpc() && getEntity() instanceof noppes.npcs.entity.EntityNPCInterface) {
|
||||
// Skip this entry - ability doesn't allow NPCs
|
||||
completeChain();
|
||||
return false;
|
||||
}
|
||||
if (!ability.getAllowedBy().allowsPlayer() && getEntity() instanceof net.minecraft.entity.player.EntityPlayer) {
|
||||
// Skip this entry - ability doesn't allow players
|
||||
completeChain();
|
||||
return false;
|
||||
}
|
||||
|
||||
// If windUpAll=false, only the first ability windups; subsequent abilities skip windup
|
||||
if (!currentChain.isWindUpAll() && chainEntryIndex > 0) {
|
||||
ability.setWindUpTicks(0);
|
||||
}
|
||||
|
||||
// Start the ability (skip its own conditions - chain conditions were already checked)
|
||||
currentAbility = ability;
|
||||
ability.start(target);
|
||||
|
||||
if (ability.getPhase() == AbilityPhase.ACTIVE) {
|
||||
// Windup was 0 - capture locks for immediate active phase, then execute
|
||||
if (ability.isRotationLockedDuringActive()) {
|
||||
captureLockedRotation();
|
||||
}
|
||||
if (ability.isMovementLockedDuringActive() && !ability.hasAbilityMovement()) {
|
||||
captureLockedPosition();
|
||||
}
|
||||
executeImmediate(ability, target);
|
||||
} else {
|
||||
// Normal windup flow
|
||||
if (ability.isRotationLockedDuringWindup()) {
|
||||
captureLockedRotation();
|
||||
}
|
||||
if (ability.isMovementLockedDuringWindup() && !ability.hasAbilityMovement()) {
|
||||
captureLockedPosition();
|
||||
}
|
||||
spawnTelegraph(ability, target);
|
||||
playAbilitySound(ability.getWindUpSound());
|
||||
playAbilityAnimation(ability.getWindUpAnimation());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete the chain execution. Rolls chain cooldown and clears all chain state.
|
||||
*/
|
||||
protected void completeChain() {
|
||||
if (currentChain != null) {
|
||||
rollChainCooldown(currentChain);
|
||||
}
|
||||
currentChain = null;
|
||||
chainEntryIndex = -1;
|
||||
chainDelayRemaining = -1;
|
||||
currentAbility = null;
|
||||
onAbilityComplete();
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,13 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.blocks.tiles.TileNpcContainer;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.containers.ContainerAuction;
|
||||
import noppes.npcs.containers.ContainerAnvilRepair;
|
||||
import noppes.npcs.containers.ContainerAuctionBidding;
|
||||
import noppes.npcs.containers.ContainerAuctionTrades;
|
||||
import noppes.npcs.containers.ContainerAuctionListing;
|
||||
import noppes.npcs.containers.ContainerAuctionSell;
|
||||
import noppes.npcs.containers.ContainerAnvilRepair;
|
||||
import noppes.npcs.containers.ContainerAuctionTrades;
|
||||
import noppes.npcs.containers.ContainerCarpentryBench;
|
||||
import noppes.npcs.containers.ContainerCrate;
|
||||
import noppes.npcs.containers.ContainerCustomGui;
|
||||
@@ -43,7 +43,6 @@ import noppes.npcs.containers.ContainerNpcQuestReward;
|
||||
import noppes.npcs.containers.ContainerNpcQuestTypeItem;
|
||||
import noppes.npcs.controllers.data.AnimationData;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
public class CommonProxy implements IGuiHandler {
|
||||
|
||||
@@ -21,13 +21,22 @@ import io.github.somehussar.janinoloader.api.IDynamicCompilerBuilder;
|
||||
import kamkeel.npcs.addon.AddonManager;
|
||||
import kamkeel.npcs.command.CommandKamkeel;
|
||||
import kamkeel.npcs.command.profile.CommandProfile;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.TelegraphController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.profile.CNPCData;
|
||||
import kamkeel.npcs.developer.Developer;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.util.BukkitUtil;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -86,15 +95,6 @@ import noppes.npcs.entity.EntityNpcDragon;
|
||||
import noppes.npcs.entity.EntityNpcPony;
|
||||
import noppes.npcs.entity.EntityNpcSlime;
|
||||
import noppes.npcs.entity.EntityProjectile;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
||||
import noppes.npcs.entity.old.EntityNPCDwarfFemale;
|
||||
import noppes.npcs.entity.old.EntityNPCDwarfMale;
|
||||
import noppes.npcs.entity.old.EntityNPCElfFemale;
|
||||
@@ -121,7 +121,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11-beta3")
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11-beta4")
|
||||
public class CustomNpcs {
|
||||
|
||||
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
|
||||
@@ -421,6 +421,8 @@ public class CustomNpcs {
|
||||
AuctionController.Instance.save();
|
||||
}
|
||||
|
||||
kamkeel.npcs.entity.EntityEnergyProjectile.clearAllProjectiles();
|
||||
|
||||
if (FMLCommonHandler.instance().getSide().isClient())
|
||||
clientJaninoCompiler = null;
|
||||
globalJaninoCompiler = null;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityAction;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilitySlot;
|
||||
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.IAbilityAction;
|
||||
import kamkeel.npcs.controllers.data.ability.ToggleEntry;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityGuard;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphRemovePacket;
|
||||
@@ -11,6 +14,7 @@ import kamkeel.npcs.network.packets.data.telegraph.TelegraphSpawnPacket;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
@@ -19,6 +23,7 @@ import noppes.npcs.scripted.event.AbilityEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
@@ -35,9 +40,9 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* List of ability slots this NPC can use (inline or reference).
|
||||
* Unified list of action slots (abilities and chained abilities).
|
||||
*/
|
||||
private List<AbilitySlot> abilitySlots = new ArrayList<>();
|
||||
private List<AbilityAction> actionSlots = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Whether the ability system is enabled for this NPC
|
||||
@@ -83,10 +88,14 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
private transient boolean hitScanActive = false;
|
||||
private transient EntityLivingBase hitScanTarget = null;
|
||||
|
||||
/** Bit flag for rotation control (LOCKED or TRACK) in data watcher slot 15 */
|
||||
/**
|
||||
* Bit flag for rotation control (LOCKED or TRACK) in data watcher slot 15
|
||||
*/
|
||||
private static final int ROTATION_CONTROLLED_FLAG = 16;
|
||||
|
||||
/** Bit flag for position lock in data watcher slot 15 */
|
||||
/**
|
||||
* Bit flag for position lock in data watcher slot 15
|
||||
*/
|
||||
private static final int POSITION_LOCKED_FLAG = 32;
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -140,12 +149,27 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
|
||||
@Override
|
||||
protected void fireInterruptEvent(Ability ability, EntityLivingBase target,
|
||||
DamageSource source, float damage) {
|
||||
DamageSource source, float damage) {
|
||||
AbilityEvent.InterruptEvent interruptEvent = new AbilityEvent.InterruptEvent(
|
||||
npc.wrappedNPC, ability, target, source, damage);
|
||||
NpcAPI.EVENT_BUS.post(interruptEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireToggleEvent(Ability ability, int oldState, int newState) {
|
||||
AbilityEvent.ToggleEvent event = new AbilityEvent.ToggleEvent(
|
||||
npc.wrappedNPC, ability, oldState, newState);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireToggleUpdateEvent(Ability ability, int tick, int state) {
|
||||
AbilityEvent.ToggleUpdateEvent event = new AbilityEvent.ToggleUpdateEvent(
|
||||
npc.wrappedNPC, ability, tick, state);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
return event.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void spawnTelegraph(Ability ability, EntityLivingBase target) {
|
||||
List<TelegraphInstance> telegraphs = ability.createTelegraphs(npc, target);
|
||||
@@ -207,6 +231,20 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
cooldownEndTime += ability.getCooldownTicks();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void rollChainCooldown(ChainedAbility chain) {
|
||||
int baseCooldown = minCooldown;
|
||||
if (maxCooldown > minCooldown) {
|
||||
baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1);
|
||||
}
|
||||
cooldownEndTime = npc.worldObj.getTotalWorldTime() + baseCooldown + chain.getCooldownTicks();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityLivingBase retargetForChain() {
|
||||
return npc.getAttackTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAbilityComplete() {
|
||||
currentAbility = null;
|
||||
@@ -230,7 +268,7 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
// Update hit scan state - actual facing is deferred to applyRotationControl()
|
||||
// which runs AFTER super.onLivingUpdate() to override AI look helper
|
||||
if (ability != null && ability.isExecuting()
|
||||
&& ability.isHitScanForCurrentPhase() && target != null) {
|
||||
&& ability.isHitScanForCurrentPhase() && target != null) {
|
||||
enableHitScan(target);
|
||||
} else if (hitScanActive) {
|
||||
releaseRotationControl();
|
||||
@@ -288,17 +326,24 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
if (rotationLocked || hitScanActive) releaseRotationControl();
|
||||
if (positionLocked) releaseLockedPosition();
|
||||
}
|
||||
// Clear chain state
|
||||
currentChain = null;
|
||||
chainEntryIndex = -1;
|
||||
chainDelayRemaining = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
// Safety: release orphaned locks if no ability is actively executing
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) {
|
||||
if ((currentAbility == null || !currentAbility.isExecuting()) && chainDelayRemaining <= 0) {
|
||||
if (rotationLocked || hitScanActive) releaseRotationControl();
|
||||
if (positionLocked) releaseLockedPosition();
|
||||
}
|
||||
|
||||
// Tick current ability if executing (shared logic from base class)
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
// Tick active toggles (independent of currentAbility)
|
||||
tickActiveToggles();
|
||||
|
||||
// Tick current ability if executing, or tick chain delay between entries
|
||||
if (chainDelayRemaining > 0 || (currentAbility != null && currentAbility.isExecuting())) {
|
||||
tickCurrentAbility();
|
||||
}
|
||||
}
|
||||
@@ -329,7 +374,7 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Try to select and start an ability for the given target.
|
||||
* Try to select and start an ability or chained ability for the given target.
|
||||
* Called by CombatHandler when NPC is in combat and ready for an ability.
|
||||
*
|
||||
* @param target The combat target
|
||||
@@ -340,24 +385,61 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
return false;
|
||||
}
|
||||
|
||||
Ability selected = selectAbility(target);
|
||||
if (selected == null) {
|
||||
// Build eligible pool from unified action slots
|
||||
List<IAbilityAction> eligible = new ArrayList<>();
|
||||
List<Integer> weights = new ArrayList<>();
|
||||
int totalWeight = 0;
|
||||
|
||||
for (AbilityAction slot : actionSlots) {
|
||||
IAbilityAction action = slot.getAction();
|
||||
if (action != null && isActionEligible(action, target)) {
|
||||
eligible.add(action);
|
||||
weights.add(action.getWeight());
|
||||
totalWeight += action.getWeight();
|
||||
}
|
||||
}
|
||||
|
||||
if (eligible.isEmpty() || totalWeight <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return startAbility(selected, target);
|
||||
// Weighted random selection
|
||||
int roll = random.nextInt(totalWeight);
|
||||
int cumulative = 0;
|
||||
IAbilityAction selected = null;
|
||||
for (int i = 0; i < eligible.size(); i++) {
|
||||
cumulative += weights.get(i);
|
||||
if (roll < cumulative) {
|
||||
selected = eligible.get(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (selected == null) {
|
||||
selected = eligible.get(eligible.size() - 1);
|
||||
}
|
||||
|
||||
// Dispatch
|
||||
lastTarget = target;
|
||||
if (selected.isChain()) {
|
||||
return startChain((ChainedAbility) selected, target);
|
||||
} else {
|
||||
return startAbility((Ability) selected, target);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an ability can be selected right now.
|
||||
*/
|
||||
public boolean canSelectAbility() {
|
||||
if (!enabled || abilitySlots.isEmpty()) {
|
||||
if (!enabled || actionSlots.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
return false;
|
||||
}
|
||||
if (isExecutingChain()) {
|
||||
return false;
|
||||
}
|
||||
// Check if still on cooldown
|
||||
if (npc.worldObj.getTotalWorldTime() < cooldownEndTime) {
|
||||
return false;
|
||||
@@ -366,65 +448,36 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
}
|
||||
|
||||
/**
|
||||
* Select an ability using weighted random from eligible abilities.
|
||||
* Check if an action (ability or chain) is eligible for use.
|
||||
*/
|
||||
private Ability selectAbility(EntityLivingBase target) {
|
||||
List<Ability> eligible = new ArrayList<>();
|
||||
int totalWeight = 0;
|
||||
|
||||
for (Ability ability : getAbilities()) {
|
||||
if (isAbilityEligible(ability, target)) {
|
||||
eligible.add(ability);
|
||||
totalWeight += ability.getWeight();
|
||||
}
|
||||
private boolean isActionEligible(IAbilityAction action, EntityLivingBase target) {
|
||||
if (!action.getAllowedBy().allowsNpc()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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 UserType allows NPCs
|
||||
if (!ability.getAllowedBy().allowsNpc()) {
|
||||
if (!action.isEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check enabled
|
||||
if (!ability.isEnabled()) {
|
||||
// Ability-specific: check if already executing
|
||||
if (!action.isChain() && ((Ability) action).isExecuting()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if already executing
|
||||
if (ability.isExecuting()) {
|
||||
// Chain-specific: must have entries
|
||||
if (action.isChain() && ((ChainedAbility) action).getEntries().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check range
|
||||
// Range check
|
||||
if (target != null) {
|
||||
float distance = npc.getDistanceToEntity(target);
|
||||
if (distance < ability.getMinRange() || distance > ability.getMaxRange()) {
|
||||
if (distance < action.getMinRange() || distance > action.getMaxRange()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Check conditions
|
||||
if (!ability.checkConditions(npc, target)) {
|
||||
// Conditions
|
||||
if (!action.checkConditions(npc, target)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -496,7 +549,9 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
return false;
|
||||
}
|
||||
|
||||
currentAbility.onDamageTaken(npc, (EntityLivingBase) source.getEntity(), source, amount);
|
||||
net.minecraft.entity.Entity sourceEntity = source.getEntity();
|
||||
EntityLivingBase attacker = sourceEntity instanceof EntityLivingBase ? (EntityLivingBase) sourceEntity : null;
|
||||
currentAbility.onDamageTaken(npc, attacker, source, amount);
|
||||
|
||||
if (currentAbility.canInterrupt(source)) {
|
||||
interruptCurrentAbility(source, amount);
|
||||
@@ -568,6 +623,10 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
currentAbility = null;
|
||||
lastTarget = null;
|
||||
}
|
||||
// Also clear chain state
|
||||
currentChain = null;
|
||||
chainEntryIndex = -1;
|
||||
chainDelayRemaining = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -575,7 +634,7 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
* If an ability is currently executing, it will be cancelled.
|
||||
*
|
||||
* @param ability The ability to start
|
||||
* @param target The target entity (can be null for self-targeted abilities)
|
||||
* @param target The target entity (can be null for self-targeted abilities)
|
||||
* @return true if the ability was started successfully
|
||||
*/
|
||||
public boolean forceStartAbility(Ability ability, EntityLivingBase target) {
|
||||
@@ -602,7 +661,7 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
* Execute an ability on this NPC by key (built-in name or custom UUID).
|
||||
* The NPC does NOT need to have this ability assigned.
|
||||
*
|
||||
* @param key The ability key (built-in name or custom UUID)
|
||||
* @param key The ability key (built-in name or custom UUID)
|
||||
* @param target The target entity (can be null for self-targeted abilities)
|
||||
* @return true if the ability was started successfully
|
||||
*/
|
||||
@@ -664,6 +723,7 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
*/
|
||||
public void reset() {
|
||||
stopCurrentAbility();
|
||||
clearActiveToggles();
|
||||
|
||||
// Roll cooldown so NPC doesn't immediately attack after reset
|
||||
rollCooldownOnReset();
|
||||
@@ -687,15 +747,22 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// ABILITY LIST MANAGEMENT
|
||||
// ACTION SLOT MANAGEMENT
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Get resolved abilities from all slots, filtering out broken references.
|
||||
* Get the unified action slot list.
|
||||
*/
|
||||
public List<AbilityAction> getAbilityActions() {
|
||||
return actionSlots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get resolved abilities from all ability slots, filtering out broken references and chains.
|
||||
*/
|
||||
public List<Ability> getAbilities() {
|
||||
List<Ability> resolved = new ArrayList<>();
|
||||
for (AbilitySlot slot : abilitySlots) {
|
||||
for (AbilityAction slot : actionSlots) {
|
||||
Ability a = slot.getAbility();
|
||||
if (a != null) {
|
||||
resolved.add(a);
|
||||
@@ -704,39 +771,62 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
return resolved;
|
||||
}
|
||||
|
||||
/** Get the raw slot list (for GUI access). */
|
||||
public List<AbilitySlot> getAbilitySlots() {
|
||||
return abilitySlots;
|
||||
}
|
||||
|
||||
/** Add an inline ability. */
|
||||
/**
|
||||
* Add an inline ability.
|
||||
*/
|
||||
public void addAbility(Ability ability) {
|
||||
abilitySlots.add(AbilitySlot.inline(ability));
|
||||
actionSlots.add(AbilityAction.inline(ability));
|
||||
}
|
||||
|
||||
/** Add a reference ability by key (built-in name or custom ability name). */
|
||||
/**
|
||||
* Add a reference ability by key (built-in name or custom ability name).
|
||||
*/
|
||||
public void addAbilityReference(String key) {
|
||||
abilitySlots.add(AbilitySlot.reference(key));
|
||||
actionSlots.add(AbilityAction.abilityReference(key));
|
||||
}
|
||||
|
||||
public void removeAbility(int index) {
|
||||
if (index >= 0 && index < abilitySlots.size()) {
|
||||
abilitySlots.remove(index);
|
||||
/**
|
||||
* Add a chained ability reference by name.
|
||||
*/
|
||||
public void addChainReference(String name) {
|
||||
if (name != null && !name.isEmpty()) {
|
||||
for (AbilityAction slot : actionSlots) {
|
||||
if (slot.isChainReference() && name.equals(slot.getReferenceId())) {
|
||||
return; // Prevent duplicates
|
||||
}
|
||||
}
|
||||
actionSlots.add(AbilityAction.chainReference(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an action slot by index.
|
||||
*/
|
||||
public void removeAction(int index) {
|
||||
if (index >= 0 && index < actionSlots.size()) {
|
||||
actionSlots.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAbility(int index) {
|
||||
removeAction(index);
|
||||
}
|
||||
|
||||
public void removeAbility(String id) {
|
||||
abilitySlots.removeIf(slot -> {
|
||||
if (slot.isReference()) {
|
||||
actionSlots.removeIf(slot -> {
|
||||
if (slot.isAbilityReference()) {
|
||||
return slot.getReferenceId().equals(id);
|
||||
}
|
||||
if (slot.isChainReference()) {
|
||||
return false; // Don't remove chain references via removeAbility
|
||||
}
|
||||
Ability a = slot.getAbility();
|
||||
return a != null && a.getId().equals(id);
|
||||
});
|
||||
}
|
||||
|
||||
public Ability getAbility(String id) {
|
||||
for (AbilitySlot slot : abilitySlots) {
|
||||
for (AbilityAction slot : actionSlots) {
|
||||
Ability a = slot.getAbility();
|
||||
if (a != null && a.getId().equals(id)) {
|
||||
return a;
|
||||
@@ -745,24 +835,28 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Check if a slot at a given index is a reference. */
|
||||
/**
|
||||
* Check if a slot at a given index is a reference.
|
||||
*/
|
||||
public boolean isSlotReference(int index) {
|
||||
if (index < 0 || index >= abilitySlots.size()) return false;
|
||||
return abilitySlots.get(index).isReference();
|
||||
if (index < 0 || index >= actionSlots.size()) return false;
|
||||
return actionSlots.get(index).isReference();
|
||||
}
|
||||
|
||||
/** Convert a reference slot to inline. Returns false if resolution fails. */
|
||||
/**
|
||||
* Convert a reference slot to inline. Returns false if resolution fails or is a chain.
|
||||
*/
|
||||
public boolean convertToInline(int index) {
|
||||
if (index < 0 || index >= abilitySlots.size()) return false;
|
||||
return abilitySlots.get(index).convertToInline();
|
||||
if (index < 0 || index >= actionSlots.size()) return false;
|
||||
return actionSlots.get(index).convertToInline();
|
||||
}
|
||||
|
||||
public void clearAbilities() {
|
||||
abilitySlots.clear();
|
||||
actionSlots.clear();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return abilitySlots.isEmpty();
|
||||
return actionSlots.isEmpty();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -875,7 +969,7 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
/**
|
||||
* Apply rotation control after super.onLivingUpdate() and super.onUpdate().
|
||||
* Handles both LOCKED (freeze at captured values) and TRACK (face target) modes.
|
||||
*
|
||||
* <p>
|
||||
* Server: computes the correct rotation (locked values or target facing).
|
||||
* Client: trusts the server-synced rotation values and prevents body smoothing override.
|
||||
*/
|
||||
@@ -977,11 +1071,21 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
compound.setInteger("AbilityMinCooldown", minCooldown);
|
||||
compound.setInteger("AbilityMaxCooldown", maxCooldown);
|
||||
|
||||
NBTTagList abilityList = new NBTTagList();
|
||||
for (AbilitySlot slot : abilitySlots) {
|
||||
abilityList.appendTag(slot.writeNBT());
|
||||
NBTTagList actionList = new NBTTagList();
|
||||
for (AbilityAction slot : actionSlots) {
|
||||
actionList.appendTag(slot.writeNBT());
|
||||
}
|
||||
compound.setTag("Abilities", abilityList);
|
||||
compound.setTag("AbilityActions", actionList);
|
||||
|
||||
// Active toggles (compound format with state)
|
||||
NBTTagList toggleList = new NBTTagList();
|
||||
for (Map.Entry<String, ToggleEntry> entry : activeToggles.entrySet()) {
|
||||
NBTTagCompound toggleNbt = new NBTTagCompound();
|
||||
toggleNbt.setString("Key", entry.getKey());
|
||||
toggleNbt.setInteger("State", entry.getValue().getState());
|
||||
toggleList.appendTag(toggleNbt);
|
||||
}
|
||||
compound.setTag("ActiveToggles", toggleList);
|
||||
|
||||
return compound;
|
||||
}
|
||||
@@ -991,13 +1095,48 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
minCooldown = compound.getInteger("AbilityMinCooldown");
|
||||
maxCooldown = compound.getInteger("AbilityMaxCooldown");
|
||||
|
||||
abilitySlots.clear();
|
||||
NBTTagList abilityList = compound.getTagList("Abilities", 10);
|
||||
for (int i = 0; i < abilityList.tagCount(); i++) {
|
||||
NBTTagCompound abilityNBT = abilityList.getCompoundTagAt(i);
|
||||
AbilitySlot slot = AbilitySlot.fromNBT(abilityNBT);
|
||||
if (slot != null) {
|
||||
abilitySlots.add(slot);
|
||||
actionSlots.clear();
|
||||
|
||||
if (compound.hasKey("AbilityActions")) {
|
||||
// New unified format
|
||||
NBTTagList actionList = compound.getTagList("AbilityActions", 10);
|
||||
for (int i = 0; i < actionList.tagCount(); i++) {
|
||||
AbilityAction slot = AbilityAction.fromNBT(actionList.getCompoundTagAt(i));
|
||||
if (slot != null) {
|
||||
actionSlots.add(slot);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Legacy migration: read old separate lists
|
||||
if (compound.hasKey("Abilities")) {
|
||||
NBTTagList abilityList = compound.getTagList("Abilities", 10);
|
||||
for (int i = 0; i < abilityList.tagCount(); i++) {
|
||||
AbilityAction slot = AbilityAction.fromNBT(abilityList.getCompoundTagAt(i));
|
||||
if (slot != null) {
|
||||
actionSlots.add(slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (compound.hasKey("ChainedAbilities")) {
|
||||
NBTTagList chainList = compound.getTagList("ChainedAbilities", 8);
|
||||
for (int i = 0; i < chainList.tagCount(); i++) {
|
||||
String ref = chainList.getStringTagAt(i);
|
||||
if (ref != null && !ref.isEmpty()) {
|
||||
actionSlots.add(AbilityAction.chainReference(ref));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Active toggles - restore state directly (no onToggleOn callback during load)
|
||||
activeToggles.clear();
|
||||
if (compound.hasKey("ActiveToggles")) {
|
||||
NBTTagList toggleNbt = compound.getTagList("ActiveToggles", 10); // 10 = TAG_COMPOUND
|
||||
for (int i = 0; i < toggleNbt.tagCount(); i++) {
|
||||
NBTTagCompound entry = toggleNbt.getCompoundTagAt(i);
|
||||
String key = entry.getString("Key");
|
||||
int state = entry.hasKey("State") ? entry.getInteger("State") : 1;
|
||||
setToggleEntryDirect(key, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ import net.minecraftforge.event.world.WorldEvent;
|
||||
import noppes.npcs.api.IBlock;
|
||||
import noppes.npcs.api.IPos;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.entity.IEnergyProjectile;
|
||||
import noppes.npcs.api.entity.IAnimatable;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.entity.IEnergyProjectile;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.entity.IProjectile;
|
||||
@@ -64,6 +64,7 @@ import noppes.npcs.scripted.event.NpcEvent;
|
||||
import noppes.npcs.scripted.event.PartyEvent;
|
||||
import noppes.npcs.scripted.event.ProjectileEvent;
|
||||
import noppes.npcs.scripted.event.RecipeScriptEvent;
|
||||
import noppes.npcs.scripted.event.player.AuctionEvent;
|
||||
import noppes.npcs.scripted.event.player.CustomGuiEvent;
|
||||
import noppes.npcs.scripted.event.player.DialogEvent;
|
||||
import noppes.npcs.scripted.event.player.FactionEvent;
|
||||
@@ -560,7 +561,7 @@ public class EventHooks {
|
||||
// ==================== ENERGY BARRIER EVENTS ====================
|
||||
|
||||
private static void dispatchBarrierEvent(net.minecraft.entity.Entity barrierEntity, int ownerEntityId,
|
||||
noppes.npcs.scripted.event.EnergyBarrierEvent event, EnumScriptType type) {
|
||||
noppes.npcs.scripted.event.EnergyBarrierEvent event, EnumScriptType type) {
|
||||
ScriptController.Instance.globalNpcScripts.callScript(type, event);
|
||||
|
||||
net.minecraft.entity.Entity owner = barrierEntity.worldObj.getEntityByID(ownerEntityId);
|
||||
@@ -880,6 +881,16 @@ public class EventHooks {
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerAbilityToggle(PlayerDataScript handler, PlayerAbilityEvent.ToggleEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_TOGGLE, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerAbilityToggleUpdate(PlayerDataScript handler, PlayerAbilityEvent.ToggleUpdateEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_TOGGLE_UPDATE, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerChangeDim(PlayerDataScript handler, IPlayer player, int fromDim, int toDim) {
|
||||
PlayerEvent.ChangedDimension event = new PlayerEvent.ChangedDimension(player, fromDim, toDim);
|
||||
handler.callScript(EnumScriptType.CHANGED_DIM, event);
|
||||
@@ -1253,4 +1264,31 @@ public class EventHooks {
|
||||
}
|
||||
postAnimationEvent(new AnimationEvent.FrameEvent.Exited(animation, frame));
|
||||
}
|
||||
|
||||
// ==================== AUCTION EVENTS ====================
|
||||
|
||||
public static boolean onAuctionCreate(PlayerDataScript handler, AuctionEvent.CreateEvent event) {
|
||||
handler.callScript(EnumScriptType.AUCTION_CREATE, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onAuctionBid(PlayerDataScript handler, AuctionEvent.BidEvent event) {
|
||||
handler.callScript(EnumScriptType.AUCTION_BID, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onAuctionBuyout(PlayerDataScript handler, AuctionEvent.BuyoutEvent event) {
|
||||
handler.callScript(EnumScriptType.AUCTION_BUYOUT, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onAuctionCancel(PlayerDataScript handler, AuctionEvent.CancelEvent event) {
|
||||
handler.callScript(EnumScriptType.AUCTION_CANCEL, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onAuctionClaim(PlayerDataScript handler, AuctionEvent.ClaimEvent event) {
|
||||
handler.callScript(EnumScriptType.AUCTION_CLAIM, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.ParticlePacket;
|
||||
import kamkeel.npcs.network.packets.data.PlayerDataInfoPacket;
|
||||
@@ -807,7 +807,7 @@ public class NoppesUtilServer {
|
||||
|
||||
public static void sendCustomAbilitiesData(EntityPlayerMP player) {
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
kamkeel.npcs.controllers.data.ability.AbilityController controller = kamkeel.npcs.controllers.data.ability.AbilityController.Instance;
|
||||
AbilityController controller = AbilityController.Instance;
|
||||
if (controller != null) {
|
||||
int index = 0;
|
||||
for (String name : controller.getCustomAbilityNames()) {
|
||||
@@ -819,6 +819,15 @@ public class NoppesUtilServer {
|
||||
sendScrollData(player, map, EnumScrollData.CUSTOM_ABILITIES);
|
||||
}
|
||||
|
||||
public static void sendChainedAbilitiesData(EntityPlayerMP player) {
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
int index = 0;
|
||||
for (String name : AbilityController.Instance.getChainedAbilityNamesSet()) {
|
||||
map.put(name, index++);
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.CHAINED_ABILITIES);
|
||||
}
|
||||
|
||||
public static DialogOption setNpcDialog(int slot, int dialogId, EntityPlayer player) throws IOException {
|
||||
return setNpcDialog(slot, dialogId, getEditingNpc(player));
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -332,10 +332,10 @@ public class ScriptPlayerEventHandler {
|
||||
return;
|
||||
|
||||
if (event.player.worldObj instanceof WorldServer && event.player instanceof EntityPlayerMP) {
|
||||
// Cancel any executing ability on dimension change
|
||||
// Fully reset ability state on dimension change (no cooldown rollover)
|
||||
PlayerData playerData = PlayerData.get(event.player);
|
||||
if (playerData != null) {
|
||||
playerData.abilityData.interruptCurrentAbility();
|
||||
playerData.abilityData.resetOnDimensionChange();
|
||||
}
|
||||
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(event.player);
|
||||
|
||||
@@ -6,9 +6,9 @@ import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.controllers.data.action.ActionManager;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package noppes.npcs.ai;
|
||||
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityGuard;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
@@ -12,10 +12,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.CustomItems;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.blocks.tiles.TileWaypoint;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
|
||||
public class BlockWaypoint extends BlockContainer {
|
||||
|
||||
|
||||
@@ -7,17 +7,17 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
/**
|
||||
* Client-side cache for auction configuration synced from server.
|
||||
* Prevents client from using local ConfigMarket which may differ from server settings.
|
||||
*
|
||||
* <p>
|
||||
* IMPORTANT: This class is CLIENT-ONLY. Server-side NBT writing is done in
|
||||
* AuctionConfigSync to avoid @SideOnly crashes on dedicated servers.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class AuctionClientConfig {
|
||||
// Cached values from server
|
||||
private static long listingFee = 0;
|
||||
private static volatile long listingFee = 0;
|
||||
private static String currencyName = "Coins";
|
||||
private static int auctionDurationHours = 24;
|
||||
private static double minBidIncrement = 0.05;
|
||||
private static volatile double minBidIncrement = 0.05;
|
||||
private static int maxActiveListings = 8;
|
||||
private static int claimExpirationDays = 20;
|
||||
private static boolean auctionEnabled = false;
|
||||
@@ -38,7 +38,7 @@ public class AuctionClientConfig {
|
||||
claimExpirationDays = compound.getInteger("ClaimExpirationDays");
|
||||
|
||||
if (currencyName.isEmpty()) {
|
||||
currencyName = "Gold";
|
||||
currencyName = "Coins";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,11 +56,31 @@ public class AuctionClientConfig {
|
||||
}
|
||||
|
||||
// Getters
|
||||
public static boolean isAuctionEnabled() { return auctionEnabled; }
|
||||
public static long getListingFee() { return listingFee; }
|
||||
public static String getCurrencyName() { return currencyName; }
|
||||
public static int getAuctionDurationHours() { return auctionDurationHours; }
|
||||
public static double getMinBidIncrement() { return minBidIncrement; }
|
||||
public static int getMaxActiveListings() { return maxActiveListings; }
|
||||
public static int getClaimExpirationDays() { return claimExpirationDays; }
|
||||
public static boolean isAuctionEnabled() {
|
||||
return auctionEnabled;
|
||||
}
|
||||
|
||||
public static long getListingFee() {
|
||||
return listingFee;
|
||||
}
|
||||
|
||||
public static String getCurrencyName() {
|
||||
return currencyName;
|
||||
}
|
||||
|
||||
public static int getAuctionDurationHours() {
|
||||
return auctionDurationHours;
|
||||
}
|
||||
|
||||
public static double getMinBidIncrement() {
|
||||
return minBidIncrement;
|
||||
}
|
||||
|
||||
public static int getMaxActiveListings() {
|
||||
return maxActiveListings;
|
||||
}
|
||||
|
||||
public static int getClaimExpirationDays() {
|
||||
return claimExpirationDays;
|
||||
}
|
||||
}
|
||||
@@ -20,12 +20,12 @@ import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderLivingEvent;
|
||||
import net.minecraftforge.client.event.RenderPlayerEvent;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import noppes.npcs.client.gui.player.AuctionTooltipHandler;
|
||||
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
|
||||
import noppes.npcs.client.gui.hud.ClientHudManager;
|
||||
import noppes.npcs.client.gui.hud.CompassHudComponent;
|
||||
import noppes.npcs.client.gui.hud.EnumHudComponent;
|
||||
import noppes.npcs.client.gui.hud.QuestTrackingComponent;
|
||||
import noppes.npcs.client.gui.player.AuctionTooltipHandler;
|
||||
import noppes.npcs.client.renderer.MarkRenderer;
|
||||
import noppes.npcs.client.renderer.RenderCNPCPlayer;
|
||||
import noppes.npcs.constants.EnumAnimationPart;
|
||||
@@ -91,9 +91,9 @@ public class ClientEventHandler {
|
||||
// Block mouse movement during ability rotation lock.
|
||||
// Allow clicks (button >= 0) and scroll (dwheel != 0) to pass through.
|
||||
if (mc.theWorld != null && mc.thePlayer != null
|
||||
&& ClientAbilityState.shouldLockRotation()
|
||||
&& (event.dx != 0 || event.dy != 0)
|
||||
&& event.button == -1 && event.dwheel == 0) {
|
||||
&& ClientAbilityState.shouldLockRotation()
|
||||
&& (event.dx != 0 || event.dy != 0)
|
||||
&& event.button == -1 && event.dwheel == 0) {
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,27 @@ import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import kamkeel.npcs.addon.client.DBCClient;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityBeam;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityDisc;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityLaser;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityOrb;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilitySweeper;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityZone;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyDome;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyPanel;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergySlicer;
|
||||
import kamkeel.npcs.client.renderer.TelegraphRenderer;
|
||||
import kamkeel.npcs.client.renderer.lightning.LightningHandler;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
@@ -88,12 +107,12 @@ import noppes.npcs.client.gui.global.GuiNPCManageAnimations;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageBanks;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageDialogs;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageEffects;
|
||||
import noppes.npcs.client.gui.global.GuiNpcManageAbilities;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageFactions;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageLinked;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageQuest;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageTags;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageTransporters;
|
||||
import noppes.npcs.client.gui.global.GuiNpcManageAbilities;
|
||||
import noppes.npcs.client.gui.global.GuiNpcManageMagic;
|
||||
import noppes.npcs.client.gui.global.GuiNpcManageRecipes;
|
||||
import noppes.npcs.client.gui.global.GuiNpcQuestReward;
|
||||
@@ -105,15 +124,15 @@ import noppes.npcs.client.gui.mainmenu.GuiNpcAI;
|
||||
import noppes.npcs.client.gui.mainmenu.GuiNpcAdvanced;
|
||||
import noppes.npcs.client.gui.mainmenu.GuiNpcDisplay;
|
||||
import noppes.npcs.client.gui.mainmenu.GuiNpcStats;
|
||||
import noppes.npcs.client.gui.player.GuiAuctionBidding;
|
||||
import noppes.npcs.client.gui.player.GuiAuctionListing;
|
||||
import noppes.npcs.client.gui.player.GuiAuctionSell;
|
||||
import noppes.npcs.client.gui.player.GuiAuctionTrades;
|
||||
import noppes.npcs.client.gui.player.GuiBigSign;
|
||||
import noppes.npcs.client.gui.player.GuiCrate;
|
||||
import noppes.npcs.client.gui.player.GuiMailbox;
|
||||
import noppes.npcs.client.gui.player.GuiMailmanWrite;
|
||||
import noppes.npcs.client.gui.player.GuiNPCBankChest;
|
||||
import noppes.npcs.client.gui.player.GuiAuctionBidding;
|
||||
import noppes.npcs.client.gui.player.GuiAuctionTrades;
|
||||
import noppes.npcs.client.gui.player.GuiAuctionListing;
|
||||
import noppes.npcs.client.gui.player.GuiAuctionSell;
|
||||
import noppes.npcs.client.gui.player.GuiNPCTrader;
|
||||
import noppes.npcs.client.gui.player.GuiNpcAnvil;
|
||||
import noppes.npcs.client.gui.player.GuiNpcCarpentryBench;
|
||||
@@ -148,25 +167,6 @@ 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.RenderAbilityOrb;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityDisc;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityLaser;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityBeam;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilitySweeper;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityZone;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyDome;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyPanel;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergySlicer;
|
||||
import kamkeel.npcs.client.renderer.lightning.LightningHandler;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
||||
import noppes.npcs.client.renderer.blocks.BlockBannerRenderer;
|
||||
import noppes.npcs.client.renderer.blocks.BlockBarrelRenderer;
|
||||
import noppes.npcs.client.renderer.blocks.BlockBeamRenderer;
|
||||
@@ -202,13 +202,16 @@ import noppes.npcs.client.renderer.items.ItemShortLampRenderer;
|
||||
import noppes.npcs.client.renderer.items.ItemTallLampRenderer;
|
||||
import noppes.npcs.client.renderer.items.ItemToolRenderer;
|
||||
import noppes.npcs.client.renderer.items.ScriptedBlockItemRenderer;
|
||||
import noppes.npcs.client.ScriptClientConfig;
|
||||
import noppes.npcs.config.ConfigClient;
|
||||
import noppes.npcs.config.ConfigItem;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.config.StringCache;
|
||||
import noppes.npcs.constants.EnumGuiType;
|
||||
import noppes.npcs.containers.ContainerAnvilRepair;
|
||||
import noppes.npcs.containers.ContainerAuctionBidding;
|
||||
import noppes.npcs.containers.ContainerAuctionListing;
|
||||
import noppes.npcs.containers.ContainerAuctionSell;
|
||||
import noppes.npcs.containers.ContainerAuctionTrades;
|
||||
import noppes.npcs.containers.ContainerCarpentryBench;
|
||||
import noppes.npcs.containers.ContainerCrate;
|
||||
import noppes.npcs.containers.ContainerCustomGui;
|
||||
@@ -221,11 +224,6 @@ import noppes.npcs.containers.ContainerNPCFollower;
|
||||
import noppes.npcs.containers.ContainerNPCFollowerHire;
|
||||
import noppes.npcs.containers.ContainerNPCFollowerSetup;
|
||||
import noppes.npcs.containers.ContainerNPCInv;
|
||||
import noppes.npcs.containers.ContainerAuction;
|
||||
import noppes.npcs.containers.ContainerAuctionBidding;
|
||||
import noppes.npcs.containers.ContainerAuctionTrades;
|
||||
import noppes.npcs.containers.ContainerAuctionListing;
|
||||
import noppes.npcs.containers.ContainerAuctionSell;
|
||||
import noppes.npcs.containers.ContainerNPCTrader;
|
||||
import noppes.npcs.containers.ContainerNPCTraderSetup;
|
||||
import noppes.npcs.containers.ContainerNpcItemGiver;
|
||||
@@ -527,9 +525,7 @@ public class ClientProxy extends CommonProxy {
|
||||
abilityNpc.width = 0.6f;
|
||||
}
|
||||
return new GuiNpcManageAbilities(abilityNpc, npc != null);
|
||||
}
|
||||
|
||||
else if (gui == EnumGuiType.MainMenuGlobal)
|
||||
} else if (gui == EnumGuiType.MainMenuGlobal)
|
||||
return new GuiNPCGlobalMainMenu(npc);
|
||||
|
||||
else if (gui == EnumGuiType.MainMenuAI)
|
||||
|
||||
@@ -6,7 +6,7 @@ import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import kamkeel.npcs.client.renderer.lightning.LightningBolt;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.CheckPlayerValue;
|
||||
@@ -136,8 +136,8 @@ public class ClientTickHandler {
|
||||
|
||||
// Prevent jumping when locked (allow gravity only if not flying)
|
||||
if ((ClientAbilityState.movementLocked || ClientAbilityState.positionLocked)
|
||||
&& !ClientAbilityState.hasAbilityMovement
|
||||
&& !AbilityController.Instance.isPlayerFlying(mc.thePlayer)) {
|
||||
&& !ClientAbilityState.hasAbilityMovement
|
||||
&& !AbilityController.Instance.isPlayerFlying(mc.thePlayer)) {
|
||||
mc.thePlayer.motionY = Math.min(mc.thePlayer.motionY, 0);
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public class ClientTickHandler {
|
||||
// Block movement keys during ability lock (only when no GUI is open and world exists).
|
||||
// Non-movement keys (ESC, chat, inventory, etc.) always pass through.
|
||||
if (mc.theWorld != null && mc.currentScreen == null && keyDown
|
||||
&& ClientAbilityState.shouldSuppressMovementInput() && isMovementKey(key)) {
|
||||
&& ClientAbilityState.shouldSuppressMovementInput() && isMovementKey(key)) {
|
||||
// Unpress the keybind so vanilla doesn't process it
|
||||
KeyBinding.setKeyBindState(key, false);
|
||||
return;
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
/**
|
||||
* Client-side cache for script configuration synced from server.
|
||||
* Prevents client from using local ConfigScript which may differ from server settings.
|
||||
*
|
||||
* <p>
|
||||
* IMPORTANT: This class is CLIENT-ONLY. Server-side NBT writing is done in
|
||||
* ScriptConfigSync to avoid @SideOnly crashes on dedicated servers.
|
||||
*/
|
||||
@@ -46,16 +46,44 @@ public class ScriptClientConfig {
|
||||
}
|
||||
|
||||
// Setters for individual packet updates
|
||||
public static void setScriptingEnabled(boolean value) { scriptingEnabled = value; }
|
||||
public static void setRunLoadedScriptsFirst(boolean value) { runLoadedScriptsFirst = value; }
|
||||
public static void setGlobalPlayerScripts(boolean value) { globalPlayerScripts = value; }
|
||||
public static void setGlobalForgeScripts(boolean value) { globalForgeScripts = value; }
|
||||
public static void setGlobalNPCScripts(boolean value) { globalNPCScripts = value; }
|
||||
public static void setScriptingEnabled(boolean value) {
|
||||
scriptingEnabled = value;
|
||||
}
|
||||
|
||||
public static void setRunLoadedScriptsFirst(boolean value) {
|
||||
runLoadedScriptsFirst = value;
|
||||
}
|
||||
|
||||
public static void setGlobalPlayerScripts(boolean value) {
|
||||
globalPlayerScripts = value;
|
||||
}
|
||||
|
||||
public static void setGlobalForgeScripts(boolean value) {
|
||||
globalForgeScripts = value;
|
||||
}
|
||||
|
||||
public static void setGlobalNPCScripts(boolean value) {
|
||||
globalNPCScripts = value;
|
||||
}
|
||||
|
||||
// Getters
|
||||
public static boolean isScriptingEnabled() { return scriptingEnabled; }
|
||||
public static boolean isRunLoadedScriptsFirst() { return runLoadedScriptsFirst; }
|
||||
public static boolean isGlobalPlayerScripts() { return globalPlayerScripts; }
|
||||
public static boolean isGlobalForgeScripts() { return globalForgeScripts; }
|
||||
public static boolean isGlobalNPCScripts() { return globalNPCScripts; }
|
||||
public static boolean isScriptingEnabled() {
|
||||
return scriptingEnabled;
|
||||
}
|
||||
|
||||
public static boolean isRunLoadedScriptsFirst() {
|
||||
return runLoadedScriptsFirst;
|
||||
}
|
||||
|
||||
public static boolean isGlobalPlayerScripts() {
|
||||
return globalPlayerScripts;
|
||||
}
|
||||
|
||||
public static boolean isGlobalForgeScripts() {
|
||||
return globalForgeScripts;
|
||||
}
|
||||
|
||||
public static boolean isGlobalNPCScripts() {
|
||||
return globalNPCScripts;
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,9 @@ public class ZoneParticleFX extends EntityFX {
|
||||
private final boolean glow;
|
||||
|
||||
public ZoneParticleFX(World world, double x, double y, double z,
|
||||
double motionX, double motionY, double motionZ,
|
||||
float r, float g, float b, float alpha,
|
||||
float scale, int maxAge, float gravity, boolean glow) {
|
||||
double motionX, double motionY, double motionZ,
|
||||
float r, float g, float b, float alpha,
|
||||
float scale, int maxAge, float gravity, boolean glow) {
|
||||
super(world, x, y, z, 0, 0, 0);
|
||||
this.motionX = motionX;
|
||||
this.motionY = motionY;
|
||||
|
||||
@@ -74,10 +74,10 @@ public class GuiNpcMobSpawnerFullscreen extends GuiDirectory implements IGuiData
|
||||
this.posZ = posZ;
|
||||
|
||||
// Configure GuiDirectory layout percentages
|
||||
leftPanelPercent = 0.15f;
|
||||
leftPanelPercent = 0.15f;
|
||||
rightPanelPercent = 0.08f;
|
||||
minLeftPanelW = 120;
|
||||
minRightPanelW = 62;
|
||||
minLeftPanelW = 120;
|
||||
minRightPanelW = 62;
|
||||
|
||||
PacketClient.sendClient(new CloneAllTagsPacket());
|
||||
if (GuiNpcMobSpawner.showingClones == 2) {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package noppes.npcs.client.gui;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.dialog.DialogSavePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiMenuTopButton;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -3,10 +3,10 @@ package noppes.npcs.client.gui.advanced;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.Condition;
|
||||
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldBuilder;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.util.GuiMenuTopButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
@@ -75,11 +75,11 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
for (FieldDef def : fieldDefs) {
|
||||
String tab = def.getTab();
|
||||
if (tab != null
|
||||
&& !TAB_NAME_GENERAL.equals(tab)
|
||||
&& !TAB_NAME_TYPE.equals(tab)
|
||||
&& !TAB_NAME_TARGET.equals(tab)
|
||||
&& !TAB_NAME_EFFECTS.equals(tab)
|
||||
&& !customTabNames.contains(tab)) {
|
||||
&& !TAB_NAME_GENERAL.equals(tab)
|
||||
&& !TAB_NAME_TYPE.equals(tab)
|
||||
&& !TAB_NAME_TARGET.equals(tab)
|
||||
&& !TAB_NAME_EFFECTS.equals(tab)
|
||||
&& !customTabNames.contains(tab)) {
|
||||
customTabNames.add(tab);
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,9 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
// Commit any focused text field before rebuilding
|
||||
GuiNpcTextField.unfocus();
|
||||
|
||||
// Save scroll position before super clears scroll windows
|
||||
GuiScrollWindow oldSw = getScrollableGui(0);
|
||||
if (oldSw != null && activeTab < tabScrollY.length) {
|
||||
@@ -187,11 +190,21 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
}
|
||||
} else {
|
||||
switch (tabIndex) {
|
||||
case TAB_GENERAL: tabName = TAB_NAME_GENERAL; break;
|
||||
case TAB_TYPE: tabName = TAB_NAME_TYPE; break;
|
||||
case TAB_TARGET: tabName = TAB_NAME_TARGET; break;
|
||||
case TAB_EFFECTS: tabName = TAB_NAME_EFFECTS; break;
|
||||
default: tabName = TAB_NAME_TYPE; break;
|
||||
case TAB_GENERAL:
|
||||
tabName = TAB_NAME_GENERAL;
|
||||
break;
|
||||
case TAB_TYPE:
|
||||
tabName = TAB_NAME_TYPE;
|
||||
break;
|
||||
case TAB_TARGET:
|
||||
tabName = TAB_NAME_TARGET;
|
||||
break;
|
||||
case TAB_EFFECTS:
|
||||
tabName = TAB_NAME_EFFECTS;
|
||||
break;
|
||||
default:
|
||||
tabName = TAB_NAME_TYPE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,17 +277,36 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
int id = guibutton.id;
|
||||
|
||||
// Tab switching — fixed tabs
|
||||
if (id == 90) { activeTab = TAB_GENERAL; initGui(); return; }
|
||||
if (id == 91) { activeTab = TAB_TYPE; initGui(); return; }
|
||||
if (id == 92) { activeTab = TAB_TARGET; initGui(); return; }
|
||||
if (id == 93) { activeTab = TAB_EFFECTS; initGui(); return; }
|
||||
if (id == 90) {
|
||||
activeTab = TAB_GENERAL;
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (id == 91) {
|
||||
activeTab = TAB_TYPE;
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (id == 92) {
|
||||
activeTab = TAB_TARGET;
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (id == 93) {
|
||||
activeTab = TAB_EFFECTS;
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
// Custom tabs (94+)
|
||||
if (id >= 94 && id < 94 + customTabNames.size()) {
|
||||
activeTab = 4 + (id - 94);
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (id == -1000) { close(); return; }
|
||||
if (id == -1000) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Condition buttons (50-80)
|
||||
if (handleConditionButton(id)) return;
|
||||
|
||||
@@ -3,18 +3,15 @@ package noppes.npcs.client.gui.advanced;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Dialog asking the user whether to clone-and-modify (convert to inline) or modify the parent ability.
|
||||
*/
|
||||
public class SubGuiAbilityEditMode extends SubGuiInterface {
|
||||
public class SubGuiAbilityEditMode extends SubGuiSimpleChoice {
|
||||
|
||||
public static final int MODE_CLONE_MODIFY = 0;
|
||||
public static final int MODE_MODIFY_PARENT = 1;
|
||||
|
||||
private int result = -1;
|
||||
|
||||
public SubGuiAbilityEditMode() {
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
@@ -39,18 +36,13 @@ public class SubGuiAbilityEditMode extends SubGuiInterface {
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (guibutton.id == 0) {
|
||||
result = MODE_CLONE_MODIFY;
|
||||
setResult(MODE_CLONE_MODIFY);
|
||||
close();
|
||||
} else if (guibutton.id == 1) {
|
||||
result = MODE_MODIFY_PARENT;
|
||||
setResult(MODE_MODIFY_PARENT);
|
||||
close();
|
||||
} else if (guibutton.id == 2) {
|
||||
result = -1;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
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.CustomAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilityGetPacket;
|
||||
|
||||
@@ -3,18 +3,15 @@ package noppes.npcs.client.gui.advanced;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Dialog asking the user whether to Clone (inline copy) or Reference the loaded ability.
|
||||
*/
|
||||
public class SubGuiAbilityLoadMode extends SubGuiInterface {
|
||||
public class SubGuiAbilityLoadMode extends SubGuiSimpleChoice {
|
||||
|
||||
public static final int MODE_CLONE = 0;
|
||||
public static final int MODE_REFERENCE = 1;
|
||||
|
||||
private int result = -1;
|
||||
|
||||
public SubGuiAbilityLoadMode() {
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
@@ -39,18 +36,13 @@ public class SubGuiAbilityLoadMode extends SubGuiInterface {
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (guibutton.id == 0) {
|
||||
result = MODE_CLONE;
|
||||
setResult(MODE_CLONE);
|
||||
close();
|
||||
} else if (guibutton.id == 1) {
|
||||
result = MODE_REFERENCE;
|
||||
setResult(MODE_REFERENCE);
|
||||
close();
|
||||
} else if (guibutton.id == 2) {
|
||||
result = -1;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface implements ISubGui
|
||||
private final Ability ability;
|
||||
private final IAbilityConfigCallback callback;
|
||||
private final Set<String> existingNames;
|
||||
private boolean saved = false;
|
||||
|
||||
public SubGuiAbilitySaveConfirm(Ability ability) {
|
||||
this(ability, null, null);
|
||||
@@ -68,6 +69,7 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface implements ISubGui
|
||||
}
|
||||
|
||||
private void doSave() {
|
||||
saved = true;
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
|
||||
if (callback != null) {
|
||||
callback.onAbilitySaved(ability);
|
||||
@@ -75,6 +77,10 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface implements ISubGui
|
||||
close();
|
||||
}
|
||||
|
||||
public boolean wasSaved() {
|
||||
return saved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiDuplicateNameConfirm) {
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitiesGetPacket;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Simple ability name picker. Shows all abilities (custom + built-in) in a
|
||||
* single scroll list with search. Returns the selected ability name.
|
||||
*/
|
||||
public class SubGuiAbilitySelect extends SubGuiInterface implements ICustomScrollListener, IScrollData {
|
||||
|
||||
private GuiCustomScroll scroll;
|
||||
private HashMap<String, Integer> customData = new HashMap<>();
|
||||
private HashMap<String, Integer> builtInData = new HashMap<>();
|
||||
private String selectedName = null;
|
||||
private String search = "";
|
||||
|
||||
public SubGuiAbilitySelect() {
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
ySize = 216;
|
||||
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 5;
|
||||
|
||||
addLabel(new GuiNpcLabel(0, "ability.select", guiLeft + 10, y));
|
||||
y += 14;
|
||||
|
||||
if (scroll == null) {
|
||||
scroll = new GuiCustomScroll(this, 0);
|
||||
scroll.setSize(200, 140);
|
||||
}
|
||||
scroll.guiLeft = guiLeft + 10;
|
||||
scroll.guiTop = y;
|
||||
scroll.setList(getFilteredList());
|
||||
if (selectedName != null) {
|
||||
scroll.setSelected(selectedName);
|
||||
}
|
||||
addScroll(scroll);
|
||||
|
||||
y += 143;
|
||||
|
||||
addTextField(new GuiNpcTextField(10, this, fontRendererObj, guiLeft + 10, y, 200, 20, search));
|
||||
|
||||
y += 24;
|
||||
|
||||
addButton(new GuiNpcButton(0, guiLeft + 10, y, 95, 20, "gui.select"));
|
||||
addButton(new GuiNpcButton(2, guiLeft + 115, y, 95, 20, "gui.cancel"));
|
||||
|
||||
getButton(0).setEnabled(selectedName != null);
|
||||
}
|
||||
|
||||
private List<String> getFilteredList() {
|
||||
HashMap<String, Integer> merged = new HashMap<>();
|
||||
merged.putAll(customData);
|
||||
merged.putAll(builtInData);
|
||||
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<>(merged.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String name : merged.keySet()) {
|
||||
if (name.toLowerCase().contains(search.toLowerCase())) {
|
||||
list.add(name);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
|
||||
if (id == 0 && selectedName != null) {
|
||||
close();
|
||||
} else if (id == 2) {
|
||||
selectedName = null;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
if (getTextField(10) != null && getTextField(10).isFocused()) {
|
||||
String newSearch = getTextField(10).getText();
|
||||
if (!search.equals(newSearch)) {
|
||||
search = newSearch;
|
||||
scroll.resetScroll();
|
||||
scroll.setList(getFilteredList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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()) {
|
||||
selectedName = selection;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||
if (type == EnumScrollData.CUSTOM_ABILITIES) {
|
||||
customData = data;
|
||||
} else if (type == EnumScrollData.BUILTIN_ABILITIES) {
|
||||
builtInData = data;
|
||||
}
|
||||
if (scroll != null) {
|
||||
scroll.setList(getFilteredList());
|
||||
if (selectedName != null) {
|
||||
scroll.setSelected(selectedName);
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(String selected) {
|
||||
this.selectedName = selected;
|
||||
if (scroll != null) {
|
||||
scroll.setSelected(selected);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected ability name after the dialog closes.
|
||||
* Returns null if cancelled.
|
||||
*/
|
||||
public String getSelectedName() {
|
||||
return selectedName;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
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.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Selector for chained ability presets. Lists chain names from synced data.
|
||||
* Returns the selected chain name via {@link #getSelectedName()}.
|
||||
*/
|
||||
public class SubGuiChainSelect extends SubGuiInterface implements ICustomScrollListener {
|
||||
|
||||
private GuiCustomScroll scroll;
|
||||
private String selectedName = null;
|
||||
|
||||
public SubGuiChainSelect() {
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
ySize = 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 5;
|
||||
addLabel(new GuiNpcLabel(0, "ability.loadChain", guiLeft + 10, y));
|
||||
y += 14;
|
||||
|
||||
List<String> names = getChainNames();
|
||||
|
||||
if (scroll == null) {
|
||||
scroll = new GuiCustomScroll(this, 0);
|
||||
scroll.setSize(200, 130);
|
||||
}
|
||||
scroll.guiLeft = guiLeft + 10;
|
||||
scroll.guiTop = y;
|
||||
scroll.setList(names);
|
||||
if (selectedName != null) {
|
||||
scroll.setSelected(selectedName);
|
||||
}
|
||||
addScroll(scroll);
|
||||
|
||||
y += 133;
|
||||
addButton(new GuiNpcButton(0, guiLeft + 10, y, 95, 20, "gui.select"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 115, y, 95, 20, "gui.cancel"));
|
||||
getButton(0).setEnabled(selectedName != null);
|
||||
}
|
||||
|
||||
private List<String> getChainNames() {
|
||||
Set<String> names = AbilityController.Instance.getChainedAbilityNamesSet();
|
||||
return new ArrayList<>(names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (guibutton.id == 0 && selectedName != null) {
|
||||
close();
|
||||
} else if (guibutton.id == 1) {
|
||||
selectedName = null;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll.id == 0) {
|
||||
selectedName = guiCustomScroll.getSelected();
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll.id == 0 && selection != null && !selection.isEmpty()) {
|
||||
selectedName = selection;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public String getSelectedName() {
|
||||
return selectedName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,851 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityAction;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.ChainedAbilityEntry;
|
||||
import kamkeel.npcs.controllers.data.ability.Condition;
|
||||
import kamkeel.npcs.controllers.data.ability.IChainedAbilityFieldProvider;
|
||||
import kamkeel.npcs.controllers.data.ability.UserType;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitySavePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.builder.GuiFieldBuilder;
|
||||
import noppes.npcs.client.gui.util.GuiMenuTopButton;
|
||||
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.GuiScrollWindow;
|
||||
import noppes.npcs.client.gui.util.IAbilityConfigCallback;
|
||||
import noppes.npcs.client.gui.util.IChainedAbilityConfigCallback;
|
||||
import noppes.npcs.client.gui.util.ISubGuiListener;
|
||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* SubGui for editing a {@link ChainedAbility}.
|
||||
* Core tabs: General, Entries, Conditions.
|
||||
* Additional tabs are injected dynamically by {@link IChainedAbilityFieldProvider}s.
|
||||
*/
|
||||
public class SubGuiChainedAbilityConfig extends SubGuiInterface implements ITextfieldListener, ISubGuiListener, IAbilityConfigCallback {
|
||||
|
||||
// ── Declarative field ID ranges ──────────────────────────────────────────
|
||||
private static final int DECLARATIVE_ID_START = 1000;
|
||||
private static final int CLEAR_ID_START = 2000;
|
||||
private static final int LABEL_ID_START = 3000;
|
||||
|
||||
// ── Tab constants (core tabs) ────────────────────────────────────────────
|
||||
private static final int TAB_GENERAL = 0;
|
||||
private static final int TAB_ENTRIES = 1;
|
||||
private static final int TAB_TARGET = 2;
|
||||
private static final int CORE_TAB_COUNT = 3;
|
||||
|
||||
// ── Tab button IDs ────────────────────────────────────────────────────────
|
||||
private static final int BTN_TAB_GENERAL = 90;
|
||||
private static final int BTN_TAB_ENTRIES = 91;
|
||||
private static final int BTN_TAB_TARGET = 92;
|
||||
private static final int BTN_TAB_EXTRA_BASE = 93;
|
||||
private static final int BTN_CLOSE = -1000;
|
||||
|
||||
// ── Entries tab: per-entry ID encoding ─────────────────────────────────────
|
||||
// Actual ID = ENTRY_BASE + i * ENTRY_STRIDE + offset
|
||||
// offset 0 = name/select button, 1 = delay text field, 2 = up, 3 = down, 4 = delete
|
||||
private static final int ENTRY_BASE = 100;
|
||||
private static final int ENTRY_END = 200;
|
||||
private static final int ENTRY_STRIDE = 10;
|
||||
private static final int BTN_ADD_ENTRY = 200;
|
||||
|
||||
// ── Conditions tab: per-condition ID encoding ─────────────────────────────
|
||||
// Actual ID = COND_BASE + i * COND_STRIDE + offset
|
||||
// offset 0 = name/click, 1 = edit, 2 = delete
|
||||
private static final int COND_BASE = 50;
|
||||
private static final int COND_END = 80;
|
||||
private static final int COND_STRIDE = 10;
|
||||
private static final int BTN_ADD_COND = 80;
|
||||
|
||||
// ── Layout constants ──────────────────────────────────────────────────────
|
||||
private static final int L_LABEL_X = 5;
|
||||
private static final int ROW_H = 24;
|
||||
private static final int MAX_ENTRIES = 10;
|
||||
|
||||
private final ChainedAbility chain;
|
||||
private final IChainedAbilityConfigCallback callback;
|
||||
private final boolean npcContext;
|
||||
private final boolean readOnlyEntries;
|
||||
private final List<AbilityAction> npcSlots;
|
||||
private int activeTab = TAB_GENERAL;
|
||||
|
||||
private List<FieldDef> fieldDefs;
|
||||
private List<ChainedAbilityEntry> entries;
|
||||
private List<Condition> conditions;
|
||||
|
||||
// Dynamic tabs injected by field providers (e.g., "Icon")
|
||||
private List<String> extraTabs = new ArrayList<>();
|
||||
|
||||
private GuiFieldBuilder builder;
|
||||
private float[] tabScrollY;
|
||||
|
||||
// Entry editing
|
||||
private int editingEntryIndex = -1;
|
||||
private String pendingTypeId;
|
||||
private boolean editingParentAbility = false;
|
||||
|
||||
// Condition editing
|
||||
private int editingConditionIndex = -1;
|
||||
|
||||
// Save only on explicit X button, not ESC
|
||||
private boolean saveOnClose = false;
|
||||
|
||||
// Track consumed NPC slot indices for deferred removal on save
|
||||
private final List<Integer> consumedSlotIndices = new ArrayList<>();
|
||||
|
||||
public SubGuiChainedAbilityConfig(ChainedAbility chain, IChainedAbilityConfigCallback callback) {
|
||||
this(chain, callback, false, null, false);
|
||||
}
|
||||
|
||||
public SubGuiChainedAbilityConfig(ChainedAbility chain, IChainedAbilityConfigCallback callback,
|
||||
boolean npcContext, List<AbilityAction> npcSlots) {
|
||||
this(chain, callback, npcContext, npcSlots, false);
|
||||
}
|
||||
|
||||
public SubGuiChainedAbilityConfig(ChainedAbility chain, IChainedAbilityConfigCallback callback,
|
||||
boolean npcContext, List<AbilityAction> npcSlots, boolean readOnlyEntries) {
|
||||
this.chain = chain;
|
||||
this.callback = callback;
|
||||
this.npcContext = npcContext;
|
||||
this.readOnlyEntries = readOnlyEntries;
|
||||
this.npcSlots = npcSlots;
|
||||
this.entries = new ArrayList<>(chain.getEntries());
|
||||
this.conditions = new ArrayList<>(chain.getConditions());
|
||||
|
||||
buildFieldDefs();
|
||||
|
||||
setBackground("menubg.png", 217);
|
||||
xSize = 356;
|
||||
ySize = 200;
|
||||
}
|
||||
|
||||
private void buildFieldDefs() {
|
||||
fieldDefs = new ArrayList<>();
|
||||
|
||||
fieldDefs.add(FieldDef.stringField("gui.name", chain::getName, chain::setName).tab("General"));
|
||||
fieldDefs.add(FieldDef.stringField("gui.displayName", chain::getRawDisplayName, chain::setDisplayName).tab("General"));
|
||||
// Computed "Valid For" label (derived from child abilities)
|
||||
fieldDefs.add(FieldDef.labelField("ability.validFor", () -> {
|
||||
UserType ut = computeAllowedBy();
|
||||
return StatCollector.translateToLocal("ability.validFor") + ": \u00A7e" + StatCollector.translateToLocal("ability.userType." + ut.name());
|
||||
}).tab("General"));
|
||||
fieldDefs.add(FieldDef.boolField("gui.enabled", chain::isEnabled, chain::setEnabled).tab("General"));
|
||||
fieldDefs.add(FieldDef.intField("ability.weight", chain::getWeight, chain::setWeight).range(1, 100).tab("General"));
|
||||
fieldDefs.add(FieldDef.boolField("ability.windUpAll", chain::isWindUpAll, chain::setWindUpAll).tab("General"));
|
||||
fieldDefs.add(FieldDef.intField("ability.cooldown", chain::getCooldownTicks, chain::setCooldownTicks).range(0, 12000).tab("General"));
|
||||
|
||||
// ── Target tab ───────────────────────────────────────────────
|
||||
fieldDefs.add(FieldDef.row(
|
||||
FieldDef.floatField("ability.minRange", chain::getMinRange, chain::setMinRange).range(0, 64),
|
||||
FieldDef.floatField("ability.maxRange", chain::getMaxRange, chain::setMaxRange).range(0, 64)
|
||||
).tab("Target"));
|
||||
|
||||
// External field providers (e.g., DBC Addon injecting an "Icon" tab)
|
||||
if (AbilityController.Instance != null) {
|
||||
for (IChainedAbilityFieldProvider provider : AbilityController.Instance.getChainedFieldProviders()) {
|
||||
provider.addFieldDefinitions(chain, fieldDefs);
|
||||
}
|
||||
}
|
||||
|
||||
// Collect extra tab names from provider-injected fields
|
||||
Set<String> tabNames = new LinkedHashSet<>();
|
||||
for (FieldDef def : fieldDefs) {
|
||||
String tab = def.getTab();
|
||||
if (tab != null && !tab.isEmpty() && !"General".equals(tab) && !"Target".equals(tab)) {
|
||||
tabNames.add(tab);
|
||||
}
|
||||
}
|
||||
extraTabs = new ArrayList<>(tabNames);
|
||||
|
||||
// Size scroll array for all tabs
|
||||
tabScrollY = new float[CORE_TAB_COUNT + extraTabs.size()];
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// COMPUTED USERTYPE
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Compute the allowed UserType from the current (possibly modified) entries list.
|
||||
* Mirrors ChainedAbility.getAllowedBy() but uses the local entries.
|
||||
*/
|
||||
private UserType computeAllowedBy() {
|
||||
if (entries.isEmpty()) return UserType.BOTH;
|
||||
boolean allAllowPlayer = true;
|
||||
boolean allAllowNpc = true;
|
||||
for (ChainedAbilityEntry entry : entries) {
|
||||
Ability a = entry.resolve();
|
||||
if (a == null) continue;
|
||||
UserType ut = a.getAllowedBy();
|
||||
if (!ut.allowsPlayer()) allAllowPlayer = false;
|
||||
if (!ut.allowsNpc()) allAllowNpc = false;
|
||||
}
|
||||
if (allAllowPlayer && allAllowNpc) return UserType.BOTH;
|
||||
if (allAllowPlayer) return UserType.PLAYER_ONLY;
|
||||
if (allAllowNpc) return UserType.NPC_ONLY;
|
||||
return UserType.NPC_ONLY;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// INIT GUI
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
// Commit any focused text field before rebuilding
|
||||
GuiNpcTextField.unfocus();
|
||||
|
||||
// Save scroll position
|
||||
GuiScrollWindow oldSw = getScrollableGui(0);
|
||||
if (oldSw != null && activeTab < tabScrollY.length) {
|
||||
tabScrollY[activeTab] = oldSw.nextScrollY;
|
||||
}
|
||||
|
||||
super.initGui();
|
||||
|
||||
// Tab buttons — core tabs
|
||||
GuiMenuTopButton generalTab = new GuiMenuTopButton(BTN_TAB_GENERAL, guiLeft + 4, guiTop - 17, "menu.general");
|
||||
generalTab.active = (activeTab == TAB_GENERAL);
|
||||
addTopButton(generalTab);
|
||||
|
||||
GuiMenuTopButton entriesTab = new GuiMenuTopButton(BTN_TAB_ENTRIES, generalTab, "ability.entries");
|
||||
entriesTab.active = (activeTab == TAB_ENTRIES);
|
||||
addTopButton(entriesTab);
|
||||
|
||||
GuiMenuTopButton targetTab = new GuiMenuTopButton(BTN_TAB_TARGET, entriesTab, "script.target");
|
||||
targetTab.active = (activeTab == TAB_TARGET);
|
||||
addTopButton(targetTab);
|
||||
|
||||
// Dynamic extra tabs from field providers
|
||||
GuiMenuTopButton prevTab = targetTab;
|
||||
for (int i = 0; i < extraTabs.size(); i++) {
|
||||
int tabIndex = CORE_TAB_COUNT + i;
|
||||
GuiMenuTopButton extraTab = new GuiMenuTopButton(BTN_TAB_EXTRA_BASE + i, prevTab, extraTabs.get(i));
|
||||
extraTab.active = (activeTab == tabIndex);
|
||||
addTopButton(extraTab);
|
||||
prevTab = extraTab;
|
||||
}
|
||||
|
||||
GuiMenuTopButton closeBtn = new GuiMenuTopButton(BTN_CLOSE, guiLeft + xSize - 22, guiTop - 17, "X");
|
||||
addTopButton(closeBtn);
|
||||
|
||||
// Scroll window dimensions
|
||||
int swX = guiLeft + 4;
|
||||
int swY = guiTop + 5;
|
||||
int swW = xSize - 8;
|
||||
int swH = ySize - 10;
|
||||
|
||||
if (activeTab == TAB_GENERAL) {
|
||||
buildFieldDefTab("General", swX, swY, swW, swH);
|
||||
} else if (activeTab == TAB_ENTRIES) {
|
||||
buildEntriesTab(swX, swY, swW, swH);
|
||||
} else if (activeTab == TAB_TARGET) {
|
||||
buildTargetTab(swX, swY, swW, swH);
|
||||
} else if (activeTab >= CORE_TAB_COUNT) {
|
||||
int extraIndex = activeTab - CORE_TAB_COUNT;
|
||||
if (extraIndex < extraTabs.size()) {
|
||||
buildFieldDefTab(extraTabs.get(extraIndex), swX, swY, swW, swH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// FIELDDEF-BASED TAB (General + dynamic provider tabs)
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
private void buildFieldDefTab(String tabName, int swX, int swY, int swW, int swH) {
|
||||
List<FieldDef> tabFields = new ArrayList<>();
|
||||
for (FieldDef def : fieldDefs) {
|
||||
if (tabName.equals(def.getTab()) && def.isVisible()) {
|
||||
tabFields.add(def);
|
||||
}
|
||||
}
|
||||
|
||||
builder = new GuiFieldBuilder(this, fontRendererObj);
|
||||
builder.startIds(DECLARATIVE_ID_START, CLEAR_ID_START, LABEL_ID_START);
|
||||
builder.startY(5);
|
||||
|
||||
GuiScrollWindow sw = builder.buildScrollWindow(tabFields, swX, swY, swW, swH);
|
||||
restoreScroll(sw);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// ENTRIES TAB
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
private void buildEntriesTab(int swX, int swY, int swW, int swH) {
|
||||
GuiScrollWindow sw = new GuiScrollWindow(this, swX, swY, swW, swH, 0);
|
||||
sw.backgroundColor = 0x88000000;
|
||||
addScrollableGui(0, sw);
|
||||
|
||||
int y = 5;
|
||||
int labelCounter = 0;
|
||||
|
||||
for (int i = 0; i < entries.size() && i < MAX_ENTRIES; i++) {
|
||||
ChainedAbilityEntry entry = entries.get(i);
|
||||
|
||||
// Index label
|
||||
sw.addLabel(new GuiNpcLabel(labelCounter++, (i + 1) + ".", L_LABEL_X, y + 5, 0xFFFFFF));
|
||||
|
||||
// Ability reference/inline button
|
||||
String btnLabel;
|
||||
if (entry.isInline()) {
|
||||
Ability a = entry.getInlineAbility();
|
||||
btnLabel = a != null ? a.getDisplayName() : "\u00A7cEmpty";
|
||||
} else {
|
||||
String refName = entry.getAbilityReference();
|
||||
if (refName == null || refName.isEmpty()) {
|
||||
btnLabel = StatCollector.translateToLocal("gui.select") + "...";
|
||||
} else {
|
||||
Ability resolved = entry.resolve();
|
||||
btnLabel = "\u00A7e> " + (resolved != null ? resolved.getDisplayName() : refName);
|
||||
}
|
||||
}
|
||||
GuiNpcButton entryBtn = new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE, L_LABEL_X + 15, y, 140, 20, btnLabel);
|
||||
if (readOnlyEntries) {
|
||||
entryBtn.setEnabled(false);
|
||||
}
|
||||
sw.addButton(entryBtn);
|
||||
|
||||
if (!readOnlyEntries) {
|
||||
// Delay label + field
|
||||
sw.addLabel(new GuiNpcLabel(labelCounter++, "ability.delay", L_LABEL_X + 160, y + 5, 0xAAAAAA));
|
||||
GuiNpcTextField delayField = new GuiNpcTextField(ENTRY_BASE + i * ENTRY_STRIDE + 1, this, fontRendererObj,
|
||||
L_LABEL_X + 195, y, 40, 20, String.valueOf(entry.getDelayTicks()));
|
||||
delayField.setIntegersOnly();
|
||||
delayField.setMinMaxDefault(0, 6000, 0);
|
||||
sw.addTextField(delayField);
|
||||
|
||||
// Up button
|
||||
if (i > 0) {
|
||||
sw.addButton(new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE + 2, L_LABEL_X + 240, y, 20, 20, "\u2191"));
|
||||
}
|
||||
|
||||
// Down button
|
||||
if (i < entries.size() - 1) {
|
||||
sw.addButton(new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE + 3, L_LABEL_X + 263, y, 20, 20, "\u2193"));
|
||||
}
|
||||
|
||||
// Delete button
|
||||
sw.addButton(new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE + 4, L_LABEL_X + 288, y, 20, 20, "X"));
|
||||
} else {
|
||||
// Read-only: show delay as label only
|
||||
int delay = entry.getDelayTicks();
|
||||
if (delay > 0) {
|
||||
sw.addLabel(new GuiNpcLabel(labelCounter++, delay + "t", L_LABEL_X + 165, y + 5, 0x888888));
|
||||
}
|
||||
}
|
||||
|
||||
y += ROW_H;
|
||||
}
|
||||
|
||||
// Add entry button (hidden in read-only mode)
|
||||
if (!readOnlyEntries && entries.size() < MAX_ENTRIES) {
|
||||
sw.addButton(new GuiNpcButton(BTN_ADD_ENTRY, L_LABEL_X, y, 80, 20, "gui.add"));
|
||||
y += ROW_H;
|
||||
}
|
||||
|
||||
sw.maxScrollY = Math.max(y - swH, 0);
|
||||
restoreScroll(sw);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// TARGET TAB (FieldDef fields + conditions list)
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
private void buildTargetTab(int swX, int swY, int swW, int swH) {
|
||||
// Build FieldDef fields (ranges, Valid For) first
|
||||
List<FieldDef> tabFields = new ArrayList<>();
|
||||
for (FieldDef def : fieldDefs) {
|
||||
if ("Target".equals(def.getTab()) && def.isVisible()) {
|
||||
tabFields.add(def);
|
||||
}
|
||||
}
|
||||
|
||||
builder = new GuiFieldBuilder(this, fontRendererObj);
|
||||
builder.startIds(DECLARATIVE_ID_START, CLEAR_ID_START, LABEL_ID_START);
|
||||
builder.startY(5);
|
||||
|
||||
GuiScrollWindow sw = builder.buildScrollWindow(tabFields, swX, swY, swW, swH);
|
||||
|
||||
// Append conditions list below the FieldDef fields
|
||||
int y = builder.getLastBuildY();
|
||||
int condY = renderConditions(sw, y, builder.getNextLabelId());
|
||||
sw.maxScrollY = Math.max(condY - swH, 0);
|
||||
|
||||
restoreScroll(sw);
|
||||
}
|
||||
|
||||
private int renderConditions(GuiScrollWindow sw, int y, int labelCounter) {
|
||||
y += 3;
|
||||
sw.addLabel(new GuiNpcLabel(labelCounter, "ability.conditions", L_LABEL_X, y + 2, 0xFFFF55));
|
||||
y += 15;
|
||||
|
||||
for (int i = 0; i < conditions.size() && i < 3; i++) {
|
||||
Condition cond = conditions.get(i);
|
||||
String condName = getConditionDisplayName(cond);
|
||||
sw.addButton(new GuiNpcButton(COND_BASE + i * COND_STRIDE, L_LABEL_X, y, 140, 20, condName));
|
||||
sw.addButton(new GuiNpcButton(COND_BASE + i * COND_STRIDE + 1, L_LABEL_X + 145, y, 40, 20, "gui.edit"));
|
||||
sw.addButton(new GuiNpcButton(COND_BASE + i * COND_STRIDE + 2, L_LABEL_X + 190, y, 20, 20, "X"));
|
||||
y += 22;
|
||||
}
|
||||
|
||||
if (conditions.size() < 3) {
|
||||
sw.addButton(new GuiNpcButton(BTN_ADD_COND, L_LABEL_X, y, 50, 20, "gui.add"));
|
||||
y += ROW_H;
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
private String getConditionDisplayName(Condition cond) {
|
||||
if (cond == null) return "None";
|
||||
String typeId = cond.getTypeId();
|
||||
switch (typeId) {
|
||||
case "hp_above":
|
||||
return StatCollector.translateToLocal("condition.hp_above") + " " + (int) (getConditionThreshold(cond) * 100) + "%";
|
||||
case "hp_below":
|
||||
return StatCollector.translateToLocal("condition.hp_below") + " " + (int) (getConditionThreshold(cond) * 100) + "%";
|
||||
case "target_hp_above":
|
||||
return StatCollector.translateToLocal("condition.target_hp_above") + " " + (int) (getConditionThreshold(cond) * 100) + "%";
|
||||
case "target_hp_below":
|
||||
return StatCollector.translateToLocal("condition.target_hp_below") + " " + (int) (getConditionThreshold(cond) * 100) + "%";
|
||||
case "hit_count":
|
||||
Condition.ConditionHitCount hc = (Condition.ConditionHitCount) cond;
|
||||
return StatCollector.translateToLocal("condition.hit_count") + ": " + hc.getRequiredHits() + "/" + hc.getWithinTicks() + "t";
|
||||
default:
|
||||
return typeId;
|
||||
}
|
||||
}
|
||||
|
||||
private float getConditionThreshold(Condition cond) {
|
||||
NBTTagCompound nbt = cond.writeNBT();
|
||||
return nbt.hasKey("threshold") ? nbt.getFloat("threshold") : 0.5f;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// SCROLL RESTORE
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
private void restoreScroll(GuiScrollWindow sw) {
|
||||
if (activeTab < tabScrollY.length) {
|
||||
float restored = Math.min(tabScrollY[activeTab], sw.maxScrollY);
|
||||
sw.nextScrollY = restored;
|
||||
sw.scrollY = restored;
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// BUTTON EVENTS
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
|
||||
// Tab switching — core tabs
|
||||
if (id == BTN_TAB_GENERAL) {
|
||||
activeTab = TAB_GENERAL;
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (id == BTN_TAB_ENTRIES) {
|
||||
activeTab = TAB_ENTRIES;
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (id == BTN_TAB_TARGET) {
|
||||
activeTab = TAB_TARGET;
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (id == BTN_CLOSE) {
|
||||
saveOnClose = true;
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Tab switching — extra tabs
|
||||
if (id >= BTN_TAB_EXTRA_BASE && id < BTN_TAB_EXTRA_BASE + extraTabs.size()) {
|
||||
activeTab = CORE_TAB_COUNT + (id - BTN_TAB_EXTRA_BASE);
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
|
||||
// Entries tab
|
||||
if (activeTab == TAB_ENTRIES) {
|
||||
if (handleEntryButton(id)) return;
|
||||
}
|
||||
|
||||
// Target tab (includes conditions)
|
||||
if (activeTab == TAB_TARGET) {
|
||||
if (handleConditionButton(id)) return;
|
||||
}
|
||||
|
||||
// FieldDef-based tabs (General + extra tabs) — declarative field handling
|
||||
if (isFieldDefTab() && builder != null) {
|
||||
if (builder.handleButtonEvent(id, guibutton)) {
|
||||
if (!hasSubGui()) {
|
||||
initGui();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the current active tab uses the declarative FieldDef system.
|
||||
*/
|
||||
private boolean isFieldDefTab() {
|
||||
return activeTab == TAB_GENERAL || activeTab == TAB_TARGET || activeTab >= CORE_TAB_COUNT;
|
||||
}
|
||||
|
||||
private boolean handleEntryButton(int id) {
|
||||
// Add entry
|
||||
if (id == BTN_ADD_ENTRY) {
|
||||
if (entries.size() < MAX_ENTRIES) {
|
||||
// Both contexts use entry source selector; hide NPC option in global context
|
||||
setSubGui(new SubGuiChainedEntrySource(npcContext));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Per-entry buttons (ENTRY_BASE to ENTRY_END)
|
||||
if (id >= ENTRY_BASE && id < ENTRY_END) {
|
||||
int entryIndex = (id - ENTRY_BASE) / ENTRY_STRIDE;
|
||||
int action = (id - ENTRY_BASE) % ENTRY_STRIDE;
|
||||
|
||||
if (entryIndex < 0 || entryIndex >= entries.size()) return false;
|
||||
|
||||
switch (action) {
|
||||
case 0: // Entry name button — reference: clone/modify dialog; inline: edit config
|
||||
ChainedAbilityEntry clickedEntry = entries.get(entryIndex);
|
||||
if (clickedEntry.isReference()) {
|
||||
editingEntryIndex = entryIndex;
|
||||
setSubGui(new SubGuiAbilityEditMode());
|
||||
} else if (clickedEntry.isInline() && clickedEntry.getInlineAbility() != null) {
|
||||
editingEntryIndex = entryIndex;
|
||||
setSubGui(new SubGuiAbilityConfig(clickedEntry.getInlineAbility(), this));
|
||||
}
|
||||
return true;
|
||||
case 2: // Up
|
||||
if (entryIndex > 0) {
|
||||
ChainedAbilityEntry entry = entries.remove(entryIndex);
|
||||
entries.add(entryIndex - 1, entry);
|
||||
initGui();
|
||||
}
|
||||
return true;
|
||||
case 3: // Down
|
||||
if (entryIndex < entries.size() - 1) {
|
||||
ChainedAbilityEntry entry = entries.remove(entryIndex);
|
||||
entries.add(entryIndex + 1, entry);
|
||||
initGui();
|
||||
}
|
||||
return true;
|
||||
case 4: // Delete
|
||||
entries.remove(entryIndex);
|
||||
initGui();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean handleConditionButton(int id) {
|
||||
if (id >= COND_BASE && id < COND_END) {
|
||||
int condIndex = (id - COND_BASE) / COND_STRIDE;
|
||||
int action = (id - COND_BASE) % COND_STRIDE;
|
||||
if (action == 0 || action == 1) {
|
||||
if (condIndex < conditions.size()) {
|
||||
editingConditionIndex = condIndex;
|
||||
setSubGui(new SubGuiConditionEdit(conditions.get(condIndex)));
|
||||
}
|
||||
} else if (action == 2) {
|
||||
if (condIndex < conditions.size()) {
|
||||
conditions.remove(condIndex);
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (id == BTN_ADD_COND) {
|
||||
if (conditions.size() < 3) {
|
||||
editingConditionIndex = conditions.size();
|
||||
setSubGui(new SubGuiConditionEdit(null));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// TEXT FIELD EVENTS
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textField) {
|
||||
int id = textField.id;
|
||||
|
||||
// FieldDef-based tabs — declarative fields
|
||||
if (isFieldDefTab() && builder != null && id >= DECLARATIVE_ID_START) {
|
||||
if (builder.handleTextFieldEvent(id, textField)) {
|
||||
initGui();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Entries tab - delay fields (ENTRY_BASE + i * ENTRY_STRIDE + 1)
|
||||
if (activeTab == TAB_ENTRIES && id >= ENTRY_BASE + 1 && id < ENTRY_END) {
|
||||
int entryIndex = (id - ENTRY_BASE - 1) / ENTRY_STRIDE;
|
||||
if (entryIndex >= 0 && entryIndex < entries.size()) {
|
||||
entries.get(entryIndex).setDelayTicks(textField.getInteger());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// SUB GUI CLOSED
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
// FieldDef-based tabs — declarative sub-gui handling
|
||||
if (isFieldDefTab() && builder != null) {
|
||||
if (builder.handleSubGuiClosed(subgui)) {
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (subgui instanceof SubGuiAbilitySelect) {
|
||||
handleAbilitySelectClosed((SubGuiAbilitySelect) subgui);
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (subgui instanceof SubGuiChainedEntrySource) {
|
||||
handleEntrySourceClosed((SubGuiChainedEntrySource) subgui);
|
||||
return;
|
||||
}
|
||||
if (subgui instanceof SubGuiNpcSlotPicker) {
|
||||
handleSlotPickerClosed((SubGuiNpcSlotPicker) subgui);
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (subgui instanceof SubGuiAbilityVariantSelect) {
|
||||
handleVariantSelectClosed((SubGuiAbilityVariantSelect) subgui);
|
||||
if (!hasSubGui()) initGui();
|
||||
return;
|
||||
}
|
||||
if (subgui instanceof SubGuiAbilityTypeSelect) {
|
||||
handleTypeSelectClosed((SubGuiAbilityTypeSelect) subgui);
|
||||
if (!hasSubGui()) initGui();
|
||||
return;
|
||||
}
|
||||
if (subgui instanceof SubGuiAbilityEditMode) {
|
||||
handleEditModeClosed((SubGuiAbilityEditMode) subgui);
|
||||
if (!hasSubGui()) initGui();
|
||||
return;
|
||||
}
|
||||
if (subgui instanceof SubGuiAbilityConfig) {
|
||||
editingEntryIndex = -1;
|
||||
editingParentAbility = false;
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (subgui instanceof SubGuiConditionEdit) {
|
||||
handleConditionEditClosed((SubGuiConditionEdit) subgui);
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleAbilitySelectClosed(SubGuiAbilitySelect gui) {
|
||||
String selectedName = gui.getSelectedName();
|
||||
if (selectedName != null) {
|
||||
if (editingEntryIndex >= 0 && editingEntryIndex < entries.size()) {
|
||||
int delay = entries.get(editingEntryIndex).getDelayTicks();
|
||||
entries.set(editingEntryIndex, ChainedAbilityEntry.reference(selectedName, delay));
|
||||
} else {
|
||||
entries.add(ChainedAbilityEntry.reference(selectedName, 0));
|
||||
}
|
||||
}
|
||||
editingEntryIndex = -1;
|
||||
}
|
||||
|
||||
private void handleEntrySourceClosed(SubGuiChainedEntrySource gui) {
|
||||
int source = gui.getResult();
|
||||
if (source == SubGuiChainedEntrySource.SOURCE_NPC_SLOTS) {
|
||||
setSubGui(new SubGuiNpcSlotPicker(npcSlots));
|
||||
} else if (source == SubGuiChainedEntrySource.SOURCE_LOAD_PRESET) {
|
||||
setSubGui(new SubGuiAbilitySelect());
|
||||
} else if (source == SubGuiChainedEntrySource.SOURCE_CREATE_NEW) {
|
||||
setSubGui(new SubGuiAbilityTypeSelect());
|
||||
}
|
||||
// Don't initGui — we're opening another SubGui
|
||||
}
|
||||
|
||||
private void handleSlotPickerClosed(SubGuiNpcSlotPicker gui) {
|
||||
int slotIndex = gui.getSelectedIndex();
|
||||
if (slotIndex >= 0 && npcSlots != null && slotIndex < npcSlots.size()) {
|
||||
AbilityAction consumed = npcSlots.get(slotIndex);
|
||||
Ability ability = consumed.getAbility();
|
||||
if (ability != null) {
|
||||
if (consumed.getSlotType() == AbilityAction.SlotType.INLINE_ABILITY) {
|
||||
entries.add(ChainedAbilityEntry.inline(ability, 0));
|
||||
} else {
|
||||
entries.add(ChainedAbilityEntry.reference(consumed.getReferenceId(), 0));
|
||||
}
|
||||
consumedSlotIndices.add(slotIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleTypeSelectClosed(SubGuiAbilityTypeSelect gui) {
|
||||
String typeId = gui.getSelectedTypeId();
|
||||
if (typeId != null) {
|
||||
List<AbilityVariant> variants = AbilityController.Instance.getVariantsForType(typeId);
|
||||
if (variants.size() > 1) {
|
||||
pendingTypeId = typeId;
|
||||
setSubGui(new SubGuiAbilityVariantSelect(variants));
|
||||
return;
|
||||
}
|
||||
Ability newAbility = AbilityController.Instance.create(typeId);
|
||||
if (newAbility != null) {
|
||||
if (variants.size() == 1) {
|
||||
variants.get(0).apply(newAbility);
|
||||
}
|
||||
newAbility.setId(java.util.UUID.randomUUID().toString());
|
||||
entries.add(ChainedAbilityEntry.inline(newAbility, 0));
|
||||
editingEntryIndex = entries.size() - 1;
|
||||
setSubGui(new SubGuiAbilityConfig(newAbility, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleVariantSelectClosed(SubGuiAbilityVariantSelect gui) {
|
||||
int idx = gui.getSelectedIndex();
|
||||
if (idx >= 0 && pendingTypeId != null) {
|
||||
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
|
||||
if (newAbility != null) {
|
||||
gui.getVariants().get(idx).apply(newAbility);
|
||||
newAbility.setId(java.util.UUID.randomUUID().toString());
|
||||
entries.add(ChainedAbilityEntry.inline(newAbility, 0));
|
||||
editingEntryIndex = entries.size() - 1;
|
||||
pendingTypeId = null;
|
||||
setSubGui(new SubGuiAbilityConfig(newAbility, this));
|
||||
return;
|
||||
}
|
||||
}
|
||||
pendingTypeId = null;
|
||||
}
|
||||
|
||||
private void handleEditModeClosed(SubGuiAbilityEditMode gui) {
|
||||
int mode = gui.getResult();
|
||||
if (mode < 0 || editingEntryIndex < 0 || editingEntryIndex >= entries.size()) {
|
||||
editingEntryIndex = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
ChainedAbilityEntry entry = entries.get(editingEntryIndex);
|
||||
|
||||
if (mode == SubGuiAbilityEditMode.MODE_CLONE_MODIFY) {
|
||||
if (entry.convertToInline()) {
|
||||
Ability a = entry.getInlineAbility();
|
||||
if (a != null) {
|
||||
a.setId(java.util.UUID.randomUUID().toString());
|
||||
setSubGui(new SubGuiAbilityConfig(a, this));
|
||||
return;
|
||||
}
|
||||
}
|
||||
editingEntryIndex = -1;
|
||||
} else if (mode == SubGuiAbilityEditMode.MODE_MODIFY_PARENT) {
|
||||
Ability resolved = entry.resolve();
|
||||
if (resolved != null) {
|
||||
editingParentAbility = true;
|
||||
setSubGui(resolved.createConfigGui(this));
|
||||
return;
|
||||
}
|
||||
editingEntryIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleConditionEditClosed(SubGuiConditionEdit gui) {
|
||||
Condition result = gui.getResult();
|
||||
if (result != null && editingConditionIndex >= 0) {
|
||||
if (editingConditionIndex < conditions.size()) {
|
||||
conditions.set(editingConditionIndex, result);
|
||||
} else {
|
||||
conditions.add(result);
|
||||
}
|
||||
}
|
||||
editingConditionIndex = -1;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
// CLOSE / APPLY
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
public void onAbilitySaved(Ability ability) {
|
||||
if (editingParentAbility) {
|
||||
// Persist the global parent ability to the server
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
|
||||
editingParentAbility = false;
|
||||
return;
|
||||
}
|
||||
// Inline ability mutated in-place; entry already holds the reference
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (saveOnClose) {
|
||||
GuiNpcTextField.unfocus();
|
||||
applyToChain();
|
||||
callback.onChainedAbilitySaved(chain);
|
||||
}
|
||||
super.close();
|
||||
}
|
||||
|
||||
|
||||
private void applyToChain() {
|
||||
// Entries
|
||||
chain.getEntries().clear();
|
||||
for (ChainedAbilityEntry entry : entries) {
|
||||
chain.addEntry(entry);
|
||||
}
|
||||
|
||||
// Conditions
|
||||
chain.getConditions().clear();
|
||||
for (Condition c : conditions) {
|
||||
chain.getConditions().add(c);
|
||||
}
|
||||
|
||||
// Remove consumed NPC slots (descending order to preserve indices)
|
||||
if (npcSlots != null && !consumedSlotIndices.isEmpty()) {
|
||||
Collections.sort(consumedSlotIndices, Collections.reverseOrder());
|
||||
for (int idx : consumedSlotIndices) {
|
||||
if (idx < npcSlots.size()) {
|
||||
npcSlots.remove(idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
|
||||
/**
|
||||
* Choice dialog for adding an entry to a chain.
|
||||
* Options: From NPC Slots (optional), Load Preset, Create New.
|
||||
*/
|
||||
public class SubGuiChainedEntrySource extends SubGuiSimpleChoice {
|
||||
|
||||
public static final int SOURCE_NONE = -1;
|
||||
public static final int SOURCE_NPC_SLOTS = 0;
|
||||
public static final int SOURCE_LOAD_PRESET = 1;
|
||||
public static final int SOURCE_CREATE_NEW = 2;
|
||||
|
||||
private final boolean showNpcOption;
|
||||
|
||||
public SubGuiChainedEntrySource() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public SubGuiChainedEntrySource(boolean showNpcOption) {
|
||||
this.showNpcOption = showNpcOption;
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
ySize = showNpcOption ? 110 : 88;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 10;
|
||||
addLabel(new GuiNpcLabel(0, "ability.entrySource", guiLeft + 10, y));
|
||||
|
||||
y += 20;
|
||||
if (showNpcOption) {
|
||||
addButton(new GuiNpcButton(0, guiLeft + 10, y, 180, 20, "ability.fromNpc"));
|
||||
y += 22;
|
||||
}
|
||||
|
||||
addButton(new GuiNpcButton(1, guiLeft + 10, y, 180, 20, "ability.byReference"));
|
||||
|
||||
y += 22;
|
||||
addButton(new GuiNpcButton(2, guiLeft + 10, y, 180, 20, "ability.createNew"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
if (id >= 0 && id <= 2) {
|
||||
setResult(id);
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
|
||||
/**
|
||||
* Choice dialog for the Load button: Load Ability or Load Chain.
|
||||
*/
|
||||
public class SubGuiLoadTypeChoice extends SubGuiSimpleChoice {
|
||||
|
||||
public static final int RESULT_NONE = -1;
|
||||
public static final int RESULT_ABILITY = 0;
|
||||
public static final int RESULT_CHAIN = 1;
|
||||
|
||||
public SubGuiLoadTypeChoice() {
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
ySize = 80;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 10;
|
||||
addLabel(new GuiNpcLabel(0, "ability.loadType", guiLeft + 10, y));
|
||||
|
||||
y += 20;
|
||||
addButton(new GuiNpcButton(0, guiLeft + 10, y, 85, 20, "ability.loadAbility"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 105, y, 85, 20, "ability.loadChain"));
|
||||
|
||||
y += 24;
|
||||
addButton(new GuiNpcButton(2, guiLeft + 55, y, 90, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
if (id == 0 || id == 1) {
|
||||
setResult(id);
|
||||
close();
|
||||
} else if (id == 2) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityAction;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
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.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Picker for selecting an NPC ability slot to consume into a chain entry.
|
||||
* Shows standalone (non-chain) ability slots from the NPC's current list.
|
||||
*/
|
||||
public class SubGuiNpcSlotPicker extends SubGuiInterface implements ICustomScrollListener {
|
||||
|
||||
private final List<AbilityAction> npcSlots;
|
||||
private final List<Integer> validIndices = new ArrayList<>();
|
||||
private GuiCustomScroll scroll;
|
||||
private int selectedIndex = -1;
|
||||
|
||||
public SubGuiNpcSlotPicker(List<AbilityAction> npcSlots) {
|
||||
this.npcSlots = npcSlots;
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
ySize = 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 5;
|
||||
addLabel(new GuiNpcLabel(0, "ability.selectSlot", guiLeft + 10, y));
|
||||
y += 14;
|
||||
|
||||
List<String> displayList = new ArrayList<>();
|
||||
validIndices.clear();
|
||||
|
||||
for (int i = 0; i < npcSlots.size(); i++) {
|
||||
AbilityAction slot = npcSlots.get(i);
|
||||
// Only show standalone abilities (not chains)
|
||||
if (slot.isChain()) continue;
|
||||
|
||||
Ability ability = slot.getAbility();
|
||||
if (ability == null) continue;
|
||||
|
||||
String typeName = I18n.format(ability.getTypeId());
|
||||
String customName = ability.getName();
|
||||
String display;
|
||||
if (customName != null && !customName.isEmpty() && !customName.equals(typeName)) {
|
||||
display = (i + 1) + ". " + customName + " (" + typeName + ")";
|
||||
} else {
|
||||
display = (i + 1) + ". " + typeName;
|
||||
}
|
||||
|
||||
if (slot.isReference()) {
|
||||
display = "\u00A7e" + display + " (Ref)";
|
||||
}
|
||||
|
||||
displayList.add(display);
|
||||
validIndices.add(i);
|
||||
}
|
||||
|
||||
if (scroll == null) {
|
||||
scroll = new GuiCustomScroll(this, 0);
|
||||
scroll.setSize(200, 130);
|
||||
}
|
||||
scroll.guiLeft = guiLeft + 10;
|
||||
scroll.guiTop = y;
|
||||
scroll.setList(displayList);
|
||||
addScroll(scroll);
|
||||
|
||||
y += 133;
|
||||
addButton(new GuiNpcButton(0, guiLeft + 10, y, 95, 20, "gui.select"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 115, y, 95, 20, "gui.cancel"));
|
||||
getButton(0).setEnabled(selectedIndex >= 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (guibutton.id == 0 && selectedIndex >= 0) {
|
||||
close();
|
||||
} else if (guibutton.id == 1) {
|
||||
selectedIndex = -1;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll.id == 0 && guiCustomScroll.selected >= 0 && guiCustomScroll.selected < validIndices.size()) {
|
||||
selectedIndex = validIndices.get(guiCustomScroll.selected);
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll.id == 0 && selectedIndex >= 0) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
return selectedIndex;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
/**
|
||||
* Base class for simple choice dialogs that present a few buttons and return an int result.
|
||||
* Subclasses define their own layout in {@code initGui()} and call {@code setResult()} from {@code buttonEvent()}.
|
||||
* The parent reads the result via {@code getResult()} in {@code subGuiClosed()}.
|
||||
*
|
||||
* <p>Result is -1 by default (cancelled / no selection).</p>
|
||||
*/
|
||||
public abstract class SubGuiSimpleChoice extends SubGuiInterface {
|
||||
|
||||
private int result = -1;
|
||||
|
||||
protected final void setResult(int result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public int getResult() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,12 @@ package noppes.npcs.client.gui.builder;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.client.gui.SubGuiColorSelector;
|
||||
import noppes.npcs.client.gui.select.GuiAnimationSelection;
|
||||
import noppes.npcs.client.gui.select.GuiSoundSelection;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -175,8 +175,8 @@ public class FieldDef {
|
||||
}
|
||||
|
||||
public static FieldDef animSubGui(String label,
|
||||
Supplier<Integer> idGetter, Consumer<Integer> idSetter,
|
||||
Supplier<String> nameGetter, Consumer<String> nameSetter) {
|
||||
Supplier<Integer> idGetter, Consumer<Integer> idSetter,
|
||||
Supplier<String> nameGetter, Consumer<String> nameSetter) {
|
||||
return subGuiField(label,
|
||||
() -> new GuiAnimationSelection(idGetter.get(), nameGetter.get()),
|
||||
gui -> {
|
||||
@@ -202,7 +202,10 @@ public class FieldDef {
|
||||
}
|
||||
return "gui.none";
|
||||
})
|
||||
.clearable(() -> { idSetter.accept(-1); nameSetter.accept(""); });
|
||||
.clearable(() -> {
|
||||
idSetter.accept(-1);
|
||||
nameSetter.accept("");
|
||||
});
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -264,21 +267,65 @@ public class FieldDef {
|
||||
// GETTERS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public String getLabel() { return label; }
|
||||
public FieldType getType() { return type; }
|
||||
public String getTab() { return tab; }
|
||||
public boolean isVisible() { return visibleWhen.getAsBoolean(); }
|
||||
public boolean isEnabled() { return enabledWhen.getAsBoolean(); }
|
||||
public String getHoverText() { return hoverText; }
|
||||
public float getMin() { return min; }
|
||||
public float getMax() { return max; }
|
||||
public boolean hasRange() { return min != Float.NEGATIVE_INFINITY || max != Float.POSITIVE_INFINITY; }
|
||||
public Class<? extends Enum<?>> getEnumClass() { return enumClass; }
|
||||
public String[] getStringEnumValues() { return stringEnumValues; }
|
||||
public Supplier<SubGuiInterface> getSubGuiFactory() { return subGuiFactory; }
|
||||
public Consumer<SubGuiInterface> getSubGuiResultHandler() { return subGuiResultHandler; }
|
||||
public boolean hasClearAction() { return clearAction != null; }
|
||||
public Runnable getClearAction() { return clearAction; }
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public FieldType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getTab() {
|
||||
return tab;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return visibleWhen.getAsBoolean();
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabledWhen.getAsBoolean();
|
||||
}
|
||||
|
||||
public String getHoverText() {
|
||||
return hoverText;
|
||||
}
|
||||
|
||||
public float getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public float getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public boolean hasRange() {
|
||||
return min != Float.NEGATIVE_INFINITY || max != Float.POSITIVE_INFINITY;
|
||||
}
|
||||
|
||||
public Class<? extends Enum<?>> getEnumClass() {
|
||||
return enumClass;
|
||||
}
|
||||
|
||||
public String[] getStringEnumValues() {
|
||||
return stringEnumValues;
|
||||
}
|
||||
|
||||
public Supplier<SubGuiInterface> getSubGuiFactory() {
|
||||
return subGuiFactory;
|
||||
}
|
||||
|
||||
public Consumer<SubGuiInterface> getSubGuiResultHandler() {
|
||||
return subGuiResultHandler;
|
||||
}
|
||||
|
||||
public boolean hasClearAction() {
|
||||
return clearAction != null;
|
||||
}
|
||||
|
||||
public Runnable getClearAction() {
|
||||
return clearAction;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return getter != null ? getter.get() : null;
|
||||
@@ -305,8 +352,13 @@ public class FieldDef {
|
||||
return buttonTextColorSupplier != null ? buttonTextColorSupplier.get() : null;
|
||||
}
|
||||
|
||||
public FieldDef getLeftChild() { return leftChild; }
|
||||
public FieldDef getRightChild() { return rightChild; }
|
||||
public FieldDef getLeftChild() {
|
||||
return leftChild;
|
||||
}
|
||||
|
||||
public FieldDef getRightChild() {
|
||||
return rightChild;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// LIST MANIPULATION (for mod injection)
|
||||
@@ -356,7 +408,7 @@ public class FieldDef {
|
||||
*
|
||||
* @param fields The field list to modify
|
||||
* @param targetLabel The label of the field to modify
|
||||
* @param condition The condition to replace
|
||||
* @param condition The condition to replace
|
||||
* @return true if the target was found and the condition was modified
|
||||
*/
|
||||
public static boolean modifyVisibility(List<FieldDef> fields, String targetLabel, BooleanSupplier condition) {
|
||||
|
||||
@@ -69,13 +69,32 @@ public class GuiFieldBuilder {
|
||||
// CONFIG CHAINING
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public GuiFieldBuilder scrollWindowId(int id) { this.scrollWindowId = id; return this; }
|
||||
public GuiFieldBuilder contentRight(int v) { this.contentRight = v; return this; }
|
||||
public GuiFieldBuilder startIds(int widget, int clear, int label) {
|
||||
this.widgetId = widget; this.clearId = clear; this.labelId = label; return this;
|
||||
public GuiFieldBuilder scrollWindowId(int id) {
|
||||
this.scrollWindowId = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiFieldBuilder contentRight(int v) {
|
||||
this.contentRight = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiFieldBuilder startIds(int widget, int clear, int label) {
|
||||
this.widgetId = widget;
|
||||
this.clearId = clear;
|
||||
this.labelId = label;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiFieldBuilder startY(int y) {
|
||||
this.startY = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiFieldBuilder rowHeight(int h) {
|
||||
this.rowHeight = h;
|
||||
return this;
|
||||
}
|
||||
public GuiFieldBuilder startY(int y) { this.startY = y; return this; }
|
||||
public GuiFieldBuilder rowHeight(int h) { this.rowHeight = h; return this; }
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// BUILD
|
||||
@@ -98,6 +117,7 @@ public class GuiFieldBuilder {
|
||||
|
||||
/**
|
||||
* Processes all fields and adds widgets to the scroll window.
|
||||
*
|
||||
* @return the final Y position after all fields
|
||||
*/
|
||||
protected int build(List<FieldDef> fields) {
|
||||
@@ -173,8 +193,14 @@ public class GuiFieldBuilder {
|
||||
}
|
||||
|
||||
private int lastHandledIndex = -1;
|
||||
protected void setLastHandledIndex(int index) { this.lastHandledIndex = index; }
|
||||
protected int getLastHandledIndex() { return lastHandledIndex; }
|
||||
|
||||
protected void setLastHandledIndex(int index) {
|
||||
this.lastHandledIndex = index;
|
||||
}
|
||||
|
||||
protected int getLastHandledIndex() {
|
||||
return lastHandledIndex;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// FIELD RENDERING
|
||||
@@ -268,7 +294,10 @@ public class GuiFieldBuilder {
|
||||
String curVal = def.getStringEnumValue();
|
||||
int selected = 0;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (values[i].equals(curVal)) { selected = i; break; }
|
||||
if (values[i].equals(curVal)) {
|
||||
selected = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
GuiNpcButton btn = new GuiNpcButton(widgetId, fieldX, y, fieldW, 20, values, selected);
|
||||
if (!def.isEnabled()) btn.setEnabled(false);
|
||||
@@ -321,14 +350,21 @@ public class GuiFieldBuilder {
|
||||
protected int getFullFieldWidth(FieldDef def) {
|
||||
switch (def.getType()) {
|
||||
case FLOAT:
|
||||
case INT: return 60;
|
||||
case STRING: return 200;
|
||||
case BOOLEAN: return 50;
|
||||
case LABEL: return 60;
|
||||
case INT:
|
||||
return 60;
|
||||
case STRING:
|
||||
return 200;
|
||||
case BOOLEAN:
|
||||
return 50;
|
||||
case LABEL:
|
||||
return 60;
|
||||
case ENUM:
|
||||
case STRING_ENUM: return 120;
|
||||
case SUB_GUI: return def.hasClearAction() ? 175 : 200;
|
||||
default: return 80;
|
||||
case STRING_ENUM:
|
||||
return 120;
|
||||
case SUB_GUI:
|
||||
return def.hasClearAction() ? 175 : 200;
|
||||
default:
|
||||
return 80;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,7 +446,8 @@ public class GuiFieldBuilder {
|
||||
def.setValue(newVal);
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {}
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
return false;
|
||||
case INT:
|
||||
try {
|
||||
@@ -421,7 +458,8 @@ public class GuiFieldBuilder {
|
||||
def.setValue(newVal);
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {}
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
return false;
|
||||
case STRING:
|
||||
String newVal = field.getText();
|
||||
@@ -453,10 +491,27 @@ public class GuiFieldBuilder {
|
||||
// GETTERS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public Map<Integer, FieldDef> getButtonFieldMap() { return buttonFieldMap; }
|
||||
public Map<Integer, FieldDef> getTextFieldMap() { return textFieldMap; }
|
||||
public Map<Integer, FieldDef> getClearFieldMap() { return clearFieldMap; }
|
||||
public GuiScrollWindow getScrollWindow() { return sw; }
|
||||
public int getLastBuildY() { return lastBuildY; }
|
||||
public int getNextLabelId() { return labelId; }
|
||||
public Map<Integer, FieldDef> getButtonFieldMap() {
|
||||
return buttonFieldMap;
|
||||
}
|
||||
|
||||
public Map<Integer, FieldDef> getTextFieldMap() {
|
||||
return textFieldMap;
|
||||
}
|
||||
|
||||
public Map<Integer, FieldDef> getClearFieldMap() {
|
||||
return clearFieldMap;
|
||||
}
|
||||
|
||||
public GuiScrollWindow getScrollWindow() {
|
||||
return sw;
|
||||
}
|
||||
|
||||
public int getLastBuildY() {
|
||||
return lastBuildY;
|
||||
}
|
||||
|
||||
public int getNextLabelId() {
|
||||
return labelId;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
package noppes.npcs.client.gui.global;
|
||||
|
||||
import kamkeel.npcs.client.renderer.TelegraphRenderer;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.BuiltInAbilityGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.ChainedAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.ChainedAbilityGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.ChainedAbilityRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.ChainedAbilitySavePacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilityGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilityRemovePacket;
|
||||
@@ -16,10 +20,9 @@ import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityTypeSelect;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityVariantSelect;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiChainedAbilityConfig;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiDuplicateNameConfirm;
|
||||
import noppes.npcs.client.gui.util.AbilityPreviewExecutor;
|
||||
import noppes.npcs.client.gui.util.GuiAbilityInterface;
|
||||
@@ -29,6 +32,7 @@ import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.GuiTexturedButton;
|
||||
import noppes.npcs.client.gui.util.IAbilityConfigCallback;
|
||||
import noppes.npcs.client.gui.util.IChainedAbilityConfigCallback;
|
||||
import noppes.npcs.client.gui.util.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.IGuiData;
|
||||
import noppes.npcs.client.gui.util.IScrollData;
|
||||
@@ -46,7 +50,7 @@ import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Global GUI for managing saved ability presets with 3D preview.
|
||||
*
|
||||
* <p>
|
||||
* Features:
|
||||
* - Left side: 3D preview of NPC with ability effects
|
||||
* - Right side: Ability list with search
|
||||
@@ -54,8 +58,29 @@ import java.util.Vector;
|
||||
* - Toggle between Custom and Built-in ability views
|
||||
*/
|
||||
public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
implements ICustomScrollListener, ISubGuiListener, IAbilityConfigCallback,
|
||||
ITextfieldListener, GuiYesNoCallback, IScrollData, IGuiData {
|
||||
implements ICustomScrollListener, ISubGuiListener, IAbilityConfigCallback,
|
||||
IChainedAbilityConfigCallback, ITextfieldListener, GuiYesNoCallback,
|
||||
IScrollData, IGuiData {
|
||||
|
||||
// ── Button IDs ────────────────────────────────────────────────────────────
|
||||
private static final int BTN_REMOVE = 1;
|
||||
private static final int BTN_ADD = 2;
|
||||
private static final int BTN_TOGGLE_VIEW = 10;
|
||||
private static final int BTN_EDIT = 100;
|
||||
private static final int BTN_PREVIEW_PLAY = 91;
|
||||
private static final int BTN_PREVIEW_PAUSE = 92;
|
||||
private static final int BTN_PREVIEW_STOP = 93;
|
||||
|
||||
// ── TextField / Label IDs ─────────────────────────────────────────────────
|
||||
private static final int TF_SEARCH = 55;
|
||||
private static final int LBL_PREVIEW_STATUS = 90;
|
||||
|
||||
// ── Scroll IDs ────────────────────────────────────────────────────────────
|
||||
private static final int SCROLL_MAIN = 0;
|
||||
|
||||
// ── Confirm dialog IDs ────────────────────────────────────────────────────
|
||||
private static final int CONFIRM_REMOVE_ABILITY = 1;
|
||||
private static final int CONFIRM_REMOVE_CHAIN = 2;
|
||||
|
||||
// ==================== DATA ====================
|
||||
private GuiCustomScroll scroll;
|
||||
@@ -65,10 +90,18 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
private String search = "";
|
||||
private Ability selectedAbility = null;
|
||||
|
||||
// ==================== BUILT-IN TOGGLE ====================
|
||||
// ==================== VIEW MODE ====================
|
||||
// 0 = Custom, 1 = Built-in, 2 = Chained
|
||||
private int viewMode = 0;
|
||||
private boolean showingBuiltIn = false;
|
||||
private boolean showingChained = false;
|
||||
private boolean currentIsBuiltIn = false;
|
||||
|
||||
// ==================== CHAINED DATA ====================
|
||||
private HashMap<String, Integer> chainedData = new HashMap<>();
|
||||
private ChainedAbility selectedChain = null;
|
||||
private ChainedAbility pendingSaveChain = null;
|
||||
|
||||
// ==================== PENDING SAVE ====================
|
||||
private Ability pendingSaveAbility = null;
|
||||
private boolean pendingNewCreation = false;
|
||||
@@ -103,45 +136,51 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
// Toggle button — added FIRST to maintain stable buttonList index
|
||||
String toggleLabel = showingBuiltIn ? "gui.builtin" : "gui.custom";
|
||||
addButton(new GuiNpcButton(10, guiLeft + 368, guiTop + 52, 45, 20, toggleLabel));
|
||||
// Toggle button — cycles: Custom → Built-in → Chained
|
||||
String toggleLabel = showingChained ? "gui.chained" : (showingBuiltIn ? "gui.builtin" : "gui.custom");
|
||||
addButton(new GuiNpcButton(BTN_TOGGLE_VIEW, guiLeft + 368, guiTop + 52, 45, 20, toggleLabel));
|
||||
|
||||
if (!showingBuiltIn) {
|
||||
// Add button — only for custom view
|
||||
addButton(new GuiNpcButton(2, guiLeft + 368, guiTop + 8, 45, 20, "gui.add"));
|
||||
|
||||
// Remove button — only for custom view
|
||||
addButton(new GuiNpcButton(1, guiLeft + 368, guiTop + 30, 45, 20, "gui.remove"));
|
||||
getButton(1).setEnabled(selected != null && !selected.isEmpty() && customData.containsKey(selected));
|
||||
if (showingChained) {
|
||||
// Chained view buttons
|
||||
addButton(new GuiNpcButton(BTN_ADD, guiLeft + 368, guiTop + 8, 45, 20, "gui.add"));
|
||||
addButton(new GuiNpcButton(BTN_REMOVE, guiLeft + 368, guiTop + 30, 45, 20, "gui.remove"));
|
||||
getButton(BTN_REMOVE).setEnabled(selected != null && !selected.isEmpty() && chainedData.containsKey(selected));
|
||||
addButton(new GuiNpcButton(BTN_EDIT, guiLeft + 368, guiTop + 74, 45, 20, "gui.edit"));
|
||||
getButton(BTN_EDIT).setEnabled(selected != null && !selected.isEmpty() && selectedChain != null);
|
||||
} else if (!showingBuiltIn) {
|
||||
// Custom view buttons
|
||||
addButton(new GuiNpcButton(BTN_ADD, guiLeft + 368, guiTop + 8, 45, 20, "gui.add"));
|
||||
addButton(new GuiNpcButton(BTN_REMOVE, guiLeft + 368, guiTop + 30, 45, 20, "gui.remove"));
|
||||
getButton(BTN_REMOVE).setEnabled(selected != null && !selected.isEmpty() && customData.containsKey(selected));
|
||||
if (!currentIsBuiltIn) {
|
||||
addButton(new GuiNpcButton(BTN_EDIT, guiLeft + 368, guiTop + 74, 45, 20, "gui.edit"));
|
||||
getButton(BTN_EDIT).setEnabled(selected != null && !selected.isEmpty() && selectedAbility != null);
|
||||
}
|
||||
}
|
||||
|
||||
// Edit button — hidden when viewing built-in
|
||||
if (!showingBuiltIn && !currentIsBuiltIn) {
|
||||
addButton(new GuiNpcButton(100, guiLeft + 368, guiTop + 74, 45, 20, "gui.edit"));
|
||||
getButton(100).setEnabled(selected != null && !selected.isEmpty() && selectedAbility != null);
|
||||
}
|
||||
|
||||
// Scroll list of abilities (right side)
|
||||
// Scroll list (right side)
|
||||
if (scroll == null) {
|
||||
scroll = new GuiCustomScroll(this, 0);
|
||||
scroll = new GuiCustomScroll(this, SCROLL_MAIN);
|
||||
scroll.setSize(143, 185);
|
||||
}
|
||||
scroll.guiLeft = guiLeft + 220;
|
||||
scroll.guiTop = guiTop + 4;
|
||||
addScroll(scroll);
|
||||
|
||||
// Update scroll list
|
||||
scroll.setList(getSearchList());
|
||||
if (selected != null) {
|
||||
scroll.setSelected(selected);
|
||||
}
|
||||
|
||||
// Search bar
|
||||
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 220, guiTop + 192, 143, 20, search));
|
||||
addTextField(new GuiNpcTextField(TF_SEARCH, this, fontRendererObj, guiLeft + 220, guiTop + 192, 143, 20, search));
|
||||
|
||||
// Show ability info only if one is selected
|
||||
if (selectedAbility == null || selected == null) {
|
||||
// Check if we have something to preview
|
||||
if (showingChained) {
|
||||
if (selectedChain == null || selected == null || selectedChain.getEntries().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
} else if (selectedAbility == null || selected == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -154,22 +193,20 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
boolean isActive = previewExecutor.isActive();
|
||||
|
||||
if (!isPlaying || isPaused) {
|
||||
// Show Play button
|
||||
String statusKey = isPaused ? "animation.paused" : "animation.stopped";
|
||||
addLabel(new GuiNpcLabel(90, statusKey, guiLeft + playButtonOffsetX, guiTop + 198));
|
||||
addButton(new GuiTexturedButton(91, "", guiLeft + playButtonOffsetX + 70, guiTop + 192, 11, 20, animTexture, 18, 71));
|
||||
addLabel(new GuiNpcLabel(LBL_PREVIEW_STATUS, statusKey, guiLeft + playButtonOffsetX, guiTop + 198));
|
||||
addButton(new GuiTexturedButton(BTN_PREVIEW_PLAY, "", guiLeft + playButtonOffsetX + 70, guiTop + 192, 11, 20, animTexture, 18, 71));
|
||||
} else {
|
||||
// Show Pause button
|
||||
addLabel(new GuiNpcLabel(90, "animation.playing", guiLeft + playButtonOffsetX, guiTop + 198));
|
||||
addButton(new GuiTexturedButton(92, "", guiLeft + playButtonOffsetX + 70, guiTop + 192, 14, 20, animTexture, 0, 71));
|
||||
addLabel(new GuiNpcLabel(LBL_PREVIEW_STATUS, "animation.playing", guiLeft + playButtonOffsetX, guiTop + 198));
|
||||
addButton(new GuiTexturedButton(BTN_PREVIEW_PAUSE, "", guiLeft + playButtonOffsetX + 70, guiTop + 192, 14, 20, animTexture, 0, 71));
|
||||
}
|
||||
if (isActive) {
|
||||
// Show Stop button
|
||||
addButton(new GuiTexturedButton(93, "", guiLeft + playButtonOffsetX + 90, guiTop + 192, 14, 20, animTexture, 33, 71));
|
||||
addButton(new GuiTexturedButton(BTN_PREVIEW_STOP, "", guiLeft + playButtonOffsetX + 90, guiTop + 192, 14, 20, animTexture, 33, 71));
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, Integer> getCurrentData() {
|
||||
if (showingChained) return chainedData;
|
||||
return showingBuiltIn ? builtInData : customData;
|
||||
}
|
||||
|
||||
@@ -240,59 +277,94 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
int id = guibutton.id;
|
||||
|
||||
// Toggle between custom and built-in views
|
||||
if (id == 10) {
|
||||
showingBuiltIn = !showingBuiltIn;
|
||||
// Toggle: Custom → Built-in → Chained → Custom
|
||||
if (id == BTN_TOGGLE_VIEW) {
|
||||
if (!showingBuiltIn && !showingChained) {
|
||||
// Custom → Built-in
|
||||
showingBuiltIn = true;
|
||||
showingChained = false;
|
||||
} else if (showingBuiltIn) {
|
||||
// Built-in → Chained
|
||||
showingBuiltIn = false;
|
||||
showingChained = true;
|
||||
} else {
|
||||
// Chained → Custom
|
||||
showingChained = false;
|
||||
showingBuiltIn = false;
|
||||
}
|
||||
selected = null;
|
||||
selectedAbility = null;
|
||||
selectedChain = null;
|
||||
currentIsBuiltIn = false;
|
||||
search = "";
|
||||
previewExecutor.stop();
|
||||
if (scroll != null) {
|
||||
scroll.clear();
|
||||
}
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
if (showingChained) {
|
||||
PacketClient.sendClient(new ChainedAbilitiesGetPacket());
|
||||
} else {
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
}
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == 2 && !showingBuiltIn) {
|
||||
// Preview controls (shared across all views)
|
||||
if (id == BTN_PREVIEW_PLAY) {
|
||||
if (previewExecutor.isPaused()) {
|
||||
previewExecutor.play();
|
||||
} else if (showingChained && selectedChain != null) {
|
||||
previewExecutor.startChainPreview(selectedChain, npc);
|
||||
} else if (selectedAbility != null) {
|
||||
previewExecutor.startPreview(selectedAbility, npc);
|
||||
}
|
||||
initGui();
|
||||
return;
|
||||
} else if (id == BTN_PREVIEW_PAUSE) {
|
||||
previewExecutor.pause();
|
||||
initGui();
|
||||
return;
|
||||
} else if (id == BTN_PREVIEW_STOP) {
|
||||
previewExecutor.stop();
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
|
||||
if (showingChained) {
|
||||
if (id == BTN_ADD) {
|
||||
// New chained ability
|
||||
ChainedAbility newChain = new ChainedAbility("New Chain");
|
||||
setSubGui(new SubGuiChainedAbilityConfig(newChain, this));
|
||||
} else if (id == BTN_REMOVE && selected != null) {
|
||||
GuiYesNo guiyesno = new GuiYesNo(this, selected, StatCollector.translateToLocal("gui.delete"), CONFIRM_REMOVE_CHAIN);
|
||||
displayGuiScreen(guiyesno);
|
||||
} else if (id == BTN_EDIT && selectedChain != null) {
|
||||
previewExecutor.stop();
|
||||
setSubGui(new SubGuiChainedAbilityConfig(selectedChain, this));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == BTN_ADD && !showingBuiltIn) {
|
||||
// Add — open type selection
|
||||
setSubGui(new SubGuiAbilityTypeSelect());
|
||||
} else if (id == 1 && !showingBuiltIn && selected != null) {
|
||||
GuiYesNo guiyesno = new GuiYesNo(this, selected, StatCollector.translateToLocal("gui.delete"), 1);
|
||||
} else if (id == BTN_REMOVE && !showingBuiltIn && selected != null) {
|
||||
GuiYesNo guiyesno = new GuiYesNo(this, selected, StatCollector.translateToLocal("gui.delete"), CONFIRM_REMOVE_ABILITY);
|
||||
displayGuiScreen(guiyesno);
|
||||
} else if (id == 100 && !showingBuiltIn && !currentIsBuiltIn && selectedAbility != null) {
|
||||
} else if (id == BTN_EDIT && !showingBuiltIn && !currentIsBuiltIn && selectedAbility != null) {
|
||||
// Edit
|
||||
previewExecutor.stop();
|
||||
setSubGui(selectedAbility.createConfigGui(this));
|
||||
} else if (id == 91) {
|
||||
// Play button
|
||||
if (selectedAbility != null) {
|
||||
if (previewExecutor.isPaused()) {
|
||||
previewExecutor.play();
|
||||
} else {
|
||||
previewExecutor.startPreview(selectedAbility, npc);
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
} else if (id == 92) {
|
||||
// Pause button
|
||||
previewExecutor.pause();
|
||||
initGui();
|
||||
} else if (id == 93) {
|
||||
// Stop button
|
||||
previewExecutor.stop();
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
if (getTextField(55) != null && getTextField(55).isFocused()) {
|
||||
if (!search.equals(getTextField(55).getText())) {
|
||||
search = getTextField(55).getText();
|
||||
if (getTextField(TF_SEARCH) != null && getTextField(TF_SEARCH).isFocused()) {
|
||||
if (!search.equals(getTextField(TF_SEARCH).getText())) {
|
||||
search = getTextField(TF_SEARCH).getText();
|
||||
scroll.resetScroll();
|
||||
scroll.setList(getSearchList());
|
||||
}
|
||||
@@ -301,13 +373,15 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
|
||||
if (scroll.id == 0) {
|
||||
if (scroll.id == SCROLL_MAIN) {
|
||||
String newSelection = scroll.getSelected();
|
||||
if (newSelection != null && !newSelection.equals(selected)) {
|
||||
previewExecutor.stop();
|
||||
selected = newSelection;
|
||||
|
||||
if (showingBuiltIn) {
|
||||
if (showingChained) {
|
||||
PacketClient.sendClient(new ChainedAbilityGetPacket(selected));
|
||||
} else if (showingBuiltIn) {
|
||||
currentIsBuiltIn = true;
|
||||
PacketClient.sendClient(new BuiltInAbilityGetPacket(selected));
|
||||
} else {
|
||||
@@ -320,9 +394,10 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (scroll.id == 0 && selection != null && !selection.isEmpty()) {
|
||||
// Double-click to edit — only for custom, non-built-in abilities
|
||||
if (!showingBuiltIn && !currentIsBuiltIn && selectedAbility != null) {
|
||||
if (scroll.id == SCROLL_MAIN && selection != null && !selection.isEmpty()) {
|
||||
if (showingChained && selectedChain != null) {
|
||||
setSubGui(new SubGuiChainedAbilityConfig(selectedChain, this));
|
||||
} else if (!showingBuiltIn && !showingChained && !currentIsBuiltIn && selectedAbility != null) {
|
||||
previewExecutor.stop();
|
||||
setSubGui(selectedAbility.createConfigGui(this));
|
||||
}
|
||||
@@ -334,7 +409,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
if (type == EnumScrollData.CUSTOM_ABILITIES) {
|
||||
String prevSelected = scroll != null ? scroll.getSelected() : null;
|
||||
this.customData = data;
|
||||
if (!showingBuiltIn && scroll != null) {
|
||||
if (!showingBuiltIn && !showingChained && scroll != null) {
|
||||
scroll.setList(getSearchList());
|
||||
if (prevSelected != null && customData.containsKey(prevSelected)) {
|
||||
scroll.setSelected(prevSelected);
|
||||
@@ -350,11 +425,33 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
} else if (type == EnumScrollData.CHAINED_ABILITIES) {
|
||||
String prevSelected = scroll != null ? scroll.getSelected() : null;
|
||||
this.chainedData = data;
|
||||
if (showingChained && scroll != null) {
|
||||
scroll.setList(getSearchList());
|
||||
if (prevSelected != null && chainedData.containsKey(prevSelected)) {
|
||||
scroll.setSelected(prevSelected);
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
// Detect chained ability response (has "Entries" tag)
|
||||
if (showingChained && compound.hasKey("Entries")) {
|
||||
selectedChain = new ChainedAbility();
|
||||
selectedChain.readNBT(compound);
|
||||
selected = selectedChain.getName();
|
||||
if (scroll != null) {
|
||||
scroll.setSelected(selected);
|
||||
}
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this is a built-in ability response
|
||||
currentIsBuiltIn = compound.hasKey("BuiltIn") && compound.getBoolean("BuiltIn");
|
||||
|
||||
@@ -380,90 +477,131 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiChainedAbilityConfig) {
|
||||
handleChainConfigClosed();
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (subgui instanceof SubGuiAbilityVariantSelect) {
|
||||
SubGuiAbilityVariantSelect variantGui = (SubGuiAbilityVariantSelect) subgui;
|
||||
int idx = variantGui.getSelectedIndex();
|
||||
if (idx >= 0 && pendingTypeId != null) {
|
||||
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
|
||||
if (newAbility != null) {
|
||||
variantGui.getVariants().get(idx).apply(newAbility);
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
pendingNewCreation = true;
|
||||
pendingTypeId = null;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return;
|
||||
}
|
||||
pendingTypeId = null;
|
||||
openConfig(newAbility);
|
||||
return;
|
||||
}
|
||||
}
|
||||
pendingTypeId = null;
|
||||
if (handleVariantSelectClosed((SubGuiAbilityVariantSelect) subgui)) return;
|
||||
} else if (subgui instanceof SubGuiAbilityTypeSelect) {
|
||||
String typeId = ((SubGuiAbilityTypeSelect) subgui).getSelectedTypeId();
|
||||
if (typeId != null) {
|
||||
java.util.List<AbilityVariant> variants = AbilityController.Instance.getVariantsForType(typeId);
|
||||
if (variants.size() > 1) {
|
||||
pendingTypeId = typeId;
|
||||
setSubGui(new SubGuiAbilityVariantSelect(variants));
|
||||
return;
|
||||
}
|
||||
Ability newAbility = AbilityController.Instance.create(typeId);
|
||||
if (newAbility != null) {
|
||||
if (variants.size() == 1) {
|
||||
variants.get(0).apply(newAbility);
|
||||
}
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
pendingNewCreation = true;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return;
|
||||
}
|
||||
openConfig(newAbility);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (handleTypeSelectClosed((SubGuiAbilityTypeSelect) subgui)) return;
|
||||
} else if (subgui instanceof SubGuiDuplicateNameConfirm) {
|
||||
SubGuiDuplicateNameConfirm confirm = (SubGuiDuplicateNameConfirm) subgui;
|
||||
if (confirm.isConfirmed() && pendingSaveAbility != null) {
|
||||
if (pendingNewCreation) {
|
||||
openConfig(pendingSaveAbility);
|
||||
pendingSaveAbility = null;
|
||||
pendingNewCreation = false;
|
||||
return;
|
||||
} else {
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
pendingSaveAbility = null;
|
||||
}
|
||||
} else if (pendingSaveAbility != null) {
|
||||
if (pendingNewCreation) {
|
||||
// Cancel new creation - discard
|
||||
pendingSaveAbility = null;
|
||||
pendingNewCreation = false;
|
||||
} else {
|
||||
// Cancel edit save - re-open config GUI to change name
|
||||
Ability ability = pendingSaveAbility;
|
||||
pendingSaveAbility = null;
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (handleDuplicateNameClosed((SubGuiDuplicateNameConfirm) subgui)) return;
|
||||
} else if (pendingSaveAbility != null) {
|
||||
// Config GUI closed with a pending save (set by onAbilitySaved)
|
||||
if (hasDuplicateName(pendingSaveAbility)) {
|
||||
pendingNewCreation = false;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return;
|
||||
}
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
pendingSaveAbility = null;
|
||||
if (handlePendingSave()) return;
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
|
||||
private void handleChainConfigClosed() {
|
||||
if (pendingSaveChain != null) {
|
||||
PacketClient.sendClient(new ChainedAbilitySavePacket(pendingSaveChain.writeNBT()));
|
||||
PacketClient.sendClient(new ChainedAbilitiesGetPacket());
|
||||
selected = pendingSaveChain.getName();
|
||||
pendingSaveChain = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if a SubGui was opened (caller should return early, skipping initGui)
|
||||
*/
|
||||
private boolean handleVariantSelectClosed(SubGuiAbilityVariantSelect gui) {
|
||||
int idx = gui.getSelectedIndex();
|
||||
if (idx >= 0 && pendingTypeId != null) {
|
||||
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
|
||||
if (newAbility != null) {
|
||||
gui.getVariants().get(idx).apply(newAbility);
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
pendingNewCreation = true;
|
||||
pendingTypeId = null;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return true;
|
||||
}
|
||||
pendingTypeId = null;
|
||||
openConfig(newAbility);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
pendingTypeId = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if a SubGui was opened (caller should return early, skipping initGui)
|
||||
*/
|
||||
private boolean handleTypeSelectClosed(SubGuiAbilityTypeSelect gui) {
|
||||
String typeId = gui.getSelectedTypeId();
|
||||
if (typeId != null) {
|
||||
java.util.List<AbilityVariant> variants = AbilityController.Instance.getVariantsForType(typeId);
|
||||
if (variants.size() > 1) {
|
||||
pendingTypeId = typeId;
|
||||
setSubGui(new SubGuiAbilityVariantSelect(variants));
|
||||
return true;
|
||||
}
|
||||
Ability newAbility = AbilityController.Instance.create(typeId);
|
||||
if (newAbility != null) {
|
||||
if (variants.size() == 1) {
|
||||
variants.get(0).apply(newAbility);
|
||||
}
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
pendingNewCreation = true;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return true;
|
||||
}
|
||||
openConfig(newAbility);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if a SubGui was opened (caller should return early, skipping initGui)
|
||||
*/
|
||||
private boolean handleDuplicateNameClosed(SubGuiDuplicateNameConfirm gui) {
|
||||
if (gui.isConfirmed() && pendingSaveAbility != null) {
|
||||
if (pendingNewCreation) {
|
||||
openConfig(pendingSaveAbility);
|
||||
pendingSaveAbility = null;
|
||||
pendingNewCreation = false;
|
||||
return true;
|
||||
} else {
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
pendingSaveAbility = null;
|
||||
}
|
||||
} else if (pendingSaveAbility != null) {
|
||||
if (pendingNewCreation) {
|
||||
pendingSaveAbility = null;
|
||||
pendingNewCreation = false;
|
||||
} else {
|
||||
Ability ability = pendingSaveAbility;
|
||||
pendingSaveAbility = null;
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if a SubGui was opened (caller should return early, skipping initGui)
|
||||
*/
|
||||
private boolean handlePendingSave() {
|
||||
if (hasDuplicateName(pendingSaveAbility)) {
|
||||
pendingNewCreation = false;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return true;
|
||||
}
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
pendingSaveAbility = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void openConfig(Ability ability) {
|
||||
selectedAbility = ability;
|
||||
selected = ability.getName();
|
||||
@@ -474,9 +612,12 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
private boolean hasDuplicateName(Ability ability) {
|
||||
String name = ability.getName();
|
||||
if (name == null || name.isEmpty()) return false;
|
||||
String oldName = ability.getId();
|
||||
// A duplicate exists if the name is already in use and it's not the same ability being edited
|
||||
return customData.containsKey(name) && !name.equals(oldName);
|
||||
if (!customData.containsKey(name)) return false;
|
||||
// Name exists — check if it belongs to a different ability (by UUID)
|
||||
String uuid = ability.getId();
|
||||
if (uuid == null || uuid.isEmpty()) return true; // New ability with conflicting name
|
||||
Ability existing = AbilityController.Instance.getCustomAbilityByName(name);
|
||||
return existing == null || !uuid.equals(existing.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -484,12 +625,18 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
NoppesUtil.openGUI(player, this);
|
||||
if (!result) return;
|
||||
|
||||
if (id == 1 && selected != null) {
|
||||
if (id == CONFIRM_REMOVE_ABILITY && selected != null) {
|
||||
PacketClient.sendClient(new CustomAbilityRemovePacket(selected));
|
||||
scroll.clear();
|
||||
selected = null;
|
||||
selectedAbility = null;
|
||||
initGui();
|
||||
} else if (id == CONFIRM_REMOVE_CHAIN && selected != null) {
|
||||
PacketClient.sendClient(new ChainedAbilityRemovePacket(selected));
|
||||
scroll.clear();
|
||||
selected = null;
|
||||
selectedChain = null;
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -499,6 +646,11 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
pendingSaveAbility = ability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChainedAbilitySaved(ChainedAbility chain) {
|
||||
pendingSaveChain = chain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textfield) {
|
||||
// Search field handling is done in keyTyped
|
||||
|
||||
@@ -18,13 +18,14 @@ import noppes.npcs.containers.ContainerAuctionTrades;
|
||||
import noppes.npcs.containers.SlotAuctionDisplay;
|
||||
import noppes.npcs.controllers.data.AuctionClaim;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
import noppes.npcs.util.AuctionFormatUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Handles adding auction information to item tooltips when viewing auction GUIs.
|
||||
* Called from ItemTooltipEvent in ClientEventHandler.
|
||||
*
|
||||
* <p>
|
||||
* Uses slot-based lookup (slot index) instead of ItemStack comparison to correctly
|
||||
* handle duplicate items with different auction data (e.g., two porkchops at different prices).
|
||||
*/
|
||||
@@ -88,25 +89,25 @@ public class AuctionTooltipHandler {
|
||||
// Current bid or starting price
|
||||
if (listing.hasBids()) {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.currentBid")
|
||||
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(listing.currentBid)));
|
||||
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(listing.currentBid)));
|
||||
tooltip.add(EnumChatFormatting.GRAY + String.format(StatCollector.translateToLocal("auction.bids"), listing.bidCount));
|
||||
} else {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.startingPrice")
|
||||
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(listing.startingPrice)));
|
||||
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(listing.startingPrice)));
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.noBids"));
|
||||
}
|
||||
|
||||
// Buyout price
|
||||
if (listing.hasBuyout()) {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.buyout")
|
||||
.replace("%s", EnumChatFormatting.GREEN + formatCurrency(listing.buyoutPrice)));
|
||||
.replace("%s", EnumChatFormatting.GREEN + AuctionFormatUtil.formatCurrencyWithName(listing.buyoutPrice)));
|
||||
}
|
||||
|
||||
// Time remaining
|
||||
long timeRemaining = listing.getTimeRemaining();
|
||||
String timeText = StatCollector.translateToLocal("auction.timeLeft")
|
||||
.replace("%s", formatTimeRemaining(timeRemaining));
|
||||
tooltip.add((timeRemaining < 3600000 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
|
||||
.replace("%s", AuctionFormatUtil.formatTimeRemaining(timeRemaining));
|
||||
tooltip.add((AuctionFormatUtil.isTimeUrgent(timeRemaining) ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
|
||||
}
|
||||
|
||||
// ========== Trades Page ==========
|
||||
@@ -144,7 +145,7 @@ public class AuctionTooltipHandler {
|
||||
|
||||
if (listing.hasBids()) {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.currentBid")
|
||||
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(listing.currentBid)));
|
||||
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(listing.currentBid)));
|
||||
tooltip.add(EnumChatFormatting.GRAY + String.format(StatCollector.translateToLocal("auction.bids"), listing.bidCount));
|
||||
} else {
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.noBids"));
|
||||
@@ -152,8 +153,8 @@ public class AuctionTooltipHandler {
|
||||
|
||||
long timeRemaining = listing.getTimeRemaining();
|
||||
String timeText = StatCollector.translateToLocal("auction.timeLeft")
|
||||
.replace("%s", formatTimeRemaining(timeRemaining));
|
||||
tooltip.add((timeRemaining < 3600000 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
|
||||
.replace("%s", AuctionFormatUtil.formatTimeRemaining(timeRemaining));
|
||||
tooltip.add((AuctionFormatUtil.isTimeUrgent(timeRemaining) ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
|
||||
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.trades.rightClickToCancel"));
|
||||
@@ -164,13 +165,13 @@ public class AuctionTooltipHandler {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.trades.bidding"));
|
||||
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.currentBid")
|
||||
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(listing.currentBid)));
|
||||
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(listing.currentBid)));
|
||||
tooltip.add(EnumChatFormatting.GRAY + String.format(StatCollector.translateToLocal("auction.bids"), listing.bidCount));
|
||||
|
||||
long timeRemaining = listing.getTimeRemaining();
|
||||
String timeText = StatCollector.translateToLocal("auction.timeLeft")
|
||||
.replace("%s", formatTimeRemaining(timeRemaining));
|
||||
tooltip.add((timeRemaining < 3600000 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
|
||||
.replace("%s", AuctionFormatUtil.formatTimeRemaining(timeRemaining));
|
||||
tooltip.add((AuctionFormatUtil.isTimeUrgent(timeRemaining) ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + timeText);
|
||||
|
||||
tooltip.add("");
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.trades.clickToRebid"));
|
||||
@@ -210,7 +211,7 @@ public class AuctionTooltipHandler {
|
||||
// Amount for currency claims
|
||||
if (claim.type.isCurrency()) {
|
||||
tooltip.add(EnumChatFormatting.YELLOW + StatCollector.translateToLocal("auction.claim.amount")
|
||||
.replace("%s", EnumChatFormatting.GOLD + formatCurrency(claim.currency)));
|
||||
.replace("%s", EnumChatFormatting.GOLD + AuctionFormatUtil.formatCurrencyWithName(claim.currency)));
|
||||
}
|
||||
|
||||
// Expiration
|
||||
@@ -254,48 +255,4 @@ public class AuctionTooltipHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// ========== Formatting Utilities ==========
|
||||
|
||||
private static String formatCurrency(long amount) {
|
||||
if (amount < 1000) {
|
||||
return amount + " " + AuctionClientConfig.getCurrencyName();
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = "" + amount;
|
||||
int count = 0;
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
if (count > 0 && count % 3 == 0) {
|
||||
sb.insert(0, ',');
|
||||
}
|
||||
sb.insert(0, str.charAt(i));
|
||||
count++;
|
||||
}
|
||||
return sb.toString() + " " + AuctionClientConfig.getCurrencyName();
|
||||
}
|
||||
|
||||
private static String formatTimeRemaining(long milliseconds) {
|
||||
if (milliseconds <= 0) {
|
||||
return StatCollector.translateToLocal("auction.ended");
|
||||
}
|
||||
|
||||
long seconds = (milliseconds / 1000) % 60;
|
||||
long minutes = (milliseconds / 60000) % 60;
|
||||
long hours = (milliseconds / 3600000) % 24;
|
||||
long days = milliseconds / 86400000;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (days > 0) {
|
||||
sb.append(days).append("d ");
|
||||
}
|
||||
if (hours > 0 || days > 0) {
|
||||
sb.append(hours).append("h ");
|
||||
}
|
||||
if (minutes > 0 || hours > 0 || days > 0) {
|
||||
sb.append(minutes).append("m");
|
||||
} else {
|
||||
sb.append(seconds).append("s");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.containers.ContainerAuctionBidding;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.util.AuctionFormatUtil;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -36,7 +37,7 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
private int btnBidY = 110;
|
||||
private int btnBuyoutX = 82;
|
||||
private int btnBuyoutY = 110;
|
||||
private int infoX = 110;
|
||||
private int infoX = 105;
|
||||
private int infoY = 50;
|
||||
|
||||
// Button IDs
|
||||
@@ -81,7 +82,9 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Update button visibility based on listing state */
|
||||
/**
|
||||
* Update button visibility based on listing state
|
||||
*/
|
||||
private void updateButtonState() {
|
||||
if (listing == null) {
|
||||
if (btnBid != null) btnBid.setVisible(false);
|
||||
@@ -184,9 +187,11 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
drawAuctionInfo();
|
||||
}
|
||||
|
||||
/** Draw auction listing information on the right side */
|
||||
/**
|
||||
* Draw auction listing information on the right side
|
||||
*/
|
||||
private void drawAuctionInfo() {
|
||||
int x = guiLeft + 105;
|
||||
int x = guiLeft + infoX;
|
||||
int y = guiTop + infoY;
|
||||
int xRight = guiLeft + 215;
|
||||
|
||||
@@ -206,7 +211,7 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
String bidLabel = StatCollector.translateToLocal("auction.info.currentBid") + ":";
|
||||
fontRendererObj.drawString(EnumChatFormatting.YELLOW + bidLabel, x, y, 0xFFFFFF);
|
||||
|
||||
label = formatCurrency(listing.currentBid);
|
||||
label = AuctionFormatUtil.formatCurrency(listing.currentBid);
|
||||
length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(EnumChatFormatting.GOLD + label, xRight - length, y, 0xFFFFFF);
|
||||
y += lineHeight + 4;
|
||||
@@ -223,9 +228,9 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
String startLabel = StatCollector.translateToLocal("auction.info.startingPrice");
|
||||
fontRendererObj.drawString(EnumChatFormatting.YELLOW + startLabel, x, y, 0xFFFFFF);
|
||||
|
||||
label = formatCurrency(listing.startingPrice);
|
||||
label = AuctionFormatUtil.formatCurrency(listing.startingPrice);
|
||||
length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(EnumChatFormatting.GOLD + label, xRight - length, y, 0xFFFFFF);
|
||||
fontRendererObj.drawString(EnumChatFormatting.GOLD + label, xRight - length, y, 0xFFFFFF);
|
||||
y += lineHeight + 4;
|
||||
}
|
||||
|
||||
@@ -234,9 +239,9 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
String buyoutLabel = StatCollector.translateToLocal("auction.info.buyoutPrice");
|
||||
fontRendererObj.drawString(EnumChatFormatting.GREEN + buyoutLabel, x, y, 0xFFFFFF);
|
||||
|
||||
label = formatCurrency(listing.buyoutPrice);
|
||||
label = AuctionFormatUtil.formatCurrency(listing.buyoutPrice);
|
||||
length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(EnumChatFormatting.GREEN + label, xRight - length, y, 0xFFFFFF);
|
||||
fontRendererObj.drawString(EnumChatFormatting.GREEN + label, xRight - length, y, 0xFFFFFF);
|
||||
y += lineHeight + 4;
|
||||
}
|
||||
|
||||
@@ -244,9 +249,9 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
String timeLabel = StatCollector.translateToLocal("auction.info.timeLeft");
|
||||
fontRendererObj.drawString(EnumChatFormatting.GRAY + timeLabel, x, y, 0xFFFFFF);
|
||||
long timeRemaining = listing.getTimeRemaining();
|
||||
EnumChatFormatting timeColor = timeRemaining < 3600000 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE;
|
||||
EnumChatFormatting timeColor = AuctionFormatUtil.isTimeUrgent(timeRemaining) ? EnumChatFormatting.RED : EnumChatFormatting.WHITE;
|
||||
|
||||
label = timeColor + formatTimeRemaining(timeRemaining);
|
||||
label = timeColor + AuctionFormatUtil.formatTimeRemaining(timeRemaining);
|
||||
length = fontRendererObj.getStringWidth(label);
|
||||
fontRendererObj.drawString(label, xRight - length, y, 0xFFFFFF);
|
||||
y += lineHeight + 4;
|
||||
@@ -278,14 +283,14 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
if (listing != null) {
|
||||
long minBid = listing.getMinimumBid(AuctionClientConfig.getMinBidIncrement());
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.bid.minimum")
|
||||
.replace("%s", EnumChatFormatting.WHITE + formatCurrency(minBid) + " " + AuctionClientConfig.getCurrencyName()));
|
||||
.replace("%s", EnumChatFormatting.WHITE + AuctionFormatUtil.formatCurrency(minBid) + " " + AuctionClientConfig.getCurrencyName()));
|
||||
}
|
||||
} else if (btnBuyout != null && btnBuyout.visible && btnBuyout.isHovered()) {
|
||||
tooltip = new ArrayList<>();
|
||||
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("auction.bid.buyout"));
|
||||
if (listing != null && listing.hasBuyout()) {
|
||||
tooltip.add(EnumChatFormatting.GRAY + StatCollector.translateToLocal("auction.info.buyoutPrice") + ":");
|
||||
tooltip.add(EnumChatFormatting.GREEN + formatCurrency(listing.buyoutPrice) + " " + AuctionClientConfig.getCurrencyName());
|
||||
tooltip.add(EnumChatFormatting.GREEN + AuctionFormatUtil.formatCurrency(listing.buyoutPrice) + " " + AuctionClientConfig.getCurrencyName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,5 +310,7 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
// Block all slot interactions - view only
|
||||
}
|
||||
|
||||
public AuctionListing getListing() { return listing; }
|
||||
public AuctionListing getListing() {
|
||||
return listing;
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,9 @@ public abstract class GuiAuctionInterface extends GuiContainerNPCInterface {
|
||||
public static final int PAGE_SELL = 1;
|
||||
public static final int PAGE_CLAIMS = 2;
|
||||
|
||||
// Overlay color
|
||||
protected static final int OVERLAY_DARK = 0xC0000000;
|
||||
|
||||
// Navigation button IDs
|
||||
protected static final int BTN_NAV_LISTINGS = 100;
|
||||
protected static final int BTN_NAV_SELL = 101;
|
||||
@@ -66,7 +69,9 @@ public abstract class GuiAuctionInterface extends GuiContainerNPCInterface {
|
||||
initNavigationButtons();
|
||||
}
|
||||
|
||||
/** Initialize navigation buttons */
|
||||
/**
|
||||
* Initialize navigation buttons
|
||||
*/
|
||||
protected void initNavigationButtons() {
|
||||
int page = getCurrentPage();
|
||||
|
||||
@@ -86,7 +91,9 @@ public abstract class GuiAuctionInterface extends GuiContainerNPCInterface {
|
||||
addButton(btnClaims);
|
||||
}
|
||||
|
||||
/** Returns current page constant - implement in subclass */
|
||||
/**
|
||||
* Returns current page constant - implement in subclass
|
||||
*/
|
||||
protected abstract int getCurrentPage();
|
||||
|
||||
@Override
|
||||
@@ -133,7 +140,9 @@ public abstract class GuiAuctionInterface extends GuiContainerNPCInterface {
|
||||
}
|
||||
}
|
||||
|
||||
/** Draw navigation button tooltips */
|
||||
/**
|
||||
* Draw navigation button tooltips
|
||||
*/
|
||||
protected void drawNavButtonTooltips(int mouseX, int mouseY) {
|
||||
List<String> tooltip = null;
|
||||
if (btnListings != null && btnListings.isHovered()) tooltip = btnListings.getTooltipLines();
|
||||
@@ -151,14 +160,18 @@ public abstract class GuiAuctionInterface extends GuiContainerNPCInterface {
|
||||
|
||||
// ========== Slot Drawing Utilities ==========
|
||||
|
||||
/** Draw auction slot background (18x18) */
|
||||
/**
|
||||
* Draw auction slot background (18x18)
|
||||
*/
|
||||
protected void drawAuctionSlot(int x, int y) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
mc.renderEngine.bindTexture(AUCTION_SLOT);
|
||||
Gui.func_146110_a(x, y, 0, 0, 18, 18, 18, 18);
|
||||
}
|
||||
|
||||
/** Draw colored overlay on slot (ARGB format) */
|
||||
/**
|
||||
* Draw colored overlay on slot (ARGB format)
|
||||
*/
|
||||
protected void drawColoredOverlay(int x, int y, int color) {
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
@@ -170,12 +183,16 @@ public abstract class GuiAuctionInterface extends GuiContainerNPCInterface {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
/** Draw dark overlay for unavailable slots */
|
||||
/**
|
||||
* Draw dark overlay for unavailable slots
|
||||
*/
|
||||
protected void drawDarkenedOverlay(int x, int y) {
|
||||
drawColoredOverlay(x, y, 0xC0000000);
|
||||
drawColoredOverlay(x, y, OVERLAY_DARK);
|
||||
}
|
||||
|
||||
/** Draw icon texture on slot (16x16) */
|
||||
/**
|
||||
* Draw icon texture on slot (16x16)
|
||||
*/
|
||||
protected void drawIconOverlay(int x, int y, ResourceLocation icon) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
@@ -189,42 +206,11 @@ public abstract class GuiAuctionInterface extends GuiContainerNPCInterface {
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
/** Subclasses implement this to draw specific content */
|
||||
/**
|
||||
* Subclasses implement this to draw specific content
|
||||
*/
|
||||
protected abstract void drawAuctionContent(float partialTicks, int mouseX, int mouseY);
|
||||
|
||||
// ========== Formatting Utilities ==========
|
||||
|
||||
/** Format currency with commas (e.g., 1000 -> "1,000") */
|
||||
protected String formatCurrency(long amount) {
|
||||
if (amount < 1000) return "" + amount;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = "" + amount;
|
||||
int count = 0;
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
if (count > 0 && count % 3 == 0) sb.insert(0, ',');
|
||||
sb.insert(0, str.charAt(i));
|
||||
count++;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/** Format time remaining (e.g., "2d 5h 30m") */
|
||||
protected String formatTimeRemaining(long ms) {
|
||||
if (ms <= 0) return "Ended";
|
||||
|
||||
long seconds = (ms / 1000) % 60;
|
||||
long minutes = (ms / 60000) % 60;
|
||||
long hours = (ms / 3600000) % 24;
|
||||
long days = ms / 86400000;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (days > 0) sb.append(days).append("d ");
|
||||
if (hours > 0 || days > 0) sb.append(hours).append("h ");
|
||||
if (minutes > 0 || hours > 0 || days > 0) sb.append(minutes).append("m");
|
||||
else sb.append(seconds).append("s");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
// Override in subclasses if needed
|
||||
|
||||
@@ -58,8 +58,6 @@ public class GuiAuctionListing extends GuiAuctionInterface implements ISubGuiLis
|
||||
private AuctionFilter filter;
|
||||
private int currentPage = 0;
|
||||
private int totalPages = 1;
|
||||
private int totalListings = 0;
|
||||
private boolean dataLoaded = false;
|
||||
|
||||
// Buttons defined on this page
|
||||
private GuiAuctionNavButton btnFilter;
|
||||
@@ -100,12 +98,16 @@ public class GuiAuctionListing extends GuiAuctionInterface implements ISubGuiLis
|
||||
return PAGE_LISTINGS;
|
||||
}
|
||||
|
||||
/** Request listings from server */
|
||||
/**
|
||||
* Request listings from server
|
||||
*/
|
||||
private void requestListings() {
|
||||
AuctionActionPacket.requestListings(filter, currentPage);
|
||||
}
|
||||
|
||||
/** Update pagination button visibility based on current page state */
|
||||
/**
|
||||
* Update pagination button visibility based on current page state
|
||||
*/
|
||||
private void updatePaginationVisibility() {
|
||||
if (btnPageUp != null) {
|
||||
btnPageUp.setVisible(currentPage > 0);
|
||||
@@ -195,7 +197,8 @@ public class GuiAuctionListing extends GuiAuctionInterface implements ISubGuiLis
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {}
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
}
|
||||
|
||||
// ========== Data Handling ==========
|
||||
|
||||
@@ -204,7 +207,6 @@ public class GuiAuctionListing extends GuiAuctionInterface implements ISubGuiLis
|
||||
if (compound.hasKey("ListingsData")) {
|
||||
currentPage = compound.getInteger("Page");
|
||||
totalPages = compound.getInteger("TotalPages");
|
||||
totalListings = compound.getInteger("TotalListings");
|
||||
|
||||
// Load listings
|
||||
listingContainer.displayInventory.clear();
|
||||
@@ -213,7 +215,7 @@ public class GuiAuctionListing extends GuiAuctionInterface implements ISubGuiLis
|
||||
AuctionListing listing = AuctionListing.fromNBT(list.getCompoundTagAt(i));
|
||||
listingContainer.displayInventory.setListing(i, listing);
|
||||
}
|
||||
dataLoaded = true;
|
||||
updatePaginationVisibility();
|
||||
} else if (compound.hasKey("ListingsRefresh")) {
|
||||
requestListings();
|
||||
}
|
||||
@@ -297,6 +299,11 @@ public class GuiAuctionListing extends GuiAuctionInterface implements ISubGuiLis
|
||||
// Block other slot interactions
|
||||
}
|
||||
|
||||
public AuctionFilter getFilter() { return filter; }
|
||||
public ContainerAuctionListing getListingContainer() { return listingContainer; }
|
||||
public AuctionFilter getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public ContainerAuctionListing getListingContainer() {
|
||||
return listingContainer;
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,17 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.AuctionClientConfig;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.util.GuiAuctionNavButton;
|
||||
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.ITextfieldListener;
|
||||
import noppes.npcs.client.AuctionClientConfig;
|
||||
import noppes.npcs.containers.ContainerAuctionSell;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.util.AuctionFormatUtil;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -103,7 +105,9 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
return PAGE_SELL;
|
||||
}
|
||||
|
||||
/** Update visibility of buyout price field based on toggle state */
|
||||
/**
|
||||
* Update visibility of buyout price field based on toggle state
|
||||
*/
|
||||
private void updateBuyoutVisibility() {
|
||||
if (lblBuyout != null) {
|
||||
lblBuyout.enabled = allowBuyout;
|
||||
@@ -117,7 +121,9 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
}
|
||||
}
|
||||
|
||||
/** Update the buyout toggle button tooltip */
|
||||
/**
|
||||
* Update the buyout toggle button tooltip
|
||||
*/
|
||||
private void updateBuyoutTooltip() {
|
||||
if (btnAllowBuyout == null) return;
|
||||
|
||||
@@ -239,7 +245,7 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
|
||||
// Draw listing fee info (uses cached config from server)
|
||||
String feeText = StatCollector.translateToLocal("auction.sell.fee")
|
||||
.replace("%s", formatCurrency(AuctionClientConfig.getListingFee()) + " " + AuctionClientConfig.getCurrencyName());
|
||||
.replace("%s", AuctionFormatUtil.formatCurrency(AuctionClientConfig.getListingFee()) + " " + AuctionClientConfig.getCurrencyName());
|
||||
fontRendererObj.drawString(EnumChatFormatting.GRAY + feeText, guiLeft + contentX, guiTop + contentY + 77, 0xFFFFFF);
|
||||
|
||||
// Draw error message if any
|
||||
@@ -250,7 +256,9 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
drawSellSlotIndicator(slotX, slotY);
|
||||
}
|
||||
|
||||
/** Draw indicator showing staged vs available items */
|
||||
/**
|
||||
* Draw indicator showing staged vs available items
|
||||
*/
|
||||
private void drawSellSlotIndicator(int slotX, int slotY) {
|
||||
ItemStack sellItem = sellContainer.getItemToSell();
|
||||
if (sellItem != null) {
|
||||
@@ -308,7 +316,9 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
drawSellPageTooltips(mouseX, mouseY);
|
||||
}
|
||||
|
||||
/** Draw tooltips for sell page buttons */
|
||||
/**
|
||||
* Draw tooltips for sell page buttons
|
||||
*/
|
||||
private void drawSellPageTooltips(int mouseX, int mouseY) {
|
||||
List<String> tooltip = null;
|
||||
|
||||
@@ -326,7 +336,11 @@ public class GuiAuctionSell extends GuiAuctionInterface implements ITextfieldLis
|
||||
}
|
||||
|
||||
if (tooltip != null && !tooltip.isEmpty()) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||
drawHoveringText(tooltip, mouseX - guiLeft, mouseY - guiTop, fontRendererObj);
|
||||
GL11.glPopAttrib();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
private int pendingSlot = -1;
|
||||
private PendingOp pendingOp = PendingOp.NONE;
|
||||
|
||||
private enum PendingOp { NONE, CANCEL, CLAIM }
|
||||
private enum PendingOp {NONE, CANCEL, CLAIM}
|
||||
|
||||
public GuiAuctionTrades(EntityNPCInterface npc, ContainerAuctionTrades container) {
|
||||
super(npc, container);
|
||||
@@ -117,7 +117,9 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
}
|
||||
}
|
||||
|
||||
/** Handle click on pending operation slot */
|
||||
/**
|
||||
* Handle click on pending operation slot
|
||||
*/
|
||||
private void handlePendingClick(int mouseButton) {
|
||||
if (pendingOp == PendingOp.CANCEL && mouseButton == 1) {
|
||||
// Right-click confirms cancel
|
||||
@@ -159,14 +161,18 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
}
|
||||
}
|
||||
|
||||
/** Set pending operation and hide slot item */
|
||||
/**
|
||||
* Set pending operation and hide slot item
|
||||
*/
|
||||
private void setPending(int slot, PendingOp op) {
|
||||
pendingSlot = slot;
|
||||
pendingOp = op;
|
||||
tradesContainer.setHiddenSlot(slot);
|
||||
}
|
||||
|
||||
/** Clear pending operation and restore slot */
|
||||
/**
|
||||
* Clear pending operation and restore slot
|
||||
*/
|
||||
private void clearPending() {
|
||||
if (pendingSlot >= 0) {
|
||||
tradesContainer.clearHiddenSlot();
|
||||
@@ -175,13 +181,17 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
pendingOp = PendingOp.NONE;
|
||||
}
|
||||
|
||||
/** Play confirmation sound */
|
||||
/**
|
||||
* Play confirmation sound
|
||||
*/
|
||||
private void playConfirmSound() {
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(
|
||||
new ResourceLocation("random.orb"), 1.0F));
|
||||
}
|
||||
|
||||
/** Get slot index at mouse position */
|
||||
/**
|
||||
* Get slot index at mouse position
|
||||
*/
|
||||
private int getSlotAt(int mouseX, int mouseY) {
|
||||
int relX = mouseX - guiLeft - GRID_X;
|
||||
int relY = mouseY - guiTop - GRID_Y;
|
||||
@@ -239,7 +249,9 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
}
|
||||
}
|
||||
|
||||
/** Get tint color for slot based on contents */
|
||||
/**
|
||||
* Get tint color for slot based on contents
|
||||
*/
|
||||
private int getSlotTint(int slot) {
|
||||
AuctionListing listing = tradesContainer.getListingAt(slot);
|
||||
AuctionClaim claim = tradesContainer.getClaimAt(slot);
|
||||
@@ -281,7 +293,9 @@ public class GuiAuctionTrades extends GuiAuctionInterface implements IGuiData {
|
||||
}
|
||||
}
|
||||
|
||||
/** Draw tooltip for a trade slot */
|
||||
/**
|
||||
* Draw tooltip for a trade slot
|
||||
*/
|
||||
private void drawTradeTooltip(int slot, int x, int y) {
|
||||
List<String> tooltip = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.util.AuctionFormatUtil;
|
||||
|
||||
/**
|
||||
* Sub GUI for placing a bid on an auction.
|
||||
@@ -49,13 +50,13 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
|
||||
|
||||
// Minimum bid info
|
||||
String minText = StatCollector.translateToLocal("auction.bid.minimum")
|
||||
.replace("%s", EnumChatFormatting.DARK_RED + formatCurrency(minimumBid) + " " + currencyName);
|
||||
.replace("%s", EnumChatFormatting.DARK_RED + AuctionFormatUtil.formatCurrency(minimumBid) + " " + currencyName);
|
||||
addLabel(new GuiNpcLabel(1, minText, guiLeft + 15, y));
|
||||
y += 14;
|
||||
|
||||
// Your balance
|
||||
String balanceText = StatCollector.translateToLocal("auction.bid.yourBalance")
|
||||
.replace("%s", EnumChatFormatting.DARK_GREEN + formatCurrency(playerBalance) + " " + currencyName);
|
||||
.replace("%s", EnumChatFormatting.DARK_GREEN + AuctionFormatUtil.formatCurrency(playerBalance) + " " + currencyName);
|
||||
addLabel(new GuiNpcLabel(2, balanceText, guiLeft + 15, y));
|
||||
y += 18;
|
||||
|
||||
@@ -77,7 +78,7 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
|
||||
int totalBtnWidth = btnWidth * 2 + btnSpacing;
|
||||
int btnX = centerX - totalBtnWidth / 2;
|
||||
|
||||
addButton(new GuiNpcButton(btnBidId, btnX, y, btnWidth, 20, "auction.bid.placeBid"));
|
||||
addButton(new GuiNpcButton(btnBidId, btnX, y, btnWidth, 20, "auction.bid.place"));
|
||||
addButton(new GuiNpcButton(btnCancelId, btnX + btnWidth + btnSpacing, y, btnWidth, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@@ -117,7 +118,7 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
|
||||
// Validate
|
||||
if (bidAmount < minimumBid) {
|
||||
errorMessage = StatCollector.translateToLocal("auction.error.bidTooLow")
|
||||
.replace("%s", formatCurrency(minimumBid));
|
||||
.replace("%s", AuctionFormatUtil.formatCurrency(minimumBid));
|
||||
updateErrorLabel();
|
||||
return;
|
||||
}
|
||||
@@ -144,17 +145,4 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
|
||||
public boolean wasSuccessful() {
|
||||
return successful;
|
||||
}
|
||||
|
||||
private String formatCurrency(long amount) {
|
||||
if (amount < 1000) return "" + amount;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = "" + amount;
|
||||
int count = 0;
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
if (count > 0 && count % 3 == 0) sb.insert(0, ',');
|
||||
sb.insert(0, str.charAt(i));
|
||||
count++;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import noppes.npcs.client.AuctionClientConfig;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.util.AuctionFormatUtil;
|
||||
|
||||
/**
|
||||
* Sub GUI for confirming a buyout purchase.
|
||||
@@ -54,14 +55,14 @@ public class SubGuiAuctionBuyNow extends SubGuiInterface {
|
||||
y += 16;
|
||||
|
||||
// Buyout price
|
||||
String priceText = EnumChatFormatting.DARK_RED + formatCurrency(buyoutPrice) + " " + currencyName;
|
||||
String priceText = EnumChatFormatting.DARK_RED + AuctionFormatUtil.formatCurrency(buyoutPrice) + " " + currencyName;
|
||||
int priceWidth = fontRendererObj.getStringWidth(priceText);
|
||||
addLabel(new GuiNpcLabel(2, priceText, centerX - priceWidth / 2, y));
|
||||
y += 20;
|
||||
|
||||
// Your balance
|
||||
String balanceLabel = StatCollector.translateToLocal("auction.bid.yourBalance");
|
||||
String balanceText = balanceLabel.replace("%s", EnumChatFormatting.DARK_GREEN + formatCurrency(playerBalance) + " " + currencyName);
|
||||
String balanceText = balanceLabel.replace("%s", EnumChatFormatting.DARK_GREEN + AuctionFormatUtil.formatCurrency(playerBalance) + " " + currencyName);
|
||||
addLabel(new GuiNpcLabel(3, balanceText, guiLeft + 20, y));
|
||||
y += 14;
|
||||
|
||||
@@ -105,17 +106,4 @@ public class SubGuiAuctionBuyNow extends SubGuiInterface {
|
||||
public boolean wasSuccessful() {
|
||||
return successful;
|
||||
}
|
||||
|
||||
private String formatCurrency(long amount) {
|
||||
if (amount < 1000) return "" + amount;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = "" + amount;
|
||||
int count = 0;
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
if (count > 0 && count % 3 == 0) sb.insert(0, ',');
|
||||
sb.insert(0, str.charAt(i));
|
||||
count++;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ 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;
|
||||
|
||||
@@ -2,8 +2,11 @@ package noppes.npcs.client.gui.util;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.ChainedAbilityEntry;
|
||||
import kamkeel.npcs.controllers.data.ability.PreviewEntityHandler;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -19,10 +22,10 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Client-side executor for previewing abilities in the GUI.
|
||||
*
|
||||
* <p>
|
||||
* Uses unified execution: calls the REAL ability methods (onWindUpTick, onExecute, onActiveTick)
|
||||
* with previewMode=true. Abilities skip damage/effects/sounds when isPreview() returns true.
|
||||
*
|
||||
* <p>
|
||||
* Lifecycle:
|
||||
* 1. WINDUP phase - real onWindUpTick() called, telegraph shown, entities may spawn
|
||||
* 2. ACTIVE phase - real onExecute() then onActiveTick() called, physics simulated
|
||||
@@ -36,8 +39,11 @@ public class AbilityPreviewExecutor implements PreviewEntityHandler {
|
||||
private Ability previewAbility;
|
||||
private EntityNPCInterface previewNpc;
|
||||
|
||||
/** Executor's own phase tracking (separate from ability.getPhase()) */
|
||||
private enum ExecutorPhase { IDLE, WINDUP, ACTIVE, EXTENDED }
|
||||
/**
|
||||
* Executor's own phase tracking (separate from ability.getPhase())
|
||||
*/
|
||||
private enum ExecutorPhase {IDLE, WINDUP, ACTIVE, EXTENDED, CHAIN_DELAY}
|
||||
|
||||
private ExecutorPhase executorPhase = ExecutorPhase.IDLE;
|
||||
|
||||
private int currentTick = 0;
|
||||
@@ -59,6 +65,14 @@ public class AbilityPreviewExecutor implements PreviewEntityHandler {
|
||||
private TelegraphInstance previewTelegraph;
|
||||
private List<Entity> previewEntities = new ArrayList<>();
|
||||
|
||||
// ==================== CHAIN PREVIEW ====================
|
||||
private ChainedAbility previewChain;
|
||||
private List<Ability> chainAbilities;
|
||||
private List<Integer> chainDelays;
|
||||
private int chainIndex = -1;
|
||||
private int chainDelayRemaining = 0;
|
||||
private boolean chainWindUpAll = true;
|
||||
|
||||
// ==================== CALLBACKS ====================
|
||||
private GuiAbilityInterface parentGui;
|
||||
|
||||
@@ -70,28 +84,21 @@ public class AbilityPreviewExecutor implements PreviewEntityHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start previewing an ability using unified execution.
|
||||
* Start previewing a single ability using unified execution.
|
||||
* Sets previewMode=true on the ability, then calls its real methods.
|
||||
*/
|
||||
public void startPreview(Ability ability, EntityNPCInterface npc) {
|
||||
stop();
|
||||
|
||||
this.previewAbility = ability;
|
||||
this.previewNpc = npc;
|
||||
this.currentTick = 0;
|
||||
this.playing = true;
|
||||
this.paused = false;
|
||||
this.maxPreviewDuration = ability.getMaxPreviewDuration();
|
||||
|
||||
// Save NPC start position for restoring later
|
||||
this.npcStartX = npc.posX;
|
||||
this.npcStartY = npc.posY;
|
||||
this.npcStartZ = npc.posZ;
|
||||
|
||||
// Enable preview mode on the ability
|
||||
ability.setPreviewMode(true);
|
||||
ability.setPreviewEntityHandler(this);
|
||||
|
||||
// Create invisible fake target NPC for targeting
|
||||
createFakeTarget(npc);
|
||||
|
||||
@@ -100,10 +107,86 @@ public class AbilityPreviewExecutor implements PreviewEntityHandler {
|
||||
parentGui.startTrackingMovement();
|
||||
}
|
||||
|
||||
beginAbilityPreview(ability);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start previewing a chained ability — plays all entries in sequence with delays.
|
||||
* Each entry is resolved and deep-copied to avoid modifying originals.
|
||||
*/
|
||||
public void startChainPreview(ChainedAbility chain, EntityNPCInterface npc) {
|
||||
stop();
|
||||
|
||||
this.previewNpc = npc;
|
||||
this.playing = true;
|
||||
this.paused = false;
|
||||
this.previewChain = chain;
|
||||
this.chainWindUpAll = chain.isWindUpAll();
|
||||
|
||||
// Save NPC start position for restoring later
|
||||
this.npcStartX = npc.posX;
|
||||
this.npcStartY = npc.posY;
|
||||
this.npcStartZ = npc.posZ;
|
||||
|
||||
// Resolve all entries to deep-copied abilities
|
||||
chainAbilities = new ArrayList<>();
|
||||
chainDelays = new ArrayList<>();
|
||||
for (ChainedAbilityEntry entry : chain.getEntries()) {
|
||||
Ability resolved = entry.resolve();
|
||||
if (resolved != null && AbilityController.Instance != null) {
|
||||
Ability copy = AbilityController.Instance.fromNBT(resolved.writeNBT());
|
||||
if (copy != null) {
|
||||
chainAbilities.add(copy);
|
||||
chainDelays.add(entry.getDelayTicks());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (chainAbilities.isEmpty()) {
|
||||
playing = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Create invisible fake target NPC for targeting
|
||||
createFakeTarget(npc);
|
||||
|
||||
// Start tracking NPC movement
|
||||
if (parentGui != null) {
|
||||
parentGui.startTrackingMovement();
|
||||
}
|
||||
|
||||
chainIndex = 0;
|
||||
beginAbilityPreview(chainAbilities.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin previewing a single ability (shared by single and chain preview).
|
||||
* Cleans up the previous ability if any (for chain advancement).
|
||||
*/
|
||||
private void beginAbilityPreview(Ability ability) {
|
||||
// Clean up previous ability if any (for chain advancement)
|
||||
if (previewAbility != null) {
|
||||
previewAbility.cleanup();
|
||||
previewAbility.setPreviewMode(false);
|
||||
previewAbility.setPreviewEntityHandler(null);
|
||||
previewAbility.reset();
|
||||
}
|
||||
|
||||
this.previewAbility = ability;
|
||||
this.currentTick = 0;
|
||||
this.maxPreviewDuration = ability.getMaxPreviewDuration();
|
||||
|
||||
// Enable preview mode on the ability
|
||||
ability.setPreviewMode(true);
|
||||
ability.setPreviewEntityHandler(this);
|
||||
|
||||
// Use the ability's real start() method with the fake target
|
||||
ability.start(fakeTarget);
|
||||
|
||||
if (ability.getWindUpTicks() <= 0) {
|
||||
// Skip windup for non-first chain entries when windUpAll is false
|
||||
boolean skipWindup = previewChain != null && !chainWindUpAll && chainIndex > 0;
|
||||
|
||||
if (ability.getWindUpTicks() <= 0 || skipWindup) {
|
||||
// No windup — go straight to active
|
||||
this.executorPhase = ExecutorPhase.ACTIVE;
|
||||
transitionToActive();
|
||||
@@ -112,12 +195,12 @@ public class AbilityPreviewExecutor implements PreviewEntityHandler {
|
||||
this.executorPhase = ExecutorPhase.WINDUP;
|
||||
|
||||
// Create telegraph for preview
|
||||
previewTelegraph = ability.createTelegraph(npc, fakeTarget);
|
||||
previewTelegraph = ability.createTelegraph(previewNpc, fakeTarget);
|
||||
|
||||
// Start windup animation
|
||||
Animation windUpAnim = ability.getWindUpAnimation();
|
||||
if (windUpAnim != null) {
|
||||
AnimationData data = npc.display.animationData;
|
||||
AnimationData data = previewNpc.display.animationData;
|
||||
data.setEnabled(true);
|
||||
data.setAnimation(windUpAnim);
|
||||
data.animation.paused = false;
|
||||
@@ -213,6 +296,13 @@ public class AbilityPreviewExecutor implements PreviewEntityHandler {
|
||||
executorPhase = ExecutorPhase.IDLE;
|
||||
currentTick = 0;
|
||||
|
||||
// Clear chain state
|
||||
previewChain = null;
|
||||
chainAbilities = null;
|
||||
chainDelays = null;
|
||||
chainIndex = -1;
|
||||
chainDelayRemaining = 0;
|
||||
|
||||
previewTelegraph = null;
|
||||
|
||||
if (parentGui != null) {
|
||||
@@ -283,6 +373,9 @@ public class AbilityPreviewExecutor implements PreviewEntityHandler {
|
||||
case EXTENDED:
|
||||
tickExtended();
|
||||
break;
|
||||
case CHAIN_DELAY:
|
||||
tickChainDelay();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -306,13 +399,21 @@ public class AbilityPreviewExecutor implements PreviewEntityHandler {
|
||||
|
||||
// Check if the ability signaled completion (phase went to IDLE)
|
||||
if (previewAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
transitionToExtended();
|
||||
if (hasNextChainEntry()) {
|
||||
transitionToChainDelay();
|
||||
} else {
|
||||
transitionToExtended();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Safety timeout
|
||||
if (currentTick >= maxPreviewDuration) {
|
||||
transitionToExtended();
|
||||
if (hasNextChainEntry()) {
|
||||
transitionToChainDelay();
|
||||
} else {
|
||||
transitionToExtended();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,6 +424,44 @@ public class AbilityPreviewExecutor implements PreviewEntityHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== CHAIN ADVANCEMENT ====================
|
||||
|
||||
private boolean hasNextChainEntry() {
|
||||
return previewChain != null && chainAbilities != null && chainIndex < chainAbilities.size() - 1;
|
||||
}
|
||||
|
||||
private void transitionToChainDelay() {
|
||||
executorPhase = ExecutorPhase.CHAIN_DELAY;
|
||||
currentTick = 0;
|
||||
|
||||
// Use the NEXT entry's delay
|
||||
int nextIndex = chainIndex + 1;
|
||||
chainDelayRemaining = (nextIndex < chainDelays.size()) ? chainDelays.get(nextIndex) : 0;
|
||||
|
||||
// Clear current animation
|
||||
if (previewNpc != null) {
|
||||
AnimationData data = previewNpc.display.animationData;
|
||||
data.setAnimation(new Animation());
|
||||
}
|
||||
}
|
||||
|
||||
private void tickChainDelay() {
|
||||
if (chainDelayRemaining > 0) {
|
||||
chainDelayRemaining--;
|
||||
return;
|
||||
}
|
||||
advanceChainEntry();
|
||||
}
|
||||
|
||||
private void advanceChainEntry() {
|
||||
chainIndex++;
|
||||
if (chainIndex >= chainAbilities.size()) {
|
||||
transitionToExtended();
|
||||
return;
|
||||
}
|
||||
beginAbilityPreview(chainAbilities.get(chainIndex));
|
||||
}
|
||||
|
||||
private void transitionToActive() {
|
||||
executorPhase = ExecutorPhase.ACTIVE;
|
||||
currentTick = 0;
|
||||
@@ -424,33 +563,73 @@ public class AbilityPreviewExecutor implements PreviewEntityHandler {
|
||||
|
||||
// ==================== GETTERS ====================
|
||||
|
||||
public boolean isPlaying() { return playing; }
|
||||
public boolean isPaused() { return paused; }
|
||||
public boolean isActive() { return playing || paused; }
|
||||
public boolean isPlaying() {
|
||||
return playing;
|
||||
}
|
||||
|
||||
public boolean isPaused() {
|
||||
return paused;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return playing || paused;
|
||||
}
|
||||
|
||||
public boolean isChainPreview() {
|
||||
return previewChain != null;
|
||||
}
|
||||
|
||||
public AbilityPhase getPhase() {
|
||||
switch (executorPhase) {
|
||||
case WINDUP: return AbilityPhase.WINDUP;
|
||||
case ACTIVE: return AbilityPhase.ACTIVE;
|
||||
default: return AbilityPhase.IDLE;
|
||||
case WINDUP:
|
||||
return AbilityPhase.WINDUP;
|
||||
case ACTIVE:
|
||||
return AbilityPhase.ACTIVE;
|
||||
default:
|
||||
return AbilityPhase.IDLE;
|
||||
}
|
||||
}
|
||||
public int getCurrentTick() { return currentTick; }
|
||||
public TelegraphInstance getTelegraph() { return previewTelegraph; }
|
||||
public List<Entity> getPreviewEntities() { return previewEntities; }
|
||||
public Ability getPreviewAbility() { return previewAbility; }
|
||||
public EntityNPCInterface getPreviewNpc() { return previewNpc; }
|
||||
|
||||
public int getCurrentTick() {
|
||||
return currentTick;
|
||||
}
|
||||
|
||||
public TelegraphInstance getTelegraph() {
|
||||
return previewTelegraph;
|
||||
}
|
||||
|
||||
public List<Entity> getPreviewEntities() {
|
||||
return previewEntities;
|
||||
}
|
||||
|
||||
public Ability getPreviewAbility() {
|
||||
return previewAbility;
|
||||
}
|
||||
|
||||
public EntityNPCInterface getPreviewNpc() {
|
||||
return previewNpc;
|
||||
}
|
||||
|
||||
public String getStatusString() {
|
||||
if (!playing && !paused) {
|
||||
return "Stopped";
|
||||
} else if (paused) {
|
||||
return "Paused";
|
||||
}
|
||||
|
||||
String chainPrefix = "";
|
||||
if (previewChain != null && chainAbilities != null) {
|
||||
chainPrefix = "Chain " + (chainIndex + 1) + "/" + chainAbilities.size() + " - ";
|
||||
}
|
||||
|
||||
if (paused) {
|
||||
return chainPrefix + "Paused";
|
||||
} else if (executorPhase == ExecutorPhase.WINDUP) {
|
||||
return "Windup: " + currentTick + "/" + (previewAbility != null ? previewAbility.getWindUpTicks() : 0);
|
||||
return chainPrefix + "Windup: " + currentTick + "/" + (previewAbility != null ? previewAbility.getWindUpTicks() : 0);
|
||||
} else if (executorPhase == ExecutorPhase.ACTIVE) {
|
||||
return "Active: " + currentTick + "/" + maxPreviewDuration;
|
||||
return chainPrefix + "Active: " + currentTick + "/" + maxPreviewDuration;
|
||||
} else if (executorPhase == ExecutorPhase.EXTENDED) {
|
||||
return "Extended: " + currentTick + "/" + EXTENDED_DURATION;
|
||||
return chainPrefix + "Extended: " + currentTick + "/" + EXTENDED_DURATION;
|
||||
} else if (executorPhase == ExecutorPhase.CHAIN_DELAY) {
|
||||
return chainPrefix + "Delay: " + chainDelayRemaining;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Base GUI class for ability preview with fixed camera.
|
||||
*
|
||||
* <p>
|
||||
* Key concepts:
|
||||
* - NPC positioned on left side of preview area
|
||||
* - NPC faces a fixed direction (NPC_FACING_YAW)
|
||||
@@ -33,15 +33,23 @@ import java.util.List;
|
||||
public class GuiAbilityInterface extends GuiNPCInterface2 {
|
||||
|
||||
// ==================== FIXED CAMERA SETTINGS ====================
|
||||
/** Fixed camera zoom level (higher = more zoomed in) */
|
||||
/**
|
||||
* Fixed camera zoom level (higher = more zoomed in)
|
||||
*/
|
||||
protected static float CAMERA_ZOOM = 45.0f;
|
||||
/** NPC facing direction - affects anchor points and visual facing */
|
||||
/**
|
||||
* NPC facing direction - affects anchor points and visual facing
|
||||
*/
|
||||
protected static float NPC_FACING_YAW = 160.0f;
|
||||
/** Camera pitch (slight downward angle) */
|
||||
/**
|
||||
* Camera pitch (slight downward angle)
|
||||
*/
|
||||
protected static float CAMERA_PITCH = 10.0f;
|
||||
|
||||
// ==================== VIEWING ROTATION ====================
|
||||
/** Viewing direction rotation (rotates entire 3D space) */
|
||||
/**
|
||||
* Viewing direction rotation (rotates entire 3D space)
|
||||
*/
|
||||
protected static float viewRotation = 0.0f;
|
||||
|
||||
private GuiNpcButton btnLeft, btnRight;
|
||||
@@ -49,21 +57,33 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
|
||||
// ==================== NPC STATE ====================
|
||||
public EntityNPCInterface npc;
|
||||
|
||||
/** NPC starting position (saved when preview starts, used to track movement) */
|
||||
/**
|
||||
* NPC starting position (saved when preview starts, used to track movement)
|
||||
*/
|
||||
protected double npcStartX, npcStartY, npcStartZ;
|
||||
/** Whether we're tracking NPC movement */
|
||||
/**
|
||||
* Whether we're tracking NPC movement
|
||||
*/
|
||||
protected boolean trackingNpcMovement = false;
|
||||
|
||||
/** Entities to render in preview space */
|
||||
/**
|
||||
* Entities to render in preview space
|
||||
*/
|
||||
protected List<Entity> previewEntities = new ArrayList<>();
|
||||
|
||||
/** Current telegraph to render in preview */
|
||||
/**
|
||||
* Current telegraph to render in preview
|
||||
*/
|
||||
protected TelegraphInstance previewTelegraph;
|
||||
|
||||
// ==================== LAYOUT ====================
|
||||
/** Preview area bounds */
|
||||
/**
|
||||
* Preview area bounds
|
||||
*/
|
||||
protected int previewX, previewY, previewWidth, previewHeight;
|
||||
/** NPC render position on screen */
|
||||
/**
|
||||
* NPC render position on screen
|
||||
*/
|
||||
protected int npcScreenX, npcScreenY;
|
||||
|
||||
public int xOffset = 0;
|
||||
@@ -74,7 +94,7 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param npc The NPC for preview rendering
|
||||
* @param npc The NPC for preview rendering
|
||||
* @param hasMenuNpc If false, the top menu tabs (Display, Stats, etc.) are hidden.
|
||||
* Use false when opened from the global menu without a real NPC.
|
||||
*/
|
||||
@@ -99,8 +119,8 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
|
||||
previewHeight = 180;
|
||||
|
||||
// NPC position: left side of preview, slightly below center
|
||||
npcScreenX = previewX + (int)(previewWidth * 0.33f) + xOffset;
|
||||
npcScreenY = previewY + (int)(previewHeight * 0.85f) + yOffset;
|
||||
npcScreenX = previewX + (int) (previewWidth * 0.33f) + xOffset;
|
||||
npcScreenY = previewY + (int) (previewHeight * 0.85f) + yOffset;
|
||||
|
||||
// Viewing rotation buttons (below preview area)
|
||||
int btnY = guiTop + 192;
|
||||
@@ -351,7 +371,7 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
|
||||
super.drawBackground();
|
||||
|
||||
drawGradientRect(previewX, previewY, previewX + previewWidth, previewY + previewHeight,
|
||||
0xc0101010, 0xd0101010);
|
||||
0xc0101010, 0xd0101010);
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
@@ -364,8 +384,9 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
|
||||
|
||||
@Override
|
||||
public void keyTyped(char par1, int par2) {
|
||||
boolean hadSubGui = hasSubGui();
|
||||
super.keyTyped(par1, par2);
|
||||
if (par2 == 1) {
|
||||
if (par2 == 1 && !hadSubGui) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,14 +64,14 @@ public class GuiAuctionNavButton extends GuiNpcButton {
|
||||
/**
|
||||
* Create a fully customizable button.
|
||||
*
|
||||
* @param id Button ID
|
||||
* @param x X position
|
||||
* @param y Y position
|
||||
* @param buttonSize Size of the button background texture (e.g., 18 for 18x18, 10 for 10x10)
|
||||
* @param iconSize Size of the icon texture (e.g., 16 for 16x16, 8 for 8x8)
|
||||
* @param tooltipKey Lang key for tooltip
|
||||
* @param iconTexture Icon texture to draw inside the button
|
||||
* @param textureNormal Background texture for normal state
|
||||
* @param id Button ID
|
||||
* @param x X position
|
||||
* @param y Y position
|
||||
* @param buttonSize Size of the button background texture (e.g., 18 for 18x18, 10 for 10x10)
|
||||
* @param iconSize Size of the icon texture (e.g., 16 for 16x16, 8 for 8x8)
|
||||
* @param tooltipKey Lang key for tooltip
|
||||
* @param iconTexture Icon texture to draw inside the button
|
||||
* @param textureNormal Background texture for normal state
|
||||
* @param texturePressed Background texture for pressed/hover state
|
||||
*/
|
||||
public GuiAuctionNavButton(int id, int x, int y, int buttonSize, int iconSize, String tooltipKey,
|
||||
|
||||
@@ -4,29 +4,29 @@ package noppes.npcs.client.gui.util;
|
||||
* Abstract base class for fullscreen directory-browsing GUIs.
|
||||
* Provides a configurable three-panel layout (left nav, center content, right actions)
|
||||
* with percentage-based sizing, panel backgrounds/borders, and an optional resizable divider.
|
||||
*
|
||||
* <p>
|
||||
* Subclasses override abstract hooks to populate each panel region.
|
||||
* Designed for reuse across Cloner, Quest Manager, Dialog Manager, etc.
|
||||
*/
|
||||
public abstract class GuiDirectory extends GuiNPCInterface implements ICustomScrollListener, ISubGuiListener {
|
||||
|
||||
// ===== LAYOUT CONFIG (subclasses may override in constructor) =====
|
||||
protected float leftPanelPercent = 0.20f;
|
||||
protected float leftPanelPercent = 0.20f;
|
||||
protected float rightPanelPercent = 0.10f;
|
||||
protected int minLeftPanelW = 80;
|
||||
protected int minLeftPanelW = 80;
|
||||
protected int minRightPanelW = 40;
|
||||
protected int minCenterW = 100;
|
||||
protected int minCenterW = 100;
|
||||
|
||||
// ===== LAYOUT CONSTANTS =====
|
||||
protected int pad = 10;
|
||||
protected int pad = 10;
|
||||
protected int topBarH = 24;
|
||||
protected int gap = 4;
|
||||
protected int btnH = 20;
|
||||
protected int gap = 4;
|
||||
protected int btnH = 20;
|
||||
|
||||
// ===== PANEL COLORS =====
|
||||
protected int panelBg = 0xC0101010;
|
||||
protected int panelBg = 0xC0101010;
|
||||
protected int panelBorder = 0xFF333333;
|
||||
protected int topBarBg = 0xC0181818;
|
||||
protected int topBarBg = 0xC0181818;
|
||||
|
||||
// ===== COMPUTED LAYOUT (populated by computeLayout) =====
|
||||
protected int originX, originY, usableW, usableH;
|
||||
@@ -35,10 +35,10 @@ public abstract class GuiDirectory extends GuiNPCInterface implements ICustomScr
|
||||
protected int rightX;
|
||||
|
||||
// ===== OPTIONAL RESIZABLE DIVIDER (between left and center) =====
|
||||
protected boolean enableDivider = false;
|
||||
protected int dividerWidth = 5;
|
||||
protected int dividerLineHeight = 20;
|
||||
protected int minDividerPanelW = 50;
|
||||
protected boolean enableDivider = false;
|
||||
protected int dividerWidth = 5;
|
||||
protected int dividerLineHeight = 20;
|
||||
protected int minDividerPanelW = 50;
|
||||
private int dividerOffset;
|
||||
private boolean isDragging = false;
|
||||
private int dragStartX;
|
||||
@@ -57,8 +57,8 @@ public abstract class GuiDirectory extends GuiNPCInterface implements ICustomScr
|
||||
usableW = width - 2 * pad;
|
||||
usableH = height - 2 * pad;
|
||||
|
||||
leftPanelW = Math.max(minLeftPanelW, (int)(usableW * leftPanelPercent));
|
||||
rightPanelW = Math.max(minRightPanelW, (int)(usableW * rightPanelPercent));
|
||||
leftPanelW = Math.max(minLeftPanelW, (int) (usableW * leftPanelPercent));
|
||||
rightPanelW = Math.max(minRightPanelW, (int) (usableW * rightPanelPercent));
|
||||
|
||||
if (rightPanelPercent <= 0) {
|
||||
rightPanelW = 0;
|
||||
@@ -73,7 +73,7 @@ public abstract class GuiDirectory extends GuiNPCInterface implements ICustomScr
|
||||
contentX = originX + leftPanelW + gap;
|
||||
contentY = originY + topBarH + gap;
|
||||
contentH = usableH - topBarH - gap;
|
||||
rightX = contentX + contentW + gap;
|
||||
rightX = contentX + contentW + gap;
|
||||
|
||||
if (enableDivider && dividerOffset == 0) {
|
||||
dividerOffset = leftPanelW;
|
||||
@@ -128,7 +128,9 @@ public abstract class GuiDirectory extends GuiNPCInterface implements ICustomScr
|
||||
drawRect(divX + 1, handleTop, divX + dividerWidth - 1, handleTop + dividerLineHeight, 0xFF707070);
|
||||
}
|
||||
|
||||
/** Override for extra drawing after super.drawScreen (e.g. status text) */
|
||||
/**
|
||||
* Override for extra drawing after super.drawScreen (e.g. status text)
|
||||
*/
|
||||
protected void drawOverlay(int mouseX, int mouseY, float partialTicks) {
|
||||
}
|
||||
|
||||
@@ -177,7 +179,9 @@ public abstract class GuiDirectory extends GuiNPCInterface implements ICustomScr
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
/** Called when divider is dragged. Override to update scroll sizes. */
|
||||
/**
|
||||
* Called when divider is dragged. Override to update scroll sizes.
|
||||
*/
|
||||
protected void onDividerMoved(int newOffset) {
|
||||
}
|
||||
|
||||
@@ -192,15 +196,23 @@ public abstract class GuiDirectory extends GuiNPCInterface implements ICustomScr
|
||||
|
||||
// ===== ABSTRACT HOOKS (subclass must implement) =====
|
||||
|
||||
/** Populate top bar buttons. topBtnY is the y-coordinate for the button row. */
|
||||
/**
|
||||
* Populate top bar buttons. topBtnY is the y-coordinate for the button row.
|
||||
*/
|
||||
protected abstract void initTopBar(int topBtnY);
|
||||
|
||||
/** Populate the left navigation panel (scrolls, search fields, buttons). */
|
||||
/**
|
||||
* Populate the left navigation panel (scrolls, search fields, buttons).
|
||||
*/
|
||||
protected abstract void initLeftPanel();
|
||||
|
||||
/** Populate the center content panel (main scroll list). */
|
||||
/**
|
||||
* Populate the center content panel (main scroll list).
|
||||
*/
|
||||
protected abstract void initCenterPanel();
|
||||
|
||||
/** Populate the right action panel. startY is the first button y-coordinate. */
|
||||
/**
|
||||
* Populate the right action panel. startY is the first button y-coordinate.
|
||||
*/
|
||||
protected abstract void initRightPanel(int startY);
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class GuiModelInterface2 extends GuiNPCInterface2 {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param npc The NPC for preview rendering
|
||||
* @param npc The NPC for preview rendering
|
||||
* @param hasMenuNpc If false, the top menu tabs (Display, Stats, etc.) are hidden.
|
||||
* Use false when opened from the global menu without a real NPC.
|
||||
*/
|
||||
@@ -151,8 +151,9 @@ public class GuiModelInterface2 extends GuiNPCInterface2 {
|
||||
|
||||
@Override
|
||||
public void keyTyped(char par1, int par2) {
|
||||
boolean hadSubGui = hasSubGui();
|
||||
super.keyTyped(par1, par2);
|
||||
if (par2 == 1) {
|
||||
if (par2 == 1 && !hadSubGui) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,12 +60,13 @@ public class GuiNpcLabel extends Gui {
|
||||
|
||||
/**
|
||||
* Draws hover tooltip if the mouse is over this label.
|
||||
* @param localMouseX Mouse X in scroll-local coordinates (for hit testing)
|
||||
* @param localMouseY Mouse Y in scroll-local coordinates (for hit testing)
|
||||
*
|
||||
* @param localMouseX Mouse X in scroll-local coordinates (for hit testing)
|
||||
* @param localMouseY Mouse Y in scroll-local coordinates (for hit testing)
|
||||
* @param screenMouseX Mouse X in screen coordinates (for tooltip positioning)
|
||||
* @param screenMouseY Mouse Y in screen coordinates (for tooltip positioning)
|
||||
* @param hasSubGui Whether a sub-gui is open
|
||||
* @param fr FontRenderer for measuring label width
|
||||
* @param hasSubGui Whether a sub-gui is open
|
||||
* @param fr FontRenderer for measuring label width
|
||||
*/
|
||||
public void drawHover(int localMouseX, int localMouseY, int screenMouseX, int screenMouseY, boolean hasSubGui, FontRenderer fr) {
|
||||
if (hasSubGui || hoverableText.isEmpty()) return;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import kamkeel.npcs.util.TextSplitter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import kamkeel.npcs.util.TextSplitter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class GuiNpcTextField extends GuiTextField {
|
||||
public boolean enabled = true;
|
||||
@@ -224,7 +224,7 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
|
||||
public boolean isMouseOver(int mouseX, int mouseY) {
|
||||
return mouseX >= xPosition && mouseX < xPosition + width &&
|
||||
mouseY >= yPosition && mouseY < yPosition + height;
|
||||
mouseY >= yPosition && mouseY < yPosition + height;
|
||||
}
|
||||
|
||||
public void drawHover(int mouseX, int mouseY, boolean hasSubGui) {
|
||||
@@ -334,14 +334,14 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
}
|
||||
|
||||
protected void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor, int zLevel) {
|
||||
float f = (float)(startColor >> 24 & 255) / 255.0F;
|
||||
float f1 = (float)(startColor >> 16 & 255) / 255.0F;
|
||||
float f2 = (float)(startColor >> 8 & 255) / 255.0F;
|
||||
float f3 = (float)(startColor & 255) / 255.0F;
|
||||
float f4 = (float)(endColor >> 24 & 255) / 255.0F;
|
||||
float f5 = (float)(endColor >> 16 & 255) / 255.0F;
|
||||
float f6 = (float)(endColor >> 8 & 255) / 255.0F;
|
||||
float f7 = (float)(endColor & 255) / 255.0F;
|
||||
float f = (float) (startColor >> 24 & 255) / 255.0F;
|
||||
float f1 = (float) (startColor >> 16 & 255) / 255.0F;
|
||||
float f2 = (float) (startColor >> 8 & 255) / 255.0F;
|
||||
float f3 = (float) (startColor & 255) / 255.0F;
|
||||
float f4 = (float) (endColor >> 24 & 255) / 255.0F;
|
||||
float f5 = (float) (endColor >> 16 & 255) / 255.0F;
|
||||
float f6 = (float) (endColor >> 8 & 255) / 255.0F;
|
||||
float f7 = (float) (endColor & 255) / 255.0F;
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
@@ -350,11 +350,11 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
net.minecraft.client.renderer.Tessellator tessellator = net.minecraft.client.renderer.Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA_F(f1, f2, f3, f);
|
||||
tessellator.addVertex((double)right, (double)top, (double)zLevel);
|
||||
tessellator.addVertex((double)left, (double)top, (double)zLevel);
|
||||
tessellator.addVertex((double) right, (double) top, (double) zLevel);
|
||||
tessellator.addVertex((double) left, (double) top, (double) zLevel);
|
||||
tessellator.setColorRGBA_F(f5, f6, f7, f4);
|
||||
tessellator.addVertex((double)left, (double)bottom, (double)zLevel);
|
||||
tessellator.addVertex((double)right, (double)bottom, (double)zLevel);
|
||||
tessellator.addVertex((double) left, (double) bottom, (double) zLevel);
|
||||
tessellator.addVertex((double) right, (double) bottom, (double) zLevel);
|
||||
tessellator.draw();
|
||||
GL11.glShadeModel(GL11.GL_FLAT);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
|
||||
|
||||
/**
|
||||
* Callback for when a chained ability is saved from the config SubGui.
|
||||
*/
|
||||
public interface IChainedAbilityConfigCallback {
|
||||
void onChainedAbilitySaved(ChainedAbility chain);
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import java.util.UUID;
|
||||
|
||||
public interface IClonerGui {
|
||||
int getShowingClones();
|
||||
|
||||
HashMap<UUID, Tag> getTags();
|
||||
|
||||
TagMap getTagMap();
|
||||
}
|
||||
@@ -79,11 +79,12 @@ public class ConfigMarket {
|
||||
CurrencyName = config.get(CURRENCY, "Currency Name", "Coins",
|
||||
"Display name for the currency (e.g. 'Coins', 'Gold', 'Credits')").getString();
|
||||
|
||||
StartingBalance = config.get(CURRENCY, "Starting Balance", 0,
|
||||
"Starting currency balance for new players").getInt(0);
|
||||
StartingBalance = parseLongConfig(config.get(CURRENCY, "Starting Balance", "0",
|
||||
"Starting currency balance for new players").getString(), 0);
|
||||
|
||||
MaxBalance = config.get(CURRENCY, "Max Balance", Integer.MAX_VALUE,
|
||||
"Maximum currency balance a player can have").getInt(Integer.MAX_VALUE);
|
||||
MaxBalance = parseLongConfig(config.get(CURRENCY, "Max Balance", String.valueOf(Long.MAX_VALUE),
|
||||
"Maximum currency balance a player can have").getString(), Long.MAX_VALUE);
|
||||
if (MaxBalance < 0) MaxBalance = Long.MAX_VALUE;
|
||||
|
||||
// =========================================
|
||||
// Auction Settings
|
||||
@@ -95,16 +96,19 @@ public class ConfigMarket {
|
||||
|
||||
AuctionDurationHours = config.get(AUCTION, "Auction Duration Hours", 24,
|
||||
"Default duration for auctions in hours").getInt(24);
|
||||
if (AuctionDurationHours < 1) AuctionDurationHours = 1;
|
||||
|
||||
ListingFee = config.get(AUCTION, "Listing Fee", 10,
|
||||
"Flat fee charged when creating a listing").getInt(10);
|
||||
ListingFee = parseLongConfig(config.get(AUCTION, "Listing Fee", "10",
|
||||
"Flat fee charged when creating a listing").getString(), 10);
|
||||
if (ListingFee < 0) ListingFee = 0;
|
||||
|
||||
MinimumListingPrice = config.get(AUCTION, "Minimum Listing Price", 1,
|
||||
"Minimum starting price for auction listings").getInt(1);
|
||||
MinimumListingPrice = parseLongConfig(config.get(AUCTION, "Minimum Listing Price", "1",
|
||||
"Minimum starting price for auction listings").getString(), 1);
|
||||
if (MinimumListingPrice < 1) MinimumListingPrice = 1;
|
||||
|
||||
SalesTaxPercent = config.get(AUCTION, "Sales Tax Percent", 0.05,
|
||||
"Percentage of sale price taken as tax (0.05 = 5%). Tax is deleted as a currency sink.").getDouble(0.05);
|
||||
SalesTaxPercent = Math.max(0.0, Math.min(1.0, SalesTaxPercent));
|
||||
|
||||
int maxTrades = config.get(AUCTION, "Default Max Trades", 8,
|
||||
"Default maximum number of trade slots per player (listings + bids + claims). Min: 1, Max: 45. Players can have more via customnpcs.auction.trades.X permissions.").getInt(8);
|
||||
@@ -112,26 +116,30 @@ public class ConfigMarket {
|
||||
|
||||
SnipeProtectionMinutes = config.get(AUCTION, "Snipe Protection Minutes", 2,
|
||||
"When a bid is placed with less than this many minutes remaining, the auction is extended to this duration").getInt(2);
|
||||
if (SnipeProtectionMinutes < 0) SnipeProtectionMinutes = 0;
|
||||
|
||||
ClaimExpirationDays = config.get(AUCTION, "Claim Expiration Days", 20,
|
||||
"Number of days before unclaimed items/currency are deleted").getInt(20);
|
||||
if (ClaimExpirationDays < 1) ClaimExpirationDays = 1;
|
||||
|
||||
MinBidIncrementPercent = config.get(AUCTION, "Min Bid Increment Percent", 0.05,
|
||||
"Minimum bid increment as a percentage of current bid (0.05 = 5%)").getDouble(0.05);
|
||||
MinBidIncrementPercent = Math.max(0.0, Math.min(1.0, MinBidIncrementPercent));
|
||||
|
||||
CancellationPenaltyPercent = config.get(AUCTION, "Cancellation Penalty Percent", 0.10,
|
||||
"Percentage of current bid taken as penalty when seller cancels an auction with bids (0.10 = 10%)").getDouble(0.10);
|
||||
CancellationPenaltyPercent = Math.max(0.0, Math.min(1.0, CancellationPenaltyPercent));
|
||||
|
||||
// =========================================
|
||||
// Auction Blacklist Settings
|
||||
// =========================================
|
||||
config.setCategoryComment(AUCTION_BLACKLIST,
|
||||
"Item Blacklist settings for the Auction House.\n" +
|
||||
"Prevents specific items, mods, or items with certain NBT tags from being listed.\n\n" +
|
||||
"ITEM FORMAT: Use 'modid:itemname' format (e.g., 'minecraft:bedrock', 'customnpcs:npcWand')\n" +
|
||||
"WILDCARDS: Use * for wildcards (e.g., 'customnpcs:npc*' blocks all items starting with 'npc')\n" +
|
||||
"MOD FORMAT: Use just the mod ID (e.g., 'projecte' blocks all items from that mod)\n" +
|
||||
"NBT FORMAT: Use the NBT tag key name (e.g., 'AdminOnly' blocks items with that tag)");
|
||||
"Prevents specific items, mods, or items with certain NBT tags from being listed.\n\n" +
|
||||
"ITEM FORMAT: Use 'modid:itemname' format (e.g., 'minecraft:bedrock', 'customnpcs:npcWand')\n" +
|
||||
"WILDCARDS: Use * for wildcards (e.g., 'customnpcs:npc*' blocks all items starting with 'npc')\n" +
|
||||
"MOD FORMAT: Use just the mod ID (e.g., 'projecte' blocks all items from that mod)\n" +
|
||||
"NBT FORMAT: Use the NBT tag key name (e.g., 'AdminOnly' blocks items with that tag)");
|
||||
|
||||
BlacklistEnabled = config.get(AUCTION_BLACKLIST, "Enable Blacklist", true,
|
||||
"Enable item blacklist checking when creating listings").getBoolean(true);
|
||||
@@ -149,17 +157,17 @@ public class ConfigMarket {
|
||||
"customnpcs:npcSoulstoneFilled"
|
||||
},
|
||||
"Items that cannot be listed on the Auction House.\n" +
|
||||
"Format: modid:itemname (supports * wildcards)\n" +
|
||||
"Example: 'minecraft:diamond_sword' or 'customnpcs:npc*'").getStringList();
|
||||
"Format: modid:itemname (supports * wildcards)\n" +
|
||||
"Example: 'minecraft:diamond_sword' or 'customnpcs:npc*'").getStringList();
|
||||
|
||||
BlacklistedMods = config.get(AUCTION_BLACKLIST, "Blacklisted Mods", new String[]{},
|
||||
"All items from these mods are blocked from the Auction House.\n" +
|
||||
"Format: modid (e.g., 'projecte', 'thaumcraft')").getStringList();
|
||||
"Format: modid (e.g., 'projecte', 'thaumcraft')").getStringList();
|
||||
|
||||
BlacklistedNBTTags = config.get(AUCTION_BLACKLIST, "Blacklisted NBT Tags", new String[]{},
|
||||
"Items containing any of these NBT tag keys are blocked.\n" +
|
||||
"Checks the root level of the item's NBT compound.\n" +
|
||||
"Example: 'AdminOnly', 'CreativeMode'").getStringList();
|
||||
"Checks the root level of the item's NBT compound.\n" +
|
||||
"Example: 'AdminOnly', 'CreativeMode'").getStringList();
|
||||
|
||||
// =========================================
|
||||
// Auction Logging Settings
|
||||
@@ -237,4 +245,13 @@ public class ConfigMarket {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static long parseLongConfig(String value, long defaultValue) {
|
||||
if (value == null || value.trim().isEmpty()) return defaultValue;
|
||||
try {
|
||||
return Long.parseLong(value.trim());
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
/**
|
||||
* Enum for auction log action types.
|
||||
* Used by AuctionController.logAuction() for type-safe logging.
|
||||
*/
|
||||
public enum EnumAuctionLogAction {
|
||||
CREATED,
|
||||
BID,
|
||||
BUYOUT,
|
||||
SOLD,
|
||||
EXPIRED,
|
||||
CANCELLED,
|
||||
CLAIMED,
|
||||
CLAIM_EXPIRED;
|
||||
|
||||
/**
|
||||
* Check if this action should be logged based on config settings
|
||||
*/
|
||||
public boolean shouldLog() {
|
||||
if (!ConfigMarket.AuctionLoggingEnabled) return false;
|
||||
switch (this) {
|
||||
case CREATED:
|
||||
return ConfigMarket.LogAuctionCreated;
|
||||
case BID:
|
||||
return ConfigMarket.LogAuctionBid;
|
||||
case BUYOUT:
|
||||
return ConfigMarket.LogAuctionBuyout;
|
||||
case SOLD:
|
||||
return ConfigMarket.LogAuctionSold;
|
||||
case EXPIRED:
|
||||
return ConfigMarket.LogAuctionExpired;
|
||||
case CANCELLED:
|
||||
return ConfigMarket.LogAuctionCancelled;
|
||||
case CLAIMED:
|
||||
case CLAIM_EXPIRED:
|
||||
return ConfigMarket.LogAuctionClaimed;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
/**
|
||||
* Enum for auction GUI page navigation.
|
||||
* Maps page indices to GUI types for packet-based navigation.
|
||||
*/
|
||||
public enum EnumAuctionPage {
|
||||
LISTINGS(EnumGuiType.PlayerAuction),
|
||||
SELL(EnumGuiType.PlayerAuctionSell),
|
||||
TRADES(EnumGuiType.PlayerAuctionTrades);
|
||||
|
||||
private final EnumGuiType guiType;
|
||||
|
||||
EnumAuctionPage(EnumGuiType guiType) {
|
||||
this.guiType = guiType;
|
||||
}
|
||||
|
||||
public EnumGuiType getGuiType() {
|
||||
return guiType;
|
||||
}
|
||||
|
||||
public static EnumAuctionPage fromOrdinal(int ordinal) {
|
||||
if (ordinal >= 0 && ordinal < values().length) {
|
||||
return values()[ordinal];
|
||||
}
|
||||
return LISTINGS;
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,8 @@ public enum EnumScriptType {
|
||||
ABILITY_COMPLETE("abilityComplete"),
|
||||
ABILITY_HIT("abilityHit"),
|
||||
ABILITY_TICK("abilityTick"),
|
||||
ABILITY_TOGGLE("abilityToggle"),
|
||||
ABILITY_TOGGLE_UPDATE("abilityToggleUpdate"),
|
||||
|
||||
ENERGY_PROJECTILE_FIRED("energyProjectileFired"),
|
||||
ENERGY_PROJECTILE_TICK("energyProjectileTick"),
|
||||
@@ -137,7 +139,14 @@ public enum EnumScriptType {
|
||||
ENERGY_BARRIER_SPAWNED("energyBarrierSpawned"),
|
||||
ENERGY_BARRIER_TICK("energyBarrierTick"),
|
||||
ENERGY_BARRIER_HIT("energyBarrierHit"),
|
||||
ENERGY_BARRIER_DESTROYED("energyBarrierDestroyed");
|
||||
ENERGY_BARRIER_DESTROYED("energyBarrierDestroyed"),
|
||||
|
||||
// Auction Events
|
||||
AUCTION_CREATE("auctionCreate"),
|
||||
AUCTION_BID("auctionBid"),
|
||||
AUCTION_BUYOUT("auctionBuyout"),
|
||||
AUCTION_CANCEL("auctionCancel"),
|
||||
AUCTION_CLAIM("auctionClaim");
|
||||
|
||||
public String function;
|
||||
|
||||
|
||||
@@ -10,5 +10,6 @@ public enum EnumScrollData {
|
||||
CUSTOM_ABILITIES,
|
||||
BUILTIN_ABILITIES,
|
||||
ANIMATIONS,
|
||||
BUILTIN_ANIMATIONS
|
||||
BUILTIN_ANIMATIONS,
|
||||
CHAINED_ABILITIES
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
/**
|
||||
* Enum for trade slot types in the player's auction trades view.
|
||||
* Used by ContainerAuctionTrades to identify what each slot contains.
|
||||
*/
|
||||
public enum EnumTradeSlotType {
|
||||
EMPTY,
|
||||
SELLING,
|
||||
BIDDING,
|
||||
CLAIM;
|
||||
|
||||
public boolean isSelling() {
|
||||
return this == SELLING;
|
||||
}
|
||||
|
||||
public boolean isBidding() {
|
||||
return this == BIDDING;
|
||||
}
|
||||
|
||||
public boolean isClaim() {
|
||||
return this == CLAIM;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this == EMPTY;
|
||||
}
|
||||
|
||||
public static EnumTradeSlotType fromOrdinal(int ordinal) {
|
||||
if (ordinal >= 0 && ordinal < values().length) {
|
||||
return values()[ordinal];
|
||||
}
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,11 @@ package noppes.npcs.constants;
|
||||
|
||||
import noppes.npcs.api.event.IAbilityEvent;
|
||||
import noppes.npcs.api.event.IAnimationEvent;
|
||||
import noppes.npcs.api.event.IAuctionEvent;
|
||||
import noppes.npcs.api.event.IBlockEvent;
|
||||
import noppes.npcs.api.event.ICustomGuiEvent;
|
||||
import noppes.npcs.api.event.IDialogEvent;
|
||||
import noppes.npcs.api.event.IEnergyBarrierEvent;
|
||||
import noppes.npcs.api.event.IEnergyProjectileEvent;
|
||||
import noppes.npcs.api.event.IFactionEvent;
|
||||
import noppes.npcs.api.event.IForgeEvent;
|
||||
@@ -57,6 +59,7 @@ public class ScriptContext {
|
||||
INpcEvent.class,
|
||||
IProjectileEvent.class,
|
||||
IEnergyProjectileEvent.class,
|
||||
IEnergyBarrierEvent.class,
|
||||
IAbilityEvent.class,
|
||||
IAnimationEvent.class
|
||||
);
|
||||
@@ -70,7 +73,9 @@ public class ScriptContext {
|
||||
IFactionEvent.class,
|
||||
ICustomGuiEvent.class,
|
||||
IEnergyProjectileEvent.class,
|
||||
IPlayerAbilityEvent.class
|
||||
IEnergyBarrierEvent.class,
|
||||
IPlayerAbilityEvent.class,
|
||||
IAuctionEvent.class
|
||||
);
|
||||
|
||||
public static final ScriptContext BLOCK = register("BLOCK", "block",
|
||||
|
||||
@@ -71,6 +71,7 @@ public class ContainerAuction extends ContainerNpcInterface {
|
||||
|
||||
/**
|
||||
* Get the ItemStack in a player inventory slot.
|
||||
*
|
||||
* @param containerSlotIndex The container slot index (0-35 for player inv)
|
||||
*/
|
||||
public ItemStack getPlayerInventoryStack(int containerSlotIndex) {
|
||||
|
||||
@@ -14,9 +14,9 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
*/
|
||||
public class ContainerAuctionBidding extends ContainerAuction {
|
||||
// Display slot layout
|
||||
private int itemSlotX = 71;
|
||||
private int itemSlotY = 76;
|
||||
private int itemSlotIndex = PLAYER_INV_SLOT_COUNT;
|
||||
private static final int ITEM_SLOT_X = 71;
|
||||
private static final int ITEM_SLOT_Y = 76;
|
||||
private static final int ITEM_SLOT_INDEX = PLAYER_INV_SLOT_COUNT;
|
||||
|
||||
private final IInventory displayInventory;
|
||||
private AuctionListing listing;
|
||||
@@ -26,11 +26,16 @@ public class ContainerAuctionBidding extends ContainerAuction {
|
||||
displayInventory = new InventoryBasic("Display", false, 1);
|
||||
|
||||
// Display slot (read-only)
|
||||
addSlotToContainer(new Slot(displayInventory, 0, itemSlotX, itemSlotY) {
|
||||
addSlotToContainer(new Slot(displayInventory, 0, ITEM_SLOT_X, ITEM_SLOT_Y) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) { return false; }
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player) { return false; }
|
||||
public boolean canTakeStack(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,6 +63,6 @@ public class ContainerAuctionBidding extends ContainerAuction {
|
||||
* Check if this is the display slot.
|
||||
*/
|
||||
public boolean isDisplaySlot(int slotIndex) {
|
||||
return slotIndex == itemSlotIndex;
|
||||
return slotIndex == ITEM_SLOT_INDEX;
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,10 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
* Items are cloned from inventory, not moved. Validation happens on submit.
|
||||
*/
|
||||
public class ContainerAuctionSell extends ContainerAuction {
|
||||
private int sellSlotX = 59;
|
||||
private int sellSlotY = 101;
|
||||
private int sellSlotIndex = PLAYER_INV_SLOT_COUNT;
|
||||
private int maxStack = 64;
|
||||
private static final int SELL_SLOT_X = 59;
|
||||
private static final int SELL_SLOT_Y = 101;
|
||||
private static final int SELL_SLOT_INDEX = PLAYER_INV_SLOT_COUNT;
|
||||
private static final int MAX_STACK = 64;
|
||||
|
||||
private final IInventory sellInventory;
|
||||
|
||||
@@ -25,11 +25,16 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
sellInventory = new InventoryBasic("Sell", false, 1);
|
||||
|
||||
// Sell slot blocks direct interaction
|
||||
addSlotToContainer(new Slot(sellInventory, 0, sellSlotX, sellSlotY) {
|
||||
addSlotToContainer(new Slot(sellInventory, 0, SELL_SLOT_X, SELL_SLOT_Y) {
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack stack) { return false; }
|
||||
public boolean isItemValid(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canTakeStack(EntityPlayer player) { return false; }
|
||||
public boolean canTakeStack(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -44,8 +49,9 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
/**
|
||||
* Add items from inventory to sell slot.
|
||||
* Not limited by inventory - just stages items for sale. Validation on submit.
|
||||
*
|
||||
* @param sourceSlot Inventory slot index
|
||||
* @param fullStack True=full stack, False=1 item
|
||||
* @param fullStack True=full stack, False=1 item
|
||||
*/
|
||||
public void addToSellSlot(int sourceSlot, boolean fullStack) {
|
||||
if (!isPlayerInventorySlot(sourceSlot)) return;
|
||||
@@ -59,11 +65,11 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
if (sellStack == null) {
|
||||
// Empty slot - create new stack
|
||||
ItemStack newStack = source.copy();
|
||||
newStack.stackSize = Math.min(toAdd, maxStack);
|
||||
newStack.stackSize = Math.min(toAdd, MAX_STACK);
|
||||
sellInventory.setInventorySlotContents(0, newStack);
|
||||
} else if (itemsMatch(sellStack, source)) {
|
||||
// Same item - add to existing (capped at 64)
|
||||
int space = maxStack - sellStack.stackSize;
|
||||
int space = MAX_STACK - sellStack.stackSize;
|
||||
int add = Math.min(toAdd, space);
|
||||
if (add > 0) {
|
||||
sellStack.stackSize += add;
|
||||
@@ -71,13 +77,14 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
} else {
|
||||
// Different item - replace
|
||||
ItemStack newStack = source.copy();
|
||||
newStack.stackSize = Math.min(toAdd, maxStack);
|
||||
newStack.stackSize = Math.min(toAdd, MAX_STACK);
|
||||
sellInventory.setInventorySlotContents(0, newStack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove items from sell slot.
|
||||
*
|
||||
* @param removeAll True=clear slot, False=remove 1 item
|
||||
*/
|
||||
public void removeFromSellSlot(boolean removeAll) {
|
||||
@@ -91,12 +98,16 @@ public class ContainerAuctionSell extends ContainerAuction {
|
||||
}
|
||||
}
|
||||
|
||||
/** Check if sell slot is this container slot index */
|
||||
/**
|
||||
* Check if sell slot is this container slot index
|
||||
*/
|
||||
public boolean isSellSlot(int slotIndex) {
|
||||
return slotIndex == sellSlotIndex;
|
||||
return slotIndex == SELL_SLOT_INDEX;
|
||||
}
|
||||
|
||||
/** Check if two stacks match using NoppesUtilPlayer.compareItems (same item, damage, and NBT) */
|
||||
/**
|
||||
* Check if two stacks match using NoppesUtilPlayer.compareItems (same item, damage, and NBT)
|
||||
*/
|
||||
private boolean itemsMatch(ItemStack a, ItemStack b) {
|
||||
return NoppesUtilPlayer.compareItems(a, b, false, false);
|
||||
}
|
||||
|
||||
@@ -5,12 +5,14 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.constants.EnumClaimType;
|
||||
import noppes.npcs.constants.EnumTradeSlotType;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
import noppes.npcs.controllers.data.AuctionClaim;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -34,7 +36,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
private int maxTradeSlots = 8; // Player's max trade slots (permission-aware, synced from server)
|
||||
|
||||
// Slot type tracking for proper accessor methods
|
||||
private int[] slotTypes = new int[SLOT_COUNT]; // 0=empty, 1=selling, 2=bidding, 3=claim
|
||||
private EnumTradeSlotType[] slotTypes = new EnumTradeSlotType[SLOT_COUNT];
|
||||
private int[] slotDataIndex = new int[SLOT_COUNT]; // Index into respective list
|
||||
|
||||
public ContainerAuctionTrades(EntityNPCInterface npc, EntityPlayer player) {
|
||||
@@ -53,7 +55,9 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
refreshData();
|
||||
}
|
||||
|
||||
/** Refresh data from controller (server-side only) */
|
||||
/**
|
||||
* Refresh data from controller (server-side only)
|
||||
*/
|
||||
public void refreshData() {
|
||||
// Clear existing data
|
||||
clearData();
|
||||
@@ -68,7 +72,9 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
populateDisplay(newListings, newBids, newClaims);
|
||||
}
|
||||
|
||||
/** Set data from NBT received from server (client-side) */
|
||||
/**
|
||||
* Set data from NBT received from server (client-side)
|
||||
*/
|
||||
public void setTradesData(NBTTagCompound compound) {
|
||||
// Clear existing data
|
||||
clearData();
|
||||
@@ -109,7 +115,9 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
populateDisplay(newListings, newBids, newClaims);
|
||||
}
|
||||
|
||||
/** Clear all data and reset display */
|
||||
/**
|
||||
* Clear all data and reset display
|
||||
*/
|
||||
private void clearData() {
|
||||
activeListings.clear();
|
||||
activeBids.clear();
|
||||
@@ -117,13 +125,15 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
displayInventory.clear();
|
||||
|
||||
// Reset slot tracking
|
||||
Arrays.fill(slotTypes, EnumTradeSlotType.EMPTY);
|
||||
for (int i = 0; i < SLOT_COUNT; i++) {
|
||||
slotTypes[i] = 0;
|
||||
slotDataIndex[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/** Populate display from provided data lists */
|
||||
/**
|
||||
* Populate display from provided data lists
|
||||
*/
|
||||
private void populateDisplay(List<AuctionListing> newListings, List<AuctionListing> newBids, List<AuctionClaim> allClaims) {
|
||||
activeListings = new ArrayList<>(newListings);
|
||||
activeBids = new ArrayList<>(newBids);
|
||||
@@ -156,7 +166,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotTypes[slot] = EnumTradeSlotType.CLAIM;
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
@@ -166,7 +176,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotTypes[slot] = EnumTradeSlotType.CLAIM;
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
@@ -176,7 +186,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotTypes[slot] = EnumTradeSlotType.CLAIM;
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
@@ -186,7 +196,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
for (AuctionListing listing : activeListings) {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
if (listing.item != null) displayInventory.setInventorySlotContents(slot, listing.item.copy());
|
||||
slotTypes[slot] = 1; // selling
|
||||
slotTypes[slot] = EnumTradeSlotType.SELLING;
|
||||
slotDataIndex[slot] = listingIdx;
|
||||
slot++;
|
||||
listingIdx++;
|
||||
@@ -197,7 +207,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
for (AuctionListing bid : activeBids) {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
if (bid.item != null) displayInventory.setInventorySlotContents(slot, bid.item.copy());
|
||||
slotTypes[slot] = 2; // bidding
|
||||
slotTypes[slot] = EnumTradeSlotType.BIDDING;
|
||||
slotDataIndex[slot] = bidIdx;
|
||||
slot++;
|
||||
bidIdx++;
|
||||
@@ -208,7 +218,7 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
if (slot >= SLOT_COUNT) break;
|
||||
claims.add(claim);
|
||||
displayInventory.setClaimItem(slot, claim);
|
||||
slotTypes[slot] = 3; // claim
|
||||
slotTypes[slot] = EnumTradeSlotType.CLAIM;
|
||||
slotDataIndex[slot] = claims.size() - 1;
|
||||
slot++;
|
||||
}
|
||||
@@ -216,25 +226,29 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
|
||||
// ========== Slot Data Accessors ==========
|
||||
|
||||
/** Get listing at slot (or null if claim/empty) */
|
||||
/**
|
||||
* Get listing at slot (or null if claim/empty)
|
||||
*/
|
||||
public AuctionListing getListingAt(int slot) {
|
||||
if (slot < 0 || slot >= SLOT_COUNT) return null;
|
||||
int type = slotTypes[slot];
|
||||
EnumTradeSlotType type = slotTypes[slot];
|
||||
int idx = slotDataIndex[slot];
|
||||
if (idx < 0) return null;
|
||||
|
||||
if (type == 1 && idx < activeListings.size()) {
|
||||
if (type == EnumTradeSlotType.SELLING && idx < activeListings.size()) {
|
||||
return activeListings.get(idx);
|
||||
} else if (type == 2 && idx < activeBids.size()) {
|
||||
} else if (type == EnumTradeSlotType.BIDDING && idx < activeBids.size()) {
|
||||
return activeBids.get(idx);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Get claim at slot (or null if listing/empty) */
|
||||
/**
|
||||
* Get claim at slot (or null if listing/empty)
|
||||
*/
|
||||
public AuctionClaim getClaimAt(int slot) {
|
||||
if (slot < 0 || slot >= SLOT_COUNT) return null;
|
||||
if (slotTypes[slot] == 3) {
|
||||
if (slotTypes[slot] == EnumTradeSlotType.CLAIM) {
|
||||
int idx = slotDataIndex[slot];
|
||||
if (idx >= 0 && idx < claims.size()) {
|
||||
return claims.get(idx);
|
||||
@@ -243,17 +257,23 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Check if slot is player's active listing */
|
||||
/**
|
||||
* Check if slot is player's active listing
|
||||
*/
|
||||
public boolean isSellingAt(int slot) {
|
||||
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == 1;
|
||||
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == EnumTradeSlotType.SELLING;
|
||||
}
|
||||
|
||||
/** Check if slot is player's active bid */
|
||||
/**
|
||||
* Check if slot is player's active bid
|
||||
*/
|
||||
public boolean isBiddingAt(int slot) {
|
||||
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == 2;
|
||||
return slot >= 0 && slot < SLOT_COUNT && slotTypes[slot] == EnumTradeSlotType.BIDDING;
|
||||
}
|
||||
|
||||
/** Find listing matching item (searches both selling and bidding) */
|
||||
/**
|
||||
* Find listing matching item (searches both selling and bidding)
|
||||
*/
|
||||
public AuctionListing getListingForItem(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
for (AuctionListing listing : activeListings) {
|
||||
@@ -265,7 +285,9 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Find listing in selling list */
|
||||
/**
|
||||
* Find listing in selling list
|
||||
*/
|
||||
public AuctionListing getSellingListingForItem(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
for (AuctionListing listing : activeListings) {
|
||||
@@ -274,7 +296,9 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Find listing in bidding list */
|
||||
/**
|
||||
* Find listing in bidding list
|
||||
*/
|
||||
public AuctionListing getBiddingListingForItem(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
for (AuctionListing bid : activeBids) {
|
||||
@@ -283,7 +307,9 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Find claim matching item */
|
||||
/**
|
||||
* Find claim matching item
|
||||
*/
|
||||
public AuctionClaim getClaimForItem(ItemStack stack) {
|
||||
if (stack == null) return null;
|
||||
for (AuctionClaim claim : claims) {
|
||||
@@ -294,14 +320,27 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
|
||||
// ========== List Getters ==========
|
||||
|
||||
public List<AuctionListing> getActiveListings() { return activeListings; }
|
||||
public List<AuctionListing> getActiveBids() { return activeBids; }
|
||||
public List<AuctionClaim> getClaims() { return claims; }
|
||||
public int getTotalTradeCount() { return activeListings.size() + activeBids.size() + claims.size(); }
|
||||
public List<AuctionListing> getActiveListings() {
|
||||
return activeListings;
|
||||
}
|
||||
|
||||
public List<AuctionListing> getActiveBids() {
|
||||
return activeBids;
|
||||
}
|
||||
|
||||
public List<AuctionClaim> getClaims() {
|
||||
return claims;
|
||||
}
|
||||
|
||||
public int getTotalTradeCount() {
|
||||
return activeListings.size() + activeBids.size() + claims.size();
|
||||
}
|
||||
|
||||
// ========== Slot Hiding (for pending operations) ==========
|
||||
|
||||
/** Hide slot for pending operation display */
|
||||
/**
|
||||
* Hide slot for pending operation display
|
||||
*/
|
||||
public void setHiddenSlot(int slot) {
|
||||
if (hiddenSlot >= 0 && hiddenSlot < SLOT_COUNT) {
|
||||
restoreSlotItem(hiddenSlot);
|
||||
@@ -312,7 +351,9 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
}
|
||||
}
|
||||
|
||||
/** Restore hidden slot */
|
||||
/**
|
||||
* Restore hidden slot
|
||||
*/
|
||||
public void clearHiddenSlot() {
|
||||
if (hiddenSlot >= 0 && hiddenSlot < SLOT_COUNT) {
|
||||
restoreSlotItem(hiddenSlot);
|
||||
@@ -320,34 +361,42 @@ public class ContainerAuctionTrades extends ContainerAuction {
|
||||
hiddenSlot = -1;
|
||||
}
|
||||
|
||||
/** Restore item at slot from data using slot tracking */
|
||||
/**
|
||||
* Restore item at slot from data using slot tracking
|
||||
*/
|
||||
private void restoreSlotItem(int slot) {
|
||||
if (slot < 0 || slot >= SLOT_COUNT) return;
|
||||
|
||||
int type = slotTypes[slot];
|
||||
EnumTradeSlotType type = slotTypes[slot];
|
||||
int idx = slotDataIndex[slot];
|
||||
if (idx < 0) return;
|
||||
|
||||
if (type == 1 && idx < activeListings.size()) {
|
||||
if (type == EnumTradeSlotType.SELLING && idx < activeListings.size()) {
|
||||
// Selling
|
||||
AuctionListing listing = activeListings.get(idx);
|
||||
if (listing != null && listing.item != null) {
|
||||
displayInventory.setInventorySlotContents(slot, listing.item.copy());
|
||||
}
|
||||
} else if (type == 2 && idx < activeBids.size()) {
|
||||
} else if (type == EnumTradeSlotType.BIDDING && idx < activeBids.size()) {
|
||||
// Bidding
|
||||
AuctionListing bid = activeBids.get(idx);
|
||||
if (bid != null && bid.item != null) {
|
||||
displayInventory.setInventorySlotContents(slot, bid.item.copy());
|
||||
}
|
||||
} else if (type == 3 && idx < claims.size()) {
|
||||
} else if (type == EnumTradeSlotType.CLAIM && idx < claims.size()) {
|
||||
// Claim
|
||||
displayInventory.setClaimItem(slot, claims.get(idx));
|
||||
}
|
||||
}
|
||||
|
||||
public int getHiddenSlot() { return hiddenSlot; }
|
||||
public int getHiddenSlot() {
|
||||
return hiddenSlot;
|
||||
}
|
||||
|
||||
/** Get player's max trade slots (synced from server based on permissions) */
|
||||
public int getMaxTradeSlots() { return maxTradeSlots; }
|
||||
/**
|
||||
* Get player's max trade slots (synced from server based on permissions)
|
||||
*/
|
||||
public int getMaxTradeSlots() {
|
||||
return maxTradeSlots;
|
||||
}
|
||||
}
|
||||
@@ -22,14 +22,17 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
@@ -364,6 +367,7 @@ public class AnimationController implements IAnimationHandler {
|
||||
|
||||
/**
|
||||
* Get a built-in animation by name.
|
||||
*
|
||||
* @param name The animation name (case-insensitive)
|
||||
* @return The built-in animation, or null if not found
|
||||
*/
|
||||
@@ -395,6 +399,7 @@ public class AnimationController implements IAnimationHandler {
|
||||
|
||||
/**
|
||||
* Check if an animation name is a built-in animation.
|
||||
*
|
||||
* @param name The animation name to check
|
||||
* @return true if this is a built-in animation
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@ import noppes.npcs.config.ConfigMarket;
|
||||
/**
|
||||
* Server-side utility for syncing auction configuration to clients.
|
||||
* Handles Vault integration for currency name resolution.
|
||||
*
|
||||
* <p>
|
||||
* This class is SERVER-SIDE ONLY. Client reads via AuctionClientConfig.
|
||||
*/
|
||||
public class AuctionConfigSync {
|
||||
@@ -15,7 +15,7 @@ public class AuctionConfigSync {
|
||||
/**
|
||||
* Write auction config to NBT for sending to client.
|
||||
* Called on server side when building login packet.
|
||||
*
|
||||
* <p>
|
||||
* Currency name is resolved from Vault if enabled and available,
|
||||
* otherwise falls back to ConfigMarket.CurrencyName.
|
||||
*/
|
||||
@@ -40,7 +40,7 @@ public class AuctionConfigSync {
|
||||
public static String getEffectiveCurrencyName() {
|
||||
if (ConfigMarket.UseVault && VaultUtil.isEnabled()) {
|
||||
String vaultName = VaultUtil.getCurrencyNamePlural();
|
||||
if (vaultName != null && !vaultName.isEmpty() && !vaultName.equals("coins")) {
|
||||
if (vaultName != null && !vaultName.isEmpty()) {
|
||||
return vaultName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,17 +6,18 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.IAuctionHandler;
|
||||
import noppes.npcs.api.handler.data.IAuctionListing;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
import noppes.npcs.constants.EnumAuctionLogAction;
|
||||
import noppes.npcs.constants.EnumAuctionSort;
|
||||
import noppes.npcs.constants.EnumAuctionStatus;
|
||||
import noppes.npcs.constants.EnumClaimType;
|
||||
@@ -26,24 +27,32 @@ import noppes.npcs.controllers.data.AuctionClaim;
|
||||
import noppes.npcs.controllers.data.AuctionFilter;
|
||||
import noppes.npcs.controllers.data.AuctionListing;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
import noppes.npcs.controllers.data.PlayerTradeData;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.player.AuctionEvent;
|
||||
import noppes.npcs.util.CustomNPCsThreader;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Main controller for the Auction system.
|
||||
*
|
||||
* <p>
|
||||
* Thread Safety:
|
||||
* - Uses ConcurrentHashMap for all data stores - no locking required
|
||||
* - Claims are stored in PlayerData, not here - reduces contention
|
||||
* - Saves are performed asynchronously on the CNPC+ thread
|
||||
*
|
||||
* <p>
|
||||
* Performance:
|
||||
* - Auction processing runs every 30 seconds (600 ticks)
|
||||
* - Save interval is every 30 seconds (600 ticks)
|
||||
@@ -60,29 +69,41 @@ public class AuctionController implements IAuctionHandler {
|
||||
// Player Indices for O(1) Lookups
|
||||
// =========================================
|
||||
|
||||
/** Listings by seller UUID - for quick "my listings" lookups */
|
||||
/**
|
||||
* Listings by seller UUID - for quick "my listings" lookups
|
||||
*/
|
||||
private final Map<UUID, Set<String>> playerListingIds = new ConcurrentHashMap<>();
|
||||
|
||||
/** Listings where player is current high bidder */
|
||||
/**
|
||||
* Listings where player is current high bidder
|
||||
*/
|
||||
private final Map<UUID, Set<String>> playerBidIds = new ConcurrentHashMap<>();
|
||||
|
||||
/** Cached max trade slots per player - computed on login, cleared on logout */
|
||||
/**
|
||||
* Cached max trade slots per player - computed on login, cleared on logout
|
||||
*/
|
||||
private final Map<UUID, Integer> playerMaxTradesCache = new ConcurrentHashMap<>();
|
||||
|
||||
// =========================================
|
||||
// Threading & State
|
||||
// =========================================
|
||||
|
||||
/** Flag indicating data needs to be saved */
|
||||
/**
|
||||
* Flag indicating data needs to be saved
|
||||
*/
|
||||
private final AtomicBoolean dirty = new AtomicBoolean(false);
|
||||
|
||||
/** Flag to prevent concurrent saves */
|
||||
/**
|
||||
* Flag to prevent concurrent saves
|
||||
*/
|
||||
private final AtomicBoolean saving = new AtomicBoolean(false);
|
||||
|
||||
private String filePath = "";
|
||||
private int tickCounter = 0;
|
||||
|
||||
/** Process auctions and save every 30 seconds (600 ticks) */
|
||||
/**
|
||||
* Process auctions and save every 30 seconds (600 ticks)
|
||||
*/
|
||||
private static final int TICK_INTERVAL = 600;
|
||||
|
||||
public AuctionController() {
|
||||
@@ -138,52 +159,56 @@ public class AuctionController implements IAuctionHandler {
|
||||
}
|
||||
|
||||
private void endAuction(AuctionListing listing) {
|
||||
listing.status = EnumAuctionStatus.ENDED;
|
||||
synchronized (listing) {
|
||||
if (listing.status != EnumAuctionStatus.ACTIVE) return;
|
||||
|
||||
// Remove from seller's active listings
|
||||
removeFromPlayerListings(listing.sellerUUID, listing.id);
|
||||
listing.status = EnumAuctionStatus.ENDED;
|
||||
|
||||
// Remove from bidder's active bids if any
|
||||
if (listing.highBidderUUID != null) {
|
||||
removeFromPlayerBids(listing.highBidderUUID, listing.id);
|
||||
}
|
||||
// Remove from seller's active listings
|
||||
removeFromPlayerListings(listing.sellerUUID, listing.id);
|
||||
|
||||
// Get item display name safely
|
||||
String itemDisplayName = listing.item != null ? listing.item.getDisplayName() : "Unknown Item";
|
||||
// Remove from bidder's active bids if any
|
||||
if (listing.highBidderUUID != null) {
|
||||
removeFromPlayerBids(listing.highBidderUUID, listing.id);
|
||||
}
|
||||
|
||||
if (listing.hasBids()) {
|
||||
// Auction sold - create claims
|
||||
AuctionClaim itemClaim = AuctionClaim.createItemWonClaim(
|
||||
listing.highBidderUUID, listing.highBidderName, listing.id, listing.item);
|
||||
addClaimToPlayer(listing.highBidderUUID, itemClaim);
|
||||
// Get item display name safely
|
||||
String itemDisplayName = listing.item != null ? listing.item.getDisplayName() : "Unknown Item";
|
||||
|
||||
long saleAmount = listing.currentBid;
|
||||
long tax = (long) (saleAmount * ConfigMarket.SalesTaxPercent);
|
||||
long sellerReceives = saleAmount - tax;
|
||||
if (listing.hasBids()) {
|
||||
// Auction sold - create claims
|
||||
AuctionClaim itemClaim = AuctionClaim.createItemWonClaim(
|
||||
listing.highBidderUUID, listing.highBidderName, listing.id, listing.item);
|
||||
addClaimToPlayer(listing.highBidderUUID, itemClaim);
|
||||
|
||||
AuctionClaim currencyClaim = AuctionClaim.createCurrencyClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, sellerReceives,
|
||||
itemDisplayName, listing.highBidderName);
|
||||
addClaimToPlayer(listing.sellerUUID, currencyClaim);
|
||||
long saleAmount = listing.currentBid;
|
||||
long tax = (long) (saleAmount * ConfigMarket.SalesTaxPercent);
|
||||
long sellerReceives = saleAmount - tax;
|
||||
|
||||
// Notifications
|
||||
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_WON, listing.id,
|
||||
"You won the auction for " + itemDisplayName + "!");
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
|
||||
"Your " + itemDisplayName + " sold for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
|
||||
AuctionClaim currencyClaim = AuctionClaim.createCurrencyClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, sellerReceives,
|
||||
itemDisplayName, listing.highBidderName);
|
||||
addClaimToPlayer(listing.sellerUUID, currencyClaim);
|
||||
|
||||
logAuction("SOLD", listing.sellerName, itemDisplayName, saleAmount,
|
||||
"Winner: " + listing.highBidderName + ", Tax: " + tax);
|
||||
} else {
|
||||
// No bids - return item to seller
|
||||
AuctionClaim returnClaim = AuctionClaim.createItemReturnedClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
|
||||
addClaimToPlayer(listing.sellerUUID, returnClaim);
|
||||
// Notifications
|
||||
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_WON, listing.id,
|
||||
"You won the auction for " + itemDisplayName + "!");
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
|
||||
"Your " + itemDisplayName + " sold for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
|
||||
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_EXPIRED, listing.id,
|
||||
"Your auction for " + itemDisplayName + " expired with no bids.");
|
||||
logAuction(EnumAuctionLogAction.SOLD, listing.sellerName, itemDisplayName, saleAmount,
|
||||
"Winner: " + listing.highBidderName + ", Tax: " + tax);
|
||||
} else {
|
||||
// No bids - return item to seller
|
||||
AuctionClaim returnClaim = AuctionClaim.createItemReturnedClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
|
||||
addClaimToPlayer(listing.sellerUUID, returnClaim);
|
||||
|
||||
logAuction("EXPIRED", listing.sellerName, itemDisplayName, listing.startingPrice, "No bids");
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_EXPIRED, listing.id,
|
||||
"Your auction for " + itemDisplayName + " expired with no bids.");
|
||||
|
||||
logAuction(EnumAuctionLogAction.EXPIRED, listing.sellerName, itemDisplayName, listing.startingPrice, "No bids");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,6 +305,15 @@ public class AuctionController implements IAuctionHandler {
|
||||
return "You cannot afford the listing fee (" + fee + " " + ConfigMarket.CurrencyName + ").";
|
||||
}
|
||||
|
||||
// Fire auction create event (cancelable)
|
||||
PlayerDataScript createHandler = ScriptController.Instance.getPlayerScripts(player);
|
||||
IPlayer iCreator = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
AuctionEvent.CreateEvent createEvent = new AuctionEvent.CreateEvent(
|
||||
iCreator, NpcAPI.Instance().getIItemStack(item), startingPrice, buyoutPrice);
|
||||
if (EventHooks.onAuctionCreate(createHandler, createEvent)) {
|
||||
return "Auction creation was cancelled.";
|
||||
}
|
||||
|
||||
// Deduct fee
|
||||
if (!currency.withdraw(fee)) {
|
||||
return "Failed to deduct listing fee.";
|
||||
@@ -295,7 +329,7 @@ public class AuctionController implements IAuctionHandler {
|
||||
|
||||
markDirty();
|
||||
|
||||
logAuction("CREATED", playerName, item.getDisplayName(), startingPrice,
|
||||
logAuction(EnumAuctionLogAction.CREATED, playerName, item.getDisplayName(), startingPrice,
|
||||
"Buyout: " + (buyoutPrice > 0 ? buyoutPrice : "None") + ", Fee: " + fee);
|
||||
|
||||
return null; // Success
|
||||
@@ -307,55 +341,74 @@ public class AuctionController implements IAuctionHandler {
|
||||
return "Listing not found.";
|
||||
}
|
||||
|
||||
if (!listing.status.canCancel()) {
|
||||
return "This auction cannot be cancelled.";
|
||||
synchronized (listing) {
|
||||
if (!listing.status.canCancel()) {
|
||||
return "This auction cannot be cancelled.";
|
||||
}
|
||||
|
||||
UUID playerUUID = player.getUniqueID();
|
||||
if (!isAdmin && !listing.isSeller(playerUUID)) {
|
||||
return "You can only cancel your own listings.";
|
||||
}
|
||||
|
||||
// Fire auction cancel event (cancelable)
|
||||
PlayerDataScript cancelHandler = ScriptController.Instance.getPlayerScripts(player);
|
||||
IPlayer iCanceller = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
AuctionEvent.CancelEvent cancelEvent = new AuctionEvent.CancelEvent(iCanceller, listing, isAdmin);
|
||||
if (EventHooks.onAuctionCancel(cancelHandler, cancelEvent)) {
|
||||
return "Auction cancellation was prevented.";
|
||||
}
|
||||
|
||||
// Handle penalty if there are bids
|
||||
if (listing.hasBids()) {
|
||||
long penalty = (long) (listing.currentBid * ConfigMarket.CancellationPenaltyPercent);
|
||||
|
||||
// Refund bidder (no item - can't rebid on cancelled auction)
|
||||
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
|
||||
listing.highBidderUUID, listing.highBidderName, listing.id, listing.currentBid,
|
||||
listing.item.getDisplayName(), listing.sellerName, null);
|
||||
addClaimToPlayer(listing.highBidderUUID, refundClaim);
|
||||
|
||||
// Remove from bidder's active bids
|
||||
removeFromPlayerBids(listing.highBidderUUID, listing.id);
|
||||
|
||||
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_OUTBID, listing.id,
|
||||
"The auction for " + listing.item.getDisplayName() + " was cancelled. Your bid has been refunded.");
|
||||
|
||||
// Return item to seller
|
||||
AuctionClaim itemClaim = AuctionClaim.createItemReturnedClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
|
||||
addClaimToPlayer(listing.sellerUUID, itemClaim);
|
||||
|
||||
// Deduct cancellation penalty from seller
|
||||
if (penalty > 0) {
|
||||
PlayerData sellerData = PlayerDataController.Instance.getData(listing.sellerUUID);
|
||||
if (sellerData != null) {
|
||||
sellerData.tradeData.withdraw(penalty);
|
||||
sellerData.save();
|
||||
}
|
||||
}
|
||||
|
||||
logAuction(EnumAuctionLogAction.CANCELLED, listing.sellerName, listing.item.getDisplayName(), listing.currentBid,
|
||||
"Penalty: " + penalty + ", Bidder refunded: " + listing.highBidderName +
|
||||
(isAdmin ? ", Cancelled by admin: " + player.getCommandSenderName() : ""));
|
||||
} else {
|
||||
// No bids - just return item
|
||||
AuctionClaim itemClaim = AuctionClaim.createItemReturnedClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
|
||||
addClaimToPlayer(listing.sellerUUID, itemClaim);
|
||||
|
||||
logAuction(EnumAuctionLogAction.CANCELLED, listing.sellerName, listing.item.getDisplayName(), listing.startingPrice,
|
||||
"No bids" + (isAdmin ? ", Cancelled by admin: " + player.getCommandSenderName() : ""));
|
||||
}
|
||||
|
||||
// Remove from seller's active listings
|
||||
removeFromPlayerListings(listing.sellerUUID, listing.id);
|
||||
|
||||
listing.status = EnumAuctionStatus.CANCELLED;
|
||||
markDirty();
|
||||
}
|
||||
|
||||
UUID playerUUID = player.getUniqueID();
|
||||
if (!isAdmin && !listing.isSeller(playerUUID)) {
|
||||
return "You can only cancel your own listings.";
|
||||
}
|
||||
|
||||
// Handle penalty if there are bids
|
||||
if (listing.hasBids()) {
|
||||
long penalty = (long) (listing.currentBid * ConfigMarket.CancellationPenaltyPercent);
|
||||
|
||||
// Refund bidder (no item - can't rebid on cancelled auction)
|
||||
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
|
||||
listing.highBidderUUID, listing.highBidderName, listing.id, listing.currentBid,
|
||||
listing.item.getDisplayName(), listing.sellerName, null);
|
||||
addClaimToPlayer(listing.highBidderUUID, refundClaim);
|
||||
|
||||
// Remove from bidder's active bids
|
||||
removeFromPlayerBids(listing.highBidderUUID, listing.id);
|
||||
|
||||
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_OUTBID, listing.id,
|
||||
"The auction for " + listing.item.getDisplayName() + " was cancelled. Your bid has been refunded.");
|
||||
|
||||
// Return item to seller
|
||||
AuctionClaim itemClaim = AuctionClaim.createItemReturnedClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
|
||||
addClaimToPlayer(listing.sellerUUID, itemClaim);
|
||||
|
||||
logAuction("CANCELLED", listing.sellerName, listing.item.getDisplayName(), listing.currentBid,
|
||||
"Penalty: " + penalty + ", Bidder refunded: " + listing.highBidderName +
|
||||
(isAdmin ? ", Cancelled by admin: " + player.getCommandSenderName() : ""));
|
||||
} else {
|
||||
// No bids - just return item
|
||||
AuctionClaim itemClaim = AuctionClaim.createItemReturnedClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, listing.item);
|
||||
addClaimToPlayer(listing.sellerUUID, itemClaim);
|
||||
|
||||
logAuction("CANCELLED", listing.sellerName, listing.item.getDisplayName(), listing.startingPrice,
|
||||
"No bids" + (isAdmin ? ", Cancelled by admin: " + player.getCommandSenderName() : ""));
|
||||
}
|
||||
|
||||
// Remove from seller's active listings
|
||||
removeFromPlayerListings(listing.sellerUUID, listing.id);
|
||||
|
||||
listing.status = EnumAuctionStatus.CANCELLED;
|
||||
markDirty();
|
||||
|
||||
return null; // Success
|
||||
}
|
||||
|
||||
@@ -376,75 +429,85 @@ public class AuctionController implements IAuctionHandler {
|
||||
return "Listing not found.";
|
||||
}
|
||||
|
||||
// Check status and expiry
|
||||
if (!listing.status.canBid()) {
|
||||
return "This auction has ended.";
|
||||
synchronized (listing) {
|
||||
// Check status and expiry
|
||||
if (!listing.status.canBid()) {
|
||||
return "This auction has ended.";
|
||||
}
|
||||
|
||||
if (listing.isExpired()) {
|
||||
return "This auction has ended.";
|
||||
}
|
||||
|
||||
// CRITICAL: Prevent bidding on own items
|
||||
if (listing.isSeller(playerUUID)) {
|
||||
return "You cannot bid on your own auction.";
|
||||
}
|
||||
|
||||
// Prevent rebidding if already highest bidder
|
||||
if (listing.isHighBidder(playerUUID)) {
|
||||
return "You are already the highest bidder. Use buyout if you want to purchase immediately.";
|
||||
}
|
||||
|
||||
// Check minimum bid
|
||||
long minBid = listing.getMinimumBid(ConfigMarket.MinBidIncrementPercent);
|
||||
if (bidAmount < minBid) {
|
||||
return "Bid must be at least " + minBid + " " + ConfigMarket.CurrencyName + ".";
|
||||
}
|
||||
|
||||
// Check currency
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
if (playerData == null) {
|
||||
return "Could not access player data.";
|
||||
}
|
||||
|
||||
PlayerTradeData currency = playerData.tradeData;
|
||||
|
||||
// Store previous bidder info
|
||||
UUID previousBidder = listing.highBidderUUID;
|
||||
long previousBid = listing.currentBid;
|
||||
|
||||
// Full bid amount charged since we don't allow rebidding
|
||||
long amountToCharge = bidAmount;
|
||||
|
||||
if (!currency.canAfford(amountToCharge)) {
|
||||
return "You cannot afford this bid.";
|
||||
}
|
||||
|
||||
// Fire auction bid event (cancelable)
|
||||
PlayerDataScript bidHandler = ScriptController.Instance.getPlayerScripts(player);
|
||||
IPlayer iBidder = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
AuctionEvent.BidEvent bidEvent = new AuctionEvent.BidEvent(iBidder, listing, bidAmount);
|
||||
if (EventHooks.onAuctionBid(bidHandler, bidEvent)) {
|
||||
return "Bid was cancelled.";
|
||||
}
|
||||
|
||||
// Deduct bid from new bidder FIRST
|
||||
if (!currency.withdraw(amountToCharge)) {
|
||||
return "Failed to deduct bid amount.";
|
||||
}
|
||||
|
||||
// Refund previous bidder (include item for rebid option)
|
||||
if (listing.hasBids() && previousBidder != null) {
|
||||
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
|
||||
previousBidder, listing.highBidderName, listing.id, previousBid,
|
||||
listing.item.getDisplayName(), playerName, listing.item);
|
||||
addClaimToPlayer(previousBidder, refundClaim);
|
||||
|
||||
// Remove from previous bidder's active bids
|
||||
removeFromPlayerBids(previousBidder, listing.id);
|
||||
|
||||
sendNotificationToPlayer(previousBidder, EnumNotificationType.AUCTION_OUTBID, listing.id,
|
||||
"You were outbid on " + listing.item.getDisplayName() + "!");
|
||||
}
|
||||
|
||||
// Update listing
|
||||
listing.highBidderUUID = playerUUID;
|
||||
listing.highBidderName = playerName;
|
||||
listing.currentBid = bidAmount;
|
||||
listing.bidCount++;
|
||||
}
|
||||
|
||||
if (listing.isExpired()) {
|
||||
return "This auction has ended.";
|
||||
}
|
||||
|
||||
// CRITICAL: Prevent bidding on own items
|
||||
if (listing.isSeller(playerUUID)) {
|
||||
return "You cannot bid on your own auction.";
|
||||
}
|
||||
|
||||
// Prevent rebidding if already highest bidder
|
||||
if (listing.isHighBidder(playerUUID)) {
|
||||
return "You are already the highest bidder. Use buyout if you want to purchase immediately.";
|
||||
}
|
||||
|
||||
// Check minimum bid
|
||||
long minBid = listing.getMinimumBid(ConfigMarket.MinBidIncrementPercent);
|
||||
if (bidAmount < minBid) {
|
||||
return "Bid must be at least " + minBid + " " + ConfigMarket.CurrencyName + ".";
|
||||
}
|
||||
|
||||
// Check currency
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
if (playerData == null) {
|
||||
return "Could not access player data.";
|
||||
}
|
||||
|
||||
PlayerTradeData currency = playerData.tradeData;
|
||||
|
||||
// Store previous bidder info
|
||||
UUID previousBidder = listing.highBidderUUID;
|
||||
long previousBid = listing.currentBid;
|
||||
|
||||
// Full bid amount charged since we don't allow rebidding
|
||||
long amountToCharge = bidAmount;
|
||||
|
||||
if (!currency.canAfford(amountToCharge)) {
|
||||
return "You cannot afford this bid.";
|
||||
}
|
||||
|
||||
// Deduct bid from new bidder FIRST
|
||||
if (!currency.withdraw(amountToCharge)) {
|
||||
return "Failed to deduct bid amount.";
|
||||
}
|
||||
|
||||
// Refund previous bidder (include item for rebid option)
|
||||
if (listing.hasBids() && previousBidder != null) {
|
||||
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
|
||||
previousBidder, listing.highBidderName, listing.id, previousBid,
|
||||
listing.item.getDisplayName(), playerName, listing.item);
|
||||
addClaimToPlayer(previousBidder, refundClaim);
|
||||
|
||||
// Remove from previous bidder's active bids
|
||||
removeFromPlayerBids(previousBidder, listing.id);
|
||||
|
||||
sendNotificationToPlayer(previousBidder, EnumNotificationType.AUCTION_OUTBID, listing.id,
|
||||
"You were outbid on " + listing.item.getDisplayName() + "!");
|
||||
}
|
||||
|
||||
// Update listing
|
||||
listing.highBidderUUID = playerUUID;
|
||||
listing.highBidderName = playerName;
|
||||
listing.currentBid = bidAmount;
|
||||
listing.bidCount++;
|
||||
|
||||
// Add to new bidder's active bids
|
||||
addToPlayerBids(playerUUID, listing.id);
|
||||
|
||||
@@ -453,7 +516,7 @@ public class AuctionController implements IAuctionHandler {
|
||||
|
||||
markDirty();
|
||||
|
||||
logAuction("BID", playerName, listing.item.getDisplayName(), bidAmount,
|
||||
logAuction(EnumAuctionLogAction.BID, playerName, listing.item.getDisplayName(), bidAmount,
|
||||
"Bids: " + listing.bidCount + ", Seller: " + listing.sellerName);
|
||||
|
||||
return null; // Success
|
||||
@@ -472,97 +535,107 @@ public class AuctionController implements IAuctionHandler {
|
||||
return "Listing not found.";
|
||||
}
|
||||
|
||||
// Check status and expiry
|
||||
if (!listing.status.canBid()) {
|
||||
return "This auction has ended.";
|
||||
}
|
||||
|
||||
if (listing.isExpired()) {
|
||||
return "This auction has ended.";
|
||||
}
|
||||
|
||||
if (!listing.hasBuyout()) {
|
||||
return "This auction does not have a buyout price.";
|
||||
}
|
||||
|
||||
// CRITICAL: Prevent buying own items
|
||||
if (listing.isSeller(playerUUID)) {
|
||||
return "You cannot buy your own auction.";
|
||||
}
|
||||
|
||||
// Check currency
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
if (playerData == null) {
|
||||
return "Could not access player data.";
|
||||
}
|
||||
|
||||
PlayerTradeData currency = playerData.tradeData;
|
||||
|
||||
// If buyer is already the high bidder, only charge the difference
|
||||
boolean isCurrentBidder = listing.isHighBidder(playerUUID);
|
||||
long amountToCharge = isCurrentBidder
|
||||
? (listing.buyoutPrice - listing.currentBid)
|
||||
: listing.buyoutPrice;
|
||||
|
||||
if (!currency.canAfford(amountToCharge)) {
|
||||
if (isCurrentBidder) {
|
||||
return "You cannot afford the remaining " + amountToCharge + " " + ConfigMarket.CurrencyName + " for buyout.";
|
||||
synchronized (listing) {
|
||||
// Check status and expiry
|
||||
if (!listing.status.canBid()) {
|
||||
return "This auction has ended.";
|
||||
}
|
||||
return "You cannot afford the buyout price.";
|
||||
|
||||
if (listing.isExpired()) {
|
||||
return "This auction has ended.";
|
||||
}
|
||||
|
||||
if (!listing.hasBuyout()) {
|
||||
return "This auction does not have a buyout price.";
|
||||
}
|
||||
|
||||
// CRITICAL: Prevent buying own items
|
||||
if (listing.isSeller(playerUUID)) {
|
||||
return "You cannot buy your own auction.";
|
||||
}
|
||||
|
||||
// Check currency
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
if (playerData == null) {
|
||||
return "Could not access player data.";
|
||||
}
|
||||
|
||||
PlayerTradeData currency = playerData.tradeData;
|
||||
|
||||
// If buyer is already the high bidder, only charge the difference
|
||||
boolean isCurrentBidder = listing.isHighBidder(playerUUID);
|
||||
long amountToCharge = isCurrentBidder
|
||||
? (listing.buyoutPrice - listing.currentBid)
|
||||
: listing.buyoutPrice;
|
||||
|
||||
if (!currency.canAfford(amountToCharge)) {
|
||||
if (isCurrentBidder) {
|
||||
return "You cannot afford the remaining " + amountToCharge + " " + ConfigMarket.CurrencyName + " for buyout.";
|
||||
}
|
||||
return "You cannot afford the buyout price.";
|
||||
}
|
||||
|
||||
// Fire auction buyout event (cancelable)
|
||||
PlayerDataScript buyoutHandler = ScriptController.Instance.getPlayerScripts(player);
|
||||
IPlayer iBuyer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
AuctionEvent.BuyoutEvent buyoutEvent = new AuctionEvent.BuyoutEvent(iBuyer, listing);
|
||||
if (EventHooks.onAuctionBuyout(buyoutHandler, buyoutEvent)) {
|
||||
return "Buyout was cancelled.";
|
||||
}
|
||||
|
||||
// Deduct buyout amount
|
||||
if (!currency.withdraw(amountToCharge)) {
|
||||
return "Failed to deduct buyout amount.";
|
||||
}
|
||||
|
||||
// Refund previous bidder if any AND they're not the buyer (no item - auction ended via buyout)
|
||||
if (listing.hasBids() && listing.highBidderUUID != null && !isCurrentBidder) {
|
||||
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
|
||||
listing.highBidderUUID, listing.highBidderName, listing.id, listing.currentBid,
|
||||
listing.item.getDisplayName(), playerName, null);
|
||||
addClaimToPlayer(listing.highBidderUUID, refundClaim);
|
||||
|
||||
// Remove from previous bidder's active bids
|
||||
removeFromPlayerBids(listing.highBidderUUID, listing.id);
|
||||
|
||||
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_OUTBID, listing.id,
|
||||
"The auction for " + listing.item.getDisplayName() + " was bought out. Your bid has been refunded.");
|
||||
} else if (isCurrentBidder) {
|
||||
// Current bidder is buying out - just remove from their active bids
|
||||
removeFromPlayerBids(playerUUID, listing.id);
|
||||
}
|
||||
|
||||
// Create claims
|
||||
AuctionClaim itemClaim = AuctionClaim.createItemWonClaim(playerUUID, playerName, listing.id, listing.item);
|
||||
addClaimToPlayer(playerUUID, itemClaim);
|
||||
|
||||
long saleAmount = listing.buyoutPrice;
|
||||
long tax = (long) (saleAmount * ConfigMarket.SalesTaxPercent);
|
||||
long sellerReceives = saleAmount - tax;
|
||||
|
||||
AuctionClaim currencyClaim = AuctionClaim.createCurrencyClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, sellerReceives,
|
||||
listing.item.getDisplayName(), playerName);
|
||||
addClaimToPlayer(listing.sellerUUID, currencyClaim);
|
||||
|
||||
// Notifications
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
|
||||
"Your " + listing.item.getDisplayName() + " was bought out for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
|
||||
|
||||
// Remove from seller's active listings
|
||||
removeFromPlayerListings(listing.sellerUUID, listing.id);
|
||||
|
||||
listing.status = EnumAuctionStatus.ENDED;
|
||||
listing.highBidderUUID = playerUUID;
|
||||
listing.highBidderName = playerName;
|
||||
listing.currentBid = listing.buyoutPrice;
|
||||
|
||||
markDirty();
|
||||
|
||||
logAuction(EnumAuctionLogAction.BUYOUT, playerName, listing.item.getDisplayName(), listing.buyoutPrice,
|
||||
"Seller: " + listing.sellerName + ", Tax: " + tax);
|
||||
}
|
||||
|
||||
// Deduct buyout amount
|
||||
if (!currency.withdraw(amountToCharge)) {
|
||||
return "Failed to deduct buyout amount.";
|
||||
}
|
||||
|
||||
// Refund previous bidder if any AND they're not the buyer (no item - auction ended via buyout)
|
||||
if (listing.hasBids() && listing.highBidderUUID != null && !isCurrentBidder) {
|
||||
AuctionClaim refundClaim = AuctionClaim.createRefundClaim(
|
||||
listing.highBidderUUID, listing.highBidderName, listing.id, listing.currentBid,
|
||||
listing.item.getDisplayName(), playerName, null);
|
||||
addClaimToPlayer(listing.highBidderUUID, refundClaim);
|
||||
|
||||
// Remove from previous bidder's active bids
|
||||
removeFromPlayerBids(listing.highBidderUUID, listing.id);
|
||||
|
||||
sendNotificationToPlayer(listing.highBidderUUID, EnumNotificationType.AUCTION_OUTBID, listing.id,
|
||||
"The auction for " + listing.item.getDisplayName() + " was bought out. Your bid has been refunded.");
|
||||
} else if (isCurrentBidder) {
|
||||
// Current bidder is buying out - just remove from their active bids
|
||||
removeFromPlayerBids(playerUUID, listing.id);
|
||||
}
|
||||
|
||||
// Create claims
|
||||
AuctionClaim itemClaim = AuctionClaim.createItemWonClaim(playerUUID, playerName, listing.id, listing.item);
|
||||
addClaimToPlayer(playerUUID, itemClaim);
|
||||
|
||||
long saleAmount = listing.buyoutPrice;
|
||||
long tax = (long) (saleAmount * ConfigMarket.SalesTaxPercent);
|
||||
long sellerReceives = saleAmount - tax;
|
||||
|
||||
AuctionClaim currencyClaim = AuctionClaim.createCurrencyClaim(
|
||||
listing.sellerUUID, listing.sellerName, listing.id, sellerReceives,
|
||||
listing.item.getDisplayName(), playerName);
|
||||
addClaimToPlayer(listing.sellerUUID, currencyClaim);
|
||||
|
||||
// Notifications
|
||||
sendNotificationToPlayer(listing.sellerUUID, EnumNotificationType.AUCTION_SOLD, listing.id,
|
||||
"Your " + listing.item.getDisplayName() + " was bought out for " + saleAmount + " " + ConfigMarket.CurrencyName + "!");
|
||||
|
||||
// Remove from seller's active listings
|
||||
removeFromPlayerListings(listing.sellerUUID, listing.id);
|
||||
|
||||
listing.status = EnumAuctionStatus.ENDED;
|
||||
listing.highBidderUUID = playerUUID;
|
||||
listing.highBidderName = playerName;
|
||||
listing.currentBid = listing.buyoutPrice;
|
||||
|
||||
markDirty();
|
||||
|
||||
logAuction("BUYOUT", playerName, listing.item.getDisplayName(), listing.buyoutPrice,
|
||||
"Seller: " + listing.sellerName + ", Tax: " + tax);
|
||||
|
||||
return null; // Success
|
||||
}
|
||||
|
||||
@@ -615,6 +688,14 @@ public class AuctionController implements IAuctionHandler {
|
||||
return "Item data is missing.";
|
||||
}
|
||||
|
||||
// Fire auction claim event (cancelable)
|
||||
PlayerDataScript itemClaimHandler = ScriptController.Instance.getPlayerScripts(player);
|
||||
IPlayer iItemClaimer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
AuctionEvent.ClaimEvent itemClaimEvent = new AuctionEvent.ClaimEvent(iItemClaimer, claim);
|
||||
if (EventHooks.onAuctionClaim(itemClaimHandler, itemClaimEvent)) {
|
||||
return "Claim was prevented.";
|
||||
}
|
||||
|
||||
// Check inventory space
|
||||
if (!player.inventory.addItemStackToInventory(claim.item.copy())) {
|
||||
return "Your inventory is full.";
|
||||
@@ -628,7 +709,7 @@ public class AuctionController implements IAuctionHandler {
|
||||
// Cleanup listing if no more claims
|
||||
cleanupListingIfComplete(claim.listingId);
|
||||
|
||||
logAuction("CLAIMED", player.getCommandSenderName(), claim.item.getDisplayName(), 0, "Item claimed");
|
||||
logAuction(EnumAuctionLogAction.CLAIMED, player.getCommandSenderName(), claim.item.getDisplayName(), 0, "Item claimed");
|
||||
|
||||
return null; // Success
|
||||
}
|
||||
@@ -652,6 +733,14 @@ public class AuctionController implements IAuctionHandler {
|
||||
return "This is not a currency claim.";
|
||||
}
|
||||
|
||||
// Fire auction claim event (cancelable)
|
||||
PlayerDataScript currencyClaimHandler = ScriptController.Instance.getPlayerScripts(player);
|
||||
IPlayer iCurrencyClaimer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
AuctionEvent.ClaimEvent currencyClaimEvent = new AuctionEvent.ClaimEvent(iCurrencyClaimer, claim);
|
||||
if (EventHooks.onAuctionClaim(currencyClaimHandler, currencyClaimEvent)) {
|
||||
return "Claim was prevented.";
|
||||
}
|
||||
|
||||
if (!playerData.tradeData.deposit(claim.currency)) {
|
||||
return "Failed to deposit currency.";
|
||||
}
|
||||
@@ -664,7 +753,7 @@ public class AuctionController implements IAuctionHandler {
|
||||
// Cleanup listing if no more claims
|
||||
cleanupListingIfComplete(claim.listingId);
|
||||
|
||||
logAuction("CLAIMED", player.getCommandSenderName(), ConfigMarket.CurrencyName, claim.currency,
|
||||
logAuction(EnumAuctionLogAction.CLAIMED, player.getCommandSenderName(), ConfigMarket.CurrencyName, claim.currency,
|
||||
claim.type == EnumClaimType.REFUND ? "Refund claimed" : "Sale proceeds claimed");
|
||||
|
||||
return null; // Success
|
||||
@@ -993,7 +1082,7 @@ public class AuctionController implements IAuctionHandler {
|
||||
if (expired > 0) {
|
||||
playerData.updateClient = true;
|
||||
playerData.save();
|
||||
logAuction("CLAIM_EXPIRED", player.getCommandSenderName(), "Multiple", expired,
|
||||
logAuction(EnumAuctionLogAction.CLAIM_EXPIRED, player.getCommandSenderName(), "Multiple", expired,
|
||||
expired + " claims expired on login");
|
||||
}
|
||||
}
|
||||
@@ -1041,52 +1130,28 @@ public class AuctionController implements IAuctionHandler {
|
||||
// Logging
|
||||
// =========================================
|
||||
|
||||
private void logAuction(String action, String playerName, String itemName, long amount, String details) {
|
||||
if (!ConfigMarket.AuctionLoggingEnabled) return;
|
||||
private void logAuction(EnumAuctionLogAction action, String playerName, String itemName, long amount, String details) {
|
||||
if (!action.shouldLog()) return;
|
||||
|
||||
boolean shouldLog = false;
|
||||
switch (action) {
|
||||
case "CREATED":
|
||||
shouldLog = ConfigMarket.LogAuctionCreated;
|
||||
break;
|
||||
case "BID":
|
||||
shouldLog = ConfigMarket.LogAuctionBid;
|
||||
break;
|
||||
case "BUYOUT":
|
||||
shouldLog = ConfigMarket.LogAuctionBuyout;
|
||||
break;
|
||||
case "SOLD":
|
||||
shouldLog = ConfigMarket.LogAuctionSold;
|
||||
break;
|
||||
case "EXPIRED":
|
||||
shouldLog = ConfigMarket.LogAuctionExpired;
|
||||
break;
|
||||
case "CANCELLED":
|
||||
shouldLog = ConfigMarket.LogAuctionCancelled;
|
||||
break;
|
||||
case "CLAIMED":
|
||||
case "CLAIM_EXPIRED":
|
||||
shouldLog = ConfigMarket.LogAuctionClaimed;
|
||||
break;
|
||||
}
|
||||
|
||||
if (shouldLog) {
|
||||
String logMessage = String.format("[AUCTION:%s] Player: %s, Item: %s, Amount: %d, Details: %s",
|
||||
action, playerName, itemName, amount, details);
|
||||
LogWriter.info(logMessage);
|
||||
}
|
||||
String logMessage = String.format("[AUCTION:%s] Player: %s, Item: %s, Amount: %d, Details: %s",
|
||||
action.name(), playerName, itemName, amount, details);
|
||||
LogWriter.info(logMessage);
|
||||
}
|
||||
|
||||
// =========================================
|
||||
// Save / Load - Async on CNPC+ Thread
|
||||
// =========================================
|
||||
|
||||
/** Mark data as dirty - will be saved on next save cycle */
|
||||
/**
|
||||
* Mark data as dirty - will be saved on next save cycle
|
||||
*/
|
||||
private void markDirty() {
|
||||
dirty.set(true);
|
||||
}
|
||||
|
||||
/** Save synchronously - used for server shutdown */
|
||||
/**
|
||||
* Save synchronously - used for server shutdown
|
||||
*/
|
||||
public void save() {
|
||||
if (!dirty.compareAndSet(true, false)) {
|
||||
return; // Nothing to save
|
||||
@@ -1094,7 +1159,9 @@ public class AuctionController implements IAuctionHandler {
|
||||
saveInternal();
|
||||
}
|
||||
|
||||
/** Save asynchronously on CNPC+ thread */
|
||||
/**
|
||||
* Save asynchronously on CNPC+ thread
|
||||
*/
|
||||
public void saveAsync() {
|
||||
if (!dirty.compareAndSet(true, false)) {
|
||||
return; // Nothing to save
|
||||
@@ -1122,7 +1189,9 @@ public class AuctionController implements IAuctionHandler {
|
||||
});
|
||||
}
|
||||
|
||||
/** Internal synchronous save */
|
||||
/**
|
||||
* Internal synchronous save
|
||||
*/
|
||||
private void saveInternal() {
|
||||
try {
|
||||
NBTTagCompound compound = writeToNBT(new NBTTagCompound());
|
||||
@@ -1141,7 +1210,9 @@ public class AuctionController implements IAuctionHandler {
|
||||
File fileOld = new File(saveDir, "auction.dat_old");
|
||||
File fileCurrent = new File(saveDir, "auction.dat");
|
||||
|
||||
CompressedStreamTools.writeCompressed(compound, new FileOutputStream(fileNew));
|
||||
try (FileOutputStream fos = new FileOutputStream(fileNew)) {
|
||||
CompressedStreamTools.writeCompressed(compound, fos);
|
||||
}
|
||||
|
||||
// Backup rotation
|
||||
if (fileOld.exists()) fileOld.delete();
|
||||
@@ -1189,7 +1260,9 @@ public class AuctionController implements IAuctionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/** Rebuild all indices from loaded data */
|
||||
/**
|
||||
* Rebuild all indices from loaded data
|
||||
*/
|
||||
private void rebuildIndices() {
|
||||
playerListingIds.clear();
|
||||
playerBidIds.clear();
|
||||
@@ -1210,7 +1283,10 @@ public class AuctionController implements IAuctionHandler {
|
||||
}
|
||||
|
||||
private void loadFromFile(File file) throws Exception {
|
||||
NBTTagCompound compound = CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
NBTTagCompound compound;
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
compound = CompressedStreamTools.readCompressed(fis);
|
||||
}
|
||||
readFromNBT(compound);
|
||||
}
|
||||
|
||||
@@ -1398,15 +1474,20 @@ public class AuctionController implements IAuctionHandler {
|
||||
}
|
||||
|
||||
public void adminCancelListing(String listingId, EntityPlayer admin, String reason) {
|
||||
AuctionListing listing = listings.get(listingId);
|
||||
String itemName = listing != null && listing.item != null ? listing.item.getDisplayName() : "Unknown";
|
||||
cancelListing(listingId, admin, true);
|
||||
if (reason != null && !reason.isEmpty()) {
|
||||
logAuction(EnumAuctionLogAction.CANCELLED, admin.getCommandSenderName(), itemName, 0, "Admin cancel - Reason: " + reason);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearEndedListings() {
|
||||
// Remove ended/cancelled listings (claims are in PlayerData now)
|
||||
listings.entrySet().removeIf(entry ->
|
||||
entry.getValue().status == EnumAuctionStatus.CLAIMED ||
|
||||
entry.getValue().status == EnumAuctionStatus.ENDED ||
|
||||
entry.getValue().status == EnumAuctionStatus.CANCELLED);
|
||||
entry.getValue().status == EnumAuctionStatus.ENDED ||
|
||||
entry.getValue().status == EnumAuctionStatus.CANCELLED);
|
||||
|
||||
// Rebuild indices
|
||||
rebuildIndices();
|
||||
|
||||
@@ -5,7 +5,7 @@ import noppes.npcs.config.ConfigScript;
|
||||
|
||||
/**
|
||||
* Server-side utility for syncing script configuration to clients.
|
||||
*
|
||||
* <p>
|
||||
* This class is SERVER-SIDE ONLY. Client reads via ScriptClientConfig.
|
||||
*/
|
||||
public class ScriptConfigSync {
|
||||
|
||||
@@ -2,11 +2,12 @@ package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.api.event.IAbilityEvent;
|
||||
import noppes.npcs.api.event.IAnimationEvent;
|
||||
import noppes.npcs.api.event.IPlayerAbilityEvent;
|
||||
import noppes.npcs.api.event.IAuctionEvent;
|
||||
import noppes.npcs.api.event.IBlockEvent;
|
||||
import noppes.npcs.api.event.ICustomGuiEvent;
|
||||
import noppes.npcs.api.event.ICustomNPCsEvent;
|
||||
import noppes.npcs.api.event.IDialogEvent;
|
||||
import noppes.npcs.api.event.IEnergyBarrierEvent;
|
||||
import noppes.npcs.api.event.IEnergyProjectileEvent;
|
||||
import noppes.npcs.api.event.IFactionEvent;
|
||||
import noppes.npcs.api.event.IForgeEvent;
|
||||
@@ -14,6 +15,7 @@ import noppes.npcs.api.event.IItemEvent;
|
||||
import noppes.npcs.api.event.ILinkedItemEvent;
|
||||
import noppes.npcs.api.event.INpcEvent;
|
||||
import noppes.npcs.api.event.IPartyEvent;
|
||||
import noppes.npcs.api.event.IPlayerAbilityEvent;
|
||||
import noppes.npcs.api.event.IPlayerEvent;
|
||||
import noppes.npcs.api.event.IProjectileEvent;
|
||||
import noppes.npcs.api.event.IQuestEvent;
|
||||
@@ -123,6 +125,12 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(NPC, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(NPC, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
|
||||
// Energy Barrier
|
||||
hook(NPC, ENERGY_BARRIER_SPAWNED, IEnergyBarrierEvent.SpawnedEvent.class);
|
||||
hook(NPC, ENERGY_BARRIER_TICK, IEnergyBarrierEvent.UpdateEvent.class);
|
||||
hook(NPC, ENERGY_BARRIER_HIT, IEnergyBarrierEvent.HitEvent.class);
|
||||
hook(NPC, ENERGY_BARRIER_DESTROYED, IEnergyBarrierEvent.DestroyedEvent.class);
|
||||
|
||||
// Animation
|
||||
hook(NPC, ANIMATION_START, IAnimationEvent.Started.class);
|
||||
hook(NPC, ANIMATION_END, IAnimationEvent.Ended.class);
|
||||
@@ -230,6 +238,12 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(PLAYER, ENERGY_PROJECTILE_BLOCK_IMPACT, IEnergyProjectileEvent.BlockImpactEvent.class);
|
||||
hook(PLAYER, ENERGY_PROJECTILE_EXPIRED, IEnergyProjectileEvent.ExpiredEvent.class);
|
||||
|
||||
// Energy Barrier
|
||||
hook(PLAYER, ENERGY_BARRIER_SPAWNED, IEnergyBarrierEvent.SpawnedEvent.class);
|
||||
hook(PLAYER, ENERGY_BARRIER_TICK, IEnergyBarrierEvent.UpdateEvent.class);
|
||||
hook(PLAYER, ENERGY_BARRIER_HIT, IEnergyBarrierEvent.HitEvent.class);
|
||||
hook(PLAYER, ENERGY_BARRIER_DESTROYED, IEnergyBarrierEvent.DestroyedEvent.class);
|
||||
|
||||
// Ability
|
||||
hook(PLAYER, ABILITY_START, IPlayerAbilityEvent.StartEvent.class);
|
||||
hook(PLAYER, ABILITY_EXECUTE, IPlayerAbilityEvent.ExecuteEvent.class);
|
||||
@@ -238,6 +252,13 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(PLAYER, ABILITY_INTERRUPT, IPlayerAbilityEvent.InterruptEvent.class);
|
||||
hook(PLAYER, ABILITY_COMPLETE, IPlayerAbilityEvent.CompleteEvent.class);
|
||||
|
||||
// Auction
|
||||
hook(PLAYER, AUCTION_CREATE, IAuctionEvent.CreateEvent.class);
|
||||
hook(PLAYER, AUCTION_BID, IAuctionEvent.BidEvent.class);
|
||||
hook(PLAYER, AUCTION_BUYOUT, IAuctionEvent.BuyoutEvent.class);
|
||||
hook(PLAYER, AUCTION_CANCEL, IAuctionEvent.CancelEvent.class);
|
||||
hook(PLAYER, AUCTION_CLAIM, IAuctionEvent.ClaimEvent.class);
|
||||
|
||||
// Profile
|
||||
hook(PLAYER, PROFILE_CHANGE, IPlayerEvent.ProfileEvent.Changed.class);
|
||||
hook(PLAYER, PROFILE_REMOVE, IPlayerEvent.ProfileEvent.Removed.class);
|
||||
|
||||
@@ -10,15 +10,16 @@ import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AuctionBlacklist {
|
||||
private static Set<String> blacklistedItems = new HashSet<>();
|
||||
private static Set<Pattern> wildcardPatterns = new HashSet<>();
|
||||
private static Set<String> blacklistedMods = new HashSet<>();
|
||||
private static Set<String> blacklistedNBTTags = new HashSet<>();
|
||||
private static volatile Set<String> blacklistedItems = new HashSet<>();
|
||||
private static volatile Set<Pattern> wildcardPatterns = new HashSet<>();
|
||||
private static volatile Set<String> blacklistedMods = new HashSet<>();
|
||||
private static volatile Set<String> blacklistedNBTTags = new HashSet<>();
|
||||
|
||||
// Built-in bound item requirement keys (always blocked)
|
||||
private static final String SOULBIND_KEY = "cnpc_soulbind";
|
||||
@@ -28,10 +29,10 @@ public class AuctionBlacklist {
|
||||
private static final String BYPASS_PERMISSION = "customnpcs.auction.blacklist.bypass";
|
||||
|
||||
public static void reload() {
|
||||
blacklistedItems.clear();
|
||||
wildcardPatterns.clear();
|
||||
blacklistedMods.clear();
|
||||
blacklistedNBTTags.clear();
|
||||
Set<String> newItems = new HashSet<>();
|
||||
Set<Pattern> newWildcards = new HashSet<>();
|
||||
Set<String> newMods = new HashSet<>();
|
||||
Set<String> newNBTTags = new HashSet<>();
|
||||
|
||||
// Load blacklisted items
|
||||
for (String item : ConfigMarket.BlacklistedItems) {
|
||||
@@ -40,23 +41,29 @@ public class AuctionBlacklist {
|
||||
|
||||
if (item.contains("*")) {
|
||||
String regex = "^" + item.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
wildcardPatterns.add(Pattern.compile(regex));
|
||||
newWildcards.add(Pattern.compile(regex));
|
||||
} else {
|
||||
blacklistedItems.add(item);
|
||||
newItems.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Load blacklisted mods
|
||||
for (String mod : ConfigMarket.BlacklistedMods) {
|
||||
if (mod == null || mod.isEmpty()) continue;
|
||||
blacklistedMods.add(mod.toLowerCase().trim());
|
||||
newMods.add(mod.toLowerCase().trim());
|
||||
}
|
||||
|
||||
// Load blacklisted NBT tags
|
||||
for (String tag : ConfigMarket.BlacklistedNBTTags) {
|
||||
if (tag == null || tag.isEmpty()) continue;
|
||||
blacklistedNBTTags.add(tag.trim());
|
||||
newNBTTags.add(tag.trim());
|
||||
}
|
||||
|
||||
// Atomic swap
|
||||
blacklistedItems = newItems;
|
||||
wildcardPatterns = newWildcards;
|
||||
blacklistedMods = newMods;
|
||||
blacklistedNBTTags = newNBTTags;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +85,6 @@ public class AuctionBlacklist {
|
||||
* Check if item is blacklisted (without bypass check)
|
||||
*/
|
||||
public static boolean isBlacklisted(ItemStack item) {
|
||||
if (!ConfigMarket.BlacklistEnabled) return false;
|
||||
if (item == null || item.getItem() == null) return true;
|
||||
|
||||
// Check bound items (always blocked, even if blacklist is "disabled")
|
||||
@@ -86,6 +92,8 @@ public class AuctionBlacklist {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ConfigMarket.BlacklistEnabled) return false;
|
||||
|
||||
// Get registry name
|
||||
GameRegistry.UniqueIdentifier uid = GameRegistry.findUniqueIdentifierFor(item.getItem());
|
||||
if (uid == null) return true;
|
||||
@@ -172,9 +180,13 @@ public class AuctionBlacklist {
|
||||
|
||||
if (registryName.contains("*")) {
|
||||
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
wildcardPatterns.add(Pattern.compile(regex));
|
||||
Set<Pattern> newWildcards = new HashSet<>(wildcardPatterns);
|
||||
newWildcards.add(Pattern.compile(regex));
|
||||
wildcardPatterns = newWildcards;
|
||||
} else {
|
||||
blacklistedItems.add(registryName);
|
||||
Set<String> newItems = new HashSet<>(blacklistedItems);
|
||||
newItems.add(registryName);
|
||||
blacklistedItems = newItems;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -185,30 +197,55 @@ public class AuctionBlacklist {
|
||||
|
||||
if (registryName.contains("*")) {
|
||||
String regex = "^" + registryName.replace(".", "\\.").replace("*", ".*") + "$";
|
||||
return wildcardPatterns.removeIf(p -> p.pattern().equals(regex));
|
||||
Set<Pattern> newWildcards = new HashSet<>(wildcardPatterns);
|
||||
boolean removed = false;
|
||||
Iterator<Pattern> it = newWildcards.iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().pattern().equals(regex)) {
|
||||
it.remove();
|
||||
removed = true;
|
||||
}
|
||||
}
|
||||
wildcardPatterns = newWildcards;
|
||||
return removed;
|
||||
} else {
|
||||
return blacklistedItems.remove(registryName);
|
||||
Set<String> newItems = new HashSet<>(blacklistedItems);
|
||||
boolean removed = newItems.remove(registryName);
|
||||
blacklistedItems = newItems;
|
||||
return removed;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean addMod(String modId) {
|
||||
if (modId == null || modId.isEmpty()) return false;
|
||||
return blacklistedMods.add(modId.toLowerCase().trim());
|
||||
Set<String> newMods = new HashSet<>(blacklistedMods);
|
||||
boolean added = newMods.add(modId.toLowerCase().trim());
|
||||
blacklistedMods = newMods;
|
||||
return added;
|
||||
}
|
||||
|
||||
public static boolean removeMod(String modId) {
|
||||
if (modId == null || modId.isEmpty()) return false;
|
||||
return blacklistedMods.remove(modId.toLowerCase().trim());
|
||||
Set<String> newMods = new HashSet<>(blacklistedMods);
|
||||
boolean removed = newMods.remove(modId.toLowerCase().trim());
|
||||
blacklistedMods = newMods;
|
||||
return removed;
|
||||
}
|
||||
|
||||
public static boolean addNBTTag(String tag) {
|
||||
if (tag == null || tag.isEmpty()) return false;
|
||||
return blacklistedNBTTags.add(tag.trim());
|
||||
Set<String> newTags = new HashSet<>(blacklistedNBTTags);
|
||||
boolean added = newTags.add(tag.trim());
|
||||
blacklistedNBTTags = newTags;
|
||||
return added;
|
||||
}
|
||||
|
||||
public static boolean removeNBTTag(String tag) {
|
||||
if (tag == null || tag.isEmpty()) return false;
|
||||
return blacklistedNBTTags.remove(tag.trim());
|
||||
Set<String> newTags = new HashSet<>(blacklistedNBTTags);
|
||||
boolean removed = newTags.remove(tag.trim());
|
||||
blacklistedNBTTags = newTags;
|
||||
return removed;
|
||||
}
|
||||
|
||||
// =========================================
|
||||
|
||||
@@ -33,7 +33,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
this.otherPlayerName = "";
|
||||
}
|
||||
|
||||
/** Create claim for winning an item (buyer won auction or buyout) */
|
||||
/**
|
||||
* Create claim for winning an item (buyer won auction or buyout)
|
||||
*/
|
||||
public static AuctionClaim createItemWonClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -46,7 +48,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
return claim;
|
||||
}
|
||||
|
||||
/** Create claim for returned item (seller's expired/cancelled listing) */
|
||||
/**
|
||||
* Create claim for returned item (seller's expired/cancelled listing)
|
||||
*/
|
||||
public static AuctionClaim createItemReturnedClaim(UUID playerUUID, String playerName, String listingId, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -59,7 +63,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
return claim;
|
||||
}
|
||||
|
||||
/** Create claim for seller's proceeds (stores item name for tooltip, not full item) */
|
||||
/**
|
||||
* Create claim for seller's proceeds (stores item name for tooltip, not full item)
|
||||
*/
|
||||
public static AuctionClaim createCurrencyClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String buyerName) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -74,7 +80,9 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
return claim;
|
||||
}
|
||||
|
||||
/** Create claim for outbid refund (stores item for display and rebid option) */
|
||||
/**
|
||||
* Create claim for outbid refund (stores item for display and rebid option)
|
||||
*/
|
||||
public static AuctionClaim createRefundClaim(UUID playerUUID, String playerName, String listingId, long currency, String itemName, String outbidderName, ItemStack item) {
|
||||
AuctionClaim claim = new AuctionClaim();
|
||||
claim.playerUUID = playerUUID;
|
||||
@@ -140,7 +148,7 @@ public class AuctionClaim implements IAuctionClaim {
|
||||
|
||||
@Override
|
||||
public boolean isCurrencyClaim() {
|
||||
return type == EnumClaimType.CURRENCY;
|
||||
return type.isCurrency();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,16 +4,12 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import noppes.npcs.constants.EnumAuctionSort;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Filter for auction listings.
|
||||
* Supports search by item name or seller name and sorting options.
|
||||
*/
|
||||
public class AuctionFilter {
|
||||
private static final Pattern COLOR_CODE_PATTERN = Pattern.compile("§[0-9a-fk-or]", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
public String searchText;
|
||||
private String searchText;
|
||||
public EnumAuctionSort sortBy;
|
||||
|
||||
// Cached normalized search for efficiency
|
||||
@@ -29,15 +25,18 @@ public class AuctionFilter {
|
||||
return searchText != null && !searchText.trim().isEmpty();
|
||||
}
|
||||
|
||||
/** Normalize string for search (strip colors, lowercase, trim) */
|
||||
/**
|
||||
* Normalize string for search (strip colors, lowercase, trim)
|
||||
*/
|
||||
public static String normalizeForSearch(String input) {
|
||||
if (input == null || input.isEmpty()) return "";
|
||||
String stripped = COLOR_CODE_PATTERN.matcher(input).replaceAll("");
|
||||
stripped = EnumChatFormatting.getTextWithoutFormattingCodes(stripped);
|
||||
return stripped.toLowerCase().trim();
|
||||
String stripped = EnumChatFormatting.getTextWithoutFormattingCodes(input);
|
||||
return stripped != null ? stripped.toLowerCase().trim() : input.toLowerCase().trim();
|
||||
}
|
||||
|
||||
/** Check if item name or seller name matches search text */
|
||||
/**
|
||||
* Check if item name or seller name matches search text
|
||||
*/
|
||||
public boolean matchesSearch(String itemName, String sellerName) {
|
||||
if (!hasSearchText()) return true;
|
||||
String normalizedItem = normalizeForSearch(itemName);
|
||||
@@ -46,12 +45,16 @@ public class AuctionFilter {
|
||||
return normalizedItem.contains(normalizedSearch) || normalizedSeller.contains(normalizedSearch);
|
||||
}
|
||||
|
||||
/** Legacy method - only checks item name */
|
||||
/**
|
||||
* Legacy method - only checks item name
|
||||
*/
|
||||
public boolean matchesSearch(String itemName) {
|
||||
return matchesSearch(itemName, "");
|
||||
}
|
||||
|
||||
/** Advanced search - all words must be present in item name OR seller name */
|
||||
/**
|
||||
* Advanced search - all words must be present in item name OR seller name
|
||||
*/
|
||||
public boolean matchesSearchAdvanced(String itemName, String sellerName) {
|
||||
if (!hasSearchText()) return true;
|
||||
String normalizedItem = normalizeForSearch(itemName);
|
||||
@@ -68,7 +71,9 @@ public class AuctionFilter {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Legacy method - only checks item name */
|
||||
/**
|
||||
* Legacy method - only checks item name
|
||||
*/
|
||||
public boolean matchesSearchAdvanced(String itemName) {
|
||||
return matchesSearchAdvanced(itemName, "");
|
||||
}
|
||||
@@ -106,13 +111,20 @@ public class AuctionFilter {
|
||||
}
|
||||
|
||||
// Getters and setters
|
||||
public String getSearchText() { return searchText; }
|
||||
public String getSearchText() {
|
||||
return searchText;
|
||||
}
|
||||
|
||||
public void setSearchText(String searchText) {
|
||||
this.searchText = searchText;
|
||||
this.normalizedSearch = normalizeForSearch(searchText);
|
||||
}
|
||||
|
||||
public EnumAuctionSort getSortBy() { return sortBy; }
|
||||
public void setSortBy(EnumAuctionSort sortBy) { this.sortBy = sortBy; }
|
||||
public EnumAuctionSort getSortBy() {
|
||||
return sortBy;
|
||||
}
|
||||
|
||||
public void setSortBy(EnumAuctionSort sortBy) {
|
||||
this.sortBy = sortBy;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.EnumNotificationType;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuctionNotification {
|
||||
public String id;
|
||||
public UUID playerUUID;
|
||||
public EnumNotificationType type;
|
||||
public String listingId;
|
||||
public String message;
|
||||
public long timestamp;
|
||||
public boolean sent;
|
||||
|
||||
public AuctionNotification() {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
this.sent = false;
|
||||
}
|
||||
|
||||
public AuctionNotification(UUID playerUUID, EnumNotificationType type, String listingId, String message) {
|
||||
this();
|
||||
this.playerUUID = playerUUID;
|
||||
this.type = type;
|
||||
this.listingId = listingId;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public boolean isForPlayer(UUID uuid) {
|
||||
return playerUUID != null && playerUUID.equals(uuid);
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("ID", id);
|
||||
compound.setString("PlayerUUID", playerUUID != null ? playerUUID.toString() : "");
|
||||
compound.setInteger("Type", type.ordinal());
|
||||
compound.setString("ListingID", listingId != null ? listingId : "");
|
||||
compound.setString("Message", message != null ? message : "");
|
||||
compound.setLong("Timestamp", timestamp);
|
||||
compound.setBoolean("Sent", sent);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
id = compound.getString("ID");
|
||||
|
||||
String playerUUIDStr = compound.getString("PlayerUUID");
|
||||
playerUUID = playerUUIDStr.isEmpty() ? null : UUID.fromString(playerUUIDStr);
|
||||
|
||||
type = EnumNotificationType.fromOrdinal(compound.getInteger("Type"));
|
||||
listingId = compound.getString("ListingID");
|
||||
message = compound.getString("Message");
|
||||
timestamp = compound.getLong("Timestamp");
|
||||
sent = compound.getBoolean("Sent");
|
||||
}
|
||||
|
||||
public static AuctionNotification fromNBT(NBTTagCompound compound) {
|
||||
AuctionNotification notification = new AuctionNotification();
|
||||
notification.readFromNBT(compound);
|
||||
return notification;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ public class BuiltInAnimation extends Animation {
|
||||
|
||||
/**
|
||||
* Built-in animations cannot be saved.
|
||||
*
|
||||
* @return this animation unchanged
|
||||
*/
|
||||
@Override
|
||||
@@ -33,6 +34,7 @@ public class BuiltInAnimation extends Animation {
|
||||
|
||||
/**
|
||||
* Built-in animations have no valid ID.
|
||||
*
|
||||
* @return always -1
|
||||
*/
|
||||
@Override
|
||||
@@ -50,6 +52,7 @@ public class BuiltInAnimation extends Animation {
|
||||
|
||||
/**
|
||||
* Check if this is a built-in animation.
|
||||
*
|
||||
* @return always true for BuiltInAnimation
|
||||
*/
|
||||
public boolean isBuiltIn() {
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.IAbilityAction;
|
||||
import kamkeel.npcs.controllers.data.ability.ToggleEntry;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityGuard;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilityStatePacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilitySyncPacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphSpawnPacket;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -15,22 +20,18 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.AbstractDataAbilities;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.player.PlayerAbilityEvent;
|
||||
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilityStatePacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilitySyncPacket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Manages player ability data - unlocked abilities, selection, cooldowns, and execution.
|
||||
@@ -152,7 +153,7 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
|
||||
@Override
|
||||
protected void fireInterruptEvent(Ability ability, EntityLivingBase target,
|
||||
DamageSource source, float damage) {
|
||||
DamageSource source, float damage) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == null) return;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
@@ -229,6 +230,11 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void rollChainCooldown(ChainedAbility chain) {
|
||||
cooldownEndTime = getWorldTime() + chain.getCooldownTicks();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAbilityComplete() {
|
||||
currentAbility = null;
|
||||
@@ -263,7 +269,10 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
// Tick active toggles (independent of currentAbility)
|
||||
tickActiveToggles();
|
||||
|
||||
if (chainDelayRemaining > 0 || (currentAbility != null && currentAbility.isExecuting())) {
|
||||
tickCurrentAbility();
|
||||
|
||||
// Apply rotation and position locks after ability tick
|
||||
@@ -303,10 +312,27 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate a specific ability by key.
|
||||
* Prefix used to identify chained ability keys in the unlocked list.
|
||||
*/
|
||||
public static final String CHAIN_PREFIX = "chain:";
|
||||
|
||||
/**
|
||||
* Resolve an action key to an IAbilityAction.
|
||||
* Handles "chain:" prefix for chained abilities, otherwise resolves from AbilityController.
|
||||
*/
|
||||
private IAbilityAction resolveActionKey(String key) {
|
||||
if (key.startsWith(CHAIN_PREFIX)) {
|
||||
return AbilityController.Instance.resolveChainedAbility(key.substring(CHAIN_PREFIX.length()));
|
||||
}
|
||||
return AbilityController.Instance.resolveAbility(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate a specific ability by key. Keys prefixed with "chain:" are
|
||||
* treated as chained abilities and resolved from {@link AbilityController}.
|
||||
*
|
||||
* @param player The player
|
||||
* @param key The ability key (built-in or preset name)
|
||||
* @param key The ability key (built-in or preset name), or "chain:name" for chains
|
||||
* @return true if the ability was started
|
||||
*/
|
||||
public boolean activateAbility(EntityPlayer player, String key) {
|
||||
@@ -314,20 +340,32 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
|
||||
// Can't activate if already executing
|
||||
if (currentAbility != null && currentAbility.isExecuting()) return false;
|
||||
if (isExecutingChain()) return false;
|
||||
|
||||
// Resolve ability from controller
|
||||
if (AbilityController.Instance == null) return false;
|
||||
Ability ability = AbilityController.Instance.resolveAbility(key);
|
||||
if (ability == null) return false;
|
||||
// Resolve via unified resolver
|
||||
IAbilityAction action = resolveActionKey(key);
|
||||
if (action == null) return false;
|
||||
|
||||
// Check user type allows player
|
||||
if (!ability.getAllowedBy().allowsPlayer()) return false;
|
||||
|
||||
// Check universal cooldown
|
||||
if (!ability.isIgnoreCooldown() && isOnCooldown()) return false;
|
||||
if (!action.getAllowedBy().allowsPlayer()) return false;
|
||||
|
||||
// Check conditions (skip target-requiring ones)
|
||||
if (!ability.checkConditionsForPlayer(player)) return false;
|
||||
if (!action.checkConditionsForPlayer(player)) return false;
|
||||
|
||||
// Dispatch: chain vs ability
|
||||
if (action.isChain()) {
|
||||
if (isOnCooldown()) return false;
|
||||
|
||||
currentAbilityKey = key;
|
||||
currentTarget = null;
|
||||
return startChain((ChainedAbility) action, null);
|
||||
}
|
||||
|
||||
// Regular ability activation
|
||||
Ability ability = (Ability) action;
|
||||
|
||||
// Check universal cooldown (abilities can optionally ignore it)
|
||||
if (!ability.isIgnoreCooldown() && isOnCooldown()) return false;
|
||||
|
||||
// Fire extender start hook (e.g., resource cost checks)
|
||||
if (!AbilityController.Instance.fireOnAbilityStart(ability, player, null)) {
|
||||
@@ -385,6 +423,34 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onToggleStateChanged(String key, boolean active, int state) {
|
||||
syncToClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireToggleEvent(Ability ability, int oldState, int newState) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == null) return false;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return false;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.ToggleEvent event = new PlayerAbilityEvent.ToggleEvent(iPlayer, ability, oldState, newState);
|
||||
return EventHooks.onPlayerAbilityToggle(handler, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireToggleUpdateEvent(Ability ability, int tick, int state) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == null) return true;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return true;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.ToggleUpdateEvent event = new PlayerAbilityEvent.ToggleUpdateEvent(iPlayer, ability, tick, state);
|
||||
EventHooks.onPlayerAbilityToggleUpdate(handler, event);
|
||||
return event.isEnabled();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SELECTION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -540,6 +606,51 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
interruptCurrentAbility(null, 0);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// DIMENSION CHANGE RESET
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Fully reset ability state when changing dimensions.
|
||||
* Unlike interruptCurrentAbility(), this does NOT roll any cooldowns
|
||||
* and ensures the player can immediately use abilities in the new dimension.
|
||||
* Also re-syncs to client since the entity may be re-created.
|
||||
*/
|
||||
public void resetOnDimensionChange() {
|
||||
// Clean up any executing ability without rolling cooldowns
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
removeTelegraph(currentAbility);
|
||||
currentAbility.cleanup();
|
||||
currentAbility.interrupt();
|
||||
stopAbilityAnimation();
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
}
|
||||
|
||||
// Clear chain state
|
||||
currentChain = null;
|
||||
chainEntryIndex = -1;
|
||||
chainDelayRemaining = -1;
|
||||
|
||||
// Clear all transient state
|
||||
currentAbility = null;
|
||||
currentAbilityKey = null;
|
||||
currentTarget = null;
|
||||
|
||||
// Reset cooldowns completely
|
||||
cooldownEndTime = 0;
|
||||
interruptCooldownRolled = false;
|
||||
|
||||
// Sync cleared state to client
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player != null) {
|
||||
syncAbilityStateClear(player);
|
||||
}
|
||||
|
||||
// Re-sync ability data (unlocked list, selection) to client
|
||||
syncToClient();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// DAMAGE HANDLING
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -750,6 +861,16 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
compound.setTag("PlayerAbilities", list);
|
||||
compound.setInteger("PlayerAbilitySelected", selectedIndex);
|
||||
compound.setBoolean("AbilityAnimating", playingAbilityAnimation);
|
||||
|
||||
// Active toggles (compound format with state)
|
||||
NBTTagList toggleList = new NBTTagList();
|
||||
for (Map.Entry<String, ToggleEntry> entry : activeToggles.entrySet()) {
|
||||
NBTTagCompound toggleNbt = new NBTTagCompound();
|
||||
toggleNbt.setString("Key", entry.getKey());
|
||||
toggleNbt.setInteger("State", entry.getValue().getState());
|
||||
toggleList.appendTag(toggleNbt);
|
||||
}
|
||||
compound.setTag("ActiveToggles", toggleList);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
@@ -772,11 +893,24 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
selectedIndex = Math.max(0, unlockedAbilities.size() - 1);
|
||||
}
|
||||
playingAbilityAnimation = compound.getBoolean("AbilityAnimating");
|
||||
|
||||
// Active toggles - restore state directly (no onToggleOn callback during load)
|
||||
activeToggles.clear();
|
||||
if (compound.hasKey("ActiveToggles")) {
|
||||
NBTTagList toggleNbt = compound.getTagList("ActiveToggles", 10); // 10 = TAG_COMPOUND
|
||||
for (int i = 0; i < toggleNbt.tagCount(); i++) {
|
||||
NBTTagCompound entry = toggleNbt.getCompoundTagAt(i);
|
||||
String key = entry.getString("Key");
|
||||
int state = entry.hasKey("State") ? entry.getInteger("State") : 1;
|
||||
setToggleEntryDirect(key, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any unlocked ability keys that can no longer be resolved.
|
||||
* Called during load to clean up references to deleted abilities.
|
||||
* Supports both regular ability keys and "chain:" prefixed chained ability keys.
|
||||
*/
|
||||
private void validateUnlockedAbilities() {
|
||||
if (AbilityController.Instance == null) return;
|
||||
@@ -784,7 +918,8 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
Iterator<String> it = unlockedAbilities.iterator();
|
||||
while (it.hasNext()) {
|
||||
String key = it.next();
|
||||
if (!AbilityController.Instance.canResolveAbility(key)) {
|
||||
IAbilityAction resolved = resolveActionKey(key);
|
||||
if (resolved == null) {
|
||||
it.remove();
|
||||
LogWriter.info("Removed invalid ability reference from player data: " + key);
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.handler.IPlayerBankData;
|
||||
import noppes.npcs.api.handler.IPlayerTradeData;
|
||||
import noppes.npcs.api.handler.IPlayerData;
|
||||
import noppes.npcs.api.handler.IPlayerDialogData;
|
||||
import noppes.npcs.api.handler.IPlayerFactionData;
|
||||
import noppes.npcs.api.handler.IPlayerItemGiverData;
|
||||
import noppes.npcs.api.handler.IPlayerMailData;
|
||||
import noppes.npcs.api.handler.IPlayerQuestData;
|
||||
import noppes.npcs.api.handler.IPlayerTradeData;
|
||||
import noppes.npcs.api.handler.IPlayerTransportData;
|
||||
import noppes.npcs.config.ConfigMain;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
@@ -47,8 +47,6 @@ import java.io.FileOutputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
||||
|
||||
public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public PlayerDialogData dialogData = new PlayerDialogData(this);
|
||||
public PlayerBankData bankData = new PlayerBankData(this);
|
||||
|
||||
@@ -8,7 +8,6 @@ import noppes.npcs.api.handler.data.IAuctionClaim;
|
||||
import noppes.npcs.config.ConfigMarket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@@ -129,12 +128,13 @@ public class PlayerTradeData implements IPlayerTradeData {
|
||||
|
||||
// Built-in currency
|
||||
long newBalance = this.balance + amount;
|
||||
if (newBalance > ConfigMarket.MaxBalance) {
|
||||
return false;
|
||||
}
|
||||
// Overflow protection
|
||||
if (newBalance < this.balance) {
|
||||
// Overflow protection
|
||||
return false;
|
||||
newBalance = ConfigMarket.MaxBalance;
|
||||
}
|
||||
// Cap at MaxBalance instead of rejecting
|
||||
if (newBalance > ConfigMarket.MaxBalance) {
|
||||
newBalance = ConfigMarket.MaxBalance;
|
||||
}
|
||||
this.balance = newBalance;
|
||||
this.lifetimeEarned += amount;
|
||||
@@ -341,18 +341,16 @@ public class PlayerTradeData implements IPlayerTradeData {
|
||||
*/
|
||||
public int processExpiredClaims() {
|
||||
int expirationDays = ConfigMarket.ClaimExpirationDays;
|
||||
int removed = 0;
|
||||
|
||||
Iterator<AuctionClaim> iterator = claims.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
AuctionClaim claim = iterator.next();
|
||||
List<AuctionClaim> expired = new ArrayList<>();
|
||||
for (AuctionClaim claim : claims) {
|
||||
if (!claim.claimed && claim.isExpired(expirationDays)) {
|
||||
claims.remove(claim);
|
||||
removed++;
|
||||
expired.add(claim);
|
||||
}
|
||||
}
|
||||
|
||||
return removed;
|
||||
if (!expired.isEmpty()) {
|
||||
claims.removeAll(expired);
|
||||
}
|
||||
return expired.size();
|
||||
}
|
||||
|
||||
// =========================================
|
||||
|
||||
@@ -345,10 +345,10 @@ public class Action implements IAction {
|
||||
try {
|
||||
onStart.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IAction" + getName() + " onStart threw an exception:";
|
||||
String err = "IAction" + getName() + " onStart threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
|
||||
manager.LOGGER.error("onStart Task of " + this + " threw an exception:", t);
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ public class Action implements IAction {
|
||||
try {
|
||||
onDone.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IAction" + getName() + " onDone threw an exception:";
|
||||
String err = "IAction" + getName() + " onDone threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
String err = "IConditionalAction '" + getName() + "' threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
|
||||
manager.LOGGER.error("Task of " + this + " threw an exception:", t);
|
||||
markDone();
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
try {
|
||||
onTermination.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IConditionalAction" + getName() + " onTermination threw an exception:";
|
||||
String err = "IConditionalAction" + getName() + " onTermination threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package noppes.npcs.items;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
|
||||
import kamkeel.npcs.controllers.data.ability.data.*;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyAnchorData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyCombatData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyDisplayData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyHomingData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyLifespanData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyLightningData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyTrajectoryData;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -22,7 +28,7 @@ import noppes.npcs.entity.EntityProjectile;
|
||||
import noppes.npcs.util.IProjectileCallback;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Color;
|
||||
|
||||
public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
|
||||
|
||||
@@ -33,7 +39,8 @@ public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
|
||||
public ItemStaff(int par1, EnumNpcToolMaterial material) {
|
||||
super(par1);
|
||||
this.material = material;
|
||||
this.color = OrbColor.get(material.ordinal());;
|
||||
this.color = OrbColor.get(material.ordinal());
|
||||
;
|
||||
setCreativeTab(CustomItems.tabWeapon);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ package noppes.npcs.scripted;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.eventhandler.EventBus;
|
||||
import foxz.command.ScriptedCommand;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.TelegraphController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
@@ -58,9 +58,9 @@ import noppes.npcs.api.IContainer;
|
||||
import noppes.npcs.api.IDamageSource;
|
||||
import noppes.npcs.api.INbt;
|
||||
import noppes.npcs.api.IParticle;
|
||||
import noppes.npcs.api.ITelegraph;
|
||||
import noppes.npcs.api.IPos;
|
||||
import noppes.npcs.api.ISkinOverlay;
|
||||
import noppes.npcs.api.ITelegraph;
|
||||
import noppes.npcs.api.ITileEntity;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
@@ -70,8 +70,8 @@ import noppes.npcs.api.gui.ICustomGui;
|
||||
import noppes.npcs.api.handler.IAbilityHandler;
|
||||
import noppes.npcs.api.handler.IActionManager;
|
||||
import noppes.npcs.api.handler.IAnimationHandler;
|
||||
import noppes.npcs.api.handler.IAuctionHandler;
|
||||
import noppes.npcs.api.handler.IAttributeHandler;
|
||||
import noppes.npcs.api.handler.IAuctionHandler;
|
||||
import noppes.npcs.api.handler.ICloneHandler;
|
||||
import noppes.npcs.api.handler.ICustomEffectHandler;
|
||||
import noppes.npcs.api.handler.IDialogHandler;
|
||||
@@ -480,6 +480,8 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
data = new ScriptEntityData(new noppes.npcs.scripted.entity.ScriptEnergyDome<>((kamkeel.npcs.entity.EntityEnergyDome) entity));
|
||||
else if (entity instanceof kamkeel.npcs.entity.EntityEnergyPanel)
|
||||
data = new ScriptEntityData(new noppes.npcs.scripted.entity.ScriptEnergyPanel<>((kamkeel.npcs.entity.EntityEnergyPanel) entity));
|
||||
else if (entity instanceof kamkeel.npcs.entity.EntityAbilitySweeper)
|
||||
data = new ScriptEntityData(new noppes.npcs.scripted.entity.ScriptEnergySweeper<>((kamkeel.npcs.entity.EntityAbilitySweeper) entity));
|
||||
else
|
||||
data = new ScriptEntityData(new ScriptEntity<>(entity));
|
||||
entity.registerExtendedProperties("ScriptedObject", data);
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package noppes.npcs.scripted;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockAir;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -21,10 +25,6 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.IBlock;
|
||||
|
||||
@@ -29,40 +29,95 @@ public abstract class ScriptEnergyAbility<T extends EntityEnergyAbility> extends
|
||||
|
||||
// ==================== DISPLAY ====================
|
||||
|
||||
public int getInnerColor() { return entity.getInnerColor(); }
|
||||
public void setInnerColor(int color) { entity.setInnerColor(color); }
|
||||
public int getInnerColor() {
|
||||
return entity.getInnerColor();
|
||||
}
|
||||
|
||||
public float getInnerAlpha() { return entity.getInnerAlpha(); }
|
||||
public void setInnerAlpha(float alpha) { entity.setInnerAlpha(alpha); }
|
||||
public void setInnerColor(int color) {
|
||||
entity.setInnerColor(color);
|
||||
}
|
||||
|
||||
public int getOuterColor() { return entity.getOuterColor(); }
|
||||
public void setOuterColor(int color) { entity.setOuterColor(color); }
|
||||
public float getInnerAlpha() {
|
||||
return entity.getInnerAlpha();
|
||||
}
|
||||
|
||||
public boolean isOuterColorEnabled() { return entity.isOuterColorEnabled(); }
|
||||
public void setOuterColorEnabled(boolean enabled) { entity.setOuterColorEnabled(enabled); }
|
||||
public void setInnerAlpha(float alpha) {
|
||||
entity.setInnerAlpha(alpha);
|
||||
}
|
||||
|
||||
public float getOuterColorWidth() { return entity.getOuterColorWidth(); }
|
||||
public void setOuterColorWidth(float width) { entity.setOuterColorWidth(width); }
|
||||
public int getOuterColor() {
|
||||
return entity.getOuterColor();
|
||||
}
|
||||
|
||||
public float getOuterColorAlpha() { return entity.getOuterColorAlpha(); }
|
||||
public void setOuterColorAlpha(float alpha) { entity.setOuterColorAlpha(alpha); }
|
||||
public void setOuterColor(int color) {
|
||||
entity.setOuterColor(color);
|
||||
}
|
||||
|
||||
public boolean isOuterColorEnabled() {
|
||||
return entity.isOuterColorEnabled();
|
||||
}
|
||||
|
||||
public void setOuterColorEnabled(boolean enabled) {
|
||||
entity.setOuterColorEnabled(enabled);
|
||||
}
|
||||
|
||||
public float getOuterColorWidth() {
|
||||
return entity.getOuterColorWidth();
|
||||
}
|
||||
|
||||
public void setOuterColorWidth(float width) {
|
||||
entity.setOuterColorWidth(width);
|
||||
}
|
||||
|
||||
public float getOuterColorAlpha() {
|
||||
return entity.getOuterColorAlpha();
|
||||
}
|
||||
|
||||
public void setOuterColorAlpha(float alpha) {
|
||||
entity.setOuterColorAlpha(alpha);
|
||||
}
|
||||
|
||||
// ==================== LIGHTNING ====================
|
||||
|
||||
public boolean hasLightningEffect() { return entity.hasLightningEffect(); }
|
||||
public void setLightningEffect(boolean enabled) { entity.setLightningEffect(enabled); }
|
||||
public boolean hasLightningEffect() {
|
||||
return entity.hasLightningEffect();
|
||||
}
|
||||
|
||||
public float getLightningDensity() { return entity.getLightningDensity(); }
|
||||
public void setLightningDensity(float density) { entity.setLightningDensity(density); }
|
||||
public void setLightningEffect(boolean enabled) {
|
||||
entity.setLightningEffect(enabled);
|
||||
}
|
||||
|
||||
public float getLightningRadius() { return entity.getLightningRadius(); }
|
||||
public void setLightningRadius(float radius) { entity.setLightningRadius(radius); }
|
||||
public float getLightningDensity() {
|
||||
return entity.getLightningDensity();
|
||||
}
|
||||
|
||||
public int getLightningFadeTime() { return entity.getLightningFadeTime(); }
|
||||
public void setLightningFadeTime(int ticks) { entity.setLightningFadeTime(ticks); }
|
||||
public void setLightningDensity(float density) {
|
||||
entity.setLightningDensity(density);
|
||||
}
|
||||
|
||||
public float getLightningRadius() {
|
||||
return entity.getLightningRadius();
|
||||
}
|
||||
|
||||
public void setLightningRadius(float radius) {
|
||||
entity.setLightningRadius(radius);
|
||||
}
|
||||
|
||||
public int getLightningFadeTime() {
|
||||
return entity.getLightningFadeTime();
|
||||
}
|
||||
|
||||
public void setLightningFadeTime(int ticks) {
|
||||
entity.setLightningFadeTime(ticks);
|
||||
}
|
||||
|
||||
// ==================== STATE ====================
|
||||
|
||||
public boolean isCharging() { return entity.isCharging(); }
|
||||
public float getChargeProgress() { return entity.getChargeProgress(); }
|
||||
public boolean isCharging() {
|
||||
return entity.isCharging();
|
||||
}
|
||||
|
||||
public float getChargeProgress() {
|
||||
return entity.getChargeProgress();
|
||||
}
|
||||
}
|
||||
@@ -81,17 +81,37 @@ public class ScriptEnergyBarrier<T extends EntityEnergyBarrier> extends ScriptEn
|
||||
|
||||
// ==================== BARRIER ====================
|
||||
|
||||
public float getDefaultMultiplier() { return entity.getBarrierData().defaultMultiplier; }
|
||||
public void setDefaultMultiplier(float multiplier) { entity.getBarrierData().defaultMultiplier = multiplier; }
|
||||
public float getDefaultMultiplier() {
|
||||
return entity.getBarrierData().defaultMultiplier;
|
||||
}
|
||||
|
||||
public boolean isKnockbackEnabled() { return entity.getBarrierData().knockbackEnabled; }
|
||||
public void setKnockbackEnabled(boolean enabled) { entity.getBarrierData().knockbackEnabled = enabled; }
|
||||
public void setDefaultMultiplier(float multiplier) {
|
||||
entity.getBarrierData().defaultMultiplier = multiplier;
|
||||
}
|
||||
|
||||
public float getKnockbackStrength() { return entity.getBarrierData().knockbackStrength; }
|
||||
public void setKnockbackStrength(float strength) { entity.getBarrierData().knockbackStrength = strength; }
|
||||
public boolean isKnockbackEnabled() {
|
||||
return entity.getBarrierData().knockbackEnabled;
|
||||
}
|
||||
|
||||
public int getKnockbackTarget() { return entity.getBarrierData().knockbackTarget; }
|
||||
public void setKnockbackTarget(int target) { entity.getBarrierData().knockbackTarget = target; }
|
||||
public void setKnockbackEnabled(boolean enabled) {
|
||||
entity.getBarrierData().knockbackEnabled = enabled;
|
||||
}
|
||||
|
||||
public float getKnockbackStrength() {
|
||||
return entity.getBarrierData().knockbackStrength;
|
||||
}
|
||||
|
||||
public void setKnockbackStrength(float strength) {
|
||||
entity.getBarrierData().knockbackStrength = strength;
|
||||
}
|
||||
|
||||
public int getKnockbackTarget() {
|
||||
return entity.getBarrierData().knockbackTarget;
|
||||
}
|
||||
|
||||
public void setKnockbackTarget(int target) {
|
||||
entity.getBarrierData().knockbackTarget = target;
|
||||
}
|
||||
|
||||
public int getBarrierType() {
|
||||
return entity instanceof EntityEnergyDome ? 0 : 1;
|
||||
|
||||
@@ -29,16 +29,33 @@ public class ScriptEnergyBeam<T extends EntityAbilityBeam> extends ScriptEnergyP
|
||||
|
||||
// ==================== BEAM-SPECIFIC ====================
|
||||
|
||||
public float getBeamWidth() { return entity.getBeamWidth(); }
|
||||
public void setBeamWidth(float width) { entity.setBeamWidth(width); }
|
||||
public float getBeamWidth() {
|
||||
return entity.getBeamWidth();
|
||||
}
|
||||
|
||||
public float getHeadSize() { return entity.getHeadSize(); }
|
||||
public void setHeadSize(float size) { entity.setHeadSize(size); }
|
||||
public void setBeamWidth(float width) {
|
||||
entity.setBeamWidth(width);
|
||||
}
|
||||
|
||||
public boolean isAttachedToOwner() { return entity.isAttachedToOwner(); }
|
||||
public void setAttachedToOwner(boolean attached) { entity.setAttachedToOwner(attached); }
|
||||
public float getHeadSize() {
|
||||
return entity.getHeadSize();
|
||||
}
|
||||
|
||||
public boolean shouldRenderTailOrb() { return entity.shouldRenderTailOrb(); }
|
||||
public void setHeadSize(float size) {
|
||||
entity.setHeadSize(size);
|
||||
}
|
||||
|
||||
public boolean isAttachedToOwner() {
|
||||
return entity.isAttachedToOwner();
|
||||
}
|
||||
|
||||
public void setAttachedToOwner(boolean attached) {
|
||||
entity.setAttachedToOwner(attached);
|
||||
}
|
||||
|
||||
public boolean shouldRenderTailOrb() {
|
||||
return entity.shouldRenderTailOrb();
|
||||
}
|
||||
|
||||
// ==================== FIRE ====================
|
||||
|
||||
|
||||
@@ -29,22 +29,49 @@ public class ScriptEnergyDisc<T extends EntityAbilityDisc> extends ScriptEnergyP
|
||||
|
||||
// ==================== DISC-SPECIFIC ====================
|
||||
|
||||
public float getDiscRadius() { return entity.getDiscRadius(); }
|
||||
public void setDiscRadius(float radius) { entity.setDiscRadius(radius); }
|
||||
public float getDiscRadius() {
|
||||
return entity.getDiscRadius();
|
||||
}
|
||||
|
||||
public float getDiscThickness() { return entity.getDiscThickness(); }
|
||||
public void setDiscThickness(float thickness) { entity.setDiscThickness(thickness); }
|
||||
public void setDiscRadius(float radius) {
|
||||
entity.setDiscRadius(radius);
|
||||
}
|
||||
|
||||
public boolean isVertical() { return entity.isVertical(); }
|
||||
public void setVertical(boolean vertical) { entity.setVertical(vertical); }
|
||||
public float getDiscThickness() {
|
||||
return entity.getDiscThickness();
|
||||
}
|
||||
|
||||
public boolean isBoomerang() { return entity.isBoomerang(); }
|
||||
public void setBoomerang(boolean boomerang) { entity.setBoomerang(boomerang); }
|
||||
public void setDiscThickness(float thickness) {
|
||||
entity.setDiscThickness(thickness);
|
||||
}
|
||||
|
||||
public int getBoomerangDelay() { return entity.getBoomerangDelay(); }
|
||||
public void setBoomerangDelay(int ticks) { entity.setBoomerangDelay(ticks); }
|
||||
public boolean isVertical() {
|
||||
return entity.isVertical();
|
||||
}
|
||||
|
||||
public boolean isReturning() { return entity.isReturning(); }
|
||||
public void setVertical(boolean vertical) {
|
||||
entity.setVertical(vertical);
|
||||
}
|
||||
|
||||
public boolean isBoomerang() {
|
||||
return entity.isBoomerang();
|
||||
}
|
||||
|
||||
public void setBoomerang(boolean boomerang) {
|
||||
entity.setBoomerang(boomerang);
|
||||
}
|
||||
|
||||
public int getBoomerangDelay() {
|
||||
return entity.getBoomerangDelay();
|
||||
}
|
||||
|
||||
public void setBoomerangDelay(int ticks) {
|
||||
entity.setBoomerangDelay(ticks);
|
||||
}
|
||||
|
||||
public boolean isReturning() {
|
||||
return entity.isReturning();
|
||||
}
|
||||
|
||||
// ==================== FIRE ====================
|
||||
|
||||
|
||||
@@ -27,6 +27,11 @@ public class ScriptEnergyDome<T extends EntityEnergyDome> extends ScriptEnergyBa
|
||||
|
||||
// ==================== DOME-SPECIFIC ====================
|
||||
|
||||
public float getDomeRadius() { return entity.getDomeRadius(); }
|
||||
public void setDomeRadius(float radius) { entity.setDomeRadius(radius); }
|
||||
public float getDomeRadius() {
|
||||
return entity.getDomeRadius();
|
||||
}
|
||||
|
||||
public void setDomeRadius(float radius) {
|
||||
entity.setDomeRadius(radius);
|
||||
}
|
||||
}
|
||||
@@ -29,31 +29,77 @@ public class ScriptEnergyLaser<T extends EntityAbilityLaser> extends ScriptEnerg
|
||||
|
||||
// ==================== LASER-SPECIFIC ====================
|
||||
|
||||
public float getLaserWidth() { return entity.getLaserWidth(); }
|
||||
public void setLaserWidth(float width) { entity.setLaserWidth(width); }
|
||||
public float getLaserWidth() {
|
||||
return entity.getLaserWidth();
|
||||
}
|
||||
|
||||
public float getExpansionSpeed() { return entity.getExpansionSpeed(); }
|
||||
public void setExpansionSpeed(float speed) { entity.setExpansionSpeed(speed); }
|
||||
public void setLaserWidth(float width) {
|
||||
entity.setLaserWidth(width);
|
||||
}
|
||||
|
||||
public int getLingerTicks() { return entity.getLingerTicks(); }
|
||||
public void setLingerTicks(int ticks) { entity.setLingerTicks(ticks); }
|
||||
public float getExpansionSpeed() {
|
||||
return entity.getExpansionSpeed();
|
||||
}
|
||||
|
||||
public float getCurrentLength() { return entity.getCurrentLength(); }
|
||||
public boolean isFullyExtended() { return entity.isFullyExtended(); }
|
||||
public void setExpansionSpeed(float speed) {
|
||||
entity.setExpansionSpeed(speed);
|
||||
}
|
||||
|
||||
public double getDirX() { return entity.getDirX(); }
|
||||
public double getDirY() { return entity.getDirY(); }
|
||||
public double getDirZ() { return entity.getDirZ(); }
|
||||
public void setDirection(double x, double y, double z) { entity.setDirection(x, y, z); }
|
||||
public int getLingerTicks() {
|
||||
return entity.getLingerTicks();
|
||||
}
|
||||
|
||||
public double getEndX() { return entity.getEndX(); }
|
||||
public double getEndY() { return entity.getEndY(); }
|
||||
public double getEndZ() { return entity.getEndZ(); }
|
||||
public void setLingerTicks(int ticks) {
|
||||
entity.setLingerTicks(ticks);
|
||||
}
|
||||
|
||||
public float getLingerAlpha() { return entity.getLingerAlpha(); }
|
||||
public float getCurrentLength() {
|
||||
return entity.getCurrentLength();
|
||||
}
|
||||
|
||||
public boolean isLockVerticalDirection() { return entity.isLockVerticalDirection(); }
|
||||
public void setLockVerticalDirection(boolean lock) { entity.setLockVerticalDirection(lock); }
|
||||
public boolean isFullyExtended() {
|
||||
return entity.isFullyExtended();
|
||||
}
|
||||
|
||||
public double getDirX() {
|
||||
return entity.getDirX();
|
||||
}
|
||||
|
||||
public double getDirY() {
|
||||
return entity.getDirY();
|
||||
}
|
||||
|
||||
public double getDirZ() {
|
||||
return entity.getDirZ();
|
||||
}
|
||||
|
||||
public void setDirection(double x, double y, double z) {
|
||||
entity.setDirection(x, y, z);
|
||||
}
|
||||
|
||||
public double getEndX() {
|
||||
return entity.getEndX();
|
||||
}
|
||||
|
||||
public double getEndY() {
|
||||
return entity.getEndY();
|
||||
}
|
||||
|
||||
public double getEndZ() {
|
||||
return entity.getEndZ();
|
||||
}
|
||||
|
||||
public float getLingerAlpha() {
|
||||
return entity.getLingerAlpha();
|
||||
}
|
||||
|
||||
public boolean isLockVerticalDirection() {
|
||||
return entity.isLockVerticalDirection();
|
||||
}
|
||||
|
||||
public void setLockVerticalDirection(boolean lock) {
|
||||
entity.setLockVerticalDirection(lock);
|
||||
}
|
||||
|
||||
// ==================== FIRE ====================
|
||||
|
||||
|
||||
@@ -27,15 +27,31 @@ public class ScriptEnergyPanel<T extends EntityEnergyPanel> extends ScriptEnergy
|
||||
|
||||
// ==================== PANEL-SPECIFIC ====================
|
||||
|
||||
public float getPanelWidth() { return entity.getPanelData().panelWidth; }
|
||||
public void setPanelWidth(float width) { entity.getPanelData().setPanelWidth(width); }
|
||||
public float getPanelWidth() {
|
||||
return entity.getPanelData().panelWidth;
|
||||
}
|
||||
|
||||
public float getPanelHeight() { return entity.getPanelData().panelHeight; }
|
||||
public void setPanelHeight(float height) { entity.getPanelData().setPanelHeight(height); }
|
||||
public void setPanelWidth(float width) {
|
||||
entity.getPanelData().setPanelWidth(width);
|
||||
}
|
||||
|
||||
public float getPanelYaw() { return entity.getPanelYaw(); }
|
||||
public float getPanelHeight() {
|
||||
return entity.getPanelData().panelHeight;
|
||||
}
|
||||
|
||||
public int getPanelMode() { return entity.getMode().ordinal(); }
|
||||
public void setPanelHeight(float height) {
|
||||
entity.getPanelData().setPanelHeight(height);
|
||||
}
|
||||
|
||||
public boolean isLaunched() { return entity.getMode() == EntityEnergyPanel.PanelMode.LAUNCHED; }
|
||||
public float getPanelYaw() {
|
||||
return entity.getPanelYaw();
|
||||
}
|
||||
|
||||
public int getPanelMode() {
|
||||
return entity.getMode().ordinal();
|
||||
}
|
||||
|
||||
public boolean isLaunched() {
|
||||
return entity.getMode() == EntityEnergyPanel.PanelMode.LAUNCHED;
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@ package noppes.npcs.scripted.entity;
|
||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.api.entity.IEnergyProjectile;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
|
||||
public class ScriptEnergyProjectile<T extends EntityEnergyProjectile> extends ScriptEnergyAbility<T> implements IEnergyProjectile {
|
||||
@@ -67,74 +67,171 @@ public class ScriptEnergyProjectile<T extends EntityEnergyProjectile> extends Sc
|
||||
|
||||
// ==================== DISPLAY (PROJECTILE-SPECIFIC) ====================
|
||||
|
||||
public float getRotationSpeed() { return entity.getRotationSpeed(); }
|
||||
public void setRotationSpeed(float speed) { entity.setRotationSpeed(speed); }
|
||||
public float getRotationSpeed() {
|
||||
return entity.getRotationSpeed();
|
||||
}
|
||||
|
||||
public void setRotationSpeed(float speed) {
|
||||
entity.setRotationSpeed(speed);
|
||||
}
|
||||
|
||||
// ==================== INTERPOLATION ====================
|
||||
|
||||
public float getInterpolatedRotationX(float partialTicks) { return entity.getInterpolatedRotationX(partialTicks); }
|
||||
public float getInterpolatedRotationY(float partialTicks) { return entity.getInterpolatedRotationY(partialTicks); }
|
||||
public float getInterpolatedRotationZ(float partialTicks) { return entity.getInterpolatedRotationZ(partialTicks); }
|
||||
public float getInterpolatedSize(float partialTicks) { return entity.getInterpolatedSize(partialTicks); }
|
||||
public float getInterpolatedRotationX(float partialTicks) {
|
||||
return entity.getInterpolatedRotationX(partialTicks);
|
||||
}
|
||||
|
||||
public float getInterpolatedRotationY(float partialTicks) {
|
||||
return entity.getInterpolatedRotationY(partialTicks);
|
||||
}
|
||||
|
||||
public float getInterpolatedRotationZ(float partialTicks) {
|
||||
return entity.getInterpolatedRotationZ(partialTicks);
|
||||
}
|
||||
|
||||
public float getInterpolatedSize(float partialTicks) {
|
||||
return entity.getInterpolatedSize(partialTicks);
|
||||
}
|
||||
|
||||
// ==================== LIFESPAN ====================
|
||||
|
||||
public float getMaxDistance() { return entity.getMaxDistance(); }
|
||||
public void setMaxDistance(float distance) { entity.setMaxDistance(distance); }
|
||||
public float getMaxDistance() {
|
||||
return entity.getMaxDistance();
|
||||
}
|
||||
|
||||
public int getMaxLifetime() { return entity.getMaxLifetime(); }
|
||||
public void setMaxLifetime(int ticks) { entity.setMaxLifetime(ticks); }
|
||||
public void setMaxDistance(float distance) {
|
||||
entity.setMaxDistance(distance);
|
||||
}
|
||||
|
||||
public int getMaxLifetime() {
|
||||
return entity.getMaxLifetime();
|
||||
}
|
||||
|
||||
public void setMaxLifetime(int ticks) {
|
||||
entity.setMaxLifetime(ticks);
|
||||
}
|
||||
|
||||
// ==================== COMBAT ====================
|
||||
|
||||
public float getDamage() { return entity.getDamage(); }
|
||||
public void setDamage(float damage) { entity.setCombatDamage(damage); }
|
||||
public float getDamage() {
|
||||
return entity.getDamage();
|
||||
}
|
||||
|
||||
public float getKnockback() { return entity.getKnockback(); }
|
||||
public void setKnockback(float knockback) { entity.setCombatKnockback(knockback); }
|
||||
public void setDamage(float damage) {
|
||||
entity.setCombatDamage(damage);
|
||||
}
|
||||
|
||||
public float getKnockbackUp() { return entity.getKnockbackUp(); }
|
||||
public void setKnockbackUp(float knockbackUp) { entity.setCombatKnockbackUp(knockbackUp); }
|
||||
public float getKnockback() {
|
||||
return entity.getKnockback();
|
||||
}
|
||||
|
||||
public boolean isExplosive() { return entity.isExplosive(); }
|
||||
public void setExplosive(boolean explosive) { entity.setExplosive(explosive); }
|
||||
public void setKnockback(float knockback) {
|
||||
entity.setCombatKnockback(knockback);
|
||||
}
|
||||
|
||||
public float getExplosionRadius() { return entity.getExplosionRadius(); }
|
||||
public void setExplosionRadius(float radius) { entity.setExplosionRadius(radius); }
|
||||
public float getKnockbackUp() {
|
||||
return entity.getKnockbackUp();
|
||||
}
|
||||
|
||||
public float getExplosionDamageFalloff() { return entity.getExplosionDamageFalloff(); }
|
||||
public void setExplosionDamageFalloff(float falloff) { entity.setExplosionDamageFalloff(falloff); }
|
||||
public void setKnockbackUp(float knockbackUp) {
|
||||
entity.setCombatKnockbackUp(knockbackUp);
|
||||
}
|
||||
|
||||
public boolean isExplosive() {
|
||||
return entity.isExplosive();
|
||||
}
|
||||
|
||||
public void setExplosive(boolean explosive) {
|
||||
entity.setExplosive(explosive);
|
||||
}
|
||||
|
||||
public float getExplosionRadius() {
|
||||
return entity.getExplosionRadius();
|
||||
}
|
||||
|
||||
public void setExplosionRadius(float radius) {
|
||||
entity.setExplosionRadius(radius);
|
||||
}
|
||||
|
||||
public float getExplosionDamageFalloff() {
|
||||
return entity.getExplosionDamageFalloff();
|
||||
}
|
||||
|
||||
public void setExplosionDamageFalloff(float falloff) {
|
||||
entity.setExplosionDamageFalloff(falloff);
|
||||
}
|
||||
|
||||
// ==================== MOVEMENT ====================
|
||||
|
||||
public float getSpeed() { return entity.getSpeed(); }
|
||||
public void setSpeed(float speed) { entity.setSpeed(speed); }
|
||||
public float getSpeed() {
|
||||
return entity.getSpeed();
|
||||
}
|
||||
|
||||
public boolean isHoming() { return entity.isHoming(); }
|
||||
public void setHoming(boolean homing) { entity.setHomingEnabled(homing); }
|
||||
public void setSpeed(float speed) {
|
||||
entity.setSpeed(speed);
|
||||
}
|
||||
|
||||
public float getHomingStrength() { return entity.getHomingStrength(); }
|
||||
public void setHomingStrength(float strength) { entity.setHomingStrength(strength); }
|
||||
public boolean isHoming() {
|
||||
return entity.isHoming();
|
||||
}
|
||||
|
||||
public float getHomingRange() { return entity.getHomingRange(); }
|
||||
public void setHomingRange(float range) { entity.setHomingRange(range); }
|
||||
public void setHoming(boolean homing) {
|
||||
entity.setHomingEnabled(homing);
|
||||
}
|
||||
|
||||
public float getHomingStrength() {
|
||||
return entity.getHomingStrength();
|
||||
}
|
||||
|
||||
public void setHomingStrength(float strength) {
|
||||
entity.setHomingStrength(strength);
|
||||
}
|
||||
|
||||
public float getHomingRange() {
|
||||
return entity.getHomingRange();
|
||||
}
|
||||
|
||||
public void setHomingRange(float range) {
|
||||
entity.setHomingRange(range);
|
||||
}
|
||||
|
||||
// ==================== ANCHOR ====================
|
||||
|
||||
public int getAnchor() { return entity.getAnchor(); }
|
||||
public float getAnchorOffsetX() { return entity.getAnchorOffsetX(); }
|
||||
public float getAnchorOffsetY() { return entity.getAnchorOffsetY(); }
|
||||
public float getAnchorOffsetZ() { return entity.getAnchorOffsetZ(); }
|
||||
public int getAnchor() {
|
||||
return entity.getAnchor();
|
||||
}
|
||||
|
||||
public float getAnchorOffsetX() {
|
||||
return entity.getAnchorOffsetX();
|
||||
}
|
||||
|
||||
public float getAnchorOffsetY() {
|
||||
return entity.getAnchorOffsetY();
|
||||
}
|
||||
|
||||
public float getAnchorOffsetZ() {
|
||||
return entity.getAnchorOffsetZ();
|
||||
}
|
||||
|
||||
// ==================== POSITION ====================
|
||||
|
||||
public double getStartX() { return entity.getStartX(); }
|
||||
public double getStartY() { return entity.getStartY(); }
|
||||
public double getStartZ() { return entity.getStartZ(); }
|
||||
public double getStartX() {
|
||||
return entity.getStartX();
|
||||
}
|
||||
|
||||
public double getStartY() {
|
||||
return entity.getStartY();
|
||||
}
|
||||
|
||||
public double getStartZ() {
|
||||
return entity.getStartZ();
|
||||
}
|
||||
|
||||
// ==================== STATE ====================
|
||||
|
||||
public boolean hasHit() { return entity.getHasHit(); }
|
||||
public boolean hasHit() {
|
||||
return entity.getHasHit();
|
||||
}
|
||||
|
||||
// ==================== FIRE ====================
|
||||
|
||||
|
||||
@@ -29,14 +29,29 @@ public class ScriptEnergySlicer<T extends EntityEnergySlicer> extends ScriptEner
|
||||
|
||||
// ==================== SLICER-SPECIFIC ====================
|
||||
|
||||
public float getSliceWidth() { return entity.getSliceWidth(); }
|
||||
public void setSliceWidth(float width) { entity.setSliceWidth(width); }
|
||||
public float getSliceWidth() {
|
||||
return entity.getSliceWidth();
|
||||
}
|
||||
|
||||
public float getSliceThickness() { return entity.getSliceThickness(); }
|
||||
public void setSliceThickness(float thickness) { entity.setSliceThickness(thickness); }
|
||||
public void setSliceWidth(float width) {
|
||||
entity.setSliceWidth(width);
|
||||
}
|
||||
|
||||
public boolean isPiercing() { return entity.isPiercing(); }
|
||||
public void setPiercing(boolean piercing) { entity.setPiercing(piercing); }
|
||||
public float getSliceThickness() {
|
||||
return entity.getSliceThickness();
|
||||
}
|
||||
|
||||
public void setSliceThickness(float thickness) {
|
||||
entity.setSliceThickness(thickness);
|
||||
}
|
||||
|
||||
public boolean isPiercing() {
|
||||
return entity.isPiercing();
|
||||
}
|
||||
|
||||
public void setPiercing(boolean piercing) {
|
||||
entity.setPiercing(piercing);
|
||||
}
|
||||
|
||||
// ==================== FIRE ====================
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
|
||||
public class ScriptEnergySweeper<T extends EntityAbilitySweeper> extends ScriptEnergyAbility<T> {
|
||||
public ScriptEnergySweeper(T entity) {
|
||||
super(entity);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
@@ -29,7 +30,6 @@ import noppes.npcs.constants.EnumMovingType;
|
||||
import noppes.npcs.constants.EnumNavType;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.constants.EnumStandingType;
|
||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
||||
import noppes.npcs.controllers.FactionController;
|
||||
import noppes.npcs.controllers.data.DialogOption;
|
||||
import noppes.npcs.controllers.data.Line;
|
||||
|
||||
@@ -203,4 +203,81 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
return EnumScriptType.ABILITY_TICK.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a toggle ability changes state.
|
||||
* Canceling prevents the toggle from changing state.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ToggleEvent extends AbilityEvent implements IAbilityEvent.ToggleEvent {
|
||||
private final int oldState;
|
||||
private final int newState;
|
||||
|
||||
public ToggleEvent(ICustomNpc npc, Ability ability, int oldState, int newState) {
|
||||
super(npc, ability, null);
|
||||
this.oldState = oldState;
|
||||
this.newState = newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTogglingOn() {
|
||||
return newState > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOldState() {
|
||||
return oldState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewState() {
|
||||
return newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_TOGGLE.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired every 10 ticks for each active toggle ability.
|
||||
* Scripts can set enabled to false to force-deactivate.
|
||||
*/
|
||||
public static class ToggleUpdateEvent extends AbilityEvent implements IAbilityEvent.ToggleUpdateEvent {
|
||||
private final int tick;
|
||||
private final int state;
|
||||
private boolean enabled = true;
|
||||
|
||||
public ToggleUpdateEvent(ICustomNpc npc, Ability ability, int tick, int state) {
|
||||
super(npc, ability, null);
|
||||
this.tick = tick;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTick() {
|
||||
return tick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_TOGGLE_UPDATE.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package noppes.npcs.scripted.event.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.event.IAuctionEvent;
|
||||
import noppes.npcs.api.handler.data.IAuctionClaim;
|
||||
import noppes.npcs.api.handler.data.IAuctionListing;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
|
||||
public class AuctionEvent extends PlayerEvent implements IAuctionEvent {
|
||||
|
||||
public AuctionEvent(IPlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "auctionEvent";
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class CreateEvent extends AuctionEvent implements IAuctionEvent.CreateEvent {
|
||||
public final IItemStack item;
|
||||
public final long startingPrice;
|
||||
public final long buyoutPrice;
|
||||
|
||||
public CreateEvent(IPlayer player, IItemStack item, long startingPrice, long buyoutPrice) {
|
||||
super(player);
|
||||
this.item = item;
|
||||
this.startingPrice = startingPrice;
|
||||
this.buyoutPrice = buyoutPrice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.AUCTION_CREATE.function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStartingPrice() {
|
||||
return startingPrice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBuyoutPrice() {
|
||||
return buyoutPrice;
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class BidEvent extends AuctionEvent implements IAuctionEvent.BidEvent {
|
||||
public final IAuctionListing listing;
|
||||
public final long bidAmount;
|
||||
|
||||
public BidEvent(IPlayer player, IAuctionListing listing, long bidAmount) {
|
||||
super(player);
|
||||
this.listing = listing;
|
||||
this.bidAmount = bidAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.AUCTION_BID.function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAuctionListing getListing() {
|
||||
return listing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBidAmount() {
|
||||
return bidAmount;
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class BuyoutEvent extends AuctionEvent implements IAuctionEvent.BuyoutEvent {
|
||||
public final IAuctionListing listing;
|
||||
|
||||
public BuyoutEvent(IPlayer player, IAuctionListing listing) {
|
||||
super(player);
|
||||
this.listing = listing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.AUCTION_BUYOUT.function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAuctionListing getListing() {
|
||||
return listing;
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class CancelEvent extends AuctionEvent implements IAuctionEvent.CancelEvent {
|
||||
public final IAuctionListing listing;
|
||||
public final boolean admin;
|
||||
|
||||
public CancelEvent(IPlayer player, IAuctionListing listing, boolean isAdmin) {
|
||||
super(player);
|
||||
this.listing = listing;
|
||||
this.admin = isAdmin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.AUCTION_CANCEL.function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAuctionListing getListing() {
|
||||
return listing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAdmin() {
|
||||
return admin;
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class ClaimEvent extends AuctionEvent implements IAuctionEvent.ClaimEvent {
|
||||
public final IAuctionClaim claim;
|
||||
|
||||
public ClaimEvent(IPlayer player, IAuctionClaim claim) {
|
||||
super(player);
|
||||
this.claim = claim;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.AUCTION_CLAIM.function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAuctionClaim getClaim() {
|
||||
return claim;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,4 +202,81 @@ public class PlayerAbilityEvent extends PlayerEvent implements IPlayerAbilityEve
|
||||
return EnumScriptType.ABILITY_HIT.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a toggle ability changes state.
|
||||
* Canceling prevents the toggle from changing state.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ToggleEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.ToggleEvent {
|
||||
private final int oldState;
|
||||
private final int newState;
|
||||
|
||||
public ToggleEvent(IPlayer player, Ability ability, int oldState, int newState) {
|
||||
super(player, ability, null);
|
||||
this.oldState = oldState;
|
||||
this.newState = newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTogglingOn() {
|
||||
return newState > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOldState() {
|
||||
return oldState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewState() {
|
||||
return newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_TOGGLE.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired every 10 ticks for each active toggle ability.
|
||||
* Scripts can set enabled to false to force-deactivate.
|
||||
*/
|
||||
public static class ToggleUpdateEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.ToggleUpdateEvent {
|
||||
private final int tick;
|
||||
private final int state;
|
||||
private boolean enabled = true;
|
||||
|
||||
public ToggleUpdateEvent(IPlayer player, Ability ability, int tick, int state) {
|
||||
super(player, ability, null);
|
||||
this.tick = tick;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTick() {
|
||||
return tick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_TOGGLE_UPDATE.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package noppes.npcs.scripted.wrapper;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilitySlot;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityAction;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.DataAbilities;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
@@ -61,7 +61,9 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
if (!ability.getAllowedBy().allowsNpc()) {
|
||||
return; // Ability is PLAYER_ONLY
|
||||
}
|
||||
data.addAbilityReference(key);
|
||||
// Store by UUID/registry key for stable reference
|
||||
String canonicalKey = ability.getId() != null ? ability.getId() : key;
|
||||
data.addAbilityReference(canonicalKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,14 +83,14 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
|
||||
@Override
|
||||
public boolean isAbilityReference(String abilityId) {
|
||||
List<AbilitySlot> slots = data.getAbilitySlots();
|
||||
List<AbilityAction> slots = data.getAbilityActions();
|
||||
for (int i = 0; i < slots.size(); i++) {
|
||||
kamkeel.npcs.controllers.data.ability.AbilitySlot slot = slots.get(i);
|
||||
if (slot.isReference()) {
|
||||
AbilityAction slot = slots.get(i);
|
||||
if (slot.isAbilityReference()) {
|
||||
if (slot.getReferenceId().equals(abilityId)) return true;
|
||||
} else {
|
||||
} else if (!slot.isReference()) {
|
||||
Ability a = slot.getAbility();
|
||||
if (a != null && a.getId().equals(abilityId)) return false;
|
||||
if (a != null && abilityId.equals(a.getId())) return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -96,10 +98,10 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
|
||||
@Override
|
||||
public boolean convertToInline(String abilityId) {
|
||||
List<kamkeel.npcs.controllers.data.ability.AbilitySlot> slots = data.getAbilitySlots();
|
||||
List<AbilityAction> slots = data.getAbilityActions();
|
||||
for (int i = 0; i < slots.size(); i++) {
|
||||
kamkeel.npcs.controllers.data.ability.AbilitySlot slot = slots.get(i);
|
||||
if (slot.isReference() && slot.getReferenceId().equals(abilityId)) {
|
||||
AbilityAction slot = slots.get(i);
|
||||
if (slot.isAbilityReference() && slot.getReferenceId().equals(abilityId)) {
|
||||
return data.convertToInline(i);
|
||||
}
|
||||
}
|
||||
@@ -133,10 +135,11 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
|
||||
@Override
|
||||
public void setGlobalCooldown(int ticks) {
|
||||
// Set the cooldown by manipulating the internal cooldown end time
|
||||
// Not directly exposed, but we can reset and let it tick down
|
||||
data.resetCooldown();
|
||||
// This is a best-effort implementation
|
||||
if (ticks <= 0) {
|
||||
data.resetCooldown();
|
||||
} else {
|
||||
data.setCooldownEndTime(npc.worldObj.getTotalWorldTime() + ticks);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package noppes.npcs.scripted.wrapper;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
@@ -36,19 +36,21 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
|
||||
if (!ability.getAllowedBy().allowsPlayer()) {
|
||||
return; // Ability is NPC-only
|
||||
}
|
||||
// Use canonical key (registry key for built-in, name for custom)
|
||||
// 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) {
|
||||
data.lockAbility(key);
|
||||
String canonicalKey = resolveCanonicalKey(key);
|
||||
data.lockAbility(canonicalKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUnlockedAbility(String key) {
|
||||
return data.hasUnlockedAbility(key);
|
||||
String canonicalKey = resolveCanonicalKey(key);
|
||||
return data.hasUnlockedAbility(canonicalKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,4 +133,38 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
|
||||
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.resolveAbility(key);
|
||||
if (ability != null && ability.getId() != null) {
|
||||
return ability.getId();
|
||||
}
|
||||
return key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package noppes.npcs.util;
|
||||
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.AuctionClientConfig;
|
||||
|
||||
/**
|
||||
* Shared formatting utilities for the auction system.
|
||||
* Consolidates duplicated format methods from GUI classes.
|
||||
*/
|
||||
public class AuctionFormatUtil {
|
||||
// Time constants in milliseconds
|
||||
public static final long MS_PER_SECOND = 1000L;
|
||||
public static final long MS_PER_MINUTE = 60L * MS_PER_SECOND;
|
||||
public static final long MS_PER_HOUR = 60L * MS_PER_MINUTE;
|
||||
public static final long MS_PER_DAY = 24L * MS_PER_HOUR;
|
||||
|
||||
/**
|
||||
* Format currency amount with commas (e.g., 1000 -> "1,000").
|
||||
* Does NOT append currency name.
|
||||
*/
|
||||
public static String formatCurrency(long amount) {
|
||||
if (amount < 1000) return "" + amount;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String str = "" + amount;
|
||||
int count = 0;
|
||||
for (int i = str.length() - 1; i >= 0; i--) {
|
||||
if (count > 0 && count % 3 == 0) sb.insert(0, ',');
|
||||
sb.insert(0, str.charAt(i));
|
||||
count++;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format currency amount with commas and append currency name.
|
||||
* (e.g., 1000 -> "1,000 Gold")
|
||||
*/
|
||||
public static String formatCurrencyWithName(long amount) {
|
||||
return formatCurrency(amount) + " " + AuctionClientConfig.getCurrencyName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format time remaining as a compact string (e.g., "2d 5h 30m").
|
||||
* Uses localized "Ended" text when time is <= 0.
|
||||
*/
|
||||
public static String formatTimeRemaining(long ms) {
|
||||
if (ms <= 0) return StatCollector.translateToLocal("auction.ended");
|
||||
|
||||
long seconds = (ms / MS_PER_SECOND) % 60;
|
||||
long minutes = (ms / MS_PER_MINUTE) % 60;
|
||||
long hours = (ms / MS_PER_HOUR) % 24;
|
||||
long days = ms / MS_PER_DAY;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (days > 0) sb.append(days).append("d ");
|
||||
if (hours > 0 || days > 0) sb.append(hours).append("h ");
|
||||
if (minutes > 0 || hours > 0 || days > 0) sb.append(minutes).append("m");
|
||||
else sb.append(seconds).append("s");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if time remaining is urgent (less than 1 hour).
|
||||
*/
|
||||
public static boolean isTimeUrgent(long ms) {
|
||||
return ms > 0 && ms < MS_PER_HOUR;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user