mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-28 00:55:38 +00:00
Merge branch 'dev' into syntax-highlighter-unified
This commit is contained in:
commit
fa38f93677
67 files changed
+642
-868
No files matched your search
@@ -35,6 +35,13 @@ import java.util.Set;
|
||||
*/
|
||||
public abstract class AbstractDataAbilities {
|
||||
|
||||
/**
|
||||
* Safety timeout (ticks) for abilities stuck in ACTIVE phase.
|
||||
* If an ability stays in ACTIVE for longer than this without calling signalCompletion(),
|
||||
* it is force-completed to prevent permanent stuck state. 30 seconds at 20 TPS.
|
||||
*/
|
||||
protected static final int MAX_ACTIVE_PHASE_TICKS = 600;
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SHARED RUNTIME STATE (not saved to NBT)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -427,7 +434,7 @@ public abstract class AbstractDataAbilities {
|
||||
EntityLivingBase entity = getEntity();
|
||||
List<String> toRemove = null;
|
||||
|
||||
for (Map.Entry<String, AbilityToggleEntry> mapEntry : activeToggles.entrySet()) {
|
||||
for (Map.Entry<String, AbilityToggleEntry> mapEntry : new ArrayList<>(activeToggles.entrySet())) {
|
||||
AbilityToggleEntry entry = mapEntry.getValue();
|
||||
entry.incrementTick();
|
||||
|
||||
@@ -864,6 +871,16 @@ public abstract class AbstractDataAbilities {
|
||||
if (positionLocked) releaseLockedPosition();
|
||||
onBurstDelayReleaseLocks();
|
||||
}
|
||||
|
||||
// Safety timeout: force-complete if stuck in ACTIVE too long.
|
||||
// Individual ability types should have their own timeouts well below this;
|
||||
// this is a last-resort failsafe to prevent permanent stuck state.
|
||||
if (currentAbility != null && currentAbility.getPhase() == AbilityPhase.ACTIVE
|
||||
&& currentAbility.getCurrentTick() > MAX_ACTIVE_PHASE_TICKS) {
|
||||
currentAbility.cancel();
|
||||
handleAbilityCompletion(target);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
case BURST_DELAY:
|
||||
|
||||
@@ -1109,7 +1109,7 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
enabled = compound.getBoolean("AbilitiesEnabled");
|
||||
enabled = compound.hasKey("AbilitiesEnabled") ? compound.getBoolean("AbilitiesEnabled") : true;
|
||||
minCooldown = compound.getInteger("AbilityMinCooldown");
|
||||
maxCooldown = compound.getInteger("AbilityMaxCooldown");
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ 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.network.packets.data.ability.PlayerAbilitySyncPacket;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
||||
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -142,8 +143,16 @@ public class ScriptPlayerEventHandler {
|
||||
playerData.timers.update();
|
||||
}
|
||||
|
||||
if (player.ticksExisted % 10 == 0)
|
||||
SyncController.syncEffects((EntityPlayerMP) player);
|
||||
if (player.ticksExisted % 10 == 0) {
|
||||
EntityPlayerMP mp = (EntityPlayerMP) player;
|
||||
SyncController.syncEffects(mp);
|
||||
SyncController.syncAbilityCooldowns(mp);
|
||||
if (playerData.abilityData.needsSync) {
|
||||
PlayerAbilitySyncPacket.sendToPlayer(mp);
|
||||
playerData.abilityData.needsSync = false;
|
||||
}
|
||||
playerData.abilityData.ensureLockStateClear();
|
||||
}
|
||||
|
||||
if (player.ticksExisted % 10 == 0)
|
||||
CustomEffectController.Instance.runEffects(player);
|
||||
|
||||
@@ -50,6 +50,9 @@ public class ServerTickHandler {
|
||||
SyncController.syncEffects(player);
|
||||
ScriptController.Instance.syncClientScripts(player);
|
||||
|
||||
// Sync clean ability state to the new client (after beginLogin initializes sync state)
|
||||
SyncController.syncAbilities(player);
|
||||
|
||||
// Send auction notifications on login
|
||||
if (AuctionController.Instance != null) {
|
||||
AuctionController.Instance.onPlayerLogin(player);
|
||||
|
||||
@@ -212,7 +212,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
|
||||
if (allAllowPlayer && allAllowNpc) return UserType.BOTH;
|
||||
if (allAllowPlayer) return UserType.PLAYER_ONLY;
|
||||
if (allAllowNpc) return UserType.NPC_ONLY;
|
||||
return UserType.NPC_ONLY;
|
||||
return UserType.NONE;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
@@ -750,7 +750,9 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
|
||||
} else {
|
||||
entries.add(ChainedAbilityEntry.reference(consumed.getReferenceId(), 0));
|
||||
}
|
||||
consumedSlotIndices.add(slotIndex);
|
||||
if (!consumedSlotIndices.contains(slotIndex)) {
|
||||
consumedSlotIndices.add(slotIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +119,7 @@ public class AbilityHotbarSlotRenderer extends Gui {
|
||||
if (iconNaturalSize <= 0) iconNaturalSize = 16f;
|
||||
float iconScale = targetSize / iconNaturalSize;
|
||||
GL11.glScalef(iconScale, iconScale, 1);
|
||||
GL11.glColor4f(1, 1, 1, slotAlpha);
|
||||
icon.draw(getToggleState());
|
||||
icon.draw(getToggleState(), slotAlpha);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
@@ -60,6 +60,10 @@ public class AbilityIcon extends Gui {
|
||||
}
|
||||
|
||||
public void draw(int state) {
|
||||
draw(state, 1.0f);
|
||||
}
|
||||
|
||||
public void draw(int state, float alpha) {
|
||||
TextureManager renderEngine = Minecraft.getMinecraft().renderEngine;
|
||||
|
||||
ImageData imageData = null;
|
||||
@@ -68,7 +72,7 @@ public class AbilityIcon extends Gui {
|
||||
}
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
GL11.glColor4f(1, 1, 1, alpha);
|
||||
|
||||
Tessellator t;
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ public class GuiAuctionBidding extends GuiAuctionInterface implements ISubGuiLis
|
||||
private void openBidSubGui() {
|
||||
if (listing == null) return;
|
||||
long minBid = listing.getMinimumBid(AuctionClientConfig.getMinBidIncrement());
|
||||
setSubGui(new SubGuiAuctionBid(listing.id, minBid, playerBalance));
|
||||
setSubGui(new SubGuiAuctionBid(listing.id, minBid, listing.buyoutPrice, playerBalance));
|
||||
}
|
||||
|
||||
private void openBuyNowSubGui() {
|
||||
|
||||
@@ -23,14 +23,16 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
|
||||
|
||||
private final String listingId;
|
||||
private final long minimumBid;
|
||||
private final long buyoutPrice;
|
||||
private final long playerBalance;
|
||||
private long bidAmount;
|
||||
private boolean successful = false;
|
||||
private String errorMessage = null;
|
||||
|
||||
public SubGuiAuctionBid(String listingId, long minimumBid, long playerBalance) {
|
||||
public SubGuiAuctionBid(String listingId, long minimumBid, long buyoutPrice, long playerBalance) {
|
||||
this.listingId = listingId;
|
||||
this.minimumBid = minimumBid;
|
||||
this.buyoutPrice = buyoutPrice;
|
||||
this.playerBalance = playerBalance;
|
||||
this.bidAmount = minimumBid;
|
||||
|
||||
@@ -129,6 +131,12 @@ public class SubGuiAuctionBid extends SubGuiInterface implements ITextfieldListe
|
||||
return;
|
||||
}
|
||||
|
||||
if (buyoutPrice > 0 && bidAmount >= buyoutPrice) {
|
||||
errorMessage = StatCollector.translateToLocal("auction.error.bidExceedsBuyout");
|
||||
updateErrorLabel();
|
||||
return;
|
||||
}
|
||||
|
||||
// Send bid packet
|
||||
AuctionActionPacket.placeBid(listingId, bidAmount);
|
||||
successful = true;
|
||||
|
||||
+26
-21
@@ -15,16 +15,19 @@ import noppes.npcs.controllers.data.AbilityHotbarData;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* SubGui for selecting an ability to assign to a hotbar slot.
|
||||
* Uses ability keys internally to avoid duplicate display name collisions.
|
||||
*/
|
||||
public class SubGuiSelectAbilityForSlot extends SubGuiInterface implements ICustomScrollListener, ITextfieldListener {
|
||||
private HashMap<String, String> displayToKey = new HashMap<>();
|
||||
private LinkedHashMap<String, String> keyToDisplay = new LinkedHashMap<>();
|
||||
private List<String> scrollKeys = new ArrayList<>();
|
||||
private GuiCustomScroll scrollAbilities;
|
||||
private String selected = null;
|
||||
private int selectedIndex = -1;
|
||||
private String search = "";
|
||||
|
||||
public boolean confirmed = false;
|
||||
@@ -36,7 +39,6 @@ public class SubGuiSelectAbilityForSlot extends SubGuiInterface implements ICust
|
||||
this.slotIndex = slotIndex;
|
||||
this.closeOnEsc = true;
|
||||
this.drawDefaultBackground = true;
|
||||
guiLeft -= 10;
|
||||
xSize = 256 + 10;
|
||||
this.setBackground("menubg.png");
|
||||
}
|
||||
@@ -44,7 +46,7 @@ public class SubGuiSelectAbilityForSlot extends SubGuiInterface implements ICust
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
guiTop += 10;
|
||||
guiTop = (this.height - ySize) / 2 + 10;
|
||||
|
||||
if (scrollAbilities == null) {
|
||||
scrollAbilities = new GuiCustomScroll(this, 0, 0);
|
||||
@@ -66,7 +68,7 @@ public class SubGuiSelectAbilityForSlot extends SubGuiInterface implements ICust
|
||||
}
|
||||
|
||||
private void loadAbilities() {
|
||||
displayToKey.clear();
|
||||
keyToDisplay.clear();
|
||||
PlayerData playerData = ClientCacheHandler.playerData;
|
||||
if (playerData == null || playerData.abilityData == null) {
|
||||
return;
|
||||
@@ -85,7 +87,7 @@ public class SubGuiSelectAbilityForSlot extends SubGuiInterface implements ICust
|
||||
AbilityController.Instance.resolveAbility(key) : null;
|
||||
displayName = ability != null ? ability.getDisplayName() : key;
|
||||
}
|
||||
displayToKey.put(displayName, key);
|
||||
keyToDisplay.put(key, displayName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,9 +95,9 @@ public class SubGuiSelectAbilityForSlot extends SubGuiInterface implements ICust
|
||||
public void actionPerformed(GuiButton button) {
|
||||
int id = button.id;
|
||||
|
||||
if (id == 0 && selected != null) {
|
||||
if (id == 0 && selectedIndex >= 0 && selectedIndex < scrollKeys.size()) {
|
||||
confirmed = true;
|
||||
selectedAbilityKey = displayToKey.get(selected);
|
||||
selectedAbilityKey = scrollKeys.get(selectedIndex);
|
||||
this.close();
|
||||
}
|
||||
if (id == 1) {
|
||||
@@ -109,15 +111,16 @@ public class SubGuiSelectAbilityForSlot extends SubGuiInterface implements ICust
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int i1, int i2, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll == scrollAbilities)
|
||||
selected = scrollAbilities.getSelected();
|
||||
if (guiCustomScroll == scrollAbilities) {
|
||||
selectedIndex = scrollAbilities.selected;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll == scrollAbilities && selection != null) {
|
||||
if (guiCustomScroll == scrollAbilities && selectedIndex >= 0 && selectedIndex < scrollKeys.size()) {
|
||||
confirmed = true;
|
||||
selectedAbilityKey = displayToKey.get(selection);
|
||||
selectedAbilityKey = scrollKeys.get(selectedIndex);
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
@@ -135,21 +138,23 @@ public class SubGuiSelectAbilityForSlot extends SubGuiInterface implements ICust
|
||||
return;
|
||||
search = getTextField(55).getText().toLowerCase();
|
||||
scrollAbilities.resetScroll();
|
||||
selectedIndex = -1;
|
||||
scrollAbilities.setList(getSearchList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getSearchList() {
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<>(displayToKey.keySet());
|
||||
}
|
||||
scrollKeys.clear();
|
||||
List<String> displayNames = new ArrayList<>();
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String name : displayToKey.keySet()) {
|
||||
if (name.toLowerCase().contains(search))
|
||||
list.add(name);
|
||||
for (Map.Entry<String, String> entry : keyToDisplay.entrySet()) {
|
||||
String displayName = entry.getValue();
|
||||
if (search.isEmpty() || displayName.toLowerCase().contains(search)) {
|
||||
scrollKeys.add(entry.getKey());
|
||||
displayNames.add(displayName);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
return displayNames;
|
||||
}
|
||||
}
|
||||
@@ -585,6 +585,11 @@ public class AuctionController implements IAuctionHandler {
|
||||
return "Bid must be at least " + minBid + " " + ConfigMarket.CurrencyName + ".";
|
||||
}
|
||||
|
||||
// Prevent bidding at or above buyout price
|
||||
if (listing.hasBuyout() && bidAmount >= listing.buyoutPrice) {
|
||||
return "Your bid meets or exceeds the buyout price. Use Buy Now instead.";
|
||||
}
|
||||
|
||||
// Check currency
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
if (playerData == null) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
@@ -90,6 +91,14 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
*/
|
||||
private transient byte lastSyncedFlags = 0;
|
||||
|
||||
/**
|
||||
* Dirty flag: set when ability data changes (unlock/lock/select/toggle).
|
||||
* Checked by the periodic 10-tick sync handler, which sends an ability
|
||||
* data packet and clears the flag. Avoids scattering sync calls across
|
||||
* every mutation method.
|
||||
*/
|
||||
public transient boolean needsSync = false;
|
||||
|
||||
/**
|
||||
* World time when the last ability was activated (for double-press cancel detection).
|
||||
*/
|
||||
@@ -251,7 +260,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
cooldownEndTime = endTime;
|
||||
globalCooldownDuration = duration;
|
||||
}
|
||||
syncCooldownToClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -259,7 +267,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
int duration = chain.getCooldownTicks();
|
||||
cooldownEndTime = getWorldTime() + duration;
|
||||
globalCooldownDuration = duration;
|
||||
syncCooldownToClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -278,6 +285,13 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
@Override
|
||||
protected void onInterruptComplete() {
|
||||
// Player clears state immediately (unlike NPC which ticks through DAZED)
|
||||
// Roll cooldown before clearing state — NPC rolls during handleAbilityCompletion
|
||||
// after ticking through DAZED, but the player skips DAZED entirely.
|
||||
if (!interruptCooldownRolled && currentAbility != null) {
|
||||
rollCooldown(currentAbility);
|
||||
}
|
||||
interruptCooldownRolled = false;
|
||||
|
||||
// Stop the dazed animation that was started in interruptCurrentAbility()
|
||||
stopAbilityAnimation();
|
||||
currentAbility = null;
|
||||
@@ -450,6 +464,8 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
playAbilityAnimation(ability.getWindUpAnimation());
|
||||
}
|
||||
|
||||
// Immediate sync on ability use
|
||||
syncToClient();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -458,31 +474,30 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Sync ability data to the client.
|
||||
* Called when abilities change (unlock/lock/select) and on login.
|
||||
* Full sync of all ability state to the client.
|
||||
* Delegates to {@link SyncController#syncAbilities(EntityPlayerMP)}.
|
||||
*/
|
||||
public void syncToClient() {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
PlayerAbilitySyncPacket.sendToPlayer((EntityPlayerMP) player);
|
||||
syncCooldownToClient();
|
||||
SyncController.syncAbilities((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync cooldown state (global + per-ability) to the client.
|
||||
* Sent as a lightweight packet separate from full ability sync.
|
||||
* Lightweight sync of cooldown state only to the client.
|
||||
* Delegates to {@link SyncController#syncAbilityCooldowns(EntityPlayerMP)}.
|
||||
*/
|
||||
public void syncCooldownToClient() {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
AbilityCooldownSyncPacket.sendToPlayer((EntityPlayerMP) player);
|
||||
SyncController.syncAbilityCooldowns((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onToggleStateChanged(String key, boolean active, int state) {
|
||||
syncToClient();
|
||||
needsSync = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -519,20 +534,20 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
public void setSelectedIndex(int index) {
|
||||
if (index == -1 || (index >= 0 && index < unlockedAbilities.size())) {
|
||||
this.selectedIndex = index;
|
||||
syncToClient();
|
||||
needsSync = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void selectNext() {
|
||||
if (unlockedAbilities.isEmpty()) return;
|
||||
selectedIndex = (selectedIndex + 1) % unlockedAbilities.size();
|
||||
syncToClient();
|
||||
needsSync = true;
|
||||
}
|
||||
|
||||
public void selectPrevious() {
|
||||
if (unlockedAbilities.isEmpty()) return;
|
||||
selectedIndex = (selectedIndex - 1 + unlockedAbilities.size()) % unlockedAbilities.size();
|
||||
syncToClient();
|
||||
needsSync = true;
|
||||
}
|
||||
|
||||
public String getSelectedAbilityKey() {
|
||||
@@ -561,13 +576,13 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
if (selectedIndex >= unlockedAbilities.size()) {
|
||||
selectedIndex = Math.max(0, unlockedAbilities.size() - 1);
|
||||
}
|
||||
syncToClient();
|
||||
needsSync = true;
|
||||
}
|
||||
|
||||
public void unlockAbility(String key) {
|
||||
if (key != null && !key.isEmpty() && !unlockedAbilities.contains(key)) {
|
||||
unlockedAbilities.add(key);
|
||||
syncToClient();
|
||||
needsSync = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -576,7 +591,7 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
if (selectedIndex >= unlockedAbilities.size()) {
|
||||
selectedIndex = Math.max(0, unlockedAbilities.size() - 1);
|
||||
}
|
||||
syncToClient();
|
||||
needsSync = true;
|
||||
}
|
||||
|
||||
public boolean hasUnlockedAbility(String key) {
|
||||
@@ -620,7 +635,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
public void resetCooldown(String key) {
|
||||
resetPerAbilityCooldown(key);
|
||||
cooldownEndTime = 0;
|
||||
syncCooldownToClient();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -629,7 +643,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
public void resetAllCooldowns() {
|
||||
cooldownEndTime = 0;
|
||||
resetAllPerAbilityCooldowns();
|
||||
syncCooldownToClient();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -664,7 +677,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
public void resetCooldown() {
|
||||
cooldownEndTime = 0;
|
||||
resetAllPerAbilityCooldowns();
|
||||
syncCooldownToClient();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -729,7 +741,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
// Clean up any executing ability silently (no script events — already fired on old entity)
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
removeTelegraph(currentAbility);
|
||||
currentAbility.cleanup();
|
||||
currentAbility.interrupt();
|
||||
stopAbilityAnimation();
|
||||
releaseRotationControl();
|
||||
@@ -782,13 +793,69 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
|
||||
/**
|
||||
* Reset ability state after death/respawn.
|
||||
* Preserves cooldowns (interrupt on death already rolled them) but clears
|
||||
* active toggles (death should end ongoing effects).
|
||||
* Preserves cooldowns (the death handler interrupted the ability which rolled cooldown
|
||||
* via onInterruptComplete) but clears active toggles (death should end ongoing effects).
|
||||
*/
|
||||
public void resetOnRespawn() {
|
||||
onEntityReconstructed(false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset ability state on login. Clears all transient execution state (current ability,
|
||||
* locks, chains, cooldowns) that may have leaked from a previous session via the
|
||||
* PlayerData cache. Toggles are NOT cleared — they are restored from NBT by readFromNBT.
|
||||
* <p>
|
||||
* Does NOT send packets — called before the client's sync state is initialized.
|
||||
* The caller must trigger a full ability sync afterwards (e.g. via syncToClient).
|
||||
*/
|
||||
public void resetOnLogin() {
|
||||
// Silently clean up any stale executing ability
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
removeTelegraph(currentAbility);
|
||||
currentAbility.interrupt();
|
||||
stopAbilityAnimation();
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
}
|
||||
|
||||
// Clear chain and concurrent state
|
||||
currentChain = null;
|
||||
chainEntryIndex = -1;
|
||||
chainDelayRemaining = -1;
|
||||
interruptConcurrentSlots();
|
||||
|
||||
// Clear all transient state
|
||||
currentAbility = null;
|
||||
currentAbilityKey = null;
|
||||
currentTarget = null;
|
||||
lastAbilityActivationTime = -1;
|
||||
|
||||
// Clear cooldowns (fresh start after relog)
|
||||
cooldownEndTime = 0;
|
||||
resetAllPerAbilityCooldowns();
|
||||
interruptCooldownRolled = false;
|
||||
|
||||
// Reset sync tracking so next sync sends fresh state
|
||||
lastSyncedFlags = 0;
|
||||
needsSync = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up ability state on disconnect. Interrupts any executing ability (fires events,
|
||||
* rolls cooldown) before the player entity goes away, then clears all transient state.
|
||||
* This ensures scripts receive proper interrupt/complete events and prevents stale state
|
||||
* from leaking into the next session via the PlayerData cache.
|
||||
*/
|
||||
public void resetOnDisconnect() {
|
||||
// Interrupt with events so scripts know the ability ended
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
interruptCurrentAbility(null, 0);
|
||||
}
|
||||
// Clear any remaining transient state (cooldowns, chains, locks)
|
||||
// Don't clear toggles — they were already saved to NBT by this point
|
||||
onEntityReconstructed(true, false);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// DAMAGE HANDLING
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -931,7 +998,8 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
if (rotationLocked && currentAbility.isRotationLockedForCurrentPhase()) {
|
||||
flags |= PlayerAbilityStatePacket.FLAG_ROTATION_LOCKED;
|
||||
}
|
||||
if (currentAbility.hasAbilityMovement() && currentAbility.getPhase() == AbilityPhase.ACTIVE) {
|
||||
if (currentAbility.hasAbilityMovement()
|
||||
&& (currentAbility.getPhase() == AbilityPhase.ACTIVE || currentAbility.getPhase() == AbilityPhase.WINDUP)) {
|
||||
flags |= PlayerAbilityStatePacket.FLAG_HAS_ABILITY_MOVEMENT;
|
||||
}
|
||||
if (positionLocked) {
|
||||
@@ -969,6 +1037,20 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Periodic safety check: if no ability is executing but the client may have
|
||||
* stale lock flags, send a clear. Prevents stuck clients from missed packets.
|
||||
*/
|
||||
public void ensureLockStateClear() {
|
||||
if (isExecutingAbility() || isExecutingChain()) return;
|
||||
EntityPlayer player = playerData.player;
|
||||
if (!(player instanceof EntityPlayerMP)) return;
|
||||
if (lastSyncedFlags != 0) {
|
||||
lastSyncedFlags = 0;
|
||||
PlayerAbilityStatePacket.sendToPlayer((EntityPlayerMP) player, (byte) 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SCRIPT EVENTS (Player-specific: start event only, others via abstract)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -1051,6 +1133,10 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
*/
|
||||
private void validateUnlockedAbilities() {
|
||||
if (AbilityController.Instance == null) return;
|
||||
// Only validate on the server - the client trusts server-sent data.
|
||||
// Custom ability definitions may not have been synced to the client yet,
|
||||
// which would cause valid abilities to be incorrectly pruned.
|
||||
if (playerData == null || !(playerData.player instanceof EntityPlayerMP)) return;
|
||||
|
||||
Iterator<String> it = unlockedAbilities.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.network.packets.data.ability.AbilityHotbarSyncPacket;
|
||||
@@ -54,6 +55,8 @@ public class PlayerAbilityHotbarData {
|
||||
|
||||
public void validateSlots() {
|
||||
if (AbilityController.Instance == null) return;
|
||||
// Only validate on the server - the client trusts server-sent data.
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) return;
|
||||
for (AbilityHotbarData slot : slots) {
|
||||
if (slot.isEmpty()) continue;
|
||||
boolean valid;
|
||||
@@ -75,6 +78,10 @@ public class PlayerAbilityHotbarData {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync hotbar data only to the client.
|
||||
* Used after server confirms a client hotbar edit.
|
||||
*/
|
||||
public void syncToClient(EntityPlayer player) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
AbilityHotbarSyncPacket.sendToPlayer((EntityPlayerMP) player);
|
||||
|
||||
@@ -94,6 +94,10 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
private boolean specialKeyDown = false;
|
||||
|
||||
public void onLogin() {
|
||||
// Clear any stale transient ability state that leaked via the PlayerData cache.
|
||||
// Must happen before the animation check since it may clear ability animation state.
|
||||
abilityData.resetOnLogin();
|
||||
|
||||
// Handle animation state from previous session
|
||||
AnimationData animationData = this.animationData;
|
||||
if (animationData != null && animationData.isClientAnimating()) {
|
||||
@@ -117,17 +121,12 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
if (!controller.playerEffects.containsKey(playerID)) {
|
||||
controller.playerEffects.put(playerID, effectData.getEffects());
|
||||
}
|
||||
|
||||
// Sync player ability data to client
|
||||
abilityData.syncToClient();
|
||||
|
||||
// Sync hotbar data to client
|
||||
hotbarData.syncToClient(player);
|
||||
}
|
||||
|
||||
public void onLogout() {
|
||||
// Cancel any executing ability and release all locks
|
||||
abilityData.interruptCurrentAbility();
|
||||
// Interrupt executing ability (fires events, rolls cooldown), then clear
|
||||
// all transient state so nothing leaks via the PlayerData cache.
|
||||
abilityData.resetOnDisconnect();
|
||||
this.partyInvites.clear();
|
||||
this.actionManager.clear();
|
||||
}
|
||||
@@ -254,6 +253,8 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
factionData.saveNBTData(compound);
|
||||
mailData.saveNBTData(compound);
|
||||
tradeData.writeToNBT(compound);
|
||||
abilityData.writeToNBT(compound);
|
||||
hotbarData.writeToNBT(compound);
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
DBCAddon.instance.writeToNBT(this, compound);
|
||||
@@ -268,6 +269,8 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
factionData.loadNBTData(data);
|
||||
mailData.loadNBTData(data);
|
||||
tradeData.readFromNBT(data);
|
||||
abilityData.readFromNBT(data);
|
||||
hotbarData.readFromNBT(data);
|
||||
if (player != null) {
|
||||
playername = player.getCommandSenderName();
|
||||
uuid = player.getPersistentID().toString();
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ItemNpcWand extends Item {
|
||||
EntityCustomNpc npc = new EntityCustomNpc(par3World);
|
||||
npc.ais.startPos = new int[]{par4, par5, par6};
|
||||
|
||||
npc.setLocationAndAngles((float) par4 + 0.5F, npc.getStartYPos(), (float) par6 + 0.5F, player.rotationYaw, player.rotationPitch);
|
||||
npc.setLocationAndAngles((float) par4 + 0.5F, npc.getStartYPos(), (float) par6 + 0.5F, player.rotationYaw, 0);
|
||||
|
||||
par3World.spawnEntityInWorld(npc);
|
||||
npc.setHealth(npc.getMaxHealth());
|
||||
|
||||
@@ -7,7 +7,6 @@ import kamkeel.npcs.controllers.data.ability.data.energy.EnergyDisplayData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyHomingData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLifespanData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLightningData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyTrajectoryData;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -117,8 +116,6 @@ public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
|
||||
EnergyLightningData lightning = new EnergyLightningData();
|
||||
EnergyLifespanData lifespan = new EnergyLifespanData(100, 72000);
|
||||
EnergyHomingData homing = new EnergyHomingData();
|
||||
EnergyTrajectoryData trajectory = new EnergyTrajectoryData();
|
||||
|
||||
homing.speed = 0.5f;
|
||||
homing.homingStrength = 0.35f;
|
||||
homing.homingRange = 20f;
|
||||
@@ -126,7 +123,7 @@ public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
|
||||
EntityAbilityOrb orb = new EntityAbilityOrb(
|
||||
player.worldObj, player, null,
|
||||
player.posX, player.posY + player.getEyeHeight(), player.posZ,
|
||||
1.0f, colorData, combat, homing, lightning, lifespan, trajectory
|
||||
1.0f, colorData, combat, homing, lightning, lifespan
|
||||
);
|
||||
|
||||
orb.setupCharging(
|
||||
|
||||
@@ -86,6 +86,9 @@ public abstract class MixinModelRenderer {
|
||||
float prevAngleX = this.rotateAngleX;
|
||||
float prevAngleY = this.rotateAngleY;
|
||||
float prevAngleZ = this.rotateAngleZ;
|
||||
float prevOffsetX = this.offsetX;
|
||||
float prevOffsetY = this.offsetY;
|
||||
float prevOffsetZ = this.offsetZ;
|
||||
|
||||
boolean changedAngles = false;
|
||||
try {
|
||||
@@ -149,6 +152,11 @@ public abstract class MixinModelRenderer {
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
// Mirror vanilla ModelRenderer behavior: always undo offset translation.
|
||||
// Without this, models that animate via offsetX/Y/Z (e.g. witch nose while drinking)
|
||||
// leak transforms into subsequent renders.
|
||||
GL11.glTranslatef(-this.offsetX, -this.offsetY, -this.offsetZ);
|
||||
|
||||
if (changedAngles) {
|
||||
this.rotationPointX = prevPointX;
|
||||
this.rotationPointY = prevPointY;
|
||||
@@ -156,6 +164,9 @@ public abstract class MixinModelRenderer {
|
||||
this.rotateAngleX = prevAngleX;
|
||||
this.rotateAngleY = prevAngleY;
|
||||
this.rotateAngleZ = prevAngleZ;
|
||||
this.offsetX = prevOffsetX;
|
||||
this.offsetY = prevOffsetY;
|
||||
this.offsetZ = prevOffsetZ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user