Merge branch 'dev' into syntax-highlighter-unified

This commit is contained in:
Kam committed 2026-02-22 16:46:18 -05:00
commit c0ce53a814
150 files changed
+3376 -1479

No files matched your search

@@ -4,8 +4,8 @@ import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityAction;
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.ChainedAbilityEntry;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.data.entry.ChainedAbilityEntry;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.ability.AbilitiesGetAllPacket;
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcGetPacket;
@@ -84,8 +84,12 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface implements ISubGui
@Override
public void subGuiClosed(SubGuiInterface subgui) {
if (subgui instanceof SubGuiDuplicateNameConfirm) {
if (((SubGuiDuplicateNameConfirm) subgui).isConfirmed()) {
SubGuiDuplicateNameConfirm confirm = (SubGuiDuplicateNameConfirm) subgui;
if (confirm.isConfirmed()) {
doSave();
} else if (confirm.isBack()) {
// Keep this save-confirm dialog open.
return;
} else {
close();
}
@@ -4,11 +4,11 @@ import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityAction;
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.ChainedAbilityEntry;
import kamkeel.npcs.controllers.data.ability.AbilityIconData;
import kamkeel.npcs.controllers.data.ability.IChainedAbilityFieldProvider;
import kamkeel.npcs.controllers.data.ability.UserType;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.data.entry.ChainedAbilityEntry;
import kamkeel.npcs.controllers.data.ability.data.AbilityIconData;
import kamkeel.npcs.controllers.data.ability.gui.IChainedAbilityFieldProvider;
import kamkeel.npcs.controllers.data.ability.enums.UserType;
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.ability.CustomAbilitySavePacket;
@@ -563,6 +563,8 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
return true;
case 2: // Up
if (entryIndex > 0) {
// Commit any focused delay field before reordering
GuiNpcTextField.unfocus();
ChainedAbilityEntry entry = entries.remove(entryIndex);
entries.add(entryIndex - 1, entry);
// Can't be concurrent at position 0
@@ -574,12 +576,16 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
return true;
case 3: // Down
if (entryIndex < entries.size() - 1) {
// Commit any focused delay field before reordering
GuiNpcTextField.unfocus();
ChainedAbilityEntry entry = entries.remove(entryIndex);
entries.add(entryIndex + 1, entry);
initGui();
}
return true;
case 4: // Delete
// Commit any focused delay field before removing
GuiNpcTextField.unfocus();
entries.remove(entryIndex);
initGui();
return true;
@@ -10,7 +10,13 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
*/
public class SubGuiDuplicateNameConfirm extends SubGuiInterface {
private boolean confirmed = false;
public enum Result {
CONTINUE,
BACK,
CANCEL
}
private Result result = Result.CANCEL;
public SubGuiDuplicateNameConfirm() {
setBackground("menubg.png");
@@ -26,22 +32,38 @@ public class SubGuiDuplicateNameConfirm extends SubGuiInterface {
addLabel(new GuiNpcLabel(0, "ability.duplicate.name", guiLeft + 10, y));
y += 30;
addButton(new GuiNpcButton(0, guiLeft + 20, y, 80, 20, "gui.continue"));
addButton(new GuiNpcButton(1, guiLeft + 120, y, 80, 20, "gui.cancel"));
addButton(new GuiNpcButton(0, guiLeft + 10, y, 65, 20, "gui.continue"));
addButton(new GuiNpcButton(1, guiLeft + 78, y, 65, 20, "gui.back"));
addButton(new GuiNpcButton(2, guiLeft + 146, y, 65, 20, "gui.cancel"));
}
@Override
public void buttonEvent(GuiButton guibutton) {
if (guibutton.id == 0) {
confirmed = true;
result = Result.CONTINUE;
close();
} else if (guibutton.id == 1) {
confirmed = false;
result = Result.BACK;
close();
} else if (guibutton.id == 2) {
result = Result.CANCEL;
close();
}
}
public Result getResult() {
return result;
}
public boolean isConfirmed() {
return confirmed;
return result == Result.CONTINUE;
}
public boolean isBack() {
return result == Result.BACK;
}
public boolean isCancelled() {
return result == Result.CANCEL;
}
}
@@ -245,6 +245,9 @@ public class GuiFieldBuilder {
case STRING: {
String sVal = def.getValue() != null ? def.getValue().toString() : "";
GuiNpcTextField tf = new GuiNpcTextField(widgetId, parent, fontRenderer, fieldX, y, fieldW, 20, sVal);
if ("gui.name".equals(def.getLabel())) {
tf.setFileNameSafe();
}
if (!def.isEnabled()) tf.setEnabled(false);
if (hover != null) tf.setHoverText(hover);
sw.addTextField(tf);
@@ -3,7 +3,7 @@ package noppes.npcs.client.gui.global;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.ability.BuiltInAbilityGetPacket;
import kamkeel.npcs.network.packets.request.ability.ChainedAbilitiesGetPacket;
@@ -24,8 +24,8 @@ import noppes.npcs.client.gui.advanced.SubGuiAbilityTypeSelect;
import noppes.npcs.client.gui.advanced.SubGuiAbilityVariantSelect;
import noppes.npcs.client.gui.advanced.SubGuiChainedAbilityConfig;
import noppes.npcs.client.gui.advanced.SubGuiDuplicateNameConfirm;
import noppes.npcs.client.gui.util.AbilityPreviewExecutor;
import noppes.npcs.client.gui.util.GuiAbilityInterface;
import kamkeel.npcs.controllers.data.ability.preview.AbilityPreviewExecutor;
import kamkeel.npcs.controllers.data.ability.gui.GuiAbilityInterface;
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
@@ -104,7 +104,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
// ==================== PENDING SAVE ====================
private Ability pendingSaveAbility = null;
private boolean pendingNewCreation = false;
// ==================== PENDING VARIANT ====================
private String pendingTypeId = null;
@@ -511,13 +510,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
if (newAbility != null) {
gui.getVariants().get(idx).apply(newAbility);
if (hasDuplicateName(newAbility)) {
pendingSaveAbility = newAbility;
pendingNewCreation = true;
pendingTypeId = null;
setSubGui(new SubGuiDuplicateNameConfirm());
return true;
}
pendingTypeId = null;
openConfig(newAbility);
return true;
@@ -544,12 +536,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
if (variants.size() == 1) {
variants.get(0).apply(newAbility);
}
if (hasDuplicateName(newAbility)) {
pendingSaveAbility = newAbility;
pendingNewCreation = true;
setSubGui(new SubGuiDuplicateNameConfirm());
return true;
}
openConfig(newAbility);
return true;
}
@@ -561,27 +547,22 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
* @return true if a SubGui was opened (caller should return early, skipping initGui)
*/
private boolean handleDuplicateNameClosed(SubGuiDuplicateNameConfirm gui) {
if (gui.isConfirmed() && pendingSaveAbility != null) {
if (pendingNewCreation) {
openConfig(pendingSaveAbility);
pendingSaveAbility = null;
pendingNewCreation = false;
return true;
} else {
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
pendingSaveAbility = null;
}
} else if (pendingSaveAbility != null) {
if (pendingNewCreation) {
pendingSaveAbility = null;
pendingNewCreation = false;
} else {
Ability ability = pendingSaveAbility;
pendingSaveAbility = null;
setSubGui(ability.createConfigGui(this));
return true;
}
if (pendingSaveAbility == null) return false;
if (gui.isConfirmed()) {
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
pendingSaveAbility = null;
return false;
}
if (gui.isBack()) {
Ability ability = pendingSaveAbility;
pendingSaveAbility = null;
setSubGui(ability.createConfigGui(this));
return true;
}
pendingSaveAbility = null;
return false;
}
@@ -590,7 +571,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
*/
private boolean handlePendingSave() {
if (hasDuplicateName(pendingSaveAbility)) {
pendingNewCreation = false;
setSubGui(new SubGuiDuplicateNameConfirm());
return true;
}
@@ -4,11 +4,12 @@ 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.IAbilityAction;
import kamkeel.npcs.controllers.data.ability.data.IAbilityAction;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.player.ability.AbilityHotbarSelectPacket;
import net.minecraft.client.Minecraft;
import noppes.npcs.client.ClientProxy;
import noppes.npcs.client.ClientAbilityState;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.ScaledResolution;
@@ -189,6 +190,7 @@ public class AbilityHotbarComponent extends HudComponent {
int centerX = overlayWidth / 2;
int centerY = overlayHeight / 2;
boolean activePhase = ClientAbilityState.activePhase;
// Compute text visibility: 0=Shown, 1=Hidden, 2=Held
boolean showText;
@@ -246,16 +248,16 @@ public class AbilityHotbarComponent extends HudComponent {
if (rawSlotIndex == -1) {
// Deselect slot — draw empty marker
drawDeselectSlot(cx, cy, scaledSize, isCenter, slotAlpha);
drawDeselectSlot(cx, cy, scaledSize, isCenter, slotAlpha, activePhase);
} else {
slots[rawSlotIndex].drawCarousel(mc, sr, slotCooldown, cx, cy, scaledSize, isCenter, slotAlpha, showText);
slots[rawSlotIndex].drawCarousel(mc, sr, slotCooldown, cx, cy, scaledSize, isCenter, slotAlpha, showText, activePhase);
}
}
GL11.glPopMatrix();
}
private void drawDeselectSlot(int cx, int cy, int size, boolean isCenter, float alpha) {
private void drawDeselectSlot(int cx, int cy, int size, boolean isCenter, float alpha, boolean activePhase) {
float radius = size / 2f;
float baseAlpha = isCenter ? 0.9f : 0.6f;
float a = baseAlpha * alpha;
@@ -268,7 +270,13 @@ public class AbilityHotbarComponent extends HudComponent {
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
if (isCenter) {
if (activePhase) {
if (isCenter) {
GL11.glColor4f(0.65f, 0.14f, 0.14f, a);
} else {
GL11.glColor4f(0.38f, 0.10f, 0.10f, a);
}
} else if (isCenter) {
GL11.glColor4f(0.5f, 0.2f, 0.2f, a);
} else {
GL11.glColor4f(0.3f, 0.3f, 0.3f, a);
@@ -292,7 +300,13 @@ public class AbilityHotbarComponent extends HudComponent {
}
// Draw X mark
if (isCenter) {
if (activePhase) {
if (isCenter) {
GL11.glColor4f(1.0f, 0.45f, 0.35f, alpha);
} else {
GL11.glColor4f(0.75f, 0.30f, 0.30f, alpha * 0.8f);
}
} else if (isCenter) {
GL11.glColor4f(0.8f, 0.4f, 0.4f, alpha);
} else {
GL11.glColor4f(0.5f, 0.5f, 0.5f, alpha * 0.8f);
@@ -3,8 +3,8 @@ package noppes.npcs.client.gui.hud.ability;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.IAbilityAction;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.data.IAbilityAction;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
@@ -48,7 +48,7 @@ public class AbilityHotbarSlotRenderer extends Gui {
public void drawCarousel(Minecraft mc, ScaledResolution sr, float cooldownProgress,
int cx, int cy, int size, boolean isCenter, float slotAlpha,
boolean showText) {
boolean showText, boolean activePhase) {
float nameAlpha = this.nameAlpha;
boolean isHorizontal = ConfigClient.AbilityHotbarHorizontal;
if (size <= 0 || slotAlpha <= 0) return;
@@ -61,21 +61,54 @@ public class AbilityHotbarSlotRenderer extends Gui {
boolean altTexture = ConfigClient.AbilityHotbarAltTexture;
if (altTexture) {
drawRoundedRect(-radius, -radius, radius, radius, 0.6f, 0.6f, 0.6f, 0.75f * alpha, false);
float fillR;
float fillG;
float fillB;
float outlineR;
float outlineG;
float outlineB;
if (activePhase) {
if (isCenter) {
drawRoundedRect(-radius, -radius, radius, radius, 0.8f, 0.8f, 0.2f, alpha, true);
fillR = 0.95f;
fillG = 0.26f;
fillB = 0.22f;
outlineR = 1.0f;
outlineG = 0.52f;
outlineB = 0.28f;
} else {
drawRoundedRect(-radius, -radius, radius, radius, 0.4f, 0.4f, 0.4f, alpha * 0.8f, true);
fillR = 0.36f;
fillG = 0.14f;
fillB = 0.14f;
outlineR = 0.65f;
outlineG = 0.22f;
outlineB = 0.20f;
}
} else if (isCenter) {
fillR = 0.8f;
fillG = 0.8f;
fillB = 0.2f;
outlineR = 0.8f;
outlineG = 0.8f;
outlineB = 0.2f;
} else {
if (isCenter) {
drawCircle(radius, 0.8f, 0.8f, 0.2f, 0.66f * alpha, false);
drawCircle(radius, 0.8f, 0.8f, 0.2f, alpha, true);
} else {
drawCircle(radius, 1f, 1f, 1f, 0.66f * alpha, false);
drawCircle(radius, 0.4f, 0.4f, 0.4f, alpha * 0.8f, true);
}
fillR = 0.4f;
fillG = 0.4f;
fillB = 0.4f;
outlineR = 1f;
outlineG = 1f;
outlineB = 1f;
}
if (altTexture) {
float baseR = activePhase ? 0.30f : 0.6f;
float baseG = activePhase ? 0.12f : 0.6f;
float baseB = activePhase ? 0.12f : 0.6f;
drawRoundedRect(-radius, -radius, radius, radius, baseR, baseG, baseB, 0.75f * alpha, false);
drawRoundedRect(-radius, -radius, radius, radius, fillR, fillG, fillB, alpha * 0.8f, true);
} else {
drawCircle(radius, outlineR, outlineG, outlineB, 0.66f * alpha, false);
drawCircle(radius, fillR, fillG, fillB, alpha * 0.8f, true);
}
// Ability icon
@@ -3,9 +3,9 @@ package noppes.npcs.client.gui.hud.ability;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityIconData;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.IAbilityAction;
import kamkeel.npcs.controllers.data.ability.data.AbilityIconData;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.data.IAbilityAction;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.Tessellator;
@@ -2,8 +2,8 @@ package noppes.npcs.client.gui.player.inventory;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.IAbilityAction;
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.AbilityHotbarSavePacket;
import kamkeel.npcs.network.packets.player.ability.AbilityHotbarSelectPacket;
@@ -2,7 +2,7 @@ package noppes.npcs.client.gui.player.inventory;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.gui.util.GuiCustomScroll;
@@ -1,636 +0,0 @@
package noppes.npcs.client.gui.util;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.controllers.AbilityController;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.ChainedAbilityEntry;
import kamkeel.npcs.controllers.data.ability.PreviewEntityHandler;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Client-side executor for previewing abilities in the GUI.
* <p>
* Uses unified execution: calls the REAL ability methods (onWindUpTick, onExecute, onActiveTick)
* with previewMode=true. Abilities skip damage/effects/sounds when isPreview() returns true.
* <p>
* Lifecycle:
* 1. WINDUP phase - real onWindUpTick() called, telegraph shown, entities may spawn
* 2. ACTIVE phase - real onExecute() then onActiveTick() called, physics simulated
* 3. EXTENDED phase - 100 extra ticks to observe results (entities continue updating)
* 4. IDLE - preview complete
*/
@SideOnly(Side.CLIENT)
public class AbilityPreviewExecutor implements PreviewEntityHandler {
// ==================== PREVIEW STATE ====================
private Ability previewAbility;
private EntityNPCInterface previewNpc;
/**
* Executor's own phase tracking (separate from ability.getPhase())
*/
private enum ExecutorPhase {IDLE, WINDUP, ACTIVE, EXTENDED, CHAIN_DELAY}
private ExecutorPhase executorPhase = ExecutorPhase.IDLE;
private int currentTick = 0;
private boolean playing = false;
private boolean paused = false;
// ==================== TIMING ====================
private static final int EXTENDED_DURATION = 100;
private int maxPreviewDuration = 200;
// ==================== FAKE TARGET ====================
private EntityNPCInterface fakeTarget;
private static final double TARGET_DISTANCE = 5.0;
// ==================== NPC START POSITION ====================
private double npcStartX, npcStartY, npcStartZ;
// ==================== PREVIEW CONTENT ====================
private TelegraphInstance previewTelegraph;
private List<Entity> previewEntities = new ArrayList<>();
// ==================== CHAIN PREVIEW ====================
private ChainedAbility previewChain;
private List<Ability> chainAbilities;
private List<Integer> chainDelays;
private int chainIndex = -1;
private int chainDelayRemaining = 0;
private boolean chainWindUpAll = true;
// ==================== CALLBACKS ====================
private GuiAbilityInterface parentGui;
public AbilityPreviewExecutor() {
}
public void setParentGui(GuiAbilityInterface gui) {
this.parentGui = gui;
}
/**
* Start previewing a single ability using unified execution.
* Sets previewMode=true on the ability, then calls its real methods.
*/
public void startPreview(Ability ability, EntityNPCInterface npc) {
stop();
this.previewNpc = npc;
this.playing = true;
this.paused = false;
// Save NPC start position for restoring later
this.npcStartX = npc.posX;
this.npcStartY = npc.posY;
this.npcStartZ = npc.posZ;
// Create invisible fake target NPC for targeting
createFakeTarget(npc);
// Start tracking NPC movement
if (parentGui != null) {
parentGui.startTrackingMovement();
}
beginAbilityPreview(ability);
}
/**
* Start previewing a chained ability — plays all entries in sequence with delays.
* Each entry is resolved and deep-copied to avoid modifying originals.
*/
public void startChainPreview(ChainedAbility chain, EntityNPCInterface npc) {
stop();
this.previewNpc = npc;
this.playing = true;
this.paused = false;
this.previewChain = chain;
this.chainWindUpAll = chain.isWindUpAll();
// Save NPC start position for restoring later
this.npcStartX = npc.posX;
this.npcStartY = npc.posY;
this.npcStartZ = npc.posZ;
// Resolve all entries to deep-copied abilities
chainAbilities = new ArrayList<>();
chainDelays = new ArrayList<>();
for (ChainedAbilityEntry entry : chain.getEntries()) {
Ability resolved = entry.resolve();
if (resolved != null && AbilityController.Instance != null) {
Ability copy = AbilityController.Instance.fromNBT(resolved.writeNBT());
if (copy != null) {
chainAbilities.add(copy);
chainDelays.add(entry.getDelayTicks());
}
}
}
if (chainAbilities.isEmpty()) {
playing = false;
return;
}
// Create invisible fake target NPC for targeting
createFakeTarget(npc);
// Start tracking NPC movement
if (parentGui != null) {
parentGui.startTrackingMovement();
}
chainIndex = 0;
beginAbilityPreview(chainAbilities.get(0));
}
/**
* Begin previewing a single ability (shared by single and chain preview).
* Cleans up the previous ability if any (for chain advancement).
*/
private void beginAbilityPreview(Ability ability) {
// Clean up previous ability if any (for chain advancement)
if (previewAbility != null) {
previewAbility.cleanup();
previewAbility.setPreviewMode(false);
previewAbility.setPreviewEntityHandler(null);
previewAbility.reset();
}
this.previewAbility = ability;
this.currentTick = 0;
this.maxPreviewDuration = ability.getMaxPreviewDuration();
// Enable preview mode on the ability
ability.setPreviewMode(true);
ability.setPreviewEntityHandler(this);
// Use the ability's real start() method with the fake target
ability.start(fakeTarget);
// Skip windup for non-first chain entries when windUpAll is false
boolean skipWindup = previewChain != null && !chainWindUpAll && chainIndex > 0;
if (ability.getWindUpTicks() <= 0 || skipWindup) {
// No windup — go straight to active
this.executorPhase = ExecutorPhase.ACTIVE;
transitionToActive();
} else {
// Normal windup flow
this.executorPhase = ExecutorPhase.WINDUP;
// Create telegraph for preview
previewTelegraph = ability.createTelegraph(previewNpc, fakeTarget);
// Start windup animation
Animation windUpAnim = ability.getWindUpAnimation();
if (windUpAnim != null) {
AnimationData data = previewNpc.display.animationData;
data.setEnabled(true);
data.setAnimation(windUpAnim);
data.animation.paused = false;
}
}
}
/**
* Create an invisible fake target NPC placed in front of the preview NPC.
*/
private void createFakeTarget(EntityNPCInterface npc) {
if (npc.worldObj == null) return;
try {
fakeTarget = new EntityCustomNpc(npc.worldObj);
float facingYaw = GuiAbilityInterface.NPC_FACING_YAW;
double yawRad = Math.toRadians(facingYaw);
double targetX = npc.posX - Math.sin(yawRad) * TARGET_DISTANCE;
double targetY = npc.posY;
double targetZ = npc.posZ + Math.cos(yawRad) * TARGET_DISTANCE;
fakeTarget.setPosition(targetX, targetY, targetZ);
fakeTarget.prevPosX = targetX;
fakeTarget.prevPosY = targetY;
fakeTarget.prevPosZ = targetZ;
} catch (Exception e) {
fakeTarget = null;
}
}
public EntityLivingBase getFakeTarget() {
return fakeTarget;
}
public void play() {
if (previewAbility == null || executorPhase == ExecutorPhase.IDLE) {
return;
}
playing = true;
paused = false;
if (previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
if (data.animation != null) {
data.animation.paused = false;
}
}
}
public void pause() {
paused = true;
// Immediately sync prevPos to pos for NPC and all entities to prevent interpolation jitter
syncPrevPositions();
if (previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
if (data.animation != null) {
data.animation.paused = true;
}
}
}
/**
* Sync prevPos to pos for the NPC and all preview entities.
* Prevents rendering interpolation jitter when standing still or paused.
*/
private void syncPrevPositions() {
if (previewNpc != null) {
previewNpc.prevPosX = previewNpc.posX;
previewNpc.prevPosY = previewNpc.posY;
previewNpc.prevPosZ = previewNpc.posZ;
}
for (Entity entity : previewEntities) {
if (entity != null && !entity.isDead) {
entity.prevPosX = entity.posX;
entity.prevPosY = entity.posY;
entity.prevPosZ = entity.posZ;
}
}
}
public void stop() {
// Clean up the ability
if (previewAbility != null) {
previewAbility.cleanup();
previewAbility.setPreviewMode(false);
previewAbility.setPreviewEntityHandler(null);
previewAbility.reset();
}
playing = false;
paused = false;
executorPhase = ExecutorPhase.IDLE;
currentTick = 0;
// Clear chain state
previewChain = null;
chainAbilities = null;
chainDelays = null;
chainIndex = -1;
chainDelayRemaining = 0;
previewTelegraph = null;
if (parentGui != null) {
for (Entity entity : previewEntities) {
parentGui.removePreviewEntity(entity);
}
parentGui.stopTrackingMovement();
parentGui.setPreviewTelegraph(null);
}
previewEntities.clear();
// Reset NPC position to start position (undo movement from Slam/Charge/Dash)
if (previewNpc != null && npcStartX != 0 && npcStartY != 0 && npcStartZ != 0) {
previewNpc.posX = npcStartX;
previewNpc.posY = npcStartY;
previewNpc.posZ = npcStartZ;
previewNpc.prevPosX = npcStartX;
previewNpc.prevPosY = npcStartY;
previewNpc.prevPosZ = npcStartZ;
previewNpc.motionX = 0;
previewNpc.motionY = 0;
previewNpc.motionZ = 0;
}
fakeTarget = null;
if (previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
data.setAnimation(new Animation());
data.animation.paused = false;
}
}
/**
* Tick the preview forward. Calls real ability methods.
*/
public void tick() {
if (!playing || previewAbility == null || previewNpc == null) {
return;
}
if (paused) {
// Sync prevPos to pos for NPC and all entities to prevent interpolation jitter while paused
syncPrevPositions();
return;
}
// Sync NPC's prevPos to current pos BEFORE any updates to prevent jitter when standing still
previewNpc.prevPosX = previewNpc.posX;
previewNpc.prevPosY = previewNpc.posY;
previewNpc.prevPosZ = previewNpc.posZ;
currentTick++;
if (previewTelegraph != null) {
previewTelegraph.tick(null);
}
tickEntities();
switch (executorPhase) {
case WINDUP:
tickWindup();
break;
case ACTIVE:
tickActive();
break;
case EXTENDED:
tickExtended();
break;
case CHAIN_DELAY:
tickChainDelay();
break;
default:
break;
}
}
private void tickWindup() {
// Call the REAL windup tick method
previewAbility.onWindUpTick(previewNpc, fakeTarget, currentTick);
if (currentTick >= previewAbility.getWindUpTicks()) {
transitionToActive();
}
}
private void tickActive() {
// Call the REAL active tick method
previewAbility.onActiveTick(previewNpc, fakeTarget, currentTick);
// Simulate physics for movement abilities
simulatePhysics();
// Check if the ability signaled completion (phase went to IDLE)
if (previewAbility.getPhase() == AbilityPhase.IDLE) {
if (hasNextChainEntry()) {
transitionToChainDelay();
} else {
transitionToExtended();
}
return;
}
// Safety timeout
if (currentTick >= maxPreviewDuration) {
if (hasNextChainEntry()) {
transitionToChainDelay();
} else {
transitionToExtended();
}
}
}
private void tickExtended() {
// Continue ticking entities so they can finish their animations
if (currentTick >= EXTENDED_DURATION) {
playing = false;
}
}
// ==================== CHAIN ADVANCEMENT ====================
private boolean hasNextChainEntry() {
return previewChain != null && chainAbilities != null && chainIndex < chainAbilities.size() - 1;
}
private void transitionToChainDelay() {
executorPhase = ExecutorPhase.CHAIN_DELAY;
currentTick = 0;
// Use the NEXT entry's delay
int nextIndex = chainIndex + 1;
chainDelayRemaining = (nextIndex < chainDelays.size()) ? chainDelays.get(nextIndex) : 0;
// Clear current animation
if (previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
data.setAnimation(new Animation());
}
}
private void tickChainDelay() {
if (chainDelayRemaining > 0) {
chainDelayRemaining--;
return;
}
advanceChainEntry();
}
private void advanceChainEntry() {
chainIndex++;
if (chainIndex >= chainAbilities.size()) {
transitionToExtended();
return;
}
beginAbilityPreview(chainAbilities.get(chainIndex));
}
private void transitionToActive() {
executorPhase = ExecutorPhase.ACTIVE;
currentTick = 0;
previewTelegraph = null;
// Call the REAL onExecute method (fires entities, initiates movement, etc.)
previewAbility.onExecute(previewNpc, fakeTarget);
// Start active animation
Animation activeAnim = previewAbility.getActiveAnimation();
if (activeAnim != null && previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
data.setAnimation(activeAnim);
data.animation.paused = false;
}
}
private void transitionToExtended() {
executorPhase = ExecutorPhase.EXTENDED;
currentTick = 0;
if (previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
data.setAnimation(new Animation());
}
}
/**
* Simulate basic physics for movement abilities (Slam, Charge, Dash).
* Applies gravity, drag, and ground clamping to NPC position.
*/
private void simulatePhysics() {
if (!previewAbility.hasAbilityMovement()) return;
if (previewNpc == null) return;
// Save previous position for interpolation
previewNpc.prevPosX = previewNpc.posX;
previewNpc.prevPosY = previewNpc.posY;
previewNpc.prevPosZ = previewNpc.posZ;
// Apply velocity
previewNpc.posX += previewNpc.motionX;
previewNpc.posY += previewNpc.motionY;
previewNpc.posZ += previewNpc.motionZ;
// Apply gravity
previewNpc.motionY -= 0.08;
previewNpc.motionY *= 0.98;
// Apply horizontal drag
previewNpc.motionX *= 0.91;
previewNpc.motionZ *= 0.91;
// Ground clamp: if below start position and falling, stop
if (previewNpc.posY < npcStartY && previewNpc.motionY < 0) {
previewNpc.posY = npcStartY;
previewNpc.motionY = 0;
previewNpc.onGround = true;
}
previewNpc.fallDistance = 0;
}
private void tickEntities() {
Iterator<Entity> iter = previewEntities.iterator();
while (iter.hasNext()) {
Entity entity = iter.next();
if (entity == null || entity.isDead) {
if (parentGui != null) {
parentGui.removePreviewEntity(entity);
}
iter.remove();
continue;
}
entity.onUpdate();
}
}
// ==================== PreviewEntityHandler ====================
@Override
public void onEntitySpawned(Entity entity) {
if (entity == null) return;
previewEntities.add(entity);
if (parentGui != null) {
parentGui.addPreviewEntity(entity);
}
}
@Override
public void onEntityRemoved(Entity entity) {
if (entity == null) return;
previewEntities.remove(entity);
if (parentGui != null) {
parentGui.removePreviewEntity(entity);
}
}
// ==================== GETTERS ====================
public boolean isPlaying() {
return playing;
}
public boolean isPaused() {
return paused;
}
public boolean isActive() {
return playing || paused;
}
public boolean isChainPreview() {
return previewChain != null;
}
public AbilityPhase getPhase() {
switch (executorPhase) {
case WINDUP:
return AbilityPhase.WINDUP;
case ACTIVE:
return AbilityPhase.ACTIVE;
default:
return AbilityPhase.IDLE;
}
}
public int getCurrentTick() {
return currentTick;
}
public TelegraphInstance getTelegraph() {
return previewTelegraph;
}
public List<Entity> getPreviewEntities() {
return previewEntities;
}
public Ability getPreviewAbility() {
return previewAbility;
}
public EntityNPCInterface getPreviewNpc() {
return previewNpc;
}
public String getStatusString() {
if (!playing && !paused) {
return "Stopped";
}
String chainPrefix = "";
if (previewChain != null && chainAbilities != null) {
chainPrefix = "Chain " + (chainIndex + 1) + "/" + chainAbilities.size() + " - ";
}
if (paused) {
return chainPrefix + "Paused";
} else if (executorPhase == ExecutorPhase.WINDUP) {
return chainPrefix + "Windup: " + currentTick + "/" + (previewAbility != null ? previewAbility.getWindUpTicks() : 0);
} else if (executorPhase == ExecutorPhase.ACTIVE) {
return chainPrefix + "Active: " + currentTick + "/" + maxPreviewDuration;
} else if (executorPhase == ExecutorPhase.EXTENDED) {
return chainPrefix + "Extended: " + currentTick + "/" + EXTENDED_DURATION;
} else if (executorPhase == ExecutorPhase.CHAIN_DELAY) {
return chainPrefix + "Delay: " + chainDelayRemaining;
}
return "";
}
}
@@ -1,409 +0,0 @@
package noppes.npcs.client.gui.util;
import kamkeel.npcs.client.renderer.TelegraphRenderer;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.client.ClientEventHandler;
import noppes.npcs.entity.EntityNPCInterface;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import java.util.ArrayList;
import java.util.List;
/**
* Base GUI class for ability preview with fixed camera.
* <p>
* Key concepts:
* - NPC positioned on left side of preview area
* - NPC faces a fixed direction (NPC_FACING_YAW)
* - Viewing direction can be rotated (rotates entire 3D space)
* - Fixed zoom level
* - Preview entities rendered in same coordinate space as NPC
* - NPC position changes (e.g. slam jump) tracked and rendered
*/
public class GuiAbilityInterface extends GuiNPCInterface2 {
// ==================== FIXED CAMERA SETTINGS ====================
/**
* Fixed camera zoom level (higher = more zoomed in)
*/
protected static float CAMERA_ZOOM = 45.0f;
/**
* NPC facing direction - affects anchor points and visual facing
*/
protected static float NPC_FACING_YAW = 160.0f;
/**
* Camera pitch (slight downward angle)
*/
protected static float CAMERA_PITCH = 10.0f;
// ==================== VIEWING ROTATION ====================
/**
* Viewing direction rotation (rotates entire 3D space)
*/
protected static float viewRotation = 0.0f;
private GuiNpcButton btnLeft, btnRight;
// ==================== NPC STATE ====================
public EntityNPCInterface npc;
/**
* NPC starting position (saved when preview starts, used to track movement)
*/
protected double npcStartX, npcStartY, npcStartZ;
/**
* Whether we're tracking NPC movement
*/
protected boolean trackingNpcMovement = false;
/**
* Entities to render in preview space
*/
protected List<Entity> previewEntities = new ArrayList<>();
/**
* Current telegraph to render in preview
*/
protected TelegraphInstance previewTelegraph;
// ==================== LAYOUT ====================
/**
* Preview area bounds
*/
protected int previewX, previewY, previewWidth, previewHeight;
/**
* NPC render position on screen
*/
protected int npcScreenX, npcScreenY;
public int xOffset = 0;
public int yOffset = 0;
public GuiAbilityInterface(EntityNPCInterface npc) {
this(npc, true);
}
/**
* @param npc The NPC for preview rendering
* @param hasMenuNpc If false, the top menu tabs (Display, Stats, etc.) are hidden.
* Use false when opened from the global menu without a real NPC.
*/
public GuiAbilityInterface(EntityNPCInterface npc, boolean hasMenuNpc) {
super(hasMenuNpc ? npc : null);
this.npc = npc;
this.drawDefaultBackground = false;
CAMERA_ZOOM = 30f;
NPC_FACING_YAW = 310f;
CAMERA_PITCH = 5f;
}
@Override
public void initGui() {
super.initGui();
// Calculate preview area (left side of GUI)
previewX = guiLeft + 10;
previewY = guiTop + 10;
previewWidth = 200;
previewHeight = 180;
// NPC position: left side of preview, slightly below center
npcScreenX = previewX + (int) (previewWidth * 0.33f) + xOffset;
npcScreenY = previewY + (int) (previewHeight * 0.85f) + yOffset;
// Viewing rotation buttons (below preview area)
int btnY = guiTop + 192;
addButton(btnLeft = new GuiNpcButton(680, guiLeft + 10, btnY, 20, 20, "<"));
addButton(btnRight = new GuiNpcButton(681, guiLeft + 32, btnY, 20, 20, ">"));
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
// Handle held rotation buttons
if (Mouse.isButtonDown(0)) {
if (btnLeft != null && btnLeft.mousePressed(mc, mouseX, mouseY)) {
viewRotation += partialTicks * 2;
} else if (btnRight != null && btnRight.mousePressed(mc, mouseX, mouseY)) {
viewRotation -= partialTicks * 2;
}
}
// Draw background and UI elements
super.drawScreen(mouseX, mouseY, partialTicks);
// Draw the 3D preview
drawPreview(mouseX, mouseY, partialTicks);
}
/**
* Draw the 3D preview with NPC and entities.
*/
protected void drawPreview(int mouseX, int mouseY, float partialTicks) {
if (hasSubGui())
return;
GL11.glColor4f(1, 1, 1, 1);
// Enable scissor to clip rendering to preview area
GL11.glEnable(GL11.GL_SCISSOR_TEST);
setScissorClip(previewX, previewY, previewWidth, previewHeight);
// Always use the standard NPC animation renderer for ability preview
EntityLivingBase renderEntity = this.npc;
// Set NPC facing direction (affects anchor points and visual facing)
npc.prevRenderYawOffset = npc.renderYawOffset = NPC_FACING_YAW;
npc.prevRotationYaw = npc.rotationYaw = NPC_FACING_YAW;
npc.prevRotationYawHead = npc.rotationYawHead = NPC_FACING_YAW;
// Also set on render entity
renderEntity.prevRenderYawOffset = renderEntity.renderYawOffset = NPC_FACING_YAW;
renderEntity.prevRotationYaw = renderEntity.rotationYaw = NPC_FACING_YAW;
renderEntity.prevRotationYawHead = renderEntity.rotationYawHead = NPC_FACING_YAW;
renderEntity.rotationPitch = 0;
// Calculate NPC position delta for movement rendering (e.g. slam jump)
// Interpolate with partial ticks for smooth movement between frames
double npcDeltaX = 0, npcDeltaY = 0, npcDeltaZ = 0;
if (trackingNpcMovement) {
double interpX = npc.prevPosX + (npc.posX - npc.prevPosX) * partialTicks;
double interpY = npc.prevPosY + (npc.posY - npc.prevPosY) * partialTicks;
double interpZ = npc.prevPosZ + (npc.posZ - npc.prevPosZ) * partialTicks;
npcDeltaX = interpX - npcStartX;
npcDeltaY = interpY - npcStartY;
npcDeltaZ = interpZ - npcStartZ;
}
// ==================== BEGIN 3D RENDERING ====================
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glPushMatrix();
// Move to NPC render position on screen
GL11.glTranslatef(npcScreenX, npcScreenY, 300F);
// Apply zoom (scale)
GL11.glScalef(-CAMERA_ZOOM, CAMERA_ZOOM, CAMERA_ZOOM);
// Flip for screen coordinates (Y is inverted)
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
// Apply slight camera pitch (looking down at scene)
GL11.glRotatef(CAMERA_PITCH, 1.0F, 0.0F, 0.0F);
// Apply VIEWING rotation (rotates entire space, not just NPC)
GL11.glRotatef(viewRotation, 0.0F, 1.0F, 0.0F);
// Setup lighting (standard item lighting for consistent colors)
GL11.glRotatef(135F, 0.0F, 1.0F, 0.0F);
RenderHelper.enableStandardItemLighting();
GL11.glRotatef(-135F, 0.0F, 1.0F, 0.0F);
// Adjust for entity offset
GL11.glTranslatef(0.0F, renderEntity.yOffset, 0.0F);
RenderManager.instance.playerViewY = 180F;
ClientEventHandler.renderingEntityInGUI = true;
// Render the NPC at its position delta (for movement like slam jumps)
RenderManager.instance.renderEntityWithPosYaw(renderEntity, npcDeltaX, npcDeltaY, npcDeltaZ, 0.0F, partialTicks);
// Render preview entities at their positions relative to NPC start position
renderPreviewEntities(partialTicks);
// Render telegraph in preview space
renderPreviewTelegraph(partialTicks);
ClientEventHandler.renderingEntityInGUI = false;
GL11.glPopMatrix();
// Cleanup GL state
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GL11.glDisable(GL11.GL_TEXTURE_2D);
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
// Disable scissor
GL11.glDisable(GL11.GL_SCISSOR_TEST);
// Clear depth buffer so UI renders on top
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
}
/**
* Render preview entities in the same coordinate space as the NPC.
* Called WITHIN the 3D matrix transformation.
*/
protected void renderPreviewEntities(float partialTicks) {
// Save current GL state that NPC render may have changed
boolean lightingWasEnabled = GL11.glIsEnabled(GL11.GL_LIGHTING);
// Use the start position as the reference point for entity offsets
double refX = trackingNpcMovement ? npcStartX : npc.posX;
double refY = trackingNpcMovement ? npcStartY : npc.posY;
double refZ = trackingNpcMovement ? npcStartZ : npc.posZ;
for (Entity entity : previewEntities) {
if (entity == null || entity.isDead) continue;
// Calculate entity position relative to reference (NPC start position)
double offsetX = entity.prevPosX + (entity.posX - entity.prevPosX) * partialTicks - refX;
double offsetY = entity.prevPosY + (entity.posY - entity.prevPosY) * partialTicks - refY;
double offsetZ = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * partialTicks - refZ;
// The NPC model was translated by npc.yOffset, so we need to subtract it
offsetY -= npc.yOffset;
// Reset GL state before each entity to ensure colors render correctly
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glDisable(GL11.GL_LIGHTING);
try {
RenderManager.instance.renderEntityWithPosYaw(entity, offsetX, offsetY, offsetZ, entity.rotationYaw, partialTicks);
} catch (Exception e) {
// Ignore rendering errors
}
}
// Restore lighting state for any subsequent rendering
if (lightingWasEnabled) {
GL11.glEnable(GL11.GL_LIGHTING);
}
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
/**
* Render the telegraph in the 3D preview space.
* Called within the GL matrix transformation.
*/
protected void renderPreviewTelegraph(float partialTicks) {
if (previewTelegraph == null) return;
if (TelegraphRenderer.Instance == null) return;
// Telegraph position is in world coords - convert to preview space
double refX = trackingNpcMovement ? npcStartX : npc.posX;
double refY = trackingNpcMovement ? npcStartY : npc.posY;
double refZ = trackingNpcMovement ? npcStartZ : npc.posZ;
double offsetX = previewTelegraph.getInterpolatedX(partialTicks) - refX;
double offsetY = previewTelegraph.getInterpolatedY(partialTicks) - refY;
double offsetZ = previewTelegraph.getInterpolatedZ(partialTicks) - refZ;
// Adjust for NPC yOffset (same as entities)
offsetY -= npc.yOffset;
TelegraphRenderer.Instance.renderTelegraphInGUI(previewTelegraph, offsetX, offsetY, offsetZ, 1.0f, partialTicks);
}
public void setPreviewTelegraph(TelegraphInstance telegraph) {
this.previewTelegraph = telegraph;
}
/**
* Set scissor clip for preview area.
*/
protected void setScissorClip(int x, int y, int width, int height) {
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
int scale = sr.getScaleFactor();
int scaledY = mc.displayHeight - (y + height) * scale;
GL11.glScissor(x * scale, scaledY, width * scale, height * scale);
}
// ==================== MOVEMENT TRACKING ====================
/**
* Start tracking NPC movement from current position.
*/
public void startTrackingMovement() {
npcStartX = npc.posX;
npcStartY = npc.posY;
npcStartZ = npc.posZ;
trackingNpcMovement = true;
}
/**
* Stop tracking NPC movement.
*/
public void stopTrackingMovement() {
trackingNpcMovement = false;
}
// ==================== PREVIEW ENTITY MANAGEMENT ====================
public void addPreviewEntity(Entity entity) {
if (entity != null && !previewEntities.contains(entity)) {
previewEntities.add(entity);
}
}
public void removePreviewEntity(Entity entity) {
previewEntities.remove(entity);
}
public void clearPreviewEntities() {
previewEntities.clear();
}
public List<Entity> getPreviewEntities() {
return previewEntities;
}
public float getNpcFacingYaw() {
return NPC_FACING_YAW;
}
// ==================== BACKGROUND ====================
@Override
protected void drawBackground() {
super.drawBackground();
drawGradientRect(previewX, previewY, previewX + previewWidth, previewY + previewHeight,
0xc0101010, 0xd0101010);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
// ==================== STANDARD OVERRIDES ====================
@Override
public boolean doesGuiPauseGame() {
return false;
}
@Override
public void keyTyped(char par1, int par2) {
boolean hadSubGui = hasSubGui();
super.keyTyped(par1, par2);
if (par2 == 1 && !hadSubGui) {
close();
}
}
public void close() {
this.mc.displayGuiScreen((GuiScreen) null);
this.mc.setIngameFocus();
}
@Override
public void save() {
}
@Override
protected void actionPerformed(GuiButton btn) {
if (btn.id == 670) {
close();
}
}
}
@@ -96,7 +96,10 @@ public class GuiMenuTopButton extends GuiNpcButton {
@Override
public boolean mousePressed(Minecraft minecraft, int i, int j) {
boolean bo = !active && getVisible() && hover;
int h = this.height - (active ? 0 : 2);
boolean bo = !active && getVisible()
&& i >= xPosition && j >= yPosition
&& i < xPosition + getWidth() && j < yPosition + h;
if (bo && listener != null) {
listener.actionPerformed(this);
return false;
@@ -1,6 +1,7 @@
package noppes.npcs.client.gui.util;
import kamkeel.npcs.util.TextSplitter;
import kamkeel.npcs.util.FileNameHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
@@ -26,6 +27,7 @@ public class GuiNpcTextField extends GuiTextField {
public float minFloat = 0, maxFloat = Float.MAX_VALUE, defFloat = 0;
protected static GuiNpcTextField activeTextfield = null;
public boolean canEdit = true;
private boolean fileNameSafe = false;
public String hoverableText = "";
private boolean wasHovered = false;
private int hoverCount = 0;
@@ -71,6 +73,11 @@ public class GuiNpcTextField extends GuiTextField {
public boolean textboxKeyTyped(char c, int i) {
if (!canEdit || !isFocused())
return false;
if (fileNameSafe && !GuiScreen.isCtrlKeyDown() && !isFileNameCharAllowed(c, i)) {
return false;
}
// Allow Ctrl shortcuts (select all, copy, paste, cut) to bypass char filter
if (GuiScreen.isCtrlKeyDown()) {
// For Ctrl+V (paste) on numeric fields, filter clipboard to valid chars
@@ -87,7 +94,17 @@ public class GuiNpcTextField extends GuiTextField {
}
return true;
}
return super.textboxKeyTyped(c, i);
if (i == 47 && fileNameSafe) {
String clipboard = GuiScreen.getClipboardString();
if (clipboard != null) {
String filtered = filterFileNameClipboard(clipboard);
if (!filtered.isEmpty())
writeText(filtered);
}
return true;
}
boolean handled = super.textboxKeyTyped(c, i);
return handled;
}
if (!charAllowed(c, i))
return false;
@@ -179,6 +196,9 @@ public class GuiNpcTextField extends GuiTextField {
else if (getFloat() > maxFloat)
setText(maxFloat + "");
}
if (fileNameSafe) {
normalizeFileNameText();
}
setCursorPositionZero();
if (listener != null)
listener.unFocused(this);
@@ -238,6 +258,51 @@ public class GuiNpcTextField extends GuiTextField {
return this;
}
public GuiNpcTextField setFileNameSafe() {
fileNameSafe = true;
normalizeFileNameText();
return this;
}
private boolean isSpecialNavigationKey(int keyCode) {
for (int allowed : allowedSpecialChars) {
if (allowed == keyCode) {
return true;
}
}
return false;
}
private boolean isFileNameCharAllowed(char c, int keyCode) {
if (isSpecialNavigationKey(keyCode) || c < 32) {
return true;
}
return Character.isLetterOrDigit(c) || c == '_' || c == '-' || c == ' ';
}
private String filterFileNameClipboard(String clipboard) {
StringBuilder filtered = new StringBuilder(clipboard.length());
for (int idx = 0; idx < clipboard.length(); idx++) {
char c = clipboard.charAt(idx);
if (Character.isLetterOrDigit(c) || c == '_' || c == '-') {
filtered.append(c);
} else if (Character.isWhitespace(c)) {
filtered.append(' ');
}
}
return filtered.toString();
}
private void normalizeFileNameText() {
String current = getText();
String sanitized = FileNameHelper.sanitizeTextInput(current);
if (sanitized.equals(current)) return;
int cursor = getCursorPosition();
setText(sanitized);
setCursorPosition(Math.min(cursor, sanitized.length()));
}
public void setHoverText(String text) {
this.hoverableText = StatCollector.translateToLocal(text);
}
@@ -1,6 +1,6 @@
package noppes.npcs.client.gui.util;
import kamkeel.npcs.controllers.data.ability.ChainedAbility;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
/**
* Callback for when a chained ability is saved from the config SubGui.