Merge branch 'dev' into core

This commit is contained in:
Kam committed 2026-03-13 19:04:20 -04:00
commit cb6e1ca386
27 files changed
+646 -170

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@ plugins {
id "dts.typescript-generator"
}
version = "1.11"
version = "1.11.1"
group= "kamkeel.customnpc-plus"
archivesBaseName = "CustomNPC-Plus"
@@ -51,6 +51,16 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
*/
private int cooldownTicks = 100;
/**
* If true, only this chain goes on cooldown (not the global cooldown).
*/
private boolean perAbilityCooldown = false;
/**
* If true, skip cooldown entirely after chain completes.
*/
private boolean ignoreCooldown = false;
/**
* Minimum range for NPC eligibility check.
*/
@@ -159,6 +169,22 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
this.cooldownTicks = Math.max(0, cooldownTicks);
}
public boolean isPerAbilityCooldown() {
return perAbilityCooldown;
}
public void setPerAbilityCooldown(boolean perAbilityCooldown) {
this.perAbilityCooldown = perAbilityCooldown;
}
public boolean isIgnoreCooldown() {
return ignoreCooldown;
}
public void setIgnoreCooldown(boolean ignoreCooldown) {
this.ignoreCooldown = ignoreCooldown;
}
public float getMinRange() {
return minRange;
}
@@ -402,6 +428,8 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
nbt.setInteger("Weight", weight);
nbt.setBoolean("WindUpAll", windUpAll);
nbt.setInteger("CooldownTicks", cooldownTicks);
nbt.setBoolean("PerAbilityCooldown", perAbilityCooldown);
nbt.setBoolean("IgnoreCooldown", ignoreCooldown);
nbt.setFloat("MinRange", minRange);
nbt.setFloat("MaxRange", maxRange);
@@ -443,6 +471,8 @@ public class ChainedAbility implements IChainedAbility, IAbilityAction {
weight = nbt.hasKey("Weight") ? nbt.getInteger("Weight") : 10;
windUpAll = !nbt.hasKey("WindUpAll") || nbt.getBoolean("WindUpAll");
cooldownTicks = nbt.hasKey("CooldownTicks") ? nbt.getInteger("CooldownTicks") : 100;
perAbilityCooldown = nbt.getBoolean("PerAbilityCooldown");
ignoreCooldown = nbt.getBoolean("IgnoreCooldown");
minRange = nbt.getFloat("MinRange");
maxRange = nbt.hasKey("MaxRange") ? nbt.getFloat("MaxRange") : 20;
// AllowedBy is computed from child abilities
@@ -28,6 +28,7 @@ public final class JobSpawnerAddPacket extends AbstractPacket {
private String selected;
private int activeTab;
private String folderName;
private int slot;
private NBTTagCompound compound;
@@ -39,6 +40,15 @@ public final class JobSpawnerAddPacket extends AbstractPacket {
this.isServer = isServer;
this.selected = selected;
this.activeTab = activeTab;
this.folderName = null;
this.slot = slot;
}
public JobSpawnerAddPacket(boolean isServer, String selected, String folderName, int slot) {
this.isServer = isServer;
this.selected = selected;
this.activeTab = -1;
this.folderName = folderName;
this.slot = slot;
}
@@ -75,6 +85,9 @@ public final class JobSpawnerAddPacket extends AbstractPacket {
if (this.isServer) {
ByteBufUtils.writeString(out, selected);
out.writeInt(this.activeTab);
if (this.activeTab == -1) {
ByteBufUtils.writeString(out, folderName != null ? folderName : "");
}
out.writeInt(this.slot);
} else {
out.writeInt(this.slot);
@@ -96,7 +109,15 @@ public final class JobSpawnerAddPacket extends AbstractPacket {
JobSpawner job = (JobSpawner) npc.jobInterface;
boolean useServerClone = in.readBoolean();
if (useServerClone) {
NBTTagCompound compound = ServerCloneController.Instance.getCloneData(null, ByteBufUtils.readString(in), in.readInt());
String selected = ByteBufUtils.readString(in);
int tab = in.readInt();
NBTTagCompound compound;
if (tab == -1) {
String folder = ByteBufUtils.readString(in);
compound = ServerCloneController.Instance.getCloneData(null, selected, folder);
} else {
compound = ServerCloneController.Instance.getCloneData(null, selected, tab);
}
job.setJobCompound(in.readInt(), compound);
} else {
job.setJobCompound(in.readInt(), ByteBufUtils.readNBT(in));
+1 -1
View File
@@ -128,7 +128,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11")
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11.1")
public class CustomNpcs {
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
+18 -5
View File
@@ -199,11 +199,19 @@ public class DataAbilities extends AbstractDataAbilities {
@Override
protected void rollChainCooldown(ChainedAbility chain) {
int baseCooldown = minCooldown;
if (maxCooldown > minCooldown) {
baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1);
if (!chain.isIgnoreCooldown()) {
int baseCooldown = minCooldown;
if (maxCooldown > minCooldown) {
baseCooldown = minCooldown + random.nextInt(maxCooldown - minCooldown + 1);
}
cooldownEndTime = npc.worldObj.getTotalWorldTime() + 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());
}
cooldownEndTime = npc.worldObj.getTotalWorldTime() + baseCooldown + chain.getCooldownTicks();
}
@Override
@@ -471,12 +479,17 @@ public class DataAbilities extends AbstractDataAbilities {
return false;
}
// Per-ability cooldown filter: ability may have its own independent cooldown
// Per-ability cooldown filter: ability/chain may have its own independent cooldown
if (!action.isChain()) {
Ability ab = (Ability) action;
if (ab.isPerAbilityCooldown() && isOnPerAbilityCooldown(ab.getName())) {
return false;
}
} else {
ChainedAbility ch = (ChainedAbility) action;
if (ch.isPerAbilityCooldown() && isOnPerAbilityCooldown(ch.getName())) {
return false;
}
}
return true;
@@ -8,22 +8,26 @@ import net.minecraft.nbt.NBTTagDouble;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.client.controllers.ClientCloneController;
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiMenuSideButton;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.ICustomScrollListener;
import noppes.npcs.client.gui.util.IGuiData;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.controllers.data.CloneFolder;
import java.util.ArrayList;
import java.util.List;
public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiData {
public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiData, ICustomScrollListener {
private GuiCustomScroll scroll;
private GuiCustomScroll navScroll;
private List<String> list;
private List<String> navList = new ArrayList<String>();
private static String search = "";
public int activeTab = 1;
public String activeFolder = null;
public boolean isServer = false;
public GuiNpcMobSpawnerSelector() {
@@ -50,40 +54,62 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
addButton(new GuiNpcButton(0, guiLeft + 171, guiTop + 80, 80, 20, "gui.done"));
addButton(new GuiNpcButton(1, guiLeft + 171, guiTop + 103, 80, 20, "gui.cancel"));
addSideButton(new GuiMenuSideButton(21, guiLeft - 90, this.guiTop + 2, 90, 22, "1"));
addSideButton(new GuiMenuSideButton(22, guiLeft - 90, this.guiTop + 23, 90, 22, "2"));
addSideButton(new GuiMenuSideButton(23, guiLeft - 90, this.guiTop + 44, 90, 22, "3"));
addSideButton(new GuiMenuSideButton(24, guiLeft - 90, this.guiTop + 65, 90, 22, "4"));
addSideButton(new GuiMenuSideButton(25, guiLeft - 90, this.guiTop + 86, 90, 22, "5"));
addSideButton(new GuiMenuSideButton(26, guiLeft - 45, this.guiTop + 107, 45, 22, "6"));
addSideButton(new GuiMenuSideButton(27, guiLeft - 90, this.guiTop + 107, 45, 22, "7"));
addSideButton(new GuiMenuSideButton(28, guiLeft - 45, this.guiTop + 128, 45, 22, "8"));
addSideButton(new GuiMenuSideButton(29, guiLeft - 90, this.guiTop + 128, 45, 22, "9"));
addSideButton(new GuiMenuSideButton(30, guiLeft - 45, this.guiTop + 149, 45, 22, "10"));
addSideButton(new GuiMenuSideButton(31, guiLeft - 90, this.guiTop + 149, 45, 22, "11"));
addSideButton(new GuiMenuSideButton(32, guiLeft - 45, this.guiTop + 170, 45, 22, "12"));
addSideButton(new GuiMenuSideButton(33, guiLeft - 90, this.guiTop + 170, 45, 22, "13"));
addSideButton(new GuiMenuSideButton(34, guiLeft - 45, this.guiTop + 191, 45, 22, "14"));
addSideButton(new GuiMenuSideButton(35, guiLeft - 90, this.guiTop + 191, 45, 22, "15"));
// Navigation scroll (tabs + folders) replacing hardcoded side buttons
buildNavList();
if (navScroll == null) {
navScroll = new GuiCustomScroll(this, 1);
} else {
navScroll.clear();
}
navScroll.setSize(90, 210);
navScroll.guiLeft = guiLeft - 94;
navScroll.guiTop = guiTop + 2;
navScroll.setList(navList);
navScroll.setSelected(getNavSelection());
addScroll(navScroll);
getSideButton(20 + activeTab).active = true;
showClones();
}
private void buildNavList() {
navList.clear();
for (int i = 1; i <= 15; i++) {
navList.add("Tab " + i);
}
if (ClientCloneController.Instance != null) {
for (CloneFolder folder : ClientCloneController.Instance.getFolderList()) {
navList.add(folder.name);
}
}
}
private String getNavSelection() {
if (activeFolder != null) return activeFolder;
if (activeTab >= 1 && activeTab <= 15) return "Tab " + activeTab;
return "Tab 1";
}
public String getSelected() {
return scroll.getSelected();
}
private void showClones() {
if (isServer) {
PacketClient.sendClient(new CloneListPacket(activeTab));
if (activeFolder != null) {
PacketClient.sendClient(new CloneListPacket(activeFolder));
} else {
PacketClient.sendClient(new CloneListPacket(activeTab));
}
return;
}
ArrayList<String> list = new ArrayList<String>();
this.list = new ArrayList<String>(ClientCloneController.Instance.getClones(activeTab));
if (activeFolder != null && ClientCloneController.Instance != null) {
this.list = new ArrayList<String>(ClientCloneController.Instance.getClones(activeFolder));
} else if (ClientCloneController.Instance != null) {
this.list = new ArrayList<String>(ClientCloneController.Instance.getClones(activeTab));
} else {
this.list = new ArrayList<String>();
}
scroll.setList(getSearchList());
}
@@ -97,6 +123,7 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
}
private List<String> getSearchList() {
if (list == null) list = new ArrayList<String>();
if (search.isEmpty())
return new ArrayList<String>(list);
List<String> list = new ArrayList<String>();
@@ -112,8 +139,15 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
if (sel == null)
return null;
NBTTagCompound compound = ClientCloneController.Instance.getCloneData(player, sel, activeTab);
compound.setString("ClonedName", sel);
NBTTagCompound compound;
if (activeFolder != null && ClientCloneController.Instance != null) {
compound = ClientCloneController.Instance.getCloneData(player, sel, activeFolder);
} else {
compound = ClientCloneController.Instance.getCloneData(player, sel, activeTab);
}
if (compound != null) {
compound.setString("ClonedName", sel);
}
return compound;
}
@@ -126,9 +160,28 @@ public class GuiNpcMobSpawnerSelector extends SubGuiInterface implements IGuiDat
scroll.clear();
close();
}
if (id > 20) {
activeTab = id - 20;
initGui();
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
if (guiCustomScroll.id == 1) {
String selected = navScroll.getSelected();
if (selected == null) return;
if (selected.startsWith("Tab ")) {
try {
int tabNum = Integer.parseInt(selected.substring(4));
if (tabNum >= 1 && tabNum <= 15) {
activeTab = tabNum;
activeFolder = null;
}
} catch (NumberFormatException ignored) {
}
} else {
activeFolder = selected;
activeTab = -1;
}
showClones();
}
}
@@ -33,6 +33,7 @@ import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.function.BooleanSupplier;
import static kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition.MAX_CONDITIONS;
@@ -153,7 +154,11 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
fieldDefs.add(FieldDef.boolField("gui.enabled", chain::isEnabled, chain::setEnabled).tab("General"));
fieldDefs.add(FieldDef.intField("ability.weight", chain::getWeight, chain::setWeight).range(1, 100).tab("General"));
fieldDefs.add(FieldDef.boolField("ability.windUpAll", chain::isWindUpAll, chain::setWindUpAll).tab("General"));
fieldDefs.add(FieldDef.intField("ability.cooldown", chain::getCooldownTicks, chain::setCooldownTicks).range(0, 12000).tab("General"));
fieldDefs.add(FieldDef.row(
FieldDef.intField("ability.cooldown", chain::getCooldownTicks, chain::setCooldownTicks).range(0, 12000),
FieldDef.boolField("ability.perAbilityCooldown", chain::isPerAbilityCooldown, chain::setPerAbilityCooldown)
).tab("General"));
fieldDefs.add(FieldDef.boolField("ability.ignoreCooldown", chain::isIgnoreCooldown, chain::setIgnoreCooldown).tab("General"));
// ── Target tab ───────────────────────────────────────────────
fieldDefs.add(FieldDef.row(
@@ -163,16 +168,20 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
// ── Icon tab ──────────────────────────────────────────────
AbilityIconData chainIcon = AbilityIconData.fromChainedAbility(chain);
BooleanSupplier isCustomIcon = chainIcon::isEnabled;
fieldDefs.add(FieldDef.section("ability.section.icon").tab("Icon"));
fieldDefs.add(FieldDef.boolField("ability.hasIcon", chainIcon::isEnabled, chainIcon::setEnabled).tab("Icon"));
fieldDefs.add(FieldDef.row(
FieldDef.intField("gui.width", chainIcon::getWidth, chainIcon::setWidth).range(1, 256),
FieldDef.intField("gui.height", chainIcon::getHeight, chainIcon::setHeight).range(1, 256)
).tab("Icon"));
fieldDefs.add(FieldDef.floatField("gui.scale", chainIcon::getScale, chainIcon::setScale).tab("Icon").range(0.1f, 10.0f));
).tab("Icon").visibleWhen(isCustomIcon));
fieldDefs.add(FieldDef.floatField("gui.scale", chainIcon::getScale, chainIcon::setScale).tab("Icon").range(0.1f, 10.0f).visibleWhen(isCustomIcon));
fieldDefs.add(FieldDef.intField("ability.icon.layers", chainIcon::getLayerCount, chainIcon::setLayerCount)
.tab("Icon").range(1, AbilityIconData.MAX_LAYERS));
.tab("Icon").range(1, AbilityIconData.MAX_LAYERS).visibleWhen(isCustomIcon));
for (int i = 0; i < AbilityIconData.MAX_LAYERS; i++) {
final int idx = i;
java.util.function.BooleanSupplier layerVisible = () -> chainIcon.getLayerCount() > idx;
java.util.function.BooleanSupplier layerVisible = () -> isCustomIcon.getAsBoolean() && chainIcon.getLayerCount() > idx;
String sectionLabel = net.minecraft.util.StatCollector.translateToLocal("ability.icon.layer") + " " + (idx + 1);
fieldDefs.add(FieldDef.section(sectionLabel).tab("Icon").visibleWhen(layerVisible));
fieldDefs.add(FieldDef.textureSubGui("gui.texture",
@@ -194,12 +203,12 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
}
// Animation
fieldDefs.add(FieldDef.section("Animation").tab("Icon"));
fieldDefs.add(FieldDef.boolField("gui.animated", chainIcon::isAnimated, chainIcon::setAnimated).tab("Icon").hover("gui.animated.hover"));
fieldDefs.add(FieldDef.section("Animation").tab("Icon").visibleWhen(isCustomIcon));
fieldDefs.add(FieldDef.boolField("gui.animated", chainIcon::isAnimated, chainIcon::setAnimated).tab("Icon").hover("gui.animated.hover").visibleWhen(isCustomIcon));
fieldDefs.add(FieldDef.intField("gui.frameCount", chainIcon::getFrameCount, chainIcon::setFrameCount)
.tab("Icon").range(1, 256).visibleWhen(chainIcon::isAnimated));
.tab("Icon").range(1, 256).visibleWhen(() -> isCustomIcon.getAsBoolean() && chainIcon.isAnimated()));
fieldDefs.add(FieldDef.intField("gui.frameTime", chainIcon::getFrameTime, chainIcon::setFrameTime)
.tab("Icon").range(1, 100).visibleWhen(chainIcon::isAnimated));
.tab("Icon").range(1, 100).visibleWhen(() -> isCustomIcon.getAsBoolean() && chainIcon.isAnimated()));
// External field providers (e.g., DBC Addon injecting a "DBC" tab)
if (AbilityController.Instance != null) {
@@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.data.IAbilityAction;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.player.ability.AbilityHotbarSelectPacket;
@@ -638,9 +639,12 @@ public class AbilityHotbarComponent extends HudComponent {
String key = slots[slotIndex].abilityKey;
Ability ability = slots[slotIndex].ability;
IAbilityAction action = slots[slotIndex].action;
if (ability != null && ability.isPerAbilityCooldown()) {
return playerData.abilityData.getPerAbilityCooldownProgress(key);
} else if (action instanceof ChainedAbility && ((ChainedAbility) action).isPerAbilityCooldown()) {
return playerData.abilityData.getPerAbilityCooldownProgress(key);
} else {
return playerData.abilityData.getGlobalCooldownProgress();
}
@@ -184,8 +184,13 @@ public class GuiNpcSpawner extends GuiNPCInterface2 implements ITextfieldListene
GuiNpcMobSpawnerSelector selector = (GuiNpcMobSpawnerSelector) gui;
if (selector.isServer) {
String selected = selector.getSelected();
if (selected != null)
PacketClient.sendClient(new JobSpawnerAddPacket(selector.isServer, selected, selector.activeTab, slot));
if (selected != null) {
if (selector.activeFolder != null) {
PacketClient.sendClient(new JobSpawnerAddPacket(selector.isServer, selected, selector.activeFolder, slot));
} else {
PacketClient.sendClient(new JobSpawnerAddPacket(selector.isServer, selected, selector.activeTab, slot));
}
}
} else {
NBTTagCompound compound = selector.getCompound();
if (compound != null) {
@@ -1,5 +1,7 @@
package noppes.npcs.client.gui.util.script.autocomplete;
import noppes.npcs.client.gui.util.script.autocomplete.weighter.CompletionWeigher;
import noppes.npcs.client.gui.util.script.autocomplete.weighter.WeigherChain;
import noppes.npcs.client.gui.util.script.interpreter.field.FieldInfo;
import noppes.npcs.client.gui.util.script.interpreter.js_parser.JSFieldInfo;
import noppes.npcs.client.gui.util.script.interpreter.js_parser.JSMethodInfo;
@@ -142,7 +144,7 @@ public class AutocompleteItem implements Comparable<AutocompleteItem> {
signature,
method.getDocumentation(),
method,
false, // TODO: Check for @Deprecated annotation
method.getJavaMethod() != null && method.getJavaMethod().isAnnotationPresent(Deprecated.class),
false, // Methods don't require imports
null,
-1 // Java methods don't use inheritance depth sorting
@@ -578,8 +580,12 @@ public class AutocompleteItem implements Comparable<AutocompleteItem> {
}
/**
* Add a boost to the match score (e.g., from usage tracking).
* @deprecated Use {@link WeigherChain} instead. This method is no longer
* called by the autocomplete system. Score boosts are now handled by
* individual {@link CompletionWeigher} implementations that return
* independent comparable values per scoring dimension.
*/
@Deprecated
public void addScoreBoost(int boost) {
this.matchScore += boost;
}
@@ -600,6 +606,7 @@ public class AutocompleteItem implements Comparable<AutocompleteItem> {
public String getImportPath() { return importPath; }
public int getMatchScore() { return matchScore; }
public int[] getMatchIndices() { return matchIndices; }
public int getInheritanceDepth() { return inheritanceDepth; }
public int getColor() { return color; };
public AutocompleteItem setColor(int col){ this.color = col;return this; }
/**
@@ -723,6 +730,10 @@ public class AutocompleteItem implements Comparable<AutocompleteItem> {
}
}
/**
* Note: No longer used for autocomplete sorting (weigher chain used instead).
* Kept for backward compatibility and collections sorting.
*/
@Override
public int compareTo(AutocompleteItem other) {
// First by match score (descending) - this includes all penalties and boosts
@@ -0,0 +1,33 @@
package noppes.npcs.client.gui.util.script.autocomplete;
import noppes.npcs.client.gui.util.script.autocomplete.weighter.*;
import java.util.Arrays;
public class CompletionWeigherChains {
public static WeigherChain javaChain() {
return new WeigherChain(Arrays.asList(
new MatchQualityWeigher(),
new MemberKindWeigher(),
new ContextFitWeigher(),
new ImportStatusWeigher(),
new UsageFrequencyWeigher(),
new DeprecatedWeigher(),
new AlphabeticalWeigher()
));
}
public static WeigherChain jsChain() {
return new WeigherChain(Arrays.asList(
new MatchQualityWeigher(),
new MemberKindWeigher(),
new ContextFitWeigher(),
new ImportStatusWeigher(),
new UsageFrequencyWeigher(),
new InheritanceDepthWeigher(),
new DeprecatedWeigher(),
new AlphabeticalWeigher()
));
}
}
@@ -1,5 +1,6 @@
package noppes.npcs.client.gui.util.script.autocomplete;
import noppes.npcs.client.gui.util.script.autocomplete.weighter.WeigherChain;
import noppes.npcs.client.gui.util.script.interpreter.js_parser.*;
import noppes.npcs.client.gui.util.script.interpreter.field.EnumConstantInfo;
import noppes.npcs.client.gui.util.script.interpreter.field.FieldInfo;
@@ -8,7 +9,6 @@ import noppes.npcs.client.gui.util.script.interpreter.type.synthetic.*;
import noppes.npcs.client.gui.util.script.interpreter.type.ScriptTypeInfo;
import noppes.npcs.client.gui.util.script.interpreter.type.TypeChecker;
import noppes.npcs.client.gui.util.script.interpreter.type.TypeInfo;
import noppes.npcs.client.gui.util.script.interpreter.type.TypeResolver;
import noppes.npcs.config.ConfigScript;
import java.lang.reflect.Modifier;
@@ -350,6 +350,11 @@ public class JSAutocompleteProvider extends JavaAutocompleteProvider {
return UsageTracker.getJSInstance();
}
@Override
protected WeigherChain getWeigherChain() {
return CompletionWeigherChains.jsChain();
}
public String[] getKeywords() {
return TypeChecker.getJavaScriptKeywords();
}
@@ -1,5 +1,7 @@
package noppes.npcs.client.gui.util.script.autocomplete;
import noppes.npcs.client.gui.util.script.autocomplete.weighter.ScoringContext;
import noppes.npcs.client.gui.util.script.autocomplete.weighter.WeigherChain;
import noppes.npcs.client.gui.util.script.interpreter.ScriptDocument;
import noppes.npcs.client.gui.util.script.interpreter.field.EnumConstantInfo;
import noppes.npcs.client.gui.util.script.interpreter.field.FieldInfo;
@@ -81,12 +83,9 @@ public class JavaAutocompleteProvider implements AutocompleteProvider {
}
}
// Filter and score by prefix, then apply usage boosts and static penalties
// Filter by prefix, then sort using weigher chain
filterAndScore(items, context.prefix, context.isMemberAccess, isStaticContext, ownerFullName);
// Sort by score
Collections.sort(items);
return items;
}
@@ -315,8 +314,6 @@ public class JavaAutocompleteProvider implements AutocompleteProvider {
if (existingSimpleNames.contains(type.getSimpleName())) {
continue;
}
// Create an item that requires import
AutocompleteItem item = new AutocompleteItem.Builder()
.name(type.getSimpleName())
.insertText(type.getSimpleName())
@@ -371,126 +368,31 @@ public class JavaAutocompleteProvider implements AutocompleteProvider {
return UsageTracker.getJavaInstance();
}
/**
* Filter items by prefix, calculate match scores, apply usage boosts, and penalize static members in instance contexts.
*/
protected void filterAndScore(List<AutocompleteItem> items, String prefix,
protected WeigherChain getWeigherChain() {
return CompletionWeigherChains.javaChain();
}
protected void filterAndScore(List<AutocompleteItem> items, String prefix,
boolean isMemberAccess, boolean isStaticContext, String ownerFullName) {
UsageTracker tracker = getUsageTracker();
if (prefix == null || prefix.isEmpty()) {
// No filtering needed, all items get a base score + usage boost
for (AutocompleteItem item : items) {
item.calculateMatchScore("", false);
applyUsageBoost(item, tracker, ownerFullName);
applyStaticPenalty(item, isMemberAccess, isStaticContext);
applyObjectMethodPenalty(item);
applyKeywordPenalty(item, prefix);
}
return;
}
// For non-member access (first word), require strict prefix matching
// For member access (after dot), allow fuzzy/contains matching
boolean requirePrefix = !isMemberAccess;
// Filter, score, apply usage boosts, and apply penalties
Iterator<AutocompleteItem> iter = items.iterator();
while (iter.hasNext()) {
AutocompleteItem item = iter.next();
int score = item.calculateMatchScore(prefix, requirePrefix);
int score = item.calculateMatchScore(
prefix != null ? prefix : "", requirePrefix);
if (score < 0) {
iter.remove();
} else {
applyUsageBoost(item, tracker, ownerFullName);
applyStaticPenalty(item, isMemberAccess, isStaticContext);
applyObjectMethodPenalty(item);
applyKeywordPenalty(item, prefix);
}
}
}
/**
* Apply usage-based score boost to an item.
*/
protected void applyUsageBoost(AutocompleteItem item, UsageTracker tracker, String ownerFullName) {
int usageCount = tracker.getUsageCount(item, ownerFullName);
int boost = UsageTracker.calculateUsageBoost(usageCount);
item.addScoreBoost(boost);
}
/**
* Apply penalty to static members when accessed in a non-static (instance) context.
* This matches IntelliJ's behavior where static members are deprioritized when
* accessing through an instance (e.g., Minecraft.getMinecraft().getMinecraft()).
* However, if the item is a very strong match (exact prefix), don't penalize as much.
*/
protected void applyStaticPenalty(AutocompleteItem item, boolean isMemberAccess, boolean isStaticContext) {
// Only apply penalty in member access contexts (after dot)
if (!isMemberAccess) {
return;
}
// Only penalize when we're in an instance context (not static)
if (isStaticContext) {
return;
}
boolean isStatic = item.isStatic();
// Apply penalty to static members in instance context
if (isStatic) {
int matchScore = item.getMatchScore();
// Strong prefix matches (score >= 800) get a lighter penalty
// Weaker matches get pushed down more aggressively
if (matchScore >= 800) {
// Light penalty for exact prefix matches - just deprioritize slightly
item.addScoreBoost(-200);
} else {
// Heavy penalty for fuzzy/substring matches - push to bottom
item.addScoreBoost(-matchScore);
}
}
}
/**
* Apply penalty to inherited Object methods to push them to bottom.
* Strong matches get lighter penalty, weak matches get pushed all the way down.
*/
protected void applyObjectMethodPenalty(AutocompleteItem item) {
if (!item.isInheritedObjectMethod()) {
return;
}
int matchScore = item.getMatchScore();
// Strong prefix matches (score >= 900) get a moderate penalty
// Everything else gets pushed to the very bottom
if (matchScore >= 900) {
// Strong match - moderate penalty to keep it visible but below normal methods
item.addScoreBoost(-500);
} else {
// Weak match - heavy penalty to push to bottom
item.addScoreBoost(-10000);
}
}
/**
* Push keywords below non-keywords unless user typed a longer prefix.
*/
protected void applyKeywordPenalty(AutocompleteItem item, String prefix) {
if (item.getKind() != AutocompleteItem.Kind.KEYWORD) {
return;
}
ScoringContext context = new ScoringContext(
prefix, isMemberAccess, isStaticContext,
ownerFullName, getUsageTracker(), requirePrefix
);
if (prefix == null || prefix.length() < 2) {
item.addScoreBoost(-10000);
}
}
/**
* Builder class for AutocompleteItem to handle cases without source data.
*/
private static class AutocompleteItemBuilder {
// This would be needed if AutocompleteItem had a builder pattern
WeigherChain weigherChain = getWeigherChain();
Comparator<AutocompleteItem> comparator = weigherChain.buildComparator(context);
items.sort(comparator);
}
}
@@ -122,7 +122,7 @@ public class UsageTracker {
// ==================== INSTANCE METHODS ====================
private UsageTracker(String filename) {
UsageTracker(String filename) {
File dir = getDir();
this.file = new File(dir, filename);
}
@@ -0,0 +1,15 @@
package noppes.npcs.client.gui.util.script.autocomplete.weighter;
import noppes.npcs.client.gui.util.script.autocomplete.AutocompleteItem;
public class AlphabeticalWeigher extends CompletionWeigher {
public AlphabeticalWeigher() {
super("alphabetical");
}
@Override
public Comparable<?> weigh(AutocompleteItem item, ScoringContext context) {
return item.getName().toLowerCase();
}
}
@@ -0,0 +1,40 @@
package noppes.npcs.client.gui.util.script.autocomplete.weighter;
import noppes.npcs.client.gui.util.script.autocomplete.AutocompleteItem;
/**
* A single scoring dimension for autocomplete ranking.
*
* Weighers are evaluated in chain order. For each pair of items being compared,
* the first weigher to return non-equal values determines the ordering.
*
* Contract:
* - weigh() MUST be a pure function (no side effects, no mutations)
* - weigh() MUST return consistent results for the same item+context
* - weigh() MAY return null to abstain (treated as equal for this weigher)
* - Lower Comparable values = higher priority (shown first) unless negated
*
* Modeled after IntelliJ's LookupElementWeigher (Apache 2.0).
*/
public abstract class CompletionWeigher {
private final String id;
private final boolean negated;
protected CompletionWeigher(String id, boolean negated) {
this.id = id;
this.negated = negated;
}
protected CompletionWeigher(String id) {
this(id, false);
}
public abstract Comparable<?> weigh(AutocompleteItem item, ScoringContext context);
public String getId() { return id; }
public boolean isNegated() { return negated; }
@Override
public String toString() { return id; }
}
@@ -0,0 +1,38 @@
package noppes.npcs.client.gui.util.script.autocomplete.weighter;
import noppes.npcs.client.gui.util.script.autocomplete.AutocompleteItem;
/**
* How well does this item fit the current access context?
*
* Combines what were previously applyStaticPenalty() and applyObjectMethodPenalty().
* Uses ordered enum categories, eliminating all magic threshold numbers.
*/
public class ContextFitWeigher extends CompletionWeigher {
public enum ContextFit {
/** Item naturally belongs in this context. */
NATURAL,
/** Static member accessed through an instance — legal but bad style. */
WRONG_STATIC_CONTEXT,
/** Inherited Object method (wait, notify, hashCode, getClass, etc.) */
OBJECT_METHOD
}
public ContextFitWeigher() {
super("contextFit");
}
@Override
public Comparable<?> weigh(AutocompleteItem item, ScoringContext context) {
if (item.isInheritedObjectMethod()) {
return ContextFit.OBJECT_METHOD;
}
if (context.isMemberAccess && !context.isStaticContext && item.isStatic()) {
return ContextFit.WRONG_STATIC_CONTEXT;
}
return ContextFit.NATURAL;
}
}
@@ -0,0 +1,15 @@
package noppes.npcs.client.gui.util.script.autocomplete.weighter;
import noppes.npcs.client.gui.util.script.autocomplete.AutocompleteItem;
public class DeprecatedWeigher extends CompletionWeigher {
public DeprecatedWeigher() {
super("deprecated");
}
@Override
public Comparable<?> weigh(AutocompleteItem item, ScoringContext context) {
return item.isDeprecated();
}
}
@@ -0,0 +1,27 @@
package noppes.npcs.client.gui.util.script.autocomplete.weighter;
import noppes.npcs.client.gui.util.script.autocomplete.AutocompleteItem;
/**
* Demote unimported classes below imported ones.
*
* Fixes the bug where the unimported class penalty (-500) was applied at
* creation time and overwritten by calculateMatchScore(). In the chain model,
* import status is a separate dimension that can never be overwritten.
*/
public class ImportStatusWeigher extends CompletionWeigher {
public enum ImportStatus {
IMPORTED,
UNIMPORTED
}
public ImportStatusWeigher() {
super("importStatus");
}
@Override
public Comparable<?> weigh(AutocompleteItem item, ScoringContext context) {
return item.requiresImport() ? ImportStatus.UNIMPORTED : ImportStatus.IMPORTED;
}
}
@@ -0,0 +1,26 @@
package noppes.npcs.client.gui.util.script.autocomplete.weighter;
import noppes.npcs.client.gui.util.script.autocomplete.AutocompleteItem;
/**
* Prefer members defined closer in the inheritance tree.
* Child class members rank above parent class members.
*
* Only meaningful for JS/.d.ts types where inheritance depth is tracked.
* For items without inheritance tracking (depth < 0), this weigher abstains.
*/
public class InheritanceDepthWeigher extends CompletionWeigher {
public InheritanceDepthWeigher() {
super("inheritanceDepth");
}
@Override
public Comparable<?> weigh(AutocompleteItem item, ScoringContext context) {
int depth = item.getInheritanceDepth();
if (depth < 0) {
return null;
}
return depth;
}
}
@@ -0,0 +1,22 @@
package noppes.npcs.client.gui.util.script.autocomplete.weighter;
import noppes.npcs.client.gui.util.script.autocomplete.AutocompleteItem;
/**
* Text match quality against the user's prefix.
* PRIMARY sort dimension — how well the item name matches what was typed.
*
* Returns the existing calculateMatchScore() result, negated so that
* higher scores = higher priority.
*/
public class MatchQualityWeigher extends CompletionWeigher {
public MatchQualityWeigher() {
super("matchQuality", true);
}
@Override
public Comparable<?> weigh(AutocompleteItem item, ScoringContext context) {
return item.getMatchScore();
}
}
@@ -0,0 +1,56 @@
package noppes.npcs.client.gui.util.script.autocomplete.weighter;
import noppes.npcs.client.gui.util.script.autocomplete.AutocompleteItem;
import noppes.npcs.client.gui.util.script.interpreter.type.TypeInfo;
public class MemberKindWeigher extends CompletionWeigher {
public enum MemberKind {
ENUM_CONSTANT,
LOCAL_VARIABLE,
INSTANCE_FIELD,
INSTANCE_METHOD,
TYPE_CLASS,
TYPE_ENUM,
TYPE_INTERFACE,
STATIC_FIELD,
STATIC_METHOD,
KEYWORD,
SNIPPET
}
public MemberKindWeigher() {
super("memberKind");
}
@Override
public Comparable<?> weigh(AutocompleteItem item, ScoringContext context) {
switch (item.getKind()) {
case ENUM_CONSTANT: return MemberKind.ENUM_CONSTANT;
case PARAMETER: return MemberKind.LOCAL_VARIABLE;
case VARIABLE: return MemberKind.LOCAL_VARIABLE;
case METHOD:
return item.isStatic() ? MemberKind.STATIC_METHOD : MemberKind.INSTANCE_METHOD;
case FIELD:
return item.isStatic() ? MemberKind.STATIC_FIELD : MemberKind.INSTANCE_FIELD;
case CLASS: return resolveTypeTier(item);
case ENUM: return MemberKind.TYPE_ENUM;
case KEYWORD: return MemberKind.KEYWORD;
case SNIPPET: return MemberKind.SNIPPET;
default: return MemberKind.INSTANCE_FIELD;
}
}
private MemberKind resolveTypeTier(AutocompleteItem item) {
Object source = item.getSourceData();
if (source instanceof TypeInfo) {
TypeInfo typeInfo = (TypeInfo) source;
switch (typeInfo.getKind()) {
case INTERFACE: return MemberKind.TYPE_INTERFACE;
case ENUM: return MemberKind.TYPE_ENUM;
default: return MemberKind.TYPE_CLASS;
}
}
return MemberKind.TYPE_CLASS;
}
}
@@ -0,0 +1,27 @@
package noppes.npcs.client.gui.util.script.autocomplete.weighter;
import noppes.npcs.client.gui.util.script.autocomplete.UsageTracker;
/**
* Immutable context for a single scoring pass.
* Created once when suggestions are requested, shared by all weighers.
*/
public class ScoringContext {
public final String prefix;
public final boolean isMemberAccess;
public final boolean isStaticContext;
public final String ownerFullName;
public final UsageTracker usageTracker;
public final boolean requirePrefix;
public ScoringContext(String prefix, boolean isMemberAccess, boolean isStaticContext,
String ownerFullName, UsageTracker usageTracker, boolean requirePrefix) {
this.prefix = prefix;
this.isMemberAccess = isMemberAccess;
this.isStaticContext = isStaticContext;
this.ownerFullName = ownerFullName;
this.usageTracker = usageTracker;
this.requirePrefix = requirePrefix;
}
}
@@ -0,0 +1,25 @@
package noppes.npcs.client.gui.util.script.autocomplete.weighter;
import noppes.npcs.client.gui.util.script.autocomplete.AutocompleteItem;
import noppes.npcs.client.gui.util.script.autocomplete.UsageTracker;
/**
* Boost items the user has selected before.
* Uses logarithmic scaling with a cap via UsageTracker.calculateUsageBoost().
* Negated: higher usage count = higher priority.
*/
public class UsageFrequencyWeigher extends CompletionWeigher {
public UsageFrequencyWeigher() {
super("usageFrequency", true);
}
@Override
public Comparable<?> weigh(AutocompleteItem item, ScoringContext context) {
if (context.usageTracker == null) {
return 0;
}
int usageCount = context.usageTracker.getUsageCount(item, context.ownerFullName);
return UsageTracker.calculateUsageBoost(usageCount);
}
}
@@ -0,0 +1,81 @@
package noppes.npcs.client.gui.util.script.autocomplete.weighter;
import noppes.npcs.client.gui.util.script.autocomplete.AutocompleteItem;
import java.util.*;
/**
* An ordered list of weighers that produces a Comparator for sorting autocomplete items.
*
* Items are compared dimension-by-dimension through the chain.
* The first weigher to produce a non-equal comparison determines the ordering.
* If all weighers return equal, items are considered equivalent (stable sort preserves
* insertion order).
*
* Simplified from IntelliJ's CompletionSorterImpl — uses Comparator instead of a
* classifier tree since we sort all items in a single batch.
*/
public class WeigherChain {
private final List<CompletionWeigher> weighers;
public WeigherChain(List<CompletionWeigher> weighers) {
this.weighers = Collections.unmodifiableList(new ArrayList<>(weighers));
}
/**
* Build a Comparator that evaluates items through the weigher chain.
*
* Weigher results are cached per item via IdentityHashMap to avoid
* recomputing weights during O(N log N) comparisons.
*/
public Comparator<AutocompleteItem> buildComparator(ScoringContext context) {
final Map<AutocompleteItem, Comparable<?>[]> cache = new IdentityHashMap<>();
final int chainLength = weighers.size();
return (a, b) -> {
Comparable<?>[] weightsA = cache.computeIfAbsent(a, k -> computeWeights(k, context));
Comparable<?>[] weightsB = cache.computeIfAbsent(b, k -> computeWeights(k, context));
for (int i = 0; i < chainLength; i++) {
Comparable<?> wA = weightsA[i];
Comparable<?> wB = weightsB[i];
if (wA == null && wB == null) continue;
if (wA == null) return 1;
if (wB == null) return -1;
@SuppressWarnings("unchecked")
int cmp = ((Comparable<Object>) wA).compareTo(wB);
if (cmp != 0) {
return weighers.get(i).isNegated() ? -cmp : cmp;
}
}
return 0;
};
}
private Comparable<?>[] computeWeights(AutocompleteItem item, ScoringContext context) {
Comparable<?>[] weights = new Comparable<?>[weighers.size()];
for (int i = 0; i < weighers.size(); i++) {
weights[i] = weighers.get(i).weigh(item, context);
}
return weights;
}
/**
* Get all weigher results for an item (for debugging/testing).
*/
public Map<String, Comparable<?>> debugWeights(AutocompleteItem item, ScoringContext context) {
Map<String, Comparable<?>> result = new LinkedHashMap<>();
for (CompletionWeigher weigher : weighers) {
result.put(weigher.getId(), weigher.weigh(item, context));
}
return result;
}
public List<CompletionWeigher> getWeighers() {
return weighers;
}
}
@@ -237,9 +237,19 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
@Override
protected void rollChainCooldown(ChainedAbility chain) {
if (chain.isIgnoreCooldown()) return;
int duration = chain.getCooldownTicks();
cooldownEndTime = getWorldTime() + duration;
globalCooldownDuration = duration;
long endTime = getWorldTime() + duration;
if (chain.isPerAbilityCooldown()) {
if (currentAbilityKey != null) {
setPerAbilityCooldown(currentAbilityKey, endTime, duration);
}
} else {
cooldownEndTime = endTime;
globalCooldownDuration = duration;
}
}
@Override
@@ -403,7 +413,14 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
// Dispatch: chain vs ability
if (action.isChain()) {
if (isOnCooldown()) return false;
ChainedAbility chain = (ChainedAbility) action;
if (!chain.isIgnoreCooldown()) {
if (chain.isPerAbilityCooldown()) {
if (isOnPerAbilityCooldown(key)) return false;
} else {
if (isOnCooldown()) return false;
}
}
currentAbilityKey = key;
currentTarget = null;
@@ -1736,6 +1736,7 @@ ability.weight=Weight
ability.windUpTicks=Wind Up
ability.cooldownTicks=Cooldown
ability.perAbilityCooldown=Per-Ability
ability.ignoreCooldown=Ignore Cooldown
ability.freeOnCast=Free on Cast
ability.hover.freeOnCast=Ability enters cooldown immediately after entities are spawned, allowing the caster to use other abilities while summoned entities remain active
ability.freeAim=Free Aim