From 07a914272ad1beecca60ede3fc72db1513d7d25c Mon Sep 17 00:00:00 2001 From: zeng-github01 <95841646+zeng-github01@users.noreply.github.com> Date: Sun, 29 Mar 2026 10:19:32 +0800 Subject: [PATCH 01/24] Fix pEffect legacy Compatibility --- src/main/java/noppes/npcs/VersionCompatibility.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/noppes/npcs/VersionCompatibility.java b/src/main/java/noppes/npcs/VersionCompatibility.java index 98dd6c20e..e468c0174 100644 --- a/src/main/java/noppes/npcs/VersionCompatibility.java +++ b/src/main/java/noppes/npcs/VersionCompatibility.java @@ -4,6 +4,7 @@ import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagInt; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.constants.EnumPotionType; import noppes.npcs.controllers.data.Line; import noppes.npcs.controllers.data.Lines; import noppes.npcs.entity.EntityNPCInterface; @@ -49,6 +50,14 @@ public class VersionCompatibility { if (compound.hasKey("DialogDarkenScreen")) { compound.removeTag("DialogDarkenScreen"); } + + if (compound.hasKey("pEffect")) { + int effect = compound.getInteger("pEffect"); + EnumPotionType enumPotionType = EnumPotionType.fromOrdinal(effect); + if (enumPotionType == EnumPotionType.Fire) { + compound.setBoolean("pBurnItem", true); + } + } } if (npc.npcVersion < 12) { CompatabilityFix(compound, npc.advanced.writeToNBT(new NBTTagCompound())); From 948eb91b42c30be4b27d0e04268236a8a4f524a0 Mon Sep 17 00:00:00 2001 From: zeng-github01 <95841646+zeng-github01@users.noreply.github.com> Date: Sun, 29 Mar 2026 10:25:02 +0800 Subject: [PATCH 02/24] Fixes --- src/main/java/noppes/npcs/VersionCompatibility.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/VersionCompatibility.java b/src/main/java/noppes/npcs/VersionCompatibility.java index e468c0174..12562f15b 100644 --- a/src/main/java/noppes/npcs/VersionCompatibility.java +++ b/src/main/java/noppes/npcs/VersionCompatibility.java @@ -54,7 +54,7 @@ public class VersionCompatibility { if (compound.hasKey("pEffect")) { int effect = compound.getInteger("pEffect"); EnumPotionType enumPotionType = EnumPotionType.fromOrdinal(effect); - if (enumPotionType == EnumPotionType.Fire) { + if (!compound.hasKey("pBurnItem") && enumPotionType == EnumPotionType.Fire) { compound.setBoolean("pBurnItem", true); } } From b8d68f771fffa0437db13e5ba7ea45ba14ddd535 Mon Sep 17 00:00:00 2001 From: zeng-github01 <95841646+zeng-github01@users.noreply.github.com> Date: Thu, 2 Apr 2026 08:38:04 +0800 Subject: [PATCH 03/24] refactor: disable auto-open GUI for BlockBorder and BlockNpcRedstone - Removed auto-open GUI logic upon placing BlockBorder and BlockNpcRedstone. - Resolved a race condition where the GUI would open before NBT/Permission data was fully synced from the server, causing "Permission Denied" or empty states. - Fixed a logic bug in SubGuiNpcAvailabilityDialog where 'questId' was incorrectly used instead of 'dialogId' when opening the selection picker. - This change ensures better UX as manual interaction guarantees all data is properly initialized. --- src/main/java/noppes/npcs/blocks/BlockBorder.java | 4 ---- src/main/java/noppes/npcs/blocks/BlockNpcRedstone.java | 7 ------- .../npcs/client/gui/SubGuiNpcAvailabilityDialog.java | 8 ++++---- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/main/java/noppes/npcs/blocks/BlockBorder.java b/src/main/java/noppes/npcs/blocks/BlockBorder.java index 3781b9c72..db7761b1c 100644 --- a/src/main/java/noppes/npcs/blocks/BlockBorder.java +++ b/src/main/java/noppes/npcs/blocks/BlockBorder.java @@ -67,10 +67,6 @@ public class BlockBorder extends BlockContainer { } tile.rotation = l; - - if (par5EntityLivingBase instanceof EntityPlayer && par1World.isRemote) { - CustomNpcs.proxy.openGui(x, y, z, EnumGuiType.Border, (EntityPlayer) par5EntityLivingBase); - } } private TileBorder getTile(World world, int x, int y, int z) { diff --git a/src/main/java/noppes/npcs/blocks/BlockNpcRedstone.java b/src/main/java/noppes/npcs/blocks/BlockNpcRedstone.java index e97096c72..6f89b442a 100644 --- a/src/main/java/noppes/npcs/blocks/BlockNpcRedstone.java +++ b/src/main/java/noppes/npcs/blocks/BlockNpcRedstone.java @@ -49,13 +49,6 @@ public class BlockNpcRedstone extends BlockContainer { par1World.notifyBlocksOfNeighborChange(par2, par3, par4 + 1, this); } - @Override - public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack item) { - if (entityliving instanceof EntityPlayer && world.isRemote) { - CustomNpcs.proxy.openGui(i, j, k, EnumGuiType.RedstoneBlock, (EntityPlayer) entityliving); - } - } - @Override public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) { onBlockAdded(par1World, par2, par3, par4); diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java index 802ede067..d3d93daa2 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java @@ -112,19 +112,19 @@ public class SubGuiNpcAvailabilityDialog extends SubGuiInterface implements GuiS } if (button.id == 10) { slot = 1; - setSubGui(new GuiDialogSelection(availabitily.questId)); + setSubGui(new GuiDialogSelection(availabitily.dialogId)); } if (button.id == 11) { slot = 2; - setSubGui(new GuiDialogSelection(availabitily.quest2Id)); + setSubGui(new GuiDialogSelection(availabitily.dialog2Id)); } if (button.id == 12) { slot = 3; - setSubGui(new GuiDialogSelection(availabitily.quest3Id)); + setSubGui(new GuiDialogSelection(availabitily.dialog3Id)); } if (button.id == 13) { slot = 4; - setSubGui(new GuiDialogSelection(availabitily.quest4Id)); + setSubGui(new GuiDialogSelection(availabitily.dialog4Id)); } if (button.id == 20) { availabitily.dialogId = -1; From 322626015d309689daaac9c1c1053bb9ef346a33 Mon Sep 17 00:00:00 2001 From: postyizhan <185839426@qq.com> Date: Sun, 2 Aug 2026 22:32:00 +0800 Subject: [PATCH 04/24] fix: adapt quest tracker height to content --- .../client/gui/hud/QuestTrackingComponent.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java b/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java index ee6a6fe51..dc32caa16 100644 --- a/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java +++ b/src/main/java/noppes/npcs/client/gui/hud/QuestTrackingComponent.java @@ -39,6 +39,7 @@ public class QuestTrackingComponent extends HudComponent { if (turnIn != null && !turnIn.isEmpty()) { turnInLines.add(convertColorCodes(turnIn)); } + updateOverlayHeight(); } /** @@ -239,6 +240,19 @@ public class QuestTrackingComponent extends HudComponent { } // ---------- Helper rendering methods ----------- (methods unchanged) ... + private void updateOverlayHeight() { + int lineHeight = mc.fontRenderer.FONT_HEIGHT + 4; + int contentHeight = 5; + contentHeight += questTitleLines.size() * lineHeight + 8; + contentHeight += questCategoryLines.size() * lineHeight + 8; + contentHeight += objectiveLines.size() * lineHeight; + if (!turnInLines.isEmpty()) { + contentHeight += 8; + } + contentHeight += turnInLines.size() * lineHeight; + overlayHeight = contentHeight; + } + private int renderTextBlock(List lines, int startY, int align, int color) { int y = startY; FontRenderer font = mc.fontRenderer; From 0829b6285f2f89a097e0834964511d28e1135ae0 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 02:17:28 -0400 Subject: [PATCH 05/24] Update EntityNPCInterface.java --- src/main/java/noppes/npcs/entity/EntityNPCInterface.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 77927d4b1..ae4aba781 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -301,7 +301,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti @Override public boolean getLeashed() { - return false; //Prevents npcs from being leashed + return false; // Prevents npcs from being leashed } @Override From 5aa843966ac1350718dd820a85f62efac3bac002 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:19:52 -0400 Subject: [PATCH 06/24] Fix divide by zero clicking the profiles scrollbar The scrollbar hit test was pure geometry, so clicking its column before the profile list had loaded - or on any list short enough not to scroll - divided by a maxScrollY of zero. The draw path already guarded on the same value. --- .../noppes/npcs/client/gui/player/inventory/GuiProfiles.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java index f9e627fe7..56777ca6f 100644 --- a/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java +++ b/src/main/java/noppes/npcs/client/gui/player/inventory/GuiProfiles.java @@ -429,6 +429,9 @@ public class GuiProfiles extends GuiCNPCInventory implements ISubGuiListener, IC } private boolean isMouseOverScrollbar(int mouseX, int mouseY) { + if (maxScrollY <= 0) + return false; + int scrollbarX = guiLeft + xSize + 30; int scrollbarY = guiTop + 27; int scrollbarHeight = ySize - 35; From 17f61de57a631cce06843e8185d021120d24d68e Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:20:34 -0400 Subject: [PATCH 07/24] Fix editor StackOverflow on self-referential generic bounds fromGenericType expanded a type variable bound, then expanded the bound''s type arguments, which led straight back to the same variable. Any enum reaches it through Enum>, so typing ability.getAllowedBy() crashed the client. Track the variables being expanded and emit repeats unbounded. --- .../script/interpreter/type/TypeInfo.java | 58 ++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/TypeInfo.java b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/TypeInfo.java index dcac25c99..df406ebba 100644 --- a/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/TypeInfo.java +++ b/src/main/java/noppes/npcs/client/gui/util/script/interpreter/type/TypeInfo.java @@ -325,78 +325,94 @@ public class TypeInfo { * @return A TypeInfo preserving the generic structure, or null if type is null */ public static TypeInfo fromGenericType(Type type) { + return fromGenericType(type, new HashSet>()); + } + + /** + * @param resolving type variables whose bounds are currently being expanded, so a + * self-referential bound such as {@code E extends Enum} terminates + */ + private static TypeInfo fromGenericType(Type type, Set> resolving) { if (type == null) return null; - + if (type instanceof Class) { // Plain class - no generic info return fromClass((Class) type); } - + if (type instanceof ParameterizedType) { // Generic type like List ParameterizedType paramType = (ParameterizedType) type; Type rawType = paramType.getRawType(); - + if (!(rawType instanceof Class)) { // Edge case - should not happen normally - return rawType != null ? fromGenericType(rawType) : null; + return rawType != null ? fromGenericType(rawType, resolving) : null; } - + // Get the raw type as TypeInfo TypeInfo rawTypeInfo = fromClass((Class) rawType); - + // Recursively convert type arguments Type[] typeArgs = paramType.getActualTypeArguments(); List appliedArgs = new ArrayList<>(typeArgs.length); for (Type arg : typeArgs) { - TypeInfo argInfo = fromGenericType(arg); + TypeInfo argInfo = fromGenericType(arg, resolving); if (argInfo != null) { appliedArgs.add(argInfo); } } - + // Return a parameterized TypeInfo if (!appliedArgs.isEmpty()) { return rawTypeInfo.parameterize(appliedArgs); } return rawTypeInfo; } - + if (type instanceof GenericArrayType) { // Array of generic type, e.g. T[] or List[] GenericArrayType arrayType = (GenericArrayType) type; - TypeInfo elementType = fromGenericType(arrayType.getGenericComponentType()); + TypeInfo elementType = fromGenericType(arrayType.getGenericComponentType(), resolving); if (elementType != null) { return arrayOf(elementType); } return fromClass(Object[].class); } - + if (type instanceof TypeVariable) { TypeVariable typeVar = (TypeVariable) type; String varName = typeVar.getName(); - // Check for bounds - if bounded, create typeParameter with bound - Type[] bounds = typeVar.getBounds(); - if (bounds != null && bounds.length > 0 && bounds[0] != Object.class) { - return TypeInfo.typeParameter(varName, fromGenericType(bounds[0])); + // Already expanding this variable - emit it unbounded rather than recursing forever + if (!resolving.add(typeVar)) { + return TypeInfo.typeParameter(varName); + } + try { + // Check for bounds - if bounded, create typeParameter with bound + Type[] bounds = typeVar.getBounds(); + if (bounds != null && bounds.length > 0 && bounds[0] != Object.class) { + return TypeInfo.typeParameter(varName, fromGenericType(bounds[0], resolving)); + } + return TypeInfo.typeParameter(varName); + } finally { + resolving.remove(typeVar); } - return TypeInfo.typeParameter(varName); } - + if (type instanceof WildcardType) { // Wildcard like ? or ? extends Number or ? super Integer WildcardType wildcard = (WildcardType) type; Type[] upperBounds = wildcard.getUpperBounds(); - + // Use the upper bound if available (most useful for ? extends T) if (upperBounds.length > 0 && upperBounds[0] != Object.class) { - return fromGenericType(upperBounds[0]); + return fromGenericType(upperBounds[0], resolving); } - + // For ? super T or plain ?, just use Object return fromClass(Object.class); } - + // Unknown type - shouldn't happen in practice return null; } From 68b5191db6790651ebeeaabdbc5761d9e37ff0e0 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:21:46 -0400 Subject: [PATCH 08/24] Fix trader edits being lost on an existing linked market Closing the setup GUI saved the market from the server''s stale role and then re-read that market over the edits it had just applied, so stock and currency cost changes never survived. The role now saves first and the market is written from it, and relinking to another market no longer pushes pre-link data over it. --- .../network/packets/request/role/RoleSavePacket.java | 9 ++++++++- .../npcs/client/gui/roles/GuiNpcTraderSetup.java | 10 +++++++++- src/main/java/noppes/npcs/roles/RoleTrader.java | 12 ++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/kamkeel/npcs/network/packets/request/role/RoleSavePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/role/RoleSavePacket.java index d63f2603c..21d0f2667 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/role/RoleSavePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/role/RoleSavePacket.java @@ -14,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.roles.RoleTrader; import java.io.IOException; @@ -63,7 +64,13 @@ public final class RoleSavePacket extends AbstractPacket { if (!PacketUtil.verifyItemPacket(packetName, EnumItemPacketType.WAND, player)) return; - npc.roleInterface.readFromNBT(ByteBufUtils.readNBT(in)); + NBTTagCompound roleCompound = ByteBufUtils.readNBT(in); + if (npc.roleInterface instanceof RoleTrader) { + // An admin edit wins over the linked market; the market is written from it afterwards. + ((RoleTrader) npc.roleInterface).readFromNBT(roleCompound, false); + } else { + npc.roleInterface.readFromNBT(roleCompound); + } npc.updateClient = true; } } diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java index 7b54518e3..1e5aab8d1 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java @@ -21,6 +21,7 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex private final ResourceLocation slot = new ResourceLocation("customnpcs", "textures/gui/slot.png"); private RoleTrader role; + private boolean marketRelinked = false; // Currency cost textfield IDs start at 100 (100-117 for slots 0-17) private static final int CURRENCY_FIELD_ID_START = 100; @@ -116,8 +117,14 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex @Override public void save() { - PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, false)); + // Linking to a different market already replaced the server's role with that market's + // data. Pushing this GUI's pre-link state back would overwrite the market being linked to. + if (marketRelinked) + return; + + // Save the role first so the market is written from the edited data, not the stale data. PacketClient.sendClient(new RoleSavePacket(role.writeToNBT(new NBTTagCompound()))); + PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, false)); } @Override @@ -129,6 +136,7 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex String name = guiNpcTextField.getText(); if (!name.equalsIgnoreCase(role.marketName)) { role.marketName = name; + marketRelinked = true; PacketClient.sendClient(new TraderMarketSavePacket(role.marketName, true)); } return; diff --git a/src/main/java/noppes/npcs/roles/RoleTrader.java b/src/main/java/noppes/npcs/roles/RoleTrader.java index 6aa69d357..717754abf 100644 --- a/src/main/java/noppes/npcs/roles/RoleTrader.java +++ b/src/main/java/noppes/npcs/roles/RoleTrader.java @@ -94,6 +94,15 @@ public class RoleTrader extends RoleInterface { @Override public void readFromNBT(NBTTagCompound nbttagcompound) { + readFromNBT(nbttagcompound, true); + } + + /** + * @param loadFromMarket pull the linked market's stored data over the compound just read. + * False when the compound is an admin edit, which is authoritative and + * would otherwise be overwritten by the market it is about to be saved to. + */ + public void readFromNBT(NBTTagCompound nbttagcompound, boolean loadFromMarket) { String oldMarket = marketName; marketName = nbttagcompound.getString("TraderMarket"); readNBT(nbttagcompound); @@ -101,6 +110,9 @@ public class RoleTrader extends RoleInterface { // Register with MarketRegistry for linked market sync MarketRegistry.updateTraderMarket(oldMarket, marketName, this); + if (!loadFromMarket) + return; + try { Market.getMarket(this, marketName); } catch (Exception ex) { From aaf6734bd99146c17f208e63a10c0605fde29336 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:22:56 -0400 Subject: [PATCH 09/24] Take deleted abilities away from players properly Deleting a custom ability only cleared the unlocked list. An active toggle kept a direct reference and went on ticking, stale hotbar slots survived, and the client was never resynced so it still showed and could select the ability. Selecting a key the player no longer has now deselects instead of firing whatever was previously selected. --- .../npcs/controllers/AbilityController.java | 18 ++++++++++++++++++ .../ability/AbilityHotbarSelectPacket.java | 7 +++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/AbilityController.java b/src/main/java/kamkeel/npcs/controllers/AbilityController.java index c352119dd..6c5810188 100644 --- a/src/main/java/kamkeel/npcs/controllers/AbilityController.java +++ b/src/main/java/kamkeel/npcs/controllers/AbilityController.java @@ -45,7 +45,9 @@ import net.minecraftforge.common.util.Constants; import noppes.npcs.controllers.data.AbilityScript; import noppes.npcs.controllers.data.ChainedAbilityScript; import net.minecraft.entity.EntityLivingBase; +import kamkeel.npcs.controllers.sync.handlers.PlayerAbilitySyncHelper; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; @@ -470,9 +472,25 @@ public class AbilityController implements IAbilityHandler { pData.abilityData.lockAbility(name); changed = true; } + + // An active toggle holds the resolved Ability directly and keeps ticking it, + // so drop it without firing onToggle against an unregistered ability. + if (uuid != null && !uuid.isEmpty()) { + pData.abilityData.setToggleEntryDirect(uuid, 0); + } + pData.abilityData.setToggleEntryDirect(name, 0); + + if (pData.hotbarData != null) { + pData.hotbarData.validateSlots(); + } + if (changed) { pData.save(); } + + if (pData.player instanceof EntityPlayerMP) { + PlayerAbilitySyncHelper.syncAbilities((EntityPlayerMP) pData.player); + } } } } diff --git a/src/main/java/kamkeel/npcs/network/packets/player/ability/AbilityHotbarSelectPacket.java b/src/main/java/kamkeel/npcs/network/packets/player/ability/AbilityHotbarSelectPacket.java index ba97769a0..87affdc1b 100644 --- a/src/main/java/kamkeel/npcs/network/packets/player/ability/AbilityHotbarSelectPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/player/ability/AbilityHotbarSelectPacket.java @@ -50,10 +50,9 @@ public final class AbilityHotbarSelectPacket extends AbstractPacket { // Deselect data.abilityData.setSelectedIndex(-1); } else { - int index = data.abilityData.getUnlockedAbilityList().indexOf(key); - if (index >= 0) { - data.abilityData.setSelectedIndex(index); - } + // A key the player no longer has deselects rather than leaving the previous + // selection in place, which would fire a different ability than the one shown. + data.abilityData.setSelectedIndex(data.abilityData.getUnlockedAbilityList().indexOf(key)); } data.save(); } From 3565c66cf89ab3f604cff9f5ea783c52aec4dd83 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:24:19 -0400 Subject: [PATCH 10/24] Keep ability cooldowns across logout Dimension change and teleport were already fixed, but disconnect still cleared cooldowns and login cleared them again, and they were never written to NBT - so relogging reset every cooldown. They are absolute world-time deadlines, so they now persist and are restored on load. --- .../controllers/data/PlayerAbilityData.java | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerAbilityData.java b/src/main/java/noppes/npcs/controllers/data/PlayerAbilityData.java index c979d5641..1da16a3af 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerAbilityData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerAbilityData.java @@ -832,9 +832,8 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA currentTarget = null; lastAbilityActivationTime = -1; - // Clear cooldowns (fresh start after relog) - cooldownEndTime = 0; - resetAllPerAbilityCooldowns(); + // Cooldowns are absolute world-time deadlines and are restored from NBT, so relogging + // must not clear them or it becomes a way to bypass them. interruptCooldownRolled = false; // Reset sync tracking so next sync sends fresh state @@ -852,9 +851,10 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA if (currentAbility != null && currentAbility.isExecuting()) { interruptCurrentAbility(null, 0); } - // Clear any remaining transient state (cooldowns, chains, locks) + // Clear any remaining transient state (chains, locks) // Don't clear toggles — they were already saved to NBT by this point - onEntityReconstructed(true, false); + // Don't clear cooldowns — they persist across sessions + onEntityReconstructed(false, false); } // ═══════════════════════════════════════════════════════════════════ @@ -1048,6 +1048,22 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA toggleList.appendTag(toggleNbt); } compound.setTag("ActiveToggles", toggleList); + + // Cooldowns are absolute world-time deadlines, so they stay meaningful across sessions + NBTTagCompound cooldowns = new NBTTagCompound(); + cooldowns.setLong("GlobalEnd", cooldownEndTime); + cooldowns.setInteger("GlobalDuration", globalCooldownDuration); + NBTTagList perAbilityList = new NBTTagList(); + for (Map.Entry entry : perAbilityCooldownEndTimes.entrySet()) { + NBTTagCompound cooldownNbt = new NBTTagCompound(); + cooldownNbt.setString("Key", entry.getKey()); + cooldownNbt.setLong("End", entry.getValue()); + Integer duration = perAbilityCooldownDurations.get(entry.getKey()); + cooldownNbt.setInteger("Duration", duration == null ? 0 : duration); + perAbilityList.appendTag(cooldownNbt); + } + cooldowns.setTag("PerAbility", perAbilityList); + compound.setTag("AbilityCooldowns", cooldowns); } public void readFromNBT(NBTTagCompound compound) { @@ -1082,6 +1098,24 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA setToggleEntryDirect(key, state); } } + + if (compound.hasKey("AbilityCooldowns")) { + cooldownEndTime = 0; + globalCooldownDuration = 0; + resetAllPerAbilityCooldowns(); + + NBTTagCompound cooldowns = compound.getCompoundTag("AbilityCooldowns"); + cooldownEndTime = cooldowns.getLong("GlobalEnd"); + globalCooldownDuration = cooldowns.getInteger("GlobalDuration"); + NBTTagList perAbilityList = cooldowns.getTagList("PerAbility", 10); // 10 = TAG_COMPOUND + for (int i = 0; i < perAbilityList.tagCount(); i++) { + NBTTagCompound entry = perAbilityList.getCompoundTagAt(i); + String key = entry.getString("Key"); + if (key == null || key.isEmpty()) continue; + perAbilityCooldownEndTimes.put(key, entry.getLong("End")); + perAbilityCooldownDurations.put(key, entry.getInteger("Duration")); + } + } } /** From abd1c7cbebb0961fc11d2b1c1e6f76ad0fb35383 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:24:59 -0400 Subject: [PATCH 11/24] Make per-ability cooldowns work on NPCs An NPC rolled both clocks and folded the ability''s cooldown into the global one as well, so the global timer always outlasted the per-ability entry and the setting could never reject anything. The global timer now only paces the NPC when the ability tracks its own cooldown. --- src/main/java/noppes/npcs/DataAbilities.java | 23 ++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/noppes/npcs/DataAbilities.java b/src/main/java/noppes/npcs/DataAbilities.java index 7772f6e22..3888df2d5 100644 --- a/src/main/java/noppes/npcs/DataAbilities.java +++ b/src/main/java/noppes/npcs/DataAbilities.java @@ -188,29 +188,34 @@ public class DataAbilities extends AbstractDataAbilities { if (maxCooldown > minCooldown) { baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1); } - cooldownEndTime = npc.worldObj.getTotalWorldTime() + baseCooldown + ability.getCooldownTicks(); + long now = npc.worldObj.getTotalWorldTime(); - // Additionally set per-ability cooldown if enabled if (ability.isPerAbilityCooldown() && ability.getCooldownTicks() > 0) { - long endTime = npc.worldObj.getTotalWorldTime() + ability.getCooldownTicks(); - setPerAbilityCooldown(ability.getName(), endTime, ability.getCooldownTicks()); + // The ability's own cooldown is tracked against the ability, so the global timer + // only paces how often the NPC acts. Folding the ability's cooldown into it as + // well would always outlast the per-ability entry and make it unreachable. + cooldownEndTime = now + baseCooldown; + setPerAbilityCooldown(ability.getName(), now + ability.getCooldownTicks(), ability.getCooldownTicks()); + } else { + cooldownEndTime = now + baseCooldown + ability.getCooldownTicks(); } } @Override protected void rollChainCooldown(ChainedAbility chain) { + long now = npc.worldObj.getTotalWorldTime(); + boolean perAbility = chain.isPerAbilityCooldown() && chain.getCooldownTicks() > 0; + if (!chain.isIgnoreCooldown()) { int baseCooldown = minCooldown; if (maxCooldown > minCooldown) { baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1); } - cooldownEndTime = npc.worldObj.getTotalWorldTime() + baseCooldown + chain.getCooldownTicks(); + cooldownEndTime = perAbility ? now + baseCooldown : now + baseCooldown + chain.getCooldownTicks(); } - // Additionally set per-ability cooldown if enabled - if (chain.isPerAbilityCooldown() && chain.getCooldownTicks() > 0) { - long endTime = npc.worldObj.getTotalWorldTime() + chain.getCooldownTicks(); - setPerAbilityCooldown(chain.getName(), endTime, chain.getCooldownTicks()); + if (perAbility) { + setPerAbilityCooldown(chain.getName(), now + chain.getCooldownTicks(), chain.getCooldownTicks()); } } From 6af66b8883d10b6a74f51be9e63925c76c6ea7a1 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:25:51 -0400 Subject: [PATCH 12/24] Fix NPCs getting stuck after using one ability The terminal DAZED to IDLE transition was swallowed before the completion switch ran, so the finished ability stayed set as the current one and the NPC never started another until it died and reset. Guard abilities compounded it: NPCs reuse a single ability instance and onExecute left pendingCompletion set, ending every later activation on its first tick. --- .../controllers/data/ability/type/AbilityDefend.java | 6 ++++++ src/main/java/noppes/npcs/AbstractDataAbilities.java | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java index 376c4ad4c..4826daee4 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java @@ -74,6 +74,12 @@ public abstract class AbilityDefend extends Ability implements IAbilityDefend { hitCount = 0; lastAttacker = null; lastDamageTaken = 0.0f; + // NPCs reuse one ability instance, so every transient field has to be cleared here. + // A leftover pendingCompletion would end the next activation on its first tick. + pendingDefendAnimation = null; + defendAnimEndTick = -1; + lastDefendTick = -1; + pendingCompletion = false; } @Override diff --git a/src/main/java/noppes/npcs/AbstractDataAbilities.java b/src/main/java/noppes/npcs/AbstractDataAbilities.java index 244ed91d1..12f1fd793 100644 --- a/src/main/java/noppes/npcs/AbstractDataAbilities.java +++ b/src/main/java/noppes/npcs/AbstractDataAbilities.java @@ -786,7 +786,15 @@ public abstract class AbstractDataAbilities { fireTickEvent(currentAbility, target); // Script may have completed/cancelled the ability during the tick event - if (currentAbility == null || !currentAbility.isExecuting()) return; + if (currentAbility == null) return; + if (!currentAbility.isExecuting()) { + // tick() itself can end the ability (DAZED -> IDLE). Run its completion here, + // otherwise it stays the current ability forever and nothing else can start. + if (phaseChanged && currentAbility.getPhase() == AbilityPhase.IDLE) { + handleAbilityCompletion(target); + } + return; + } // Fire extender tick hook (e.g., per-tick resource drain) if (!AbilityController.Instance.fireOnAbilityTick(currentAbility, entity, target, From 9f4334a8031d3051111d4d2158d78a3652b163d1 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:26:32 -0400 Subject: [PATCH 13/24] Line the monkey tail up with the player model heightFactor did not fully cancel ModelTail''s anchor, leaving both the wrapped and plain monkey tails two pixels below where JBRA renders them on players. --- .../noppes/npcs/client/model/part/tails/ModelMonkeyTail.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/client/model/part/tails/ModelMonkeyTail.java b/src/main/java/noppes/npcs/client/model/part/tails/ModelMonkeyTail.java index fae556349..347b5ebfa 100644 --- a/src/main/java/noppes/npcs/client/model/part/tails/ModelMonkeyTail.java +++ b/src/main/java/noppes/npcs/client/model/part/tails/ModelMonkeyTail.java @@ -34,7 +34,9 @@ public class ModelMonkeyTail extends ModelRenderer { public ModelMonkeyTail(ModelBiped base) { super(base); - float heightFactor = -9.0f; + // Cancels ModelTail's rotationPointY of 11 so the boxes land where JBRA puts them + // on players: plain tail at 10, wrapped tail at 0. + float heightFactor = -11.0f; (this.monkey_large = new ModelRenderer(base, 38, 54)).addBox(-2.0f, -2.0f, 0.0f, 4, 4, 6); this.setRotation(this.monkey_large, -0.5235988f, 0.0f, 0.0f); From 7cafa4f67720621f8418942be01823f876ffb12b Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:28:49 -0400 Subject: [PATCH 14/24] Make anchored lasers and rotation lock affect ability aim - Anchored lasers re-derived their direction straight at the target every tick, discarding the rate-limited look vector, so track speed did nothing and the beam was undodgeable. They now converge on the point the owner is aiming at. - Rotation-locked NPCs aimed energy projectiles and hit-scan projectiles from the target''s position, so the lock was purely visual. Both now respect the frozen heading. --- .../data/ability/type/AbilityProjectile.java | 9 +++++++ .../type/energy/AbilityEnergyProjectile.java | 7 ++++- .../npcs/entity/EntityAbilityLaser.java | 27 ++++++++++--------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityProjectile.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityProjectile.java index 104209eeb..3caabc678 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityProjectile.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityProjectile.java @@ -97,6 +97,15 @@ public class AbilityProjectile extends Ability implements IAbilityProjectile { dz /= len; } + // A rotation-locked NPC cannot turn to follow the target, so it can only hit what its + // frozen heading still covers - the same cone the player hit scan uses. + if (isRotationLockedForCurrentPhase()) { + Vec3 look = caster.getLookVec(); + if (look != null && (dx * look.xCoord + dy * look.yCoord + dz * look.zCoord) < 0.95) { + return; + } + } + applyAbilityDamageWithDirection(caster, target, damage, knockback, dx, dz); world.playSoundAtEntity(caster, "random.bow", 1.0f, 0.8f); diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/energy/AbilityEnergyProjectile.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/energy/AbilityEnergyProjectile.java index 7e7986d20..723781d36 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/energy/AbilityEnergyProjectile.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/energy/AbilityEnergyProjectile.java @@ -248,7 +248,12 @@ public abstract class AbilityEnergyProjectile * NPCs use their resolved target so launch math can track the target immediately. */ protected EntityLivingBase getLaunchTarget(EntityLivingBase caster, EntityLivingBase target) { - return isPlayerCaster(caster) ? null : target; + if (isPlayerCaster(caster)) return null; + // A rotation-locked NPC cannot turn, so launching from the target's position would let + // it fire a perfectly aimed shot regardless of where it is facing. Fall back to the + // look vector, which reflects the frozen heading. + if (isRotationLockedForCurrentPhase()) return null; + return target; } /** diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityLaser.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityLaser.java index 546457f4d..f8f5d44f5 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityLaser.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityLaser.java @@ -264,18 +264,21 @@ public class EntityAbilityLaser extends EntityEnergyProjectile { Vec3 anchorPos = AnchorPointHelper.calculateAnchorPosition(livingOwner, anchorData); setPosition(anchorPos.xCoord, anchorPos.yCoord, anchorPos.zCoord); - Entity targetEntity = getTargetEntity(); - if (targetEntity instanceof EntityLivingBase && targetEntity.isEntityAlive()) { - EntityLivingBase target = (EntityLivingBase) targetEntity; - double dx = target.posX - anchorPos.xCoord; - double dy = (target.posY + target.getEyeHeight() - 0.4) - anchorPos.yCoord; - double dz = target.posZ - anchorPos.zCoord; - double len = Math.sqrt(dx * dx + dy * dy + dz * dz); - if (len > 0.0001) { - dirX = dx / len; - dirY = dy / len; - dirZ = dz / len; - } + // Converge on the point the owner is aiming at, not on the target itself. Aiming + // straight at the target would re-derive the direction every tick and ignore the + // rotation the owner is actually allowed to reach, which is what track speed and + // rotation lock constrain. + double aimX = livingOwner.posX + dirX * maxLength; + double aimY = livingOwner.posY + livingOwner.getEyeHeight() + dirY * maxLength; + double aimZ = livingOwner.posZ + dirZ * maxLength; + double dx = aimX - anchorPos.xCoord; + double dy = aimY - anchorPos.yCoord; + double dz = aimZ - anchorPos.zCoord; + double len = Math.sqrt(dx * dx + dy * dy + dz * dz); + if (len > 0.0001) { + dirX = dx / len; + dirY = dy / len; + dirZ = dz / len; } } else { Vec3 direction = Vec3.createVectorHelper(dirX, dirY, dirZ); From 6477ede022abccc21e432d1e0aba0b3150c31848 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:31:38 -0400 Subject: [PATCH 15/24] Make hazard radius and barrier duration accurate - Hazards only checked who was inside once per damage interval, so the boundary where damage started and stopped drifted by however far an entity moved in between - several blocks at sprint speed. Membership is now checked every tick and damage accrues per entity from the time it actually spends inside. - Barriers counted elapsed ticks instead of holding a deadline, so every tick the entity missed extended it past its configured duration. They now expire on an absolute world time like the other energy entities. --- .../npcs/entity/EntityAbilityZone.java | 34 +++++++++++++------ .../npcs/entity/EntityEnergyBarrier.java | 19 +++++++---- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityZone.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityZone.java index 7913386c6..2a4632e77 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityZone.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityZone.java @@ -23,8 +23,10 @@ import noppes.npcs.NpcDamageSource; import noppes.npcs.entity.EntityNPCInterface; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -170,8 +172,9 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD private transient Set triggeredEntities = new HashSet<>(); private transient int triggerFlashTick = -1; - private transient int ticksSinceDamage = 0; private transient Set damagedThisTick = new HashSet<>(); + /** Ticks each entity has spent inside the zone since it was last damaged, by entity id. */ + private transient Map ticksInZone = new HashMap<>(); private transient Ability sourceAbility = null; @@ -216,7 +219,6 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD this.ownerEntityId = owner != null ? owner.getEntityId() : -1; double groundY = Ability.findGroundLevel(worldObj, x, y, z) + GROUND_OFFSET; this.setPosition(x, groundY, z); - this.ticksSinceDamage = damageInterval; } /** @@ -309,7 +311,6 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD zone.effects.add(e.copy()); } } - zone.ticksSinceDamage = damageInterval; return zone; } @@ -495,13 +496,10 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD private void tickHazard() { damagedThisTick.clear(); - ticksSinceDamage++; - - if (ticksSinceDamage < damageInterval) { - return; - } - ticksSinceDamage = 0; + // Membership is checked every tick, not once per damage interval. Sampling on the + // interval alone made the effective boundary drift by however far an entity moved in + // between, which on a large radius reads as the radius itself being wrong. AxisAlignedBB searchBox = AxisAlignedBB.getBoundingBox( posX - radius, posY - 0.5, posZ - radius, posX + radius, posY + zoneHeight, posZ + radius @@ -511,19 +509,35 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD @SuppressWarnings("unchecked") List entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, searchBox); + Set insideThisTick = new HashSet<>(); for (EntityLivingBase entity : entities) { if (owner != null && entity == owner && !affectsCaster) continue; if (damagedThisTick.contains(entity.getEntityId())) continue; if (entity != owner && owner instanceof EntityLivingBase && !AbilityTargetHelper.shouldAffect((EntityLivingBase) owner, entity, TargetFilter.ENEMIES, false)) continue; if (!isInZone(entity)) continue; + int entityId = entity.getEntityId(); + insideThisTick.add(entityId); + + // Entities that just entered are hit immediately, then once per interval of time + // actually spent inside. + Integer elapsed = ticksInZone.get(entityId); + int ticks = elapsed == null ? damageInterval : elapsed + 1; + if (ticks < damageInterval) { + ticksInZone.put(entityId, ticks); + continue; + } + ticksInZone.put(entityId, 0); + if (damagePerSecond > 0) { applyDamage(entity, owner, damagePerSecond); } applyEffects(entity); - damagedThisTick.add(entity.getEntityId()); + damagedThisTick.add(entityId); } + + ticksInZone.keySet().retainAll(insideThisTick); } private boolean isInZone(EntityLivingBase entity) { diff --git a/src/main/java/kamkeel/npcs/entity/EntityEnergyBarrier.java b/src/main/java/kamkeel/npcs/entity/EntityEnergyBarrier.java index 4ccb01269..8b5da0ad5 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityEnergyBarrier.java +++ b/src/main/java/kamkeel/npcs/entity/EntityEnergyBarrier.java @@ -114,6 +114,8 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility { protected EnergyBarrierData barrierData = new EnergyBarrierData(); protected float currentHealth; protected int ticksAlive = 0; + /** Absolute world time the barrier expires at, so ticks it misses cannot extend it. */ + protected long barrierDeathTime = -1; // ==================== DATA WATCHER INDICES ==================== protected static final int DW_HEALTH_PERCENT = 21; @@ -510,15 +512,16 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility { } } - // Duration check - if (barrierData.useDuration && ticksAlive >= barrierData.durationTicks) { - onBarrierDestroyed(); - this.setDead(); - return true; + // Set the deadline on the first tick after charging, so lifetime starts when the + // barrier is actually up. Counting elapsed ticks instead would let any tick the + // entity misses - chunk unload, for one - extend it past its configured duration. + if (barrierDeathTime < 0 && !isCharging()) { + barrierDeathTime = worldObj.getTotalWorldTime() + + (barrierData.useDuration ? barrierData.durationTicks : BARRIER_HARD_LIFETIME_CAP); } - // Absolute hard lifetime cap (safety net for barriers with no duration) - if (ticksAlive > BARRIER_HARD_LIFETIME_CAP) { + // Duration check, and the hard lifetime cap for barriers with no duration + if (barrierDeathTime >= 0 && worldObj.getTotalWorldTime() >= barrierDeathTime) { onBarrierDestroyed(); this.setDead(); return true; @@ -865,6 +868,7 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility { protected void writeBarrierBaseNBT(NBTTagCompound nbt) { writeEnergyBaseNBT(nbt); nbt.setInteger("TicksAlive", ticksAlive); + nbt.setLong("BarrierDeathTime", barrierDeathTime); nbt.setFloat("CurrentHealth", currentHealth); nbt.setBoolean("Charging", charging); nbt.setInteger("ChargeTick", chargeTick); @@ -879,6 +883,7 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility { protected void readBarrierBaseNBT(NBTTagCompound nbt) { readEnergyBaseNBT(nbt); this.ticksAlive = nbt.getInteger("TicksAlive"); + this.barrierDeathTime = nbt.hasKey("BarrierDeathTime") ? nbt.getLong("BarrierDeathTime") : -1; this.currentHealth = nbt.getFloat("CurrentHealth"); if (Float.isNaN(currentHealth) || Float.isInfinite(currentHealth) || currentHealth < 0) currentHealth = barrierData.maxHealth; this.charging = nbt.hasKey("Charging") && nbt.getBoolean("Charging"); From 4341c15cf4daf53e599a9f3aff51fa94214da1ce Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:33:04 -0400 Subject: [PATCH 16/24] Scale melee damage dealt to barriers Barriers are plain entities, so no LivingHurtEvent fires for them and nothing scaled an incoming melee hit - vanilla handed over the bare attackDamage attribute and a dome took one point per swing however strong the attacker was. Attributes now apply, and modifyBarrierMeleeDamage gives addons the same seam they already have for barrier health. --- .../npcs/controllers/AbilityController.java | 12 ++++++++++++ .../data/ability/extender/IAbilityExtender.java | 16 ++++++++++++++++ .../kamkeel/npcs/entity/EntityEnergyBarrier.java | 16 +++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/kamkeel/npcs/controllers/AbilityController.java b/src/main/java/kamkeel/npcs/controllers/AbilityController.java index 6c5810188..66c057929 100644 --- a/src/main/java/kamkeel/npcs/controllers/AbilityController.java +++ b/src/main/java/kamkeel/npcs/controllers/AbilityController.java @@ -46,6 +46,7 @@ import noppes.npcs.controllers.data.AbilityScript; import noppes.npcs.controllers.data.ChainedAbilityScript; import net.minecraft.entity.EntityLivingBase; import kamkeel.npcs.controllers.sync.handlers.PlayerAbilitySyncHelper; +import kamkeel.npcs.entity.EntityEnergyBarrier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; @@ -1381,6 +1382,17 @@ public class AbilityController implements IAbilityHandler { return health; } + /** + * Fire modifyBarrierMeleeDamage on all extenders. Cumulative — each extender's output feeds the next. + */ + public float fireModifyBarrierMeleeDamage(EntityEnergyBarrier barrier, EntityLivingBase attacker, float baseDamage) { + float damage = baseDamage; + for (IAbilityExtender ext : extenders) { + damage = ext.modifyBarrierMeleeDamage(barrier, attacker, damage); + } + return damage; + } + /** * Fire onAbilityHeal on all extenders. Chain of responsibility — first true wins. */ diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/extender/IAbilityExtender.java b/src/main/java/kamkeel/npcs/controllers/data/ability/extender/IAbilityExtender.java index d691a6d18..2a0b90344 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/extender/IAbilityExtender.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/extender/IAbilityExtender.java @@ -3,6 +3,7 @@ package kamkeel.npcs.controllers.data.ability.extender; import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition; import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase; import kamkeel.npcs.controllers.data.ability.Ability; +import kamkeel.npcs.entity.EntityEnergyBarrier; import net.minecraft.entity.EntityLivingBase; /** @@ -108,6 +109,21 @@ public interface IAbilityExtender { return baseHealth; } + /** + * Called when a barrier entity takes a melee hit, allowing extenders to scale the damage. + * A barrier is a plain Entity, so no LivingHurtEvent fires for it and an extender has no + * other opportunity to scale melee against it the way it scales {@link #modifyBarrierHealth}. + * Cumulative: all extenders apply in sequence, each receiving the previous output. + * + * @param barrier The barrier being hit + * @param attacker The entity dealing the hit + * @param baseDamage The damage after the barrier's own melee multiplier + * @return The modified damage value + */ + default float modifyBarrierMeleeDamage(EntityEnergyBarrier barrier, EntityLivingBase attacker, float baseDamage) { + return baseDamage; + } + /** * Called when an ability is about to heal an entity. * Return true to handle the healing (skip default entity.heal()). diff --git a/src/main/java/kamkeel/npcs/entity/EntityEnergyBarrier.java b/src/main/java/kamkeel/npcs/entity/EntityEnergyBarrier.java index 8b5da0ad5..da9edb676 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityEnergyBarrier.java +++ b/src/main/java/kamkeel/npcs/entity/EntityEnergyBarrier.java @@ -1,5 +1,7 @@ package kamkeel.npcs.entity; +import kamkeel.npcs.addon.DBCAddon; +import kamkeel.npcs.controllers.AbilityController; import kamkeel.npcs.controllers.data.ability.util.AbilityTargetHelper; import kamkeel.npcs.controllers.data.ability.data.energy.EnergyBarrierData; import kamkeel.npcs.network.packets.data.energy.BarrierClientSyncPacket; @@ -15,6 +17,7 @@ import net.minecraft.util.DamageSource; import net.minecraft.world.World; import noppes.npcs.CustomNpcs; import noppes.npcs.EventHooks; +import noppes.npcs.config.ConfigMain; import noppes.npcs.controllers.data.MagicData; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.entity.EntityNPCInterface; @@ -438,8 +441,19 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility { float damage = amount * barrierData.meleeDamageMultiplier; - // Apply magic interactions from attacker's magic vs barrier's magic Entity attacker = source.getEntity(); + + // A barrier is a plain Entity, so no LivingHurtEvent fires for it and nothing scales the + // hit the way it would against a living target - vanilla hands us the bare attackDamage + // attribute. Run the scaling here instead, or the barrier only ever takes a point of it. + if (attacker instanceof EntityLivingBase) { + damage = AbilityController.Instance.fireModifyBarrierMeleeDamage(this, (EntityLivingBase) attacker, damage); + } + if (attacker instanceof EntityPlayer && ConfigMain.AttributesEnabled && !DBCAddon.IsAvailable()) { + damage = AttributeAttackUtil.calculateOutgoing((EntityPlayer) attacker, damage); + } + + // Apply magic interactions from attacker's magic vs barrier's magic if (attacker != null) { MagicData attackerMagic = null; if (attacker instanceof EntityPlayer) { From 1acda0e6b088ff16ca855eafba23e94c2198869c Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 04:23:59 -0400 Subject: [PATCH 17/24] Scale hazard damage to its interval and floor the interval at 5 ticks The value is configured, stored and labelled as damage per second, but a pulse applied it whole, so the real rate was damage per interval - it only matched at the default interval of 20. A pulse now deals the share of a second it covers. The interval is floored at 5 ticks, which also bounds how often a zone scans; this replaces the per-tick membership check, which cost 20x the entity queries. --- .../data/ability/type/AbilityHazard.java | 5 ++- .../npcs/entity/EntityAbilityZone.java | 44 +++++++------------ 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java index 47f9156a8..2086d4e8f 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityHazard.java @@ -107,7 +107,7 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard { readZoneNBT(nbt, 300); this.radius = nbt.getFloat("radius"); this.damagePerSecond = nbt.getFloat("damagePerSecond"); - this.damageInterval = nbt.getInteger("damageInterval"); + setDamageInterval(nbt.getInteger("damageInterval")); this.affectsCaster = nbt.getBoolean("affectsCaster"); } @@ -138,7 +138,7 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard { } public void setDamageInterval(int damageInterval) { - this.damageInterval = damageInterval; + this.damageInterval = Math.max(EntityAbilityZone.MIN_DAMAGE_INTERVAL, damageInterval); } public boolean isAffectsCaster() { @@ -171,6 +171,7 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard { FieldDef.row( FieldDef.floatField("gui.dps", this::getDamagePerSecond, this::setDamagePerSecond), FieldDef.intField("gui.interval", this::getDamageInterval, this::setDamageInterval) + .range(EntityAbilityZone.MIN_DAMAGE_INTERVAL, 2000) ), FieldDef.boolField("ability.affectsCaster", this::isAffectsCaster, this::setAffectsCaster) .hover("ability.hover.affectsCaster"), diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityZone.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityZone.java index 2a4632e77..529d59d74 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityZone.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityZone.java @@ -23,10 +23,8 @@ import noppes.npcs.NpcDamageSource; import noppes.npcs.entity.EntityNPCInterface; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; /** @@ -157,6 +155,9 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD // HAZARD-SPECIFIC PROPERTIES // ═══════════════════════════════════════════════════════════════════ + /** Floor on how often a hazard pulses, so a small interval cannot turn into a per-tick scan. */ + public static final int MIN_DAMAGE_INTERVAL = 5; + private float damagePerSecond = 1.0f; private int damageInterval = 20; private boolean ignoreIFrames = false; @@ -172,9 +173,8 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD private transient Set triggeredEntities = new HashSet<>(); private transient int triggerFlashTick = -1; + private transient int ticksSinceDamage = 0; private transient Set damagedThisTick = new HashSet<>(); - /** Ticks each entity has spent inside the zone since it was last damaged, by entity id. */ - private transient Map ticksInZone = new HashMap<>(); private transient Ability sourceAbility = null; @@ -219,6 +219,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD this.ownerEntityId = owner != null ? owner.getEntityId() : -1; double groundY = Ability.findGroundLevel(worldObj, x, y, z) + GROUND_OFFSET; this.setPosition(x, groundY, z); + this.ticksSinceDamage = damageInterval; } /** @@ -293,7 +294,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD zone.shape = shape; zone.radius = radius; zone.damagePerSecond = damagePerSecond; - zone.damageInterval = damageInterval; + zone.damageInterval = Math.max(MIN_DAMAGE_INTERVAL, damageInterval); zone.ignoreIFrames = ignoreIFrames; zone.affectsCaster = affectsCaster; zone.durationTicks = durationTicks; @@ -496,10 +497,13 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD private void tickHazard() { damagedThisTick.clear(); + ticksSinceDamage++; + + if (ticksSinceDamage < damageInterval) { + return; + } + ticksSinceDamage = 0; - // Membership is checked every tick, not once per damage interval. Sampling on the - // interval alone made the effective boundary drift by however far an entity moved in - // between, which on a large radius reads as the radius itself being wrong. AxisAlignedBB searchBox = AxisAlignedBB.getBoundingBox( posX - radius, posY - 0.5, posZ - radius, posX + radius, posY + zoneHeight, posZ + radius @@ -509,35 +513,21 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD @SuppressWarnings("unchecked") List entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, searchBox); - Set insideThisTick = new HashSet<>(); for (EntityLivingBase entity : entities) { if (owner != null && entity == owner && !affectsCaster) continue; if (damagedThisTick.contains(entity.getEntityId())) continue; if (entity != owner && owner instanceof EntityLivingBase && !AbilityTargetHelper.shouldAffect((EntityLivingBase) owner, entity, TargetFilter.ENEMIES, false)) continue; if (!isInZone(entity)) continue; - int entityId = entity.getEntityId(); - insideThisTick.add(entityId); - - // Entities that just entered are hit immediately, then once per interval of time - // actually spent inside. - Integer elapsed = ticksInZone.get(entityId); - int ticks = elapsed == null ? damageInterval : elapsed + 1; - if (ticks < damageInterval) { - ticksInZone.put(entityId, ticks); - continue; - } - ticksInZone.put(entityId, 0); - if (damagePerSecond > 0) { - applyDamage(entity, owner, damagePerSecond); + // The configured value is damage per second, so a pulse deals the share of a + // second it covers. Applying it whole made the real rate depend on the interval. + applyDamage(entity, owner, damagePerSecond * (damageInterval / 20.0f)); } applyEffects(entity); - damagedThisTick.add(entityId); + damagedThisTick.add(entity.getEntityId()); } - - ticksInZone.keySet().retainAll(insideThisTick); } private boolean isInZone(EntityLivingBase entity) { @@ -829,7 +819,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD public float getDamagePerSecond() { return damagePerSecond; } public void setDamagePerSecond(float dps) { this.damagePerSecond = dps; } public int getDamageInterval() { return damageInterval; } - public void setDamageInterval(int ticks) { this.damageInterval = ticks; } + public void setDamageInterval(int ticks) { this.damageInterval = Math.max(MIN_DAMAGE_INTERVAL, ticks); } public boolean isAffectsCaster() { return affectsCaster; } public void setAffectsCaster(boolean affects) { this.affectsCaster = affects; } From c79f5998d621fae8b90c7415d0b2353caaa61b80 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 04:23:59 -0400 Subject: [PATCH 18/24] Stop NPC pathfinding fighting Charge's own movement Charge drives the NPC with applyVelocityFlat but never declared that it does, so locking movement during the active phase zeroed its motion outright while not locking left the navigator running against it - no setting worked. It now declares its own movement and locks both phases, so the navigator stays clear. --- .../npcs/controllers/data/ability/type/AbilityCharge.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCharge.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCharge.java index c88d63c30..d5c293c64 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCharge.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityCharge.java @@ -43,7 +43,7 @@ public class AbilityCharge extends AbilityMovement implements IAbilityCharge { this.targetingMode = TargetingMode.AGGRO_TARGET; this.maxRange = 20.0f; this.minRange = 4.0f; - this.lockMovement = LockMode.WINDUP; + this.lockMovement = LockMode.WINDUP_AND_ACTIVE; this.cooldownTicks = 0; this.windUpTicks = 20; // LINE telegraph showing charge path @@ -58,6 +58,11 @@ public class AbilityCharge extends AbilityMovement implements IAbilityCharge { }; } + @Override + public boolean hasAbilityMovement() { + return true; // This ability drives the NPC's motion itself + } + @Override public boolean isTargetingModeLocked() { return true; From dedbe94cd8e2a9551ee808d7a2b24c678c0819ce Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 04:44:14 -0400 Subject: [PATCH 19/24] Keep client-only sub-GUI types out of Ability's method descriptors The magic editor field was built with lambdas inside Ability.getAllDefinitions. subGuiField is generic, so those lambdas took SubGuiAbilityMagic as their descriptor type. @SideOnly strips the annotated method on a server but not the synthetic lambdas it generates, so anything reflecting over Ability's declared methods - Nashorn's adapter generator when a script touches an ability - hit NoClassDefFoundError. Building the field in the client class keeps the type out of Ability entirely. --- .../controllers/data/ability/Ability.java | 14 +--------- .../gui/advanced/SubGuiAbilityMagic.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java index 05049d8bb..a73a8a0a2 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java @@ -840,19 +840,7 @@ public abstract class Ability implements IAbility, IAbilityAction { return sb.toString(); }).tab("General")); - defs.add(FieldDef.subGuiField("ability.magic.editor", - () -> new SubGuiAbilityMagic(magicData.copy()), - gui -> { - MagicData result = ((SubGuiAbilityMagic) gui).magicData; - magicData.getMagics().clear(); - for (Map.Entry e : result.getMagics().entrySet()) { - magicData.getMagics().put(e.getKey(), e.getValue()); - } - }) - .buttonLabel(() -> magicData.isEmpty() - ? StatCollector.translateToLocal("ability.magic.usesCaster") - : magicData.getMagics().size() + " Magic(s)") - .tab("General")); + defs.add(SubGuiAbilityMagic.createMagicField(magicData)); } // ── Target tab ─────────────────────────────────────────────── diff --git a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityMagic.java b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityMagic.java index 8543ad208..8f555017a 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityMagic.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiAbilityMagic.java @@ -1,6 +1,8 @@ package noppes.npcs.client.gui.advanced; import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.StatCollector; +import noppes.npcs.client.gui.builder.FieldDef; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; @@ -11,6 +13,7 @@ import noppes.npcs.client.gui.util.SubGuiInterface; import noppes.npcs.controllers.MagicController; import noppes.npcs.controllers.data.Magic; import noppes.npcs.controllers.data.MagicData; +import noppes.npcs.controllers.data.MagicEntry; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -36,6 +39,30 @@ public class SubGuiAbilityMagic extends SubGuiInterface implements ICustomScroll private GuiNpcTextField splitField; + /** + * Builds the ability editor's magic field. + *

+ * This lives here rather than in Ability because the lambdas below carry this class in + * their method descriptors. Ability is a both-side class, and anything reflecting over its + * declared methods on a server - Nashorn's adapter generator, for one - would resolve those + * descriptors and fail to find this client-only type. + */ + public static FieldDef createMagicField(MagicData magicData) { + return FieldDef.subGuiField("ability.magic.editor", + () -> new SubGuiAbilityMagic(magicData.copy()), + gui -> { + MagicData result = ((SubGuiAbilityMagic) gui).magicData; + magicData.getMagics().clear(); + for (Map.Entry e : result.getMagics().entrySet()) { + magicData.getMagics().put(e.getKey(), e.getValue()); + } + }) + .buttonLabel(() -> magicData.isEmpty() + ? StatCollector.translateToLocal("ability.magic.usesCaster") + : magicData.getMagics().size() + " Magic(s)") + .tab("General"); + } + public SubGuiAbilityMagic(MagicData data) { this.magicData = data; setBackground("menubg.png"); From 466b49db5ee5648932e44de0d7a7e2f6abab0eb3 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 04:52:50 -0400 Subject: [PATCH 20/24] Let the day/night transform actually fire EntityAITransform claimed the PASSIVE mutex, so any running movement or look task blocked it from ever starting. The swap only happened in the gaps where those yielded - which is why it appeared to trigger when an NPC said a line and for a moment afterwards. The task only polls world time and flips the state, so it needs no mutex at all. --- src/main/java/noppes/npcs/ai/EntityAITransform.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/noppes/npcs/ai/EntityAITransform.java b/src/main/java/noppes/npcs/ai/EntityAITransform.java index 9f565bccc..b0c3fa30e 100644 --- a/src/main/java/noppes/npcs/ai/EntityAITransform.java +++ b/src/main/java/noppes/npcs/ai/EntityAITransform.java @@ -10,7 +10,10 @@ public class EntityAITransform extends EntityAIBase { public EntityAITransform(EntityNPCInterface npc) { this.npc = npc; - setMutexBits(AiMutex.PASSIVE); + // No mutex: this only polls the world time and flips the transform, it drives nothing. + // Claiming PASSIVE let any running movement or look task starve it, so the day/night + // swap only fired in the gaps where those yielded - such as while saying a line. + setMutexBits(0); } @Override From 677d50fa03fae36155f76b0d3998a92a425eae9a Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 05:00:02 -0400 Subject: [PATCH 21/24] Keep client-only sub-GUI types out of condition and zone descriptors Same leak as the ability magic editor: @SideOnly strips the annotated method on a server but not the synthetic lambdas it generates, so ConditionHasEffect, ConditionQuestCompleted, AbilityTrap and AbilityZone all shipped methods whose descriptors named a client-only GUI class. Each field is now built in the GUI class it belongs to. --- .../conditions/ConditionHasEffect.java | 26 +++++------------- .../conditions/ConditionQuestCompleted.java | 15 +---------- .../data/ability/type/AbilityTrap.java | 9 +------ .../data/ability/type/AbilityZone.java | 9 +------ .../client/gui/SubGuiTrapPresetSelector.java | 20 ++++++++++++++ .../client/gui/SubGuiZonePresetSelector.java | 20 ++++++++++++++ .../advanced/SubGuiCustomEffectSelect.java | 27 +++++++++++++++++++ .../client/gui/select/GuiQuestSelection.java | 27 +++++++++++++++++++ 8 files changed, 104 insertions(+), 49 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionHasEffect.java b/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionHasEffect.java index eca7aded0..a608a92e6 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionHasEffect.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionHasEffect.java @@ -34,27 +34,15 @@ public class ConditionHasEffect extends AbilityCondition { return CustomEffectController.getInstance().hasEffect(player, effectId, effectIndex); } + public void setEffect(int effectId, int effectIndex) { + this.effectId = effectId; + this.effectIndex = effectIndex; + } + @SideOnly(Side.CLIENT) @Override public void getConditionDefinitions(List defs) { - defs.add(FieldDef.subGuiField("condition.select_effect", - () -> new SubGuiCustomEffectSelect(effectId, effectIndex), - gui -> { - SubGuiCustomEffectSelect sel = (SubGuiCustomEffectSelect) gui; - if (sel.getSelectedEffectId() >= 0) { - effectId = sel.getSelectedEffectId(); - effectIndex = sel.getSelectedIndex(); - } - }) - .buttonLabel(() -> { - if (effectId < 0) return "None"; - CustomEffect effect = getEffect(); - return effect != null ? effect.getName() : "ID:" + effectId; - }) - .clearable(() -> { - effectId = -1; - effectIndex = 0; - })); + defs.add(SubGuiCustomEffectSelect.createSelectField(this)); } @SideOnly(Side.CLIENT) @@ -74,7 +62,7 @@ public class ConditionHasEffect extends AbilityCondition { return effectId >= 0; } - private CustomEffect getEffect() { + public CustomEffect getEffect() { HashMap map = CustomEffectController.getInstance().getEffectMap(effectIndex); return map != null ? map.get(effectId) : null; } diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionQuestCompleted.java b/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionQuestCompleted.java index 2955b7610..ac8a05272 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionQuestCompleted.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/conditions/ConditionQuestCompleted.java @@ -38,20 +38,7 @@ public class ConditionQuestCompleted extends AbilityCondition { @SideOnly(Side.CLIENT) @Override public void getConditionDefinitions(List defs) { - defs.add(FieldDef.subGuiField("condition.select_quest", - () -> new GuiQuestSelection(questId), - gui -> { - GuiQuestSelection sel = (GuiQuestSelection) gui; - if (sel.selectedQuest != null) { - questId = sel.selectedQuest.id; - } - }) - .buttonLabel(() -> { - if (questId < 0) return "None"; - Quest q = QuestController.Instance.quests.get(questId); - return q != null ? q.title : "ID:" + questId; - }) - .clearable(() -> questId = -1)); + defs.add(GuiQuestSelection.createConditionField(this)); } @SideOnly(Side.CLIENT) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java index 5e508069a..1c40b202e 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityTrap.java @@ -300,14 +300,7 @@ public class AbilityTrap extends AbilityZone implements IAbilityTrap { @SideOnly(Side.CLIENT) @Override protected void addPresetFieldDef(List defs) { - defs.add(FieldDef.subGuiField("gui.applyPreset", - SubGuiTrapPresetSelector::new, - gui -> { - SubGuiTrapPresetSelector selector = (SubGuiTrapPresetSelector) gui; - if (selector.selectedPreset != null) { - applyTrapPresetDefaults(selector.selectedPreset); - } - })); + defs.add(SubGuiTrapPresetSelector.createPresetField(this::applyTrapPresetDefaults)); } @SideOnly(Side.CLIENT) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityZone.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityZone.java index 968ff03ba..a2f9fdeb7 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityZone.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityZone.java @@ -690,14 +690,7 @@ public abstract class AbilityZone extends Ability { @SideOnly(Side.CLIENT) protected void addPresetFieldDef(List defs) { - defs.add(FieldDef.subGuiField("gui.applyPreset", - SubGuiZonePresetSelector::new, - gui -> { - SubGuiZonePresetSelector selector = (SubGuiZonePresetSelector) gui; - if (selector.selectedPreset != null) { - applyPresetDefaults(selector.selectedPreset); - } - })); + defs.add(SubGuiZonePresetSelector.createPresetField(this::applyPresetDefaults)); } @SideOnly(Side.CLIENT) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiTrapPresetSelector.java b/src/main/java/noppes/npcs/client/gui/SubGuiTrapPresetSelector.java index b8fb9e376..086e27569 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiTrapPresetSelector.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiTrapPresetSelector.java @@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.StatCollector; +import noppes.npcs.client.gui.builder.FieldDef; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.SubGuiInterface; @@ -12,6 +13,25 @@ public class SubGuiTrapPresetSelector extends SubGuiInterface { public String selectedPreset = null; + /** + * Builds the trap editor's preset field. + *

+ * This lives here rather than in AbilityTrap because the lambda below carries this class in + * its method descriptor. AbilityTrap is a both-side class, and @SideOnly does not strip the + * synthetic lambda methods it generates - so anything reflecting over its declared methods + * on a server would resolve that descriptor and fail to find this client-only type. + */ + public static FieldDef createPresetField(java.util.function.Consumer applyPreset) { + return FieldDef.subGuiField("gui.applyPreset", + SubGuiTrapPresetSelector::new, + gui -> { + SubGuiTrapPresetSelector selector = (SubGuiTrapPresetSelector) gui; + if (selector.selectedPreset != null) { + applyPreset.accept(selector.selectedPreset); + } + }); + } + private static final String[] PRESET_NAMES = {"HIDDEN", "VENOM", "EXPLOSIVE", "CURSED", "SHOCK", "SNARE"}; private static final String[] PRESET_LABELS = { "ability.preset.hidden", "ability.preset.venom", "ability.preset.explosive", diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiZonePresetSelector.java b/src/main/java/noppes/npcs/client/gui/SubGuiZonePresetSelector.java index f67ef3db1..5bdc9c291 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiZonePresetSelector.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiZonePresetSelector.java @@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.StatCollector; +import noppes.npcs.client.gui.builder.FieldDef; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.SubGuiInterface; @@ -12,6 +13,25 @@ public class SubGuiZonePresetSelector extends SubGuiInterface { public String selectedPreset = null; + /** + * Builds the zone editor's preset field. + *

+ * This lives here rather than in AbilityZone because the lambda below carries this class in + * its method descriptor. AbilityZone is a both-side class, and @SideOnly does not strip the + * synthetic lambda methods it generates - so anything reflecting over its declared methods + * on a server would resolve that descriptor and fail to find this client-only type. + */ + public static FieldDef createPresetField(java.util.function.Consumer applyPreset) { + return FieldDef.subGuiField("gui.applyPreset", + SubGuiZonePresetSelector::new, + gui -> { + SubGuiZonePresetSelector selector = (SubGuiZonePresetSelector) gui; + if (selector.selectedPreset != null) { + applyPreset.accept(selector.selectedPreset); + } + }); + } + private static final String[] PRESET_NAMES = {"DEFAULT", "TOXIC", "INFERNO", "ARCANE", "ELECTRIC", "FROST"}; private static final String[] PRESET_LABELS = { "ability.preset.default", "ability.preset.toxic", "ability.preset.inferno", diff --git a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiCustomEffectSelect.java b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiCustomEffectSelect.java index 411d03351..233ad8ece 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/SubGuiCustomEffectSelect.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/SubGuiCustomEffectSelect.java @@ -3,6 +3,8 @@ 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 kamkeel.npcs.controllers.data.ability.conditions.ConditionHasEffect; +import noppes.npcs.client.gui.builder.FieldDef; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcTextField; @@ -25,6 +27,31 @@ import java.util.Map; @SideOnly(Side.CLIENT) public class SubGuiCustomEffectSelect extends SubGuiInterface implements ICustomScrollListener, ITextfieldListener { + /** + * Builds the condition editor's effect-select field. + *

+ * This lives here rather than in ConditionHasEffect because the lambdas below carry this + * class in their method descriptors. The condition is a both-side class, and @SideOnly does + * not strip the synthetic lambda methods it generates - so anything reflecting over its + * declared methods on a server would resolve those descriptors and fail to find this type. + */ + public static FieldDef createSelectField(ConditionHasEffect condition) { + return FieldDef.subGuiField("condition.select_effect", + () -> new SubGuiCustomEffectSelect(condition.getEffectId(), condition.getEffectIndex()), + gui -> { + SubGuiCustomEffectSelect sel = (SubGuiCustomEffectSelect) gui; + if (sel.getSelectedEffectId() >= 0) { + condition.setEffect(sel.getSelectedEffectId(), sel.getSelectedIndex()); + } + }) + .buttonLabel(() -> { + if (condition.getEffectId() < 0) return "None"; + CustomEffect effect = condition.getEffect(); + return effect != null ? effect.getName() : "ID:" + condition.getEffectId(); + }) + .clearable(() -> condition.setEffect(-1, 0)); + } + private GuiCustomScroll scroll; private final HashMap displayNameToId = new HashMap<>(); private final HashMap allDisplayNameToId = new HashMap<>(); diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java index 288964545..cf805fe44 100644 --- a/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java +++ b/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java @@ -2,6 +2,8 @@ package noppes.npcs.client.gui.select; import com.google.common.collect.Lists; import net.minecraft.client.gui.GuiButton; +import kamkeel.npcs.controllers.data.ability.conditions.ConditionQuestCompleted; +import noppes.npcs.client.gui.builder.FieldDef; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiNpcLabel; @@ -27,6 +29,31 @@ public class GuiQuestSelection extends SubGuiInterface implements ICustomScrollL private QuestCategory selectedCategory; public Quest selectedQuest; + /** + * Builds the condition editor's quest-select field. + *

+ * This lives here rather than in ConditionQuestCompleted because the lambdas below carry + * this class in their method descriptors. The condition is a both-side class, and @SideOnly + * does not strip the synthetic lambda methods it generates - so anything reflecting over its + * declared methods on a server would resolve those descriptors and fail to find this type. + */ + public static FieldDef createConditionField(ConditionQuestCompleted condition) { + return FieldDef.subGuiField("condition.select_quest", + () -> new GuiQuestSelection(condition.getQuestId()), + gui -> { + GuiQuestSelection sel = (GuiQuestSelection) gui; + if (sel.selectedQuest != null) { + condition.setQuestId(sel.selectedQuest.id); + } + }) + .buttonLabel(() -> { + if (condition.getQuestId() < 0) return "None"; + Quest q = QuestController.Instance.quests.get(condition.getQuestId()); + return q != null ? q.title : "ID:" + condition.getQuestId(); + }) + .clearable(() -> condition.setQuestId(-1)); + } + private GuiSelectionListener listener; private String catSearch = ""; private String questSearch = ""; From 71bb4b451ea67fedbcb2542ff8e7e51c30f9ed81 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 05:01:50 -0400 Subject: [PATCH 22/24] Honour the effective windup instead of the raw field start() and tick() compared against the raw windUpTicks, but when the windup is synced to an animation the value that applies comes from getWindUpTicks(). An ability configured that way skipped its windup entirely and fired on the first tick. The telegraph duration used the raw field too, so it disagreed with the phase it was meant to cover. --- .../npcs/controllers/data/ability/Ability.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java index a73a8a0a2..d944f7535 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/Ability.java @@ -1050,10 +1050,11 @@ public abstract class Ability implements IAbility, IAbilityAction { return null; } - telegraph.setDurationTicks(windUpTicks); + int windUp = getWindUpTicks(); + telegraph.setDurationTicks(windUp); telegraph.setColor(windUpColor); telegraph.setWarningColor(activeColor); - telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4)); + telegraph.setWarningStartTick(Math.max(5, windUp / 4)); telegraph.setHeightOffset(telegraphHeightOffset); TelegraphInstance instance = new TelegraphInstance(telegraph, x, y, z, yaw); @@ -1171,7 +1172,9 @@ public abstract class Ability implements IAbility, IAbilityAction { this.burstIndex = 0; this.burstEntities.clear(); - if (windUpTicks <= 0) { + // Use the effective windup, not the raw field: when the windup is synced to an + // animation the raw field is not the duration that actually applies. + if (getWindUpTicks() <= 0) { this.phase = AbilityPhase.ACTIVE; } else { this.phase = AbilityPhase.WINDUP; @@ -1193,7 +1196,7 @@ public abstract class Ability implements IAbility, IAbilityAction { switch (phase) { case WINDUP: - if (currentTick >= windUpTicks) { + if (currentTick >= getWindUpTicks()) { phase = AbilityPhase.ACTIVE; currentTick = 0; return true; From a028142dda9e2e362e1a144e126b0bab44e4fb43 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 05:08:15 -0400 Subject: [PATCH 23/24] Fix mouse wheel scrolling in the script editors Mouse.getDWheel() clears the accumulated delta, so whichever widget polled it first in a frame took it and every later reader saw zero. The script text areas polled it themselves, after the parent screen had already drained it for its scroll lists, so the wheel did nothing in the player, NPC and event script GUIs. The screen now reads the wheel once per frame into the mouseScroll field it already declared for this, and each widget zeroes it when it consumes it. --- .../npcs/client/gui/util/GuiNPCInterface.java | 17 +++++++++++++++-- .../npcs/client/gui/util/GuiScriptTextArea.java | 6 ++++-- .../client/gui/util/GuiScriptTextArea1.java | 6 ++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java index 08a5dff00..24d08cff2 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -515,15 +515,28 @@ public abstract class GuiNPCInterface extends GuiScreen { } boolean subGui = hasSubGui(); + + // Mouse.getDWheel() clears the accumulated delta, so only the first caller in a frame + // ever sees it. Read it once here and let each widget take it in turn; anything that + // consumes it zeroes it so later widgets - the script editor, for one - are not left + // reading an already-drained wheel. + mouseScroll = Mouse.getDWheel(); + drawCenteredString(fontRendererObj, title, width / 2, guiTop + 4, 0xffffff); for (GuiNpcLabel label : labels.values()) label.drawLabel(this, fontRendererObj); for (GuiCustomScroll scroll : scrolls.values()) { scroll.updateSubGUI(subGui); - scroll.drawScreen(drawX, drawY, f, !subGui && scroll.isMouseOver(drawX, drawY) ? Mouse.getDWheel() : 0); + int delta = !subGui && scroll.isMouseOver(drawX, drawY) ? mouseScroll : 0; + if (delta != 0) + mouseScroll = 0; + scroll.drawScreen(drawX, drawY, f, delta); } for (GuiScrollWindow guiScrollableComponent : scrollWindows.values()) { - guiScrollableComponent.drawScreen(drawX, drawY, f, !subGui && guiScrollableComponent.isMouseOver(drawX, drawY) ? Mouse.getDWheel() : 0); + int delta = !subGui && guiScrollableComponent.isMouseOver(drawX, drawY) ? mouseScroll : 0; + if (delta != 0) + mouseScroll = 0; + guiScrollableComponent.drawScreen(drawX, drawY, f, delta); } for (GuiDiagram diagram : diagrams.values()) { diagram.drawDiagram(drawX, drawY, subGui); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java index 647621117..70283b7e0 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea.java @@ -624,9 +624,11 @@ public class GuiScriptTextArea extends GuiNpcTextField { int maxScroll = Math.max(0, getPaddedLineCount() - container.visibleLines); // Handle mouse wheel scroll - int wheelDelta = ((GuiNPCInterface) listener).mouseScroll = Mouse.getDWheel(); + // Take whatever the parent screen has left for this frame rather than polling the wheel + // again - the poll is destructive and the parent has already drained it. + int wheelDelta = listener instanceof GuiNPCInterface ? ((GuiNPCInterface) listener).mouseScroll : Mouse.getDWheel(); if (listener instanceof GuiNPCInterface) { - ((GuiNPCInterface) listener).mouseScroll = wheelDelta; + ((GuiNPCInterface) listener).mouseScroll = 0; // Intercept wheel scroll for tooltip (highest priority) // Only consume the wheel event when the tooltip actually has content to scroll; diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea1.java b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea1.java index 60e5a38a0..a5a555514 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea1.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScriptTextArea1.java @@ -486,9 +486,11 @@ public class GuiScriptTextArea1 extends GuiNpcTextField { int maxScroll = Math.max(0, getPaddedLineCount() - container.visibleLines); // Handle mouse wheel scroll - int wheelDelta = ((GuiNPCInterface) listener).mouseScroll = Mouse.getDWheel(); + // Take whatever the parent screen has left for this frame rather than polling the wheel + // again - the poll is destructive and the parent has already drained it. + int wheelDelta = listener instanceof GuiNPCInterface ? ((GuiNPCInterface) listener).mouseScroll : Mouse.getDWheel(); if (listener instanceof GuiNPCInterface) { - ((GuiNPCInterface) listener).mouseScroll = wheelDelta; + ((GuiNPCInterface) listener).mouseScroll = 0; boolean canScroll = !KEYS_OVERLAY.isVisible() || KEYS_OVERLAY.isVisible() && !KEYS_OVERLAY.aboveOverlay; if (wheelDelta != 0 && canScroll) scroll.applyWheelScroll(wheelDelta, maxScroll); From fab1062ce82308e6da9221ad41b111ed3dc4cfd9 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 05:52:30 -0400 Subject: [PATCH 24/24] Bump ModRev so the pBurnItem migration can run The migration sat in the npcVersion < 17 block, but ModRev has been 23 since 2023 and CheckNpcCompatibility returns early when the save already matches it - so every NPC affected by the regression was skipped. Moved to a < 24 block and bumped ModRev to 24 so it actually reaches them. --- .../noppes/npcs/VersionCompatibility.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/noppes/npcs/VersionCompatibility.java b/src/main/java/noppes/npcs/VersionCompatibility.java index 12562f15b..460d240e3 100644 --- a/src/main/java/noppes/npcs/VersionCompatibility.java +++ b/src/main/java/noppes/npcs/VersionCompatibility.java @@ -14,11 +14,21 @@ import java.util.Collection; import java.util.List; public class VersionCompatibility { - public static int ModRev = 23; + public static int ModRev = 24; public static void CheckNpcCompatibility(EntityNPCInterface npc, NBTTagCompound compound) { if (npc.npcVersion == ModRev) return; + if (npc.npcVersion < 24) { + // Fire projectiles used to ignite unconditionally. The ignite check now also requires + // pBurnItem, which reads false when the key is absent, so restore it for anything + // saved before the flag existed. + if (compound.hasKey("pEffect") && !compound.hasKey("pBurnItem")) { + if (EnumPotionType.fromOrdinal(compound.getInteger("pEffect")) == EnumPotionType.Fire) { + compound.setBoolean("pBurnItem", true); + } + } + } if (npc.npcVersion < 23) { if (compound.hasKey("AimWhileShooting")) { boolean aimShot = compound.getBoolean("AimWhileShooting"); @@ -50,14 +60,6 @@ public class VersionCompatibility { if (compound.hasKey("DialogDarkenScreen")) { compound.removeTag("DialogDarkenScreen"); } - - if (compound.hasKey("pEffect")) { - int effect = compound.getInteger("pEffect"); - EnumPotionType enumPotionType = EnumPotionType.fromOrdinal(effect); - if (!compound.hasKey("pBurnItem") && enumPotionType == EnumPotionType.Fire) { - compound.setBoolean("pBurnItem", true); - } - } } if (npc.npcVersion < 12) { CompatabilityFix(compound, npc.advanced.writeToNBT(new NBTTagCompound()));