Merge branch 'dev' into syntax-highlighter-unified

This commit is contained in:
Kam committed 2026-02-19 20:06:47 -05:00
commit c2f9fdb47f
82 files changed
+2673 -695

No files matched your search

@@ -5,6 +5,7 @@ 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.ConcurrentSlot;
import kamkeel.npcs.controllers.data.ability.ToggleEntry;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import net.minecraft.entity.EntityLivingBase;
@@ -13,6 +14,7 @@ import noppes.npcs.controllers.AnimationController;
import noppes.npcs.controllers.data.Animation;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -57,6 +59,7 @@ public abstract class AbstractDataAbilities {
* Position lock state
*/
protected boolean positionLocked = false;
protected boolean wasFlyingAtLock = false;
protected double lockedPosX = 0;
protected double lockedPosY = 0;
protected double lockedPosZ = 0;
@@ -73,6 +76,12 @@ public abstract class AbstractDataAbilities {
*/
protected boolean interruptCooldownRolled = false;
/**
* Concurrent ability execution slots. Ticked independently alongside the primary ability.
* Concurrent abilities skip animations, sounds, and movement/rotation locks.
*/
protected List<ConcurrentSlot> concurrentSlots = new ArrayList<>();
// ═══════════════════════════════════════════════════════════════════
// ABSTRACT METHODS - Subclasses must implement
// ═══════════════════════════════════════════════════════════════════
@@ -530,6 +539,13 @@ public abstract class AbstractDataAbilities {
lockedPosY = entity.posY;
lockedPosZ = entity.posZ;
positionLocked = true;
// Record flight state at lock time so airborne players stay at their height
// even if their flight system deactivates during input suppression
wasFlyingAtLock = entity instanceof net.minecraft.entity.player.EntityPlayer
&& AbilityController.Instance != null
&& AbilityController.Instance.isPlayerFlying((net.minecraft.entity.player.EntityPlayer) entity);
onPositionLockChanged(true);
}
@@ -538,9 +554,17 @@ public abstract class AbstractDataAbilities {
*/
protected void releaseLockedPosition() {
positionLocked = false;
wasFlyingAtLock = false;
onPositionLockChanged(false);
}
/**
* Whether the entity was flying when the position lock was captured.
*/
public boolean wasFlyingAtLock() {
return wasFlyingAtLock;
}
/**
* Hook for subclass to react to position lock state changes (e.g., NPC sets data watcher flag).
*/
@@ -590,8 +614,12 @@ public abstract class AbstractDataAbilities {
return;
}
}
startChainEntry(chainTarget);
if (startChainEntry(chainTarget)) {
launchConsecutiveConcurrentEntries(chainTarget);
}
}
// Tick concurrent slots even during chain delay
tickConcurrentSlots();
return;
}
@@ -731,6 +759,9 @@ public abstract class AbstractDataAbilities {
// Post-phase hook (NPC: hit scan + movement control)
onPostPhaseTick(currentAbility, target);
// Tick concurrent slots independently
tickConcurrentSlots();
}
// ═══════════════════════════════════════════════════════════════════
@@ -768,6 +799,10 @@ public abstract class AbstractDataAbilities {
int delay = completedEntry.getDelayTicks();
chainEntryIndex++;
// Skip any consecutive concurrent entries — launch them to concurrent slots
launchConsecutiveConcurrentEntries(target);
if (chainEntryIndex < currentChain.getEntries().size()) {
// Check if target died and retarget
if (target != null && target.isDead) {
@@ -868,6 +903,9 @@ public abstract class AbstractDataAbilities {
chainDelayRemaining = -1;
}
// Interrupt all concurrent slots
interruptConcurrentSlots();
// Let subclass handle cleanup
onInterruptComplete();
}
@@ -899,7 +937,11 @@ public abstract class AbstractDataAbilities {
chainDelayRemaining = -1;
// AFTER semantics: no delay before first entry (delay applies after each entry completes)
return startChainEntry(target);
boolean started = startChainEntry(target);
if (started) {
launchConsecutiveConcurrentEntries(target);
}
return started;
}
/**
@@ -967,8 +1009,74 @@ public abstract class AbstractDataAbilities {
return true;
}
// ═══════════════════════════════════════════════════════════════════
// CONCURRENT SLOT MANAGEMENT
// ═══════════════════════════════════════════════════════════════════
/**
* Tick all active concurrent slots. Remove completed ones.
* Called from tickCurrentAbility() and during chain delay countdown.
*/
protected void tickConcurrentSlots() {
if (concurrentSlots.isEmpty()) return;
EntityLivingBase entity = getEntity();
EntityLivingBase target = getTarget();
Iterator<ConcurrentSlot> it = concurrentSlots.iterator();
while (it.hasNext()) {
ConcurrentSlot slot = it.next();
slot.tick(entity, target);
if (slot.isCompleted()) {
it.remove();
}
}
}
/**
* After starting a primary chain entry, scan forward and launch any consecutive
* concurrent entries (with delay=0) to concurrent slots immediately.
* This enables simultaneous execution of Effect abilities alongside the primary.
*/
protected void launchConsecutiveConcurrentEntries(EntityLivingBase target) {
if (currentChain == null) return;
List<ChainedAbilityEntry> entries = currentChain.getEntries();
while (chainEntryIndex + 1 < entries.size()) {
ChainedAbilityEntry nextEntry = entries.get(chainEntryIndex + 1);
Ability resolved = nextEntry.resolve();
if (resolved == null || !resolved.isConcurrentCapable()
|| !nextEntry.isConcurrentEnabled()) break;
// Only auto-launch concurrent entries with 0 delay
if (nextEntry.getDelayTicks() > 0) break;
// Advance past this entry in the chain (it runs concurrently, not sequentially)
chainEntryIndex++;
// Deep copy the ability so it has its own state
Ability concurrentCopy = AbilityController.Instance.fromNBT(resolved.writeNBT());
if (concurrentCopy == null) continue;
ConcurrentSlot slot = new ConcurrentSlot(concurrentCopy);
concurrentSlots.add(slot);
slot.start(getEntity(), target);
}
}
/**
* Interrupt all active concurrent slots. Called on ability interrupt or combat reset.
*/
protected void interruptConcurrentSlots() {
for (ConcurrentSlot slot : concurrentSlots) {
slot.interrupt();
}
concurrentSlots.clear();
}
/**
* Complete the chain execution. Rolls chain cooldown and clears all chain state.
* NOTE: Does NOT clear concurrent slots — they outlive the chain and tick independently.
*/
protected void completeChain() {
if (currentChain != null) {
+6 -4
View File
@@ -326,10 +326,11 @@ public class DataAbilities extends AbstractDataAbilities {
if (rotationLocked || hitScanActive) releaseRotationControl();
if (positionLocked) releaseLockedPosition();
}
// Clear chain state
// Clear chain and concurrent state
currentChain = null;
chainEntryIndex = -1;
chainDelayRemaining = -1;
interruptConcurrentSlots();
return;
}
@@ -392,7 +393,7 @@ public class DataAbilities extends AbstractDataAbilities {
for (AbilityAction slot : actionSlots) {
IAbilityAction action = slot.getAction();
if (action != null && isActionEligible(action, target)) {
if (action != null && isActionEligible(slot, action, target)) {
eligible.add(action);
weights.add(action.getWeight());
totalWeight += action.getWeight();
@@ -450,11 +451,11 @@ public class DataAbilities extends AbstractDataAbilities {
/**
* Check if an action (ability or chain) is eligible for use.
*/
private boolean isActionEligible(IAbilityAction action, EntityLivingBase target) {
private boolean isActionEligible(AbilityAction slot, IAbilityAction action, EntityLivingBase target) {
if (!action.getAllowedBy().allowsNpc()) {
return false;
}
if (!action.isEnabled()) {
if (!slot.isSlotEnabled()) {
return false;
}
@@ -724,6 +725,7 @@ public class DataAbilities extends AbstractDataAbilities {
public void reset() {
stopCurrentAbility();
clearActiveToggles();
interruptConcurrentSlots();
// Roll cooldown so NPC doesn't immediately attack after reset
rollCooldownOnReset();
@@ -106,9 +106,14 @@ public class ScriptPlayerEventHandler {
if (playerData.abilityData.isMovementLocked()) {
Ability current = playerData.abilityData.getCurrentAbility();
if (current == null || !current.hasAbilityMovement()) {
boolean sFlying = playerData.abilityData.wasFlyingAtLock()
|| AbilityController.Instance.isPlayerFlying(player);
player.motionX = 0;
if (!AbilityController.Instance.isPlayerFlying(player)) {
if (!sFlying) {
player.motionY = Math.min(player.motionY, 0);
} else {
player.motionY = 0;
}
player.motionZ = 0;
player.velocityChanged = true;
@@ -650,10 +655,12 @@ public class ScriptPlayerEventHandler {
return;
if (event.player.worldObj instanceof WorldServer && event.player instanceof EntityPlayerMP) {
// Cancel any executing ability on respawn
// Reset ability state for reconstructed entity and re-sync to client.
// The death handler already interrupted the ability (with events/cooldowns),
// so this just cleans up transient state and syncs the new entity.
PlayerData playerData = PlayerData.get(event.player);
if (playerData != null) {
playerData.abilityData.interruptCurrentAbility();
playerData.abilityData.resetOnRespawn();
}
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(event.player);
@@ -15,6 +15,7 @@ public class ClientAbilityState {
public static boolean rotationLocked = false;
public static boolean hasAbilityMovement = false;
public static boolean positionLocked = false;
public static boolean wasFlyingAtLock = false;
public static float lockedYaw = 0;
public static float lockedPitch = 0;
@@ -26,6 +27,7 @@ public class ClientAbilityState {
rotationLocked = (flags & PlayerAbilityStatePacket.FLAG_ROTATION_LOCKED) != 0;
hasAbilityMovement = (flags & PlayerAbilityStatePacket.FLAG_HAS_ABILITY_MOVEMENT) != 0;
positionLocked = (flags & PlayerAbilityStatePacket.FLAG_POSITION_LOCKED) != 0;
wasFlyingAtLock = (flags & PlayerAbilityStatePacket.FLAG_WAS_FLYING_AT_LOCK) != 0;
lockedYaw = yaw;
lockedPitch = pitch;
}
@@ -53,6 +55,7 @@ public class ClientAbilityState {
rotationLocked = false;
hasAbilityMovement = false;
positionLocked = false;
wasFlyingAtLock = false;
lockedYaw = 0;
lockedPitch = 0;
}
@@ -81,8 +81,6 @@ public class ClientTickHandler {
// Only suppress when no GUI screen is open (screens already capture input).
if (mc.currentScreen == null && ClientAbilityState.shouldSuppressMovementInput()) {
// Unpress movement keybinds at the source BEFORE updatePlayerMoveState() reads them.
// This is more robust than just zeroing movementInput fields, because
// updatePlayerMoveState() reads directly from keybind pressed state.
KeyBinding.setKeyBindState(mc.gameSettings.keyBindForward.getKeyCode(), false);
KeyBinding.setKeyBindState(mc.gameSettings.keyBindBack.getKeyCode(), false);
KeyBinding.setKeyBindState(mc.gameSettings.keyBindLeft.getKeyCode(), false);
@@ -91,7 +89,6 @@ public class ClientTickHandler {
KeyBinding.setKeyBindState(mc.gameSettings.keyBindSneak.getKeyCode(), false);
KeyBinding.setKeyBindState(mc.gameSettings.keyBindSprint.getKeyCode(), false);
// Also zero the movementInput values directly as a safety net
mc.thePlayer.movementInput.moveForward = 0;
mc.thePlayer.movementInput.moveStrafe = 0;
mc.thePlayer.movementInput.jump = false;
@@ -128,17 +125,20 @@ public class ClientTickHandler {
mc.thePlayer.movementInput.jump = false;
mc.thePlayer.movementInput.sneak = false;
// Zero horizontal motion (unless ability provides its own movement)
// Zero all motion — position lock holds the player in place (server is authoritative)
if (!ClientAbilityState.hasAbilityMovement) {
mc.thePlayer.motionX = 0;
mc.thePlayer.motionZ = 0;
}
// Prevent jumping when locked (allow gravity only if not flying)
// Zero vertical motion: grounded players can't jump, flying players are frozen in air
if ((ClientAbilityState.movementLocked || ClientAbilityState.positionLocked)
&& !ClientAbilityState.hasAbilityMovement
&& !AbilityController.Instance.isPlayerFlying(mc.thePlayer)) {
mc.thePlayer.motionY = Math.min(mc.thePlayer.motionY, 0);
&& !ClientAbilityState.hasAbilityMovement) {
if (ClientAbilityState.wasFlyingAtLock) {
mc.thePlayer.motionY = 0;
} else {
mc.thePlayer.motionY = Math.min(mc.thePlayer.motionY, 0);
}
}
}
@@ -34,6 +34,7 @@ import noppes.npcs.constants.EnumScrollData;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -187,7 +188,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
}
availableTypesScroll.guiLeft = guiLeft + 5;
availableTypesScroll.guiTop = y + 12;
availableTypesScroll.setList(getFilteredTypeList());
availableTypesScroll.setUnsortedList(getFilteredTypeList());
addScroll(availableTypesScroll);
// Search bar for types
@@ -218,14 +219,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
// On/Off toggle for selected slot (under Load button) — chains and abilities
if (selectedSlotIndex >= 0 && selectedSlotIndex < npcSlots.size() && selectedEntryIndex == -1) {
AbilityAction selectedSlot = npcSlots.get(selectedSlotIndex);
boolean isEnabled = false;
if (selectedSlot.isChain()) {
ChainedAbility chain = selectedSlot.isInlineChain() ? selectedSlot.getInlineChain() : selectedSlot.getChainedAbility();
isEnabled = chain != null && chain.isEnabled();
} else {
Ability ability = selectedSlot.getAbility();
isEnabled = ability != null && ability.isEnabled();
}
boolean isEnabled = selectedSlot.isSlotEnabled();
GuiNpcButton toggleBtn = new GuiNpcButton(BTN_TOGGLE_SLOT, centerX, y + 112, 40, 20,
new String[]{"gui.off", "gui.on"}, isEnabled ? 1 : 0);
addButton(toggleBtn);
@@ -241,6 +235,14 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
Ability a = sel.getAbility();
if (a != null && a.isBuiltIn()) selectedIsBuiltIn = true;
}
// Chain entries referencing built-in abilities are not editable
if (selectedIsChainEntry && sel.isChain()) {
ChainedAbility biChain = sel.isInlineChain() ? sel.getInlineChain() : sel.getChainedAbility();
if (biChain != null && selectedEntryIndex < biChain.getEntries().size()) {
Ability resolved = biChain.getEntries().get(selectedEntryIndex).resolve();
if (resolved != null && resolved.isBuiltIn()) selectedIsBuiltIn = true;
}
}
// Sub-entries of reference chains are not directly editable from the NPC list
if (selectedIsChainEntry && sel.isChainReference()) {
selectedIsRefChainEntry = true;
@@ -369,6 +371,10 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
ChainedAbility chain = slot.isInlineChain() ? slot.getInlineChain() : slot.getChainedAbility();
if (chain != null && selectedEntryIndex < chain.getEntries().size()) {
ChainedAbilityEntry entry = chain.getEntries().get(selectedEntryIndex);
// Built-in abilities are always references — no editing allowed
Ability resolvedEntry = entry.resolve();
if (resolvedEntry != null && resolvedEntry.isBuiltIn()) return;
if (entry.isInline() && slot.isInlineChain()) {
// Inline entry in inline chain — edit directly
Ability a = entry.getInlineAbility();
@@ -460,7 +466,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
pendingSaveEntryIdx = -1;
}
if (abilityToSave != null) {
if (abilityToSave != null && !abilityToSave.isBuiltIn()) {
if (abilityToSave.getName() == null || abilityToSave.getName().isEmpty()) {
abilityToSave.setNpcInlineEdit(true);
setSubGui(abilityToSave.createConfigGui(this));
@@ -541,7 +547,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
filteredAbilityTypes.putAll(getFilteredData(allAbilityTypes));
if (availableTypesScroll != null) {
availableTypesScroll.setList(getFilteredTypeList());
availableTypesScroll.setUnsortedList(getFilteredTypeList());
}
} else if (type == EnumScrollData.CUSTOM_ABILITIES) {
existingPresetNames.clear();
@@ -605,7 +611,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
if (search.equals(getTextField(TF_SEARCH).getText()))
return;
search = getTextField(TF_SEARCH).getText().toLowerCase();
availableTypesScroll.setList(getFilteredTypeList());
availableTypesScroll.setUnsortedList(getFilteredTypeList());
availableTypesScroll.resetScroll();
}
}
@@ -640,16 +646,21 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
displayNameToTypeId.clear();
for (String typeId : filteredAbilityTypes.keySet()) {
String displayName = I18n.format(typeId);
// Search matches either the display name or the typeId
if (search.isEmpty() || displayName.toLowerCase().contains(search) || typeId.toLowerCase().contains(search)) {
// Gray out built-in types to distinguish them from configurable types
if (AbilityController.Instance.isBuiltInType(typeId)) {
// Search matches either the display name or the typeId (strip color codes for matching)
String stripped = displayName.replaceAll("\u00A7.", "");
if (search.isEmpty() || stripped.toLowerCase().contains(search) || typeId.toLowerCase().contains(search)) {
// Yellow for concurrent-capable types, gray for other built-in types
if (AbilityController.Instance.isConcurrentCapableType(typeId)) {
displayName = "\u00A7e" + displayName;
} else if (AbilityController.Instance.isBuiltInType(typeId)) {
displayName = "\u00A77" + displayName;
}
list.add(displayName);
displayNameToTypeId.put(displayName, typeId);
}
}
Collections.sort(list, (a, b) -> String.CASE_INSENSITIVE_ORDER.compare(
a.replaceAll("\u00A7.", ""), b.replaceAll("\u00A7.", "")));
return list;
}
@@ -707,7 +718,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
String typeName = getDisplayName(ability.getTypeId());
String customName = ability.getName();
String colorPrefix = ability.isEnabled() ? "\u00A7a\u25CF\u00A7r " : "\u00A7c\u25CF\u00A7r ";
String colorPrefix = slot.isSlotEnabled() ? "\u00A7a\u25CF\u00A7r " : "\u00A7c\u25CF\u00A7r ";
String nameDisplay;
if (customName != null && !customName.isEmpty() && !customName.equals(typeName)) {
@@ -728,8 +739,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
private String getChainHeaderEntry(int index, AbilityAction slot) {
ChainedAbility chain = slot.isInlineChain() ? slot.getInlineChain() : slot.getChainedAbility();
String chainName = chain != null ? chain.getDisplayName() : "???";
boolean enabled = chain != null && chain.isEnabled();
String colorPrefix = enabled ? "\u00A7a\u25CF\u00A7r " : "\u00A7c\u25CF\u00A7r ";
String colorPrefix = slot.isSlotEnabled() ? "\u00A7a\u25CF\u00A7r " : "\u00A7c\u25CF\u00A7r ";
if (slot.isChainReference()) {
return colorPrefix + (index + 1) + ". \u00A7e> [Chain] " + chainName + "\u00A7r";
}
@@ -974,6 +984,13 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
}
} else if (slot.isChain() && selectedEntryIndex >= 0) {
// Chain entry reference
// Block all editing for built-in abilities
ChainedAbility resolveChain = slot.isInlineChain() ? slot.getInlineChain() : slot.getChainedAbility();
if (resolveChain != null && selectedEntryIndex < resolveChain.getEntries().size()) {
Ability entryResolved = resolveChain.getEntries().get(selectedEntryIndex).resolve();
if (entryResolved != null && entryResolved.isBuiltIn()) return;
}
if (mode == SubGuiAbilityEditMode.MODE_CLONE_MODIFY) {
if (slot.isChainReference()) {
slot.convertToInline();
@@ -983,7 +1000,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
ChainedAbilityEntry entry = chain.getEntries().get(selectedEntryIndex);
if (entry.convertToInline()) {
Ability a = entry.getInlineAbility();
if (a != null) {
if (a != null && !a.isBuiltIn()) {
editingChainEntry = true;
editChainSlotIdx = selectedSlotIndex;
editChainEntryIdx = selectedEntryIndex;
@@ -999,7 +1016,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
if (chain != null && selectedEntryIndex < chain.getEntries().size()) {
ChainedAbilityEntry entry = chain.getEntries().get(selectedEntryIndex);
Ability resolved = entry.resolve();
if (resolved != null) {
if (resolved != null && !resolved.isBuiltIn()) {
editingChainEntryParent = true;
setSubGui(resolved.createConfigGui(this));
}
@@ -1007,9 +1024,11 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
}
} else if (mode == SubGuiAbilityEditMode.MODE_CLONE_MODIFY) {
// Standalone ability reference → convert to inline
Ability preCheck = slot.getAbility();
if (preCheck != null && preCheck.isBuiltIn()) return;
if (slot.convertToInline()) {
Ability ability = slot.getAbility();
if (ability != null) {
if (ability != null && !ability.isBuiltIn()) {
ability.setId(UUID.randomUUID().toString());
ability.setNpcInlineEdit(true);
setSubGui(ability.createConfigGui(this));
@@ -1019,7 +1038,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
}
} else if (mode == SubGuiAbilityEditMode.MODE_MODIFY_PARENT) {
Ability ability = slot.getAbility();
if (ability != null) {
if (ability != null && !ability.isBuiltIn()) {
setSubGui(ability.createConfigGui(this));
}
}
@@ -1084,39 +1103,29 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
* Called from SubGuiAbilityConfig when ability is saved.
*/
public void onAbilitySaved(Ability ability) {
// Check if we were editing a global parent ability via "Modify Parent" on a chain entry
// Editing a global parent ability via "Modify Parent" on a chain entry
if (editingChainEntryParent) {
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
editingChainEntryParent = false;
return;
}
// Check if we were editing an ability inside a chain entry
if (editingChainEntry && editChainSlotIdx >= 0 && editChainSlotIdx < npcSlots.size()) {
AbilityAction slot = npcSlots.get(editChainSlotIdx);
ChainedAbility chain = slot.isInlineChain() ? slot.getInlineChain() : null;
if (chain != null && editChainEntryIdx >= 0 && editChainEntryIdx < chain.getEntries().size()) {
// Update the inline ability on the entry — it's already the same object reference,
// but refresh the list and save to persist
}
editingChainEntry = false;
editChainSlotIdx = -1;
editChainEntryIdx = -1;
updateNpcAbilitiesList();
save();
// Editing an ability inside a chain entry — already same object reference.
// handleAbilityConfigClosed() will call updateNpcAbilitiesList() + save().
if (editingChainEntry) {
return;
}
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
AbilityAction slot = npcSlots.get(selectedAbilityIndex);
if (slot.isReference()) {
// Modify Parent on standalone reference — save to global preset
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
} else {
// Inline ability — update slot data
npcSlots.set(selectedAbilityIndex, AbilityAction.inline(ability));
}
updateNpcAbilitiesList();
save();
}
// updateNpcAbilitiesList() + save() deferred to handleAbilityConfigClosed()
}
@Override
@@ -144,9 +144,12 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
int y = 5;
int labelCounter = LABEL_ID_START;
// General tab: type label at top — need to reserve space before building
// General tab: type label + optional concurrent label at top — reserve space
if (activeTab == TAB_GENERAL) {
y += ROW_H;
if (ability.isConcurrentCapable()) {
y += 15;
}
}
// Build declarative fields into an auto-created scroll window
@@ -157,10 +160,15 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
GuiScrollWindow sw = builder.buildScrollWindow(tabFields, swX, swY, swW, swH);
// General tab: add type label at top of scroll window
// General tab: add type label + optional concurrent label at top of scroll window
if (activeTab == TAB_GENERAL) {
sw.addLabel(new GuiNpcLabel(builder.getNextLabelId(), "gui.type", 5, 5 + 5, 0xFFFFFF));
sw.addLabel(new GuiNpcLabel(builder.getNextLabelId() + 1, ability.getTypeId(), 55, 5 + 5, 0xFFFFFF));
int baseId = builder.getNextLabelId();
sw.addLabel(new GuiNpcLabel(baseId, "gui.type", 5, 10, 0xFFFFFF));
sw.addLabel(new GuiNpcLabel(baseId + 1, ability.getTypeId(), 55, 10, 0xFFFFFF));
if (ability.isConcurrentCapable()) {
sw.addLabel(new GuiNpcLabel(baseId + 2,
StatCollector.translateToLocal("ability.concurrentInfo"), 5, 25, 0x55FF55));
}
}
// Conditions on target tab — appended after field defs
@@ -18,18 +18,32 @@ 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.
* Simple ability name picker with optional filter mode.
* Shows custom, built-in, or all abilities in a scroll list with search.
* Returns the selected ability name.
*/
public class SubGuiAbilitySelect extends SubGuiInterface implements ICustomScrollListener, IScrollData {
/** Show all abilities (custom + built-in). */
public static final int FILTER_ALL = 0;
/** Show only custom abilities. */
public static final int FILTER_CUSTOM_ONLY = 1;
/** Show only built-in abilities. */
public static final int FILTER_BUILTIN_ONLY = 2;
private GuiCustomScroll scroll;
private HashMap<String, Integer> customData = new HashMap<>();
private HashMap<String, Integer> builtInData = new HashMap<>();
private String selectedName = null;
private String search = "";
private final int filterMode;
public SubGuiAbilitySelect() {
this(FILTER_ALL);
}
public SubGuiAbilitySelect(int filterMode) {
this.filterMode = filterMode;
setBackground("menubg.png");
xSize = 220;
ySize = 216;
@@ -72,8 +86,12 @@ public class SubGuiAbilitySelect extends SubGuiInterface implements ICustomScrol
private List<String> getFilteredList() {
HashMap<String, Integer> merged = new HashMap<>();
merged.putAll(customData);
merged.putAll(builtInData);
if (filterMode != FILTER_BUILTIN_ONLY) {
merged.putAll(customData);
}
if (filterMode != FILTER_CUSTOM_ONLY) {
merged.putAll(builtInData);
}
if (search.isEmpty()) {
return new ArrayList<>(merged.keySet());
@@ -1,6 +1,7 @@
package noppes.npcs.client.gui.advanced;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.util.Register;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.I18n;
import noppes.npcs.client.gui.util.GuiCustomScroll;
@@ -11,6 +12,7 @@ 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.HashMap;
import java.util.List;
import java.util.Map;
@@ -20,6 +22,11 @@ import java.util.Map;
*/
public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomScrollListener, ITextfieldListener {
private static final int BTN_ADD = 0;
private static final int BTN_CANCEL = 1;
private static final int BTN_SCROLL_TYPE = 2;
private static final int TF_SEARCH = 10;
private GuiCustomScroll scroll;
private final HashMap<String, String> displayNameToTypeId = new HashMap<>();
private final HashMap<String, String> allDisplayNameToTypeId = new HashMap<>();
@@ -36,62 +43,135 @@ public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomS
public void initGui() {
super.initGui();
addTextField(new GuiNpcTextField(10, this, fontRendererObj, guiLeft + 5, guiTop + 5, 190, 18, search));
int y = guiTop + 5;
// Scroll type filter button
addButton(new GuiNpcButton(BTN_SCROLL_TYPE, guiLeft + 5, y, 190, 20, GuiNPCAbilities.scrollType.toString()));
y += 24;
// Search bar
addTextField(new GuiNpcTextField(TF_SEARCH, this, fontRendererObj, guiLeft + 5, y, 190, 18, search));
y += 20;
// Scroll list (shortened to fit filter button within original ySize)
if (scroll == null) {
scroll = new GuiCustomScroll(this, 0);
scroll.setSize(190, 145);
scroll.setSize(190, 121);
}
scroll.guiLeft = guiLeft + 5;
scroll.guiTop = guiTop + 26;
scroll.guiTop = y;
addScroll(scroll);
buildAllTypes();
scroll.setList(getFilteredTypeList());
scroll.setUnsortedList(getFilteredTypeList());
addButton(new GuiNpcButton(0, guiLeft + 5, guiTop + 188, 90, 20, "gui.add"));
getButton(0).setEnabled(scroll.hasSelected());
addButton(new GuiNpcButton(1, guiLeft + 105, guiTop + 188, 90, 20, "gui.cancel"));
addButton(new GuiNpcButton(BTN_ADD, guiLeft + 5, guiTop + 188, 90, 20, "gui.add"));
getButton(BTN_ADD).setEnabled(scroll.hasSelected());
addButton(new GuiNpcButton(BTN_CANCEL, guiLeft + 105, guiTop + 188, 90, 20, "gui.cancel"));
}
private void buildAllTypes() {
allDisplayNameToTypeId.clear();
String[] types = AbilityController.Instance.getTypes();
for (String typeId : types) {
// Never show built-in types — they are immutable and cannot be created
if (AbilityController.Instance.isBuiltInType(typeId))
continue;
// Apply scroll type filter
if (!matchesScrollType(typeId))
continue;
String displayName = I18n.format(typeId);
if (AbilityController.Instance.isConcurrentCapableType(typeId)) {
displayName = "\u00A7e" + displayName;
}
allDisplayNameToTypeId.put(displayName, typeId);
}
}
private boolean matchesScrollType(String typeId) {
GuiNPCAbilities.ScrollType type = GuiNPCAbilities.scrollType;
if (type == GuiNPCAbilities.ScrollType.ALL) {
return true;
} else if (type == GuiNPCAbilities.ScrollType.CNPC) {
return typeId.startsWith("ability.cnpc.");
} else if (type == GuiNPCAbilities.ScrollType.MODDED) {
if (!Register.isEmpty("ability")) {
List<String> registerList = Register.REGISTERED_NAMESPACES.get("ability");
if (!registerList.isEmpty()) {
String namespace = registerList.get(GuiNPCAbilities.modIndex);
return typeId.startsWith("ability." + namespace + ".");
}
}
return false;
}
return true;
}
private List<String> getFilteredTypeList() {
List<String> list = new ArrayList<>();
displayNameToTypeId.clear();
for (Map.Entry<String, String> entry : allDisplayNameToTypeId.entrySet()) {
String displayName = entry.getKey();
if (search.isEmpty() || displayName.toLowerCase().contains(search) || entry.getValue().toLowerCase().contains(search)) {
String stripped = displayName.replaceAll("\u00A7.", "");
if (search.isEmpty() || stripped.toLowerCase().contains(search) || entry.getValue().toLowerCase().contains(search)) {
list.add(displayName);
displayNameToTypeId.put(displayName, entry.getValue());
}
}
Collections.sort(list, (a, b) -> String.CASE_INSENSITIVE_ORDER.compare(
a.replaceAll("\u00A7.", ""), b.replaceAll("\u00A7.", "")));
return list;
}
@Override
public void buttonEvent(GuiButton guibutton) {
if (guibutton.id == 0 && scroll.hasSelected()) {
int id = guibutton.id;
if (id == BTN_ADD && scroll.hasSelected()) {
String displayName = scroll.getSelected();
selectedTypeId = displayNameToTypeId.get(displayName);
close();
} else if (guibutton.id == 1) {
} else if (id == BTN_CANCEL) {
selectedTypeId = null;
close();
} else if (id == BTN_SCROLL_TYPE) {
cycleScrollType();
if (scroll != null) {
scroll.resetScroll();
}
initGui();
}
}
private void cycleScrollType() {
if (GuiNPCAbilities.scrollType != GuiNPCAbilities.ScrollType.MODDED) {
GuiNPCAbilities.ScrollType[] values = GuiNPCAbilities.ScrollType.values();
GuiNPCAbilities.ScrollType next = values[(GuiNPCAbilities.scrollType.ordinal() + 1) % values.length];
if (next == GuiNPCAbilities.ScrollType.MODDED && Register.isEmpty("ability")) {
next = GuiNPCAbilities.ScrollType.ALL;
}
GuiNPCAbilities.scrollType = next;
} else {
List<String> list = Register.REGISTERED_NAMESPACES.get("ability");
if (list != null && !list.isEmpty()) {
if (GuiNPCAbilities.modIndex == list.size() - 1) {
GuiNPCAbilities.scrollType = GuiNPCAbilities.ScrollType.ALL;
} else {
GuiNPCAbilities.modIndex = (GuiNPCAbilities.modIndex + 1) % list.size();
}
} else {
GuiNPCAbilities.modIndex = 0;
GuiNPCAbilities.scrollType = GuiNPCAbilities.ScrollType.ALL;
}
}
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
if (guiCustomScroll.id == 0) {
getButton(0).setEnabled(scroll.hasSelected());
getButton(BTN_ADD).setEnabled(scroll.hasSelected());
}
}
@@ -106,9 +186,9 @@ public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomS
@Override
public void keyTyped(char c, int i) {
super.keyTyped(c, i);
if (getTextField(10) != null && getTextField(10).isFocused()) {
if (!search.equals(getTextField(10).getText())) {
search = getTextField(10).getText().toLowerCase();
if (getTextField(TF_SEARCH) != null && getTextField(TF_SEARCH).isFocused()) {
if (!search.equals(getTextField(TF_SEARCH).getText())) {
search = getTextField(TF_SEARCH).getText().toLowerCase();
scroll.setList(getFilteredTypeList());
scroll.resetScroll();
}
@@ -144,7 +144,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
// 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());
return "\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"));
@@ -325,12 +325,22 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
sw.addButton(entryBtn);
if (!readOnlyEntries) {
// Check if this entry is concurrent-active (delay disabled)
Ability resolvedAbility = entry.resolve();
boolean isConcurrentActive = resolvedAbility != null
&& resolvedAbility.isConcurrentCapable()
&& entry.isConcurrentEnabled();
// Delay label + field
sw.addLabel(new GuiNpcLabel(labelCounter++, "ability.delay", L_LABEL_X + 160, y + 5, 0xAAAAAA));
sw.addLabel(new GuiNpcLabel(labelCounter++, "ability.delay", L_LABEL_X + 160, y + 5,
isConcurrentActive ? 0x555555 : 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);
if (isConcurrentActive) {
delayField.setEnabled(false);
}
sw.addTextField(delayField);
// Up button
@@ -343,8 +353,16 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
sw.addButton(new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE + 3, L_LABEL_X + 263, y, 20, 20, "\u2193"));
}
// Concurrent toggle (only shown if resolved ability is concurrent-capable, never for first entry)
if (i > 0 && resolvedAbility != null && resolvedAbility.isConcurrentCapable()) {
String cLabel = entry.isConcurrentEnabled() ? "\u00A7aC" : "\u00A77C";
GuiNpcButton cBtn = new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE + 5, L_LABEL_X + 288, y, 20, 20, cLabel);
cBtn.setHoverText("ability.hover.concurrent");
sw.addButton(cBtn);
}
// Delete button
sw.addButton(new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE + 4, L_LABEL_X + 288, y, 20, 20, "X"));
sw.addButton(new GuiNpcButton(ENTRY_BASE + i * ENTRY_STRIDE + 4, L_LABEL_X + 313, y, 20, 20, "X"));
} else {
// Read-only: show delay as label only
int delay = entry.getDelayTicks();
@@ -538,17 +556,26 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
case 0: // Entry name button — reference: clone/modify dialog; inline: edit config
ChainedAbilityEntry clickedEntry = entries.get(entryIndex);
if (clickedEntry.isReference()) {
// Built-in abilities are always references — no editing allowed
Ability refResolved = clickedEntry.resolve();
if (refResolved != null && refResolved.isBuiltIn()) return true;
editingEntryIndex = entryIndex;
setSubGui(new SubGuiAbilityEditMode());
} else if (clickedEntry.isInline() && clickedEntry.getInlineAbility() != null) {
Ability inlineAbility = clickedEntry.getInlineAbility();
if (inlineAbility.isBuiltIn()) return true;
editingEntryIndex = entryIndex;
setSubGui(new SubGuiAbilityConfig(clickedEntry.getInlineAbility(), this));
setSubGui(new SubGuiAbilityConfig(inlineAbility, this));
}
return true;
case 2: // Up
if (entryIndex > 0) {
ChainedAbilityEntry entry = entries.remove(entryIndex);
entries.add(entryIndex - 1, entry);
// Can't be concurrent at position 0
if (entryIndex - 1 == 0) {
entry.setConcurrentEnabled(false);
}
initGui();
}
return true;
@@ -563,6 +590,15 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
entries.remove(entryIndex);
initGui();
return true;
case 5: // Concurrent toggle
ChainedAbilityEntry toggleEntry = entries.get(entryIndex);
boolean newState = !toggleEntry.isConcurrentEnabled();
toggleEntry.setConcurrentEnabled(newState);
if (newState) {
toggleEntry.setDelayTicks(0);
}
initGui();
return true;
}
}
@@ -695,9 +731,11 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
if (source == SubGuiChainedEntrySource.SOURCE_NPC_SLOTS) {
setSubGui(new SubGuiNpcSlotPicker(npcSlots));
} else if (source == SubGuiChainedEntrySource.SOURCE_LOAD_PRESET) {
setSubGui(new SubGuiAbilitySelect());
setSubGui(new SubGuiAbilitySelect(SubGuiAbilitySelect.FILTER_CUSTOM_ONLY));
} else if (source == SubGuiChainedEntrySource.SOURCE_CREATE_NEW) {
setSubGui(new SubGuiAbilityTypeSelect());
} else if (source == SubGuiChainedEntrySource.SOURCE_BUILT_IN) {
setSubGui(new SubGuiAbilitySelect(SubGuiAbilitySelect.FILTER_BUILTIN_ONLY));
}
// Don't initGui — we're opening another SubGui
}
@@ -728,7 +766,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
return;
}
Ability newAbility = AbilityController.Instance.create(typeId);
if (newAbility != null) {
if (newAbility != null && !newAbility.isBuiltIn()) {
if (variants.size() == 1) {
variants.get(0).apply(newAbility);
}
@@ -744,7 +782,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
int idx = gui.getSelectedIndex();
if (idx >= 0 && pendingTypeId != null) {
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
if (newAbility != null) {
if (newAbility != null && !newAbility.isBuiltIn()) {
gui.getVariants().get(idx).apply(newAbility);
newAbility.setId(java.util.UUID.randomUUID().toString());
entries.add(ChainedAbilityEntry.inline(newAbility, 0));
@@ -766,10 +804,17 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
ChainedAbilityEntry entry = entries.get(editingEntryIndex);
// Block all editing for built-in abilities
Ability preCheck = entry.resolve();
if (preCheck != null && preCheck.isBuiltIn()) {
editingEntryIndex = -1;
return;
}
if (mode == SubGuiAbilityEditMode.MODE_CLONE_MODIFY) {
if (entry.convertToInline()) {
Ability a = entry.getInlineAbility();
if (a != null) {
if (a != null && !a.isBuiltIn()) {
a.setId(java.util.UUID.randomUUID().toString());
setSubGui(new SubGuiAbilityConfig(a, this));
return;
@@ -778,7 +823,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
editingEntryIndex = -1;
} else if (mode == SubGuiAbilityEditMode.MODE_MODIFY_PARENT) {
Ability resolved = entry.resolve();
if (resolved != null) {
if (resolved != null && !resolved.isBuiltIn()) {
editingParentAbility = true;
setSubGui(resolved.createConfigGui(this));
return;
@@ -6,7 +6,7 @@ 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.
* Options: By Reference, Create New, Built-in, From NPC Slots (optional).
*/
public class SubGuiChainedEntrySource extends SubGuiSimpleChoice {
@@ -14,6 +14,7 @@ public class SubGuiChainedEntrySource extends SubGuiSimpleChoice {
public static final int SOURCE_NPC_SLOTS = 0;
public static final int SOURCE_LOAD_PRESET = 1;
public static final int SOURCE_CREATE_NEW = 2;
public static final int SOURCE_BUILT_IN = 3;
private final boolean showNpcOption;
@@ -25,7 +26,7 @@ public class SubGuiChainedEntrySource extends SubGuiSimpleChoice {
this.showNpcOption = showNpcOption;
setBackground("menubg.png");
xSize = 200;
ySize = showNpcOption ? 110 : 88;
ySize = showNpcOption ? 132 : 110;
}
@Override
@@ -36,21 +37,24 @@ public class SubGuiChainedEntrySource extends SubGuiSimpleChoice {
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"));
addButton(new GuiNpcButton(SOURCE_LOAD_PRESET, guiLeft + 10, y, 180, 20, "ability.byReference"));
y += 22;
addButton(new GuiNpcButton(2, guiLeft + 10, y, 180, 20, "ability.createNew"));
addButton(new GuiNpcButton(SOURCE_CREATE_NEW, guiLeft + 10, y, 180, 20, "ability.createNew"));
y += 22;
addButton(new GuiNpcButton(SOURCE_BUILT_IN, guiLeft + 10, y, 180, 20, "gui.builtin"));
if (showNpcOption) {
y += 22;
addButton(new GuiNpcButton(SOURCE_NPC_SLOTS, guiLeft + 10, y, 180, 20, "ability.fromNpc"));
}
}
@Override
public void buttonEvent(GuiButton guibutton) {
int id = guibutton.id;
if (id >= 0 && id <= 2) {
if (id >= 0 && id <= 3) {
setResult(id);
close();
}
@@ -0,0 +1,220 @@
package noppes.npcs.client.gui.advanced;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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.GuiNpcTextField;
import noppes.npcs.client.gui.util.ICustomScrollListener;
import noppes.npcs.client.gui.util.ITextfieldListener;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.controllers.CustomEffectController;
import noppes.npcs.controllers.data.CustomEffect;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* SubGui for selecting a custom effect from CustomEffectController.
* Supports switching between effect maps (index 0 = custom, addon indices via toggle button).
*/
@SideOnly(Side.CLIENT)
public class SubGuiCustomEffectSelect extends SubGuiInterface implements ICustomScrollListener, ITextfieldListener {
private GuiCustomScroll scroll;
private final HashMap<String, Integer> displayNameToId = new HashMap<>();
private final HashMap<String, Integer> allDisplayNameToId = new HashMap<>();
private int selectedEffectId = -1;
private int selectedIndex = 0;
private String search = "";
private final int preselectedId;
private final int preselectedIndex;
/** The effect map index currently being viewed */
private int viewIndex = 0;
/** Ordered list of available indices for toggling */
private List<Integer> availableIndices;
public SubGuiCustomEffectSelect(int preselectedId) {
this(preselectedId, 0);
}
public SubGuiCustomEffectSelect(int preselectedId, int preselectedIndex) {
this.preselectedId = preselectedId;
this.preselectedIndex = preselectedIndex;
this.viewIndex = preselectedIndex;
setBackground("menubg.png");
xSize = 200;
ySize = 216;
}
@Override
public void initGui() {
super.initGui();
buildAvailableIndices();
addTextField(new GuiNpcTextField(10, this, fontRendererObj, guiLeft + 5, guiTop + 5, 190, 18, search));
// Toggle button for switching between effect lists (only if addon indices exist)
if (availableIndices.size() > 1) {
String label = getViewLabel();
addButton(new GuiNpcButton(2, guiLeft + 5, guiTop + 26, 190, 20, label));
}
int scrollTop = availableIndices.size() > 1 ? guiTop + 49 : guiTop + 26;
int scrollHeight = availableIndices.size() > 1 ? 122 : 145;
if (scroll == null) {
scroll = new GuiCustomScroll(this, 0);
}
scroll.setSize(190, scrollHeight);
scroll.guiLeft = guiLeft + 5;
scroll.guiTop = scrollTop;
addScroll(scroll);
buildAllEffects();
List<String> filtered = getFilteredList();
scroll.setUnsortedList(filtered);
// Pre-select current effect (only if viewing the same index)
if (preselectedId >= 0 && viewIndex == preselectedIndex && !scroll.hasSelected()) {
for (String name : filtered) {
Integer id = displayNameToId.get(name);
if (id != null && id == preselectedId) {
scroll.setSelected(name);
break;
}
}
}
addButton(new GuiNpcButton(0, guiLeft + 5, guiTop + 188, 90, 20, "gui.select"));
getButton(0).setEnabled(scroll.hasSelected());
addButton(new GuiNpcButton(1, guiLeft + 105, guiTop + 188, 90, 20, "gui.cancel"));
}
private void buildAvailableIndices() {
availableIndices = new ArrayList<>();
CustomEffectController controller = CustomEffectController.getInstance();
// Always include index 0
availableIndices.add(0);
// Add any addon indices that have registered labels
HashMap<Integer, String> labels = controller.getIndexLabels();
for (int idx : labels.keySet()) {
if (idx != 0 && controller.getEffectMap(idx) != null) {
availableIndices.add(idx);
}
}
Collections.sort(availableIndices);
// Ensure viewIndex is valid
if (!availableIndices.contains(viewIndex)) {
viewIndex = 0;
}
}
private String getViewLabel() {
if (viewIndex == 0) {
return "Custom Effects";
}
HashMap<Integer, String> labels = CustomEffectController.getInstance().getIndexLabels();
String label = labels.get(viewIndex);
return label != null ? label : "Index " + viewIndex;
}
private void buildAllEffects() {
allDisplayNameToId.clear();
HashMap<Integer, CustomEffect> effects = CustomEffectController.getInstance().getEffectMap(viewIndex);
if (effects == null) return;
for (CustomEffect ce : effects.values()) {
if (ce.getName() != null && !ce.getName().isEmpty()) {
allDisplayNameToId.put(ce.getName(), ce.id);
}
}
}
private List<String> getFilteredList() {
List<String> list = new ArrayList<>();
displayNameToId.clear();
for (Map.Entry<String, Integer> entry : allDisplayNameToId.entrySet()) {
String name = entry.getKey();
if (search.isEmpty() || name.toLowerCase().contains(search)) {
list.add(name);
displayNameToId.put(name, entry.getValue());
}
}
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
return list;
}
@Override
public void buttonEvent(GuiButton guibutton) {
if (guibutton.id == 0 && scroll.hasSelected()) {
String name = scroll.getSelected();
Integer id = displayNameToId.get(name);
selectedEffectId = id != null ? id : -1;
selectedIndex = viewIndex;
close();
} else if (guibutton.id == 1) {
selectedEffectId = -1;
close();
} else if (guibutton.id == 2) {
// Toggle to next available index
int currentPos = availableIndices.indexOf(viewIndex);
int nextPos = (currentPos + 1) % availableIndices.size();
viewIndex = availableIndices.get(nextPos);
search = "";
scroll = null;
initGui();
}
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
if (guiCustomScroll.id == 0) {
getButton(0).setEnabled(scroll.hasSelected());
}
}
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll guiCustomScroll) {
if (guiCustomScroll.id == 0 && selection != null) {
Integer id = displayNameToId.get(selection);
selectedEffectId = id != null ? id : -1;
selectedIndex = viewIndex;
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().toLowerCase();
if (!search.equals(newSearch)) {
search = newSearch;
scroll.setUnsortedList(getFilteredList());
scroll.resetScroll();
}
}
}
@Override
public void unFocused(GuiNpcTextField textField) {
}
public int getSelectedEffectId() {
return selectedEffectId;
}
public int getSelectedIndex() {
return selectedIndex;
}
}
@@ -15,5 +15,7 @@ public enum FieldType {
SECTION_HEADER,
LABEL,
EFFECTS_LIST,
CUSTOM_EFFECTS_LIST,
EFFECT_ACTIONS_LIST,
ROW
}
@@ -497,7 +497,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
private void handleChainConfigClosed() {
if (pendingSaveChain != null) {
PacketClient.sendClient(new ChainedAbilitySavePacket(pendingSaveChain.writeNBT()));
PacketClient.sendClient(new ChainedAbilitiesGetPacket());
selected = pendingSaveChain.getName();
pendingSaveChain = null;
}
@@ -570,7 +569,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
return true;
} else {
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
PacketClient.sendClient(new CustomAbilitiesGetPacket());
pendingSaveAbility = null;
}
} else if (pendingSaveAbility != null) {
@@ -597,12 +595,12 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
return true;
}
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
PacketClient.sendClient(new CustomAbilitiesGetPacket());
pendingSaveAbility = null;
return false;
}
private void openConfig(Ability ability) {
if (ability.isBuiltIn()) return; // Built-in abilities are immutable
selectedAbility = ability;
selected = ability.getName();
previewExecutor.stop();
@@ -22,15 +22,15 @@ public class GuiNpcTextField extends GuiTextField {
private ITextfieldListener listener;
public int id;
public int min = 0, max = Integer.MAX_VALUE, def = 0;
public double minDouble = Double.NEGATIVE_INFINITY, maxDouble = Double.POSITIVE_INFINITY, defDouble = 0;
public float minFloat = Float.NEGATIVE_INFINITY, maxFloat = Float.POSITIVE_INFINITY, defFloat = 0;
public double minDouble = 0, maxDouble = Double.MAX_VALUE, defDouble = 0;
public float minFloat = 0, maxFloat = Float.MAX_VALUE, defFloat = 0;
protected static GuiNpcTextField activeTextfield = null;
public boolean canEdit = true;
public String hoverableText = "";
private boolean wasHovered = false;
private int hoverCount = 0;
private final int[] allowedSpecialChars = {14, 211, 203, 205};
private final int[] allowedSpecialChars = {14, 211, 203, 205, 199, 207};
public GuiNpcTextField(int id, GuiScreen parent, FontRenderer fontRenderer, int i, int j, int k, int l, String s) {
super(fontRenderer, i, j, k, l);
@@ -69,11 +69,35 @@ public class GuiNpcTextField extends GuiTextField {
@Override
public boolean textboxKeyTyped(char c, int i) {
if (!charAllowed(c, i) || !canEdit)
if (!canEdit || !isFocused())
return false;
// Allow Ctrl shortcuts (select all, copy, paste, cut) to bypass char filter
if (GuiScreen.isCtrlKeyDown()) {
// For Ctrl+V (paste) on numeric fields, filter clipboard to valid chars
if (i == 47 && isNumericField()) {
String clipboard = GuiScreen.getClipboardString();
if (clipboard != null) {
StringBuilder filtered = new StringBuilder();
for (char ch : clipboard.toCharArray()) {
if (Character.isDigit(ch) || ch == '-' || ((doublesOnly || floatsOnly) && ch == '.'))
filtered.append(ch);
}
if (filtered.length() > 0)
writeText(filtered.toString());
}
return true;
}
return super.textboxKeyTyped(c, i);
}
if (!charAllowed(c, i))
return false;
return super.textboxKeyTyped(c, i);
}
private boolean isNumericField() {
return integersOnly || doublesOnly || floatsOnly;
}
public boolean isEmpty() {
return getText().trim().length() == 0;
}
@@ -37,6 +37,7 @@ public class CustomEffectController implements ICustomEffectHandler {
public static CustomEffectController Instance = new CustomEffectController();
public HashMap<Integer, HashMap<Integer, CustomEffect>> indexMapper = new HashMap<>();
private HashMap<Integer, String> indexLabels = new HashMap<>();
public HashMap<Integer, CustomEffect> customEffectsSync = new HashMap<>();
@@ -59,6 +60,14 @@ public class CustomEffectController implements ICustomEffectHandler {
indexMapper.put(index, (HashMap<Integer, CustomEffect>) effectHashMap);
}
public void registerEffectMapLabel(int index, String label) {
indexLabels.put(index, label);
}
public HashMap<Integer, String> getIndexLabels() {
return indexLabels;
}
public HashMap<Integer, CustomEffect> getCustomEffects() {
return indexMapper.get(0);
}
@@ -354,10 +363,7 @@ public class CustomEffectController implements ICustomEffectHandler {
}
public HashMap<Integer, CustomEffect> getEffectMap(int index) {
if (indexMapper.containsKey(index)) {
return getEffectMap(index);
}
return null;
return indexMapper.get(index);
}
private File getDir() {
@@ -607,17 +607,25 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
}
// ═══════════════════════════════════════════════════════════════════
// DIMENSION CHANGE RESET
// ENTITY RECONSTRUCTION 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.
* Handle entity reconstruction events (dimension change, death/respawn, etc.).
* Cleans up any executing ability state without firing script events (those were
* already fired on the original entity), clears transient runtime state, and
* re-syncs ability data to the client on the new entity.
* <p>
* This should be called whenever the player's entity object is recreated by Forge,
* since the client-side entity loses all synced ability state.
*
* @param clearCooldowns true to fully reset cooldowns (dimension change),
* false to preserve cooldowns (death/respawn — interrupt already rolled them)
* @param clearToggles true to clear active toggles (death/respawn),
* false to keep them (dimension change)
*/
public void resetOnDimensionChange() {
// Clean up any executing ability without rolling cooldowns
public void onEntityReconstructed(boolean clearCooldowns, boolean clearToggles) {
// Clean up any executing ability silently (no script events — already fired on old entity)
if (currentAbility != null && currentAbility.isExecuting()) {
removeTelegraph(currentAbility);
currentAbility.cleanup();
@@ -627,30 +635,57 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
releaseLockedPosition();
}
// Clear chain state
// Clear chain and concurrent state
currentChain = null;
chainEntryIndex = -1;
chainDelayRemaining = -1;
interruptConcurrentSlots();
// Clear all transient state
currentAbility = null;
currentAbilityKey = null;
currentTarget = null;
// Reset cooldowns completely
cooldownEndTime = 0;
if (clearCooldowns) {
cooldownEndTime = 0;
}
interruptCooldownRolled = false;
// Sync cleared state to client
EntityPlayer player = playerData.player;
if (player != null) {
syncAbilityStateClear(player);
if (clearToggles) {
clearActiveToggles();
}
// Re-sync ability data (unlocked list, selection) to client
// Force-send cleared lock state to client. We must always send this
// (not gated by lastSyncedFlags != 0) because the NEW entity's client
// may have stale lock state from before the reconstruction.
lastSyncedFlags = 0;
EntityPlayer player = playerData.player;
if (player instanceof EntityPlayerMP) {
PlayerAbilityStatePacket.sendToPlayer((EntityPlayerMP) player, (byte) 0, 0, 0);
}
// Re-sync full ability data (unlocked list, selection, toggles) to client
syncToClient();
}
/**
* Fully reset ability state when changing dimensions.
* Clears cooldowns so the player can immediately use abilities in the new dimension.
* Keeps active toggles (dimension change shouldn't reset ongoing effects).
*/
public void resetOnDimensionChange() {
onEntityReconstructed(true, false);
}
/**
* Reset ability state after death/respawn.
* Preserves cooldowns (interrupt on death already rolled them) but clears
* active toggles (death should end ongoing effects).
*/
public void resetOnRespawn() {
onEntityReconstructed(false, true);
}
// ═══════════════════════════════════════════════════════════════════
// DAMAGE HANDLING
// ═══════════════════════════════════════════════════════════════════
@@ -764,23 +799,12 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
private void applyPositionLock(EntityPlayer player) {
if (!positionLocked) return;
boolean flying = AbilityController.Instance != null
&& AbilityController.Instance.isPlayerFlying(player);
if (flying) {
// Flying players: lock X/Z only, preserve Y freedom
player.setPosition(lockedPosX, player.posY, lockedPosZ);
player.prevPosX = lockedPosX;
player.prevPosZ = lockedPosZ;
} else {
// Grounded players: full position lock including Y
player.setPosition(lockedPosX, lockedPosY, lockedPosZ);
player.prevPosX = lockedPosX;
player.prevPosY = lockedPosY;
player.prevPosZ = lockedPosZ;
player.motionY = 0;
}
player.setPosition(lockedPosX, lockedPosY, lockedPosZ);
player.prevPosX = lockedPosX;
player.prevPosY = lockedPosY;
player.prevPosZ = lockedPosZ;
player.motionX = 0;
player.motionY = 0;
player.motionZ = 0;
}
@@ -807,6 +831,9 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
if (positionLocked) {
flags |= PlayerAbilityStatePacket.FLAG_POSITION_LOCKED;
}
if (wasFlyingAtLock) {
flags |= PlayerAbilityStatePacket.FLAG_WAS_FLYING_AT_LOCK;
}
return flags;
}