Ability Preview GUI

This commit is contained in:
Kam committed 2026-01-28 20:43:32 -05:00
1 parent 216a3dbbf8
commit 55658a7956
37 files changed
+2396 -162

No files matched your search

@@ -66,6 +66,7 @@ public class CustomNpcsPermissions {
public static final Permission GLOBAL_NATURALSPAWN = new Permission("customnpcs.global.naturalspawn");
public static final Permission GLOBAL_TAG = new Permission("customnpcs.global.tag");
public static final Permission GLOBAL_ANIMATION = new Permission("customnpcs.global.animation");
public static final Permission GLOBAL_ABILITY = new Permission("customnpcs.global.ability");
public static final Permission GLOBAL_MAGIC = new Permission("customnpcs.global.magic");
public static final Permission GLOBAL_EFFECT = new Permission("customnpcs.global.effect");
@@ -785,6 +785,18 @@ public class NoppesUtilServer {
sendScrollData(player, map, EnumScrollData.ABILITY_TYPES);
}
public static void sendSavedAbilitiesData(EntityPlayerMP player) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
kamkeel.npcs.controllers.data.ability.AbilityController controller = kamkeel.npcs.controllers.data.ability.AbilityController.Instance;
if (controller != null) {
int index = 0;
for (String name : controller.getSavedAbilityNames()) {
map.put(name, index++);
}
}
sendScrollData(player, map, EnumScrollData.ABILITIES);
}
public static DialogOption setNpcDialog(int slot, int dialogId, EntityPlayer player) throws IOException {
return setNpcDialog(slot, dialogId, getEditingNpc(player));
}
@@ -87,6 +87,7 @@ import noppes.npcs.client.gui.global.GuiNPCManageAnimations;
import noppes.npcs.client.gui.global.GuiNPCManageBanks;
import noppes.npcs.client.gui.global.GuiNPCManageDialogs;
import noppes.npcs.client.gui.global.GuiNPCManageEffects;
import noppes.npcs.client.gui.global.GuiNpcManageAbilities;
import noppes.npcs.client.gui.global.GuiNPCManageFactions;
import noppes.npcs.client.gui.global.GuiNPCManageLinked;
import noppes.npcs.client.gui.global.GuiNPCManageQuest;
@@ -497,6 +498,20 @@ public class ClientProxy extends CommonProxy {
else if (gui == EnumGuiType.ManageEffects)
return new GuiNPCManageEffects(npc);
else if (gui == EnumGuiType.ManageAbilities) {
EntityCustomNpc abilityNpc;
if (npc != null) {
abilityNpc = new EntityCustomNpc(npc.worldObj);
abilityNpc.copyDataFrom(npc, true);
abilityNpc.display.showName = 1;
abilityNpc.display.showBossBar = 0;
} else {
abilityNpc = new EntityCustomNpc(Minecraft.getMinecraft().theWorld);
abilityNpc.display.texture = "customnpcs:textures/entity/humanmale/AnimationBody.png";
}
return new GuiNpcManageAbilities(abilityNpc);
}
else if (gui == EnumGuiType.MainMenuGlobal)
return new GuiNPCGlobalMainMenu(npc);
@@ -281,6 +281,13 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
@Override
public void setGuiData(NBTTagCompound compound) {
// Only process NPC ability data, not saved ability preset data
// SubGuiAbilityLoad also implements IGuiData and may receive responses
// that get forwarded here - ignore those by checking for expected keys
if (!compound.hasKey("Abilities")) {
return;
}
abilitiesEnabled = compound.getBoolean("AbilitiesEnabled");
// Support old globalCooldown for backwards compatibility
@@ -1,6 +1,7 @@
package noppes.npcs.client.gui.advanced;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.ability.SavedAbilityRemovePacket;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
@@ -8,15 +9,20 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
/**
* Confirmation dialog for deleting an ability preset.
* Uses packet-based communication for proper client-server architecture.
*/
public class SubGuiAbilityDeleteConfirm extends SubGuiInterface {
private final String abilityName;
private final SubGuiAbilityLoad loadGui;
private final Runnable onDeleted;
public SubGuiAbilityDeleteConfirm(String abilityName, SubGuiAbilityLoad loadGui) {
public SubGuiAbilityDeleteConfirm(String abilityName) {
this(abilityName, null);
}
public SubGuiAbilityDeleteConfirm(String abilityName, Runnable onDeleted) {
this.abilityName = abilityName;
this.loadGui = loadGui;
this.onDeleted = onDeleted;
setBackground("menubg.png");
xSize = 200;
@@ -44,9 +50,11 @@ public class SubGuiAbilityDeleteConfirm extends SubGuiInterface {
int id = guibutton.id;
if (id == 0) {
// Delete the ability
AbilityController.Instance.deleteAbility(abilityName);
loadGui.onAbilityDeleted(abilityName);
// Delete the ability via packet
PacketClient.sendClient(new SavedAbilityRemovePacket(abilityName));
if (onDeleted != null) {
onDeleted.run();
}
close();
} else if (id == 1) {
close();
@@ -2,28 +2,39 @@ package noppes.npcs.client.gui.advanced;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.ability.SavedAbilitiesGetPacket;
import kamkeel.npcs.network.packets.request.ability.SavedAbilityGetPacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.ICustomScrollListener;
import noppes.npcs.client.gui.util.IGuiData;
import noppes.npcs.client.gui.util.IScrollData;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.constants.EnumScrollData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Vector;
/**
* Dialog for loading a saved ability preset.
* Can be opened from SubGuiAbilityConfig (to load into editing ability)
* or from GuiNPCAbilities (to add ability directly to NPC).
* Uses packet-based communication for proper client-server architecture.
*/
public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollListener {
public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollListener, IScrollData, IGuiData {
private final SubGuiAbilityConfig parentConfig;
private final GuiNPCAbilities parentAbilities;
private String selectedName = null;
private List<String> abilityNames = new ArrayList<>();
private HashMap<String, Integer> abilityData = new HashMap<>();
private GuiCustomScroll scroll;
// Track if we're waiting for a load
private boolean waitingForLoad = false;
public SubGuiAbilityLoad(SubGuiAbilityConfig parentConfig) {
this.parentConfig = parentConfig;
@@ -32,6 +43,9 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
setBackground("menubg.png");
xSize = 220;
ySize = 180;
// Request ability list from server
PacketClient.sendClient(new SavedAbilitiesGetPacket());
}
public SubGuiAbilityLoad(GuiNPCAbilities parentAbilities) {
@@ -41,28 +55,29 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
setBackground("menubg.png");
xSize = 220;
ySize = 180;
// Request ability list from server
PacketClient.sendClient(new SavedAbilitiesGetPacket());
}
@Override
public void initGui() {
super.initGui();
// Load ability names
Set<String> names = AbilityController.Instance.getSavedAbilityNames();
abilityNames = new ArrayList<>(names);
int y = guiTop + 5;
addLabel(new GuiNpcLabel(0, "ability.load.select", guiLeft + 10, y));
y += 14;
// Scroll list of saved abilities
GuiCustomScroll scroll = new GuiCustomScroll(this, 0);
scroll.setSize(200, 110);
if (scroll == null) {
scroll = new GuiCustomScroll(this, 0);
scroll.setSize(200, 110);
}
scroll.guiLeft = guiLeft + 10;
scroll.guiTop = y;
scroll.setUnsortedList(abilityNames);
if (selectedName != null && abilityNames.contains(selectedName)) {
scroll.setList(getFilteredList());
if (selectedName != null && abilityData.containsKey(selectedName)) {
scroll.setSelected(selectedName);
}
addScroll(scroll);
@@ -70,13 +85,15 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
y += 115;
// Buttons
addButton(new GuiNpcButton(0, guiLeft + 10, y, 60, 20, "gui.load"));
addButton(new GuiNpcButton(1, guiLeft + 80, y, 60, 20, "gui.delete"));
addButton(new GuiNpcButton(2, guiLeft + 150, y, 60, 20, "gui.cancel"));
addButton(new GuiNpcButton(0, guiLeft + 10, y, 95, 20, "gui.load"));
addButton(new GuiNpcButton(2, guiLeft + 115, y, 95, 20, "gui.cancel"));
// Disable load/delete if nothing selected
// Disable load if nothing selected
getButton(0).setEnabled(selectedName != null && !selectedName.isEmpty());
getButton(1).setEnabled(selectedName != null && !selectedName.isEmpty());
}
private List<String> getFilteredList() {
return new ArrayList<>(abilityData.keySet());
}
@Override
@@ -84,19 +101,9 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
int id = guibutton.id;
if (id == 0 && selectedName != null) {
// Load the selected ability
Ability loaded = AbilityController.Instance.getSavedAbility(selectedName);
if (loaded != null) {
if (parentConfig != null) {
parentConfig.loadAbility(loaded);
} else if (parentAbilities != null) {
parentAbilities.loadAbility(loaded);
}
}
close();
} else if (id == 1 && selectedName != null) {
// Delete confirmation
setSubGui(new SubGuiAbilityDeleteConfirm(selectedName, this));
// Request ability data from server
waitingForLoad = true;
PacketClient.sendClient(new SavedAbilityGetPacket(selectedName));
} else if (id == 2) {
close();
}
@@ -113,8 +120,34 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
@Override
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
if (scroll.id == 0 && selection != null && !selection.isEmpty()) {
// Double-click to load immediately
Ability loaded = AbilityController.Instance.getSavedAbility(selection);
// Double-click to load - request from server
selectedName = selection;
waitingForLoad = true;
PacketClient.sendClient(new SavedAbilityGetPacket(selection));
}
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
if (type == EnumScrollData.ABILITIES) {
String name = scroll != null ? scroll.getSelected() : null;
this.abilityData = data;
if (scroll != null) {
scroll.setList(getFilteredList());
if (name != null && abilityData.containsKey(name)) {
scroll.setSelected(name);
}
}
initGui();
}
}
@Override
public void setGuiData(NBTTagCompound compound) {
// Received ability data from server
if (waitingForLoad) {
waitingForLoad = false;
Ability loaded = AbilityController.Instance.fromNBT(compound);
if (loaded != null) {
if (parentConfig != null) {
parentConfig.loadAbility(loaded);
@@ -126,13 +159,11 @@ public class SubGuiAbilityLoad extends SubGuiInterface implements ICustomScrollL
}
}
/**
* Called after an ability is deleted to refresh the list.
*/
public void onAbilityDeleted(String name) {
if (name.equals(selectedName)) {
selectedName = null;
@Override
public void setSelected(String selected) {
this.selectedName = selected;
if (scroll != null) {
scroll.setSelected(selected);
}
initGui();
}
}
@@ -1,23 +1,30 @@
package noppes.npcs.client.gui.advanced;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.ability.SavedAbilitySavePacket;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.IAbilityConfigCallback;
import noppes.npcs.client.gui.util.SubGuiInterface;
/**
* Confirmation dialog for saving an ability preset.
* Uses packet-based communication for proper client-server architecture.
*/
public class SubGuiAbilitySaveConfirm extends SubGuiInterface {
private final Ability ability;
private final boolean exists;
private final IAbilityConfigCallback callback;
public SubGuiAbilitySaveConfirm(Ability ability) {
this(ability, null);
}
public SubGuiAbilitySaveConfirm(Ability ability, IAbilityConfigCallback callback) {
this.ability = ability;
this.exists = AbilityController.Instance.hasSavedAbility(ability.getName());
this.callback = callback;
setBackground("menubg.png");
xSize = 200;
@@ -30,15 +37,9 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface {
int y = guiTop + 10;
if (exists) {
addLabel(new GuiNpcLabel(0, "ability.save.overwrite", guiLeft + 10, y));
y += 12;
addLabel(new GuiNpcLabel(1, "'" + ability.getName() + "'?", guiLeft + 10, y));
} else {
addLabel(new GuiNpcLabel(0, "ability.save.confirm", guiLeft + 10, y));
y += 12;
addLabel(new GuiNpcLabel(1, "'" + ability.getName() + "'?", guiLeft + 10, y));
}
addLabel(new GuiNpcLabel(0, "ability.save.confirm", guiLeft + 10, y));
y += 12;
addLabel(new GuiNpcLabel(1, "'" + ability.getName() + "'?", guiLeft + 10, y));
y += 30;
@@ -51,8 +52,11 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface {
int id = guibutton.id;
if (id == 0) {
// Save the ability
AbilityController.Instance.saveAbility(ability);
// Save the ability via packet
PacketClient.sendClient(new SavedAbilitySavePacket(ability.writeNBT()));
if (callback != null) {
callback.onAbilitySaved(ability);
}
close();
} else if (id == 1) {
close();
@@ -1,122 +1,266 @@
package noppes.npcs.client.gui.global;
import kamkeel.npcs.client.renderer.TelegraphRenderer;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityController;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.network.PacketClient;
import kamkeel.npcs.network.packets.request.ability.SavedAbilitiesGetPacket;
import kamkeel.npcs.network.packets.request.ability.SavedAbilityGetPacket;
import kamkeel.npcs.network.packets.request.ability.SavedAbilityRemovePacket;
import kamkeel.npcs.network.packets.request.ability.SavedAbilitySavePacket;
import net.minecraft.client.gui.GuiButton;
import noppes.npcs.client.gui.advanced.SubGuiAbilityDeleteConfirm;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.NoppesUtil;
import noppes.npcs.client.gui.util.AbilityPreviewExecutor;
import noppes.npcs.client.gui.util.GuiAbilityInterface;
import noppes.npcs.client.gui.util.GuiCustomScroll;
import noppes.npcs.client.gui.util.GuiNPCInterface2;
import noppes.npcs.client.gui.util.GuiNpcButton;
import noppes.npcs.client.gui.util.GuiNpcLabel;
import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.GuiTexturedButton;
import noppes.npcs.client.gui.util.IAbilityConfigCallback;
import noppes.npcs.client.gui.util.ICustomScrollListener;
import noppes.npcs.client.gui.util.IGuiData;
import noppes.npcs.client.gui.util.IScrollData;
import noppes.npcs.client.gui.util.ISubGuiListener;
import noppes.npcs.client.gui.util.ITextfieldListener;
import noppes.npcs.client.gui.util.SubGuiInterface;
import noppes.npcs.constants.EnumScrollData;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Vector;
/**
* Global GUI for managing saved ability presets.
* Allows viewing, editing, and deleting saved abilities.
* Global GUI for managing saved ability presets with 3D preview.
*
* Features:
* - Left side: 3D preview of NPC with ability effects
* - Right side: Ability list with search
* - Play/Pause/Stop buttons to preview abilities
*/
public class GuiNpcManageAbilities extends GuiNPCInterface2 implements ICustomScrollListener, ISubGuiListener, IAbilityConfigCallback {
public class GuiNpcManageAbilities extends GuiAbilityInterface
implements ICustomScrollListener, ISubGuiListener, IAbilityConfigCallback,
ITextfieldListener, GuiYesNoCallback, IScrollData, IGuiData {
// ==================== DATA ====================
private GuiCustomScroll scroll;
private String selectedName = null;
private List<String> abilityNames = new ArrayList<>();
private HashMap<String, Integer> abilityData = new HashMap<>();
private String selected = null;
private String search = "";
private Ability selectedAbility = null;
// ==================== PREVIEW ====================
private AbilityPreviewExecutor previewExecutor;
private long prevTick = 0;
public GuiNpcManageAbilities(EntityNPCInterface npc) {
super(npc);
loadAbilityNames();
}
private void loadAbilityNames() {
Set<String> names = AbilityController.Instance.getSavedAbilityNames();
abilityNames = new ArrayList<>(names);
// Layout offset
this.xOffset = -148 + 110;
this.yOffset = -170 + 167;
// Initialize preview executor
previewExecutor = new AbilityPreviewExecutor();
previewExecutor.setParentGui(this);
// Request ability data from server
PacketClient.sendClient(new SavedAbilitiesGetPacket());
// Enable animation data
AnimationData data = npc.display.animationData;
data.setEnabled(true);
}
@Override
public void initGui() {
super.initGui();
int y = guiTop + 10;
// Edit button (above Remove)
addButton(new GuiNpcButton(100, guiLeft + 368, guiTop + 8, 45, 20, "gui.edit"));
getButton(100).setEnabled(selected != null && !selected.isEmpty() && selectedAbility != null);
// Title label
addLabel(new GuiNpcLabel(0, "ability.manager.title", guiLeft + 10, y));
y += 20;
// Remove button
addButton(new GuiNpcButton(1, guiLeft + 368, guiTop + 30, 45, 20, "gui.remove"));
getButton(1).setEnabled(selected != null && !selected.isEmpty() && abilityData.containsKey(selected));
// Scroll list of saved abilities
// Scroll list of saved abilities (right side)
if (scroll == null) {
scroll = new GuiCustomScroll(this, 0);
scroll.setSize(143, 185);
}
scroll.setSize(xSize - 90, 160);
scroll.guiLeft = guiLeft + 10;
scroll.guiTop = y;
scroll.setUnsortedList(getFilteredList());
if (selectedName != null && abilityNames.contains(selectedName)) {
scroll.setSelected(selectedName);
}
scroll.guiLeft = guiLeft + 220;
scroll.guiTop = guiTop + 4;
addScroll(scroll);
// Update scroll list
scroll.setList(getSearchList());
if (selected != null && abilityData.containsKey(selected)) {
scroll.setSelected(selected);
}
// Search bar
addTextField(new GuiNpcTextField(1, this, fontRendererObj, guiLeft + 10, y + 163, xSize - 90, 18, search));
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 220, guiTop + 192, 143, 20, search));
// Right side buttons
int btnX = guiLeft + xSize - 70;
addButton(new GuiNpcButton(1, btnX, y, 60, 20, "gui.edit"));
addButton(new GuiNpcButton(2, btnX, y + 25, 60, 20, "gui.delete"));
addButton(new GuiNpcButton(3, btnX, y + 60, 60, 20, "selectServer.refresh"));
// Show ability info only if one is selected
if (selectedAbility == null || selected == null) {
return;
}
// Enable/disable buttons based on selection
getButton(1).setEnabled(selectedName != null && !selectedName.isEmpty());
getButton(2).setEnabled(selectedName != null && !selectedName.isEmpty());
// ID/Name label (below search bar)
addLabel(new GuiNpcLabel(10, "ID: " + selectedAbility.getId(), guiLeft + 220, guiTop + 215));
// Play/Pause/Stop buttons (below model preview area)
String animTexture = "customnpcs:textures/gui/animation.png";
int playButtonOffsetX = 60;
boolean isPlaying = previewExecutor.isPlaying() && !previewExecutor.isPaused();
boolean isPaused = previewExecutor.isPaused();
boolean isActive = previewExecutor.isActive();
if (!isPlaying || isPaused) {
// Show Play button
String statusKey = isPaused ? "animation.paused" : "animation.stopped";
addLabel(new GuiNpcLabel(90, statusKey, guiLeft + playButtonOffsetX, guiTop + 198));
addButton(new GuiTexturedButton(91, "", guiLeft + playButtonOffsetX + 70, guiTop + 192, 11, 20, animTexture, 18, 71));
} else {
// Show Pause button
addLabel(new GuiNpcLabel(90, "animation.playing", guiLeft + playButtonOffsetX, guiTop + 198));
addButton(new GuiTexturedButton(92, "", guiLeft + playButtonOffsetX + 70, guiTop + 192, 14, 20, animTexture, 0, 71));
}
if (isActive) {
// Show Stop button
addButton(new GuiTexturedButton(93, "", guiLeft + playButtonOffsetX + 90, guiTop + 192, 14, 20, animTexture, 33, 71));
}
}
private List<String> getFilteredList() {
private List<String> getSearchList() {
if (search.isEmpty()) {
return new ArrayList<>(abilityNames);
return new ArrayList<>(abilityData.keySet());
}
List<String> filtered = new ArrayList<>();
for (String name : abilityNames) {
List<String> list = new ArrayList<>();
for (String name : abilityData.keySet()) {
if (name.toLowerCase().contains(search.toLowerCase())) {
filtered.add(name);
list.add(name);
}
}
return filtered;
return list;
}
@Override
public void buttonEvent(GuiButton guibutton) {
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
// IMPORTANT: Set NPC rotation BEFORE ticking entities
// This ensures anchor point calculations use the correct facing direction
npc.prevRenderYawOffset = npc.renderYawOffset = NPC_FACING_YAW;
npc.prevRotationYaw = npc.rotationYaw = NPC_FACING_YAW;
npc.prevRotationYawHead = npc.rotationYawHead = NPC_FACING_YAW;
// Tick preview executor (entities will use the rotation set above)
tickPreview();
// Draw base (includes 3D preview via parent class)
super.drawScreen(mouseX, mouseY, partialTicks);
// Draw status text
if (previewExecutor.isActive()) {
String status = previewExecutor.getStatusString();
fontRendererObj.drawString(status, guiLeft + 12, guiTop + 175, 0xFFFFFF);
}
}
/**
* Tick the preview executor and animations.
*/
private void tickPreview() {
if (previewExecutor.isPlaying() && !previewExecutor.isPaused()) {
long time = mc.theWorld != null ? mc.theWorld.getTotalWorldTime() : System.currentTimeMillis() / 50;
if (time != prevTick) {
// Advance animation
npc.display.animationData.increaseTime();
// Tick preview
previewExecutor.tick();
// Sync telegraph to GUI for rendering
setPreviewTelegraph(previewExecutor.getTelegraph());
prevTick = time;
// Check if preview finished
if (!previewExecutor.isActive()) {
initGui();
}
}
}
}
@Override
protected void actionPerformed(GuiButton guibutton) {
super.actionPerformed(guibutton);
int id = guibutton.id;
if (id == 1 && selectedName != null) {
if (id == 1 && selected != null && abilityData.containsKey(selected)) {
// Remove - show confirmation
GuiYesNo guiyesno = new GuiYesNo(this, selected, StatCollector.translateToLocal("gui.delete"), 1);
displayGuiScreen(guiyesno);
} else if (id == 100 && selectedAbility != null) {
// Edit
Ability ability = AbilityController.Instance.getSavedAbility(selectedName);
if (ability != null) {
setSubGui(ability.createConfigGui(this));
previewExecutor.stop();
setSubGui(selectedAbility.createConfigGui(this));
} else if (id == 91) {
// Play button
if (selectedAbility != null) {
if (previewExecutor.isPaused()) {
previewExecutor.play();
} else {
previewExecutor.startPreview(selectedAbility, npc);
}
initGui();
}
} else if (id == 2 && selectedName != null) {
// Delete
setSubGui(new SubGuiAbilityDeleteConfirm(selectedName, null));
} else if (id == 3) {
// Refresh
AbilityController.Instance.load();
loadAbilityNames();
selectedName = null;
} else if (id == 92) {
// Pause button
previewExecutor.pause();
initGui();
} else if (id == 93) {
// Stop button
previewExecutor.stop();
initGui();
}
}
@Override
public void keyTyped(char c, int i) {
super.keyTyped(c, i);
if (getTextField(55) != null && getTextField(55).isFocused()) {
if (!search.equals(getTextField(55).getText())) {
search = getTextField(55).getText();
scroll.resetScroll();
scroll.setList(getSearchList());
}
}
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
if (scroll.id == 0) {
selectedName = scroll.getSelected();
initGui();
String newSelection = scroll.getSelected();
if (newSelection != null && !newSelection.equals(selected)) {
// Stop any playing preview
previewExecutor.stop();
selected = newSelection;
// Request ability data from server
PacketClient.sendClient(new SavedAbilityGetPacket(selected));
}
}
}
@@ -124,48 +268,90 @@ public class GuiNpcManageAbilities extends GuiNPCInterface2 implements ICustomSc
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
if (scroll.id == 0 && selection != null && !selection.isEmpty()) {
// Double-click to edit
Ability ability = AbilityController.Instance.getSavedAbility(selection);
if (ability != null) {
setSubGui(ability.createConfigGui(this));
if (selectedAbility != null) {
previewExecutor.stop();
setSubGui(selectedAbility.createConfigGui(this));
}
}
}
@Override
public void keyTyped(char c, int i) {
super.keyTyped(c, i);
if (getTextField(1) != null && getTextField(1).isFocused()) {
if (!search.equals(getTextField(1).getText())) {
search = getTextField(1).getText();
scroll.setUnsortedList(getFilteredList());
scroll.resetScroll();
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
if (type == EnumScrollData.ABILITIES) {
String name = scroll != null ? scroll.getSelected() : null;
this.abilityData = data;
if (scroll != null) {
scroll.setList(getSearchList());
if (name != null && abilityData.containsKey(name)) {
scroll.setSelected(name);
}
}
initGui();
}
}
@Override
public void setGuiData(NBTTagCompound compound) {
// Received ability data from server
selectedAbility = AbilityController.Instance.fromNBT(compound);
if (selectedAbility != null) {
selected = selectedAbility.getName();
if (scroll != null) {
scroll.setSelected(selected);
}
}
previewExecutor.stop();
initGui();
}
@Override
public void setSelected(String selected) {
this.selected = selected;
if (scroll != null) {
scroll.setSelected(selected);
}
}
@Override
public void subGuiClosed(SubGuiInterface subgui) {
// Refresh list after any sub gui closes
loadAbilityNames();
if (subgui instanceof SubGuiAbilityDeleteConfirm) {
// After delete, clear selection if it was deleted
if (selectedName != null && !abilityNames.contains(selectedName)) {
selectedName = null;
}
}
initGui();
}
@Override
public void confirmClicked(boolean result, int id) {
NoppesUtil.openGUI(player, this);
if (!result) return;
if (id == 1 && selected != null && abilityData.containsKey(selected)) {
// Delete ability via packet
PacketClient.sendClient(new SavedAbilityRemovePacket(selected));
scroll.clear();
selected = null;
selectedAbility = null;
initGui();
}
}
@Override
public void onAbilitySaved(Ability ability) {
// Save the edited ability
AbilityController.Instance.saveAbility(ability);
loadAbilityNames();
initGui();
// Save the edited ability via packet
PacketClient.sendClient(new SavedAbilitySavePacket(ability.writeNBT()));
}
@Override
public void unFocused(GuiNpcTextField textfield) {
// Search field handling is done in keyTyped
}
@Override
public void save() {
// Nothing to save - abilities are saved individually
// Nothing to save - abilities are saved individually via packets
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
// Stop preview when GUI closes
previewExecutor.stop();
}
}
@@ -39,6 +39,7 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
private GuiNpcSquareButton effectsButton;
private GuiNpcSquareButton magicsButton;
private GuiNpcSquareButton abilitiesButton;
private GuiNpcSquareButton auctionsButton;
public GuiNPCGlobalMainMenu(EntityNPCInterface npc) {
super(npc, 5);
@@ -96,7 +97,10 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
magicsButton.setIconPos(24, 24, 48, 56).setIconTexture(specialIcons);
registerButton(abilitiesButton = new GuiNpcSquareButton(21, 0, 0, 20, "global.abilities", 0xFF333333));
abilitiesButton.setIconPos(24, 24, 72, 56).setIconTexture(specialIcons); // Placeholder icon position
abilitiesButton.setIconPos(24, 24, 72, 56).setIconTexture(specialIcons);
registerButton(auctionsButton = new GuiNpcSquareButton(22, 0, 0, 20, "global.auction", 0xFF333333));
auctionsButton.setIconPos(24, 24, 96, 56).setIconTexture(specialIcons);
// Layout composite buttons optimally.
layoutButtons();
@@ -240,7 +244,10 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2 {
NoppesUtil.requestOpenGUI(EnumGuiType.ManageEffects);
}
if (id == 21) {
NoppesUtil.openGUI(player, new noppes.npcs.client.gui.global.GuiNpcManageAbilities(npc));
NoppesUtil.requestOpenGUI(EnumGuiType.ManageAbilities);
}
if (id == 22) {
// NoppesUtil.requestOpenGUI(EnumGuiType.ManageAuction);
}
}
@@ -0,0 +1,368 @@
package noppes.npcs.client.gui.util;
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.AbilityPhase;
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
import kamkeel.npcs.entity.EntityAbilityBeam;
import kamkeel.npcs.entity.EntityAbilityDisc;
import kamkeel.npcs.entity.EntityAbilityLaser;
import kamkeel.npcs.entity.EntityAbilityOrb;
import kamkeel.npcs.entity.EntityAbilityProjectile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.world.World;
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.
*
* Lifecycle:
* 1. WINDUP phase - plays windup animation, entities spawn and charge
* 2. ACTIVE phase - plays active animation, entities fire and move
* 3. EXTENDED phase - continues for +100 ticks after animations to see results
* 4. IDLE - preview complete
*
* Features:
* - Invisible fake target NPC placed in front of the preview NPC for targeting
* - NPC movement tracking for abilities that move the NPC (e.g. slam)
*/
@SideOnly(Side.CLIENT)
public class AbilityPreviewExecutor {
// ==================== PREVIEW STATE ====================
private Ability previewAbility;
private EntityNPCInterface previewNpc;
private AbilityPhase phase = AbilityPhase.IDLE;
private int currentTick = 0;
private boolean playing = false;
private boolean paused = false;
// ==================== TIMING ====================
private static final int EXTENDED_DURATION = 100;
private int activeDuration = 40;
// ==================== FAKE TARGET ====================
/** Invisible fake target NPC for ability targeting (placed 5 blocks in front of preview NPC) */
private EntityNPCInterface fakeTarget;
private static final double TARGET_DISTANCE = 5.0;
// ==================== NPC START POSITION ====================
/** Saved NPC position for restoring after movement abilities */
private double npcStartX, npcStartY, npcStartZ;
// ==================== PREVIEW CONTENT ====================
private TelegraphInstance previewTelegraph;
private List<Entity> previewEntities = new ArrayList<>();
// ==================== CALLBACKS ====================
private GuiAbilityInterface parentGui;
public AbilityPreviewExecutor() {
}
public void setParentGui(GuiAbilityInterface gui) {
this.parentGui = gui;
}
/**
* Start previewing an ability.
*/
public void startPreview(Ability ability, EntityNPCInterface npc) {
stop();
this.previewAbility = ability;
this.previewNpc = npc;
this.phase = AbilityPhase.WINDUP;
this.currentTick = 0;
this.playing = true;
this.paused = false;
this.activeDuration = ability.getPreviewActiveDuration();
// 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);
// Set preview target on the ability
ability.setPreviewTarget(fakeTarget);
// Start tracking NPC movement
if (parentGui != null) {
parentGui.startTrackingMovement();
}
// Create telegraph for preview
previewTelegraph = ability.createTelegraph(npc, fakeTarget);
// Start windup animation
Animation windUpAnim = ability.getWindUpAnimation();
if (windUpAnim != null) {
AnimationData data = npc.display.animationData;
data.setEnabled(true);
data.setAnimation(windUpAnim);
data.animation.paused = false;
}
// Spawn preview entity on first tick if ability spawns during windup
if (ability.spawnPreviewDuringWindup()) {
spawnPreviewEntity();
}
}
/**
* Create an invisible fake target NPC placed in front of the preview NPC.
* This entity is NOT rendered - it only exists for ability targeting logic.
*/
private void createFakeTarget(EntityNPCInterface npc) {
if (npc.worldObj == null) return;
try {
fakeTarget = new EntityCustomNpc(npc.worldObj);
// Position target in front of NPC based on its facing direction
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;
}
}
/**
* Get the fake target entity for abilities that need a target.
*/
public EntityLivingBase getFakeTarget() {
return fakeTarget;
}
public void play() {
if (previewAbility == null || phase == AbilityPhase.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;
if (previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
if (data.animation != null) {
data.animation.paused = true;
}
}
}
public void stop() {
playing = false;
paused = false;
phase = AbilityPhase.IDLE;
currentTick = 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;
}
// Remove fake target
fakeTarget = null;
if (previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
data.setAnimation(new Animation());
data.animation.paused = false;
}
}
/**
* Tick the preview forward.
*/
public void tick() {
if (!playing || paused || previewAbility == null || previewNpc == null) {
return;
}
currentTick++;
if (previewTelegraph != null) {
previewTelegraph.tick(null);
}
tickEntities();
switch (phase) {
case WINDUP:
tickWindup();
break;
case ACTIVE:
tickActive();
break;
case IDLE:
tickExtended();
break;
default:
break;
}
}
private void tickWindup() {
previewAbility.onPreviewWindUpTick(previewNpc, currentTick);
if (currentTick >= previewAbility.getWindUpTicks()) {
transitionToActive();
}
}
private void tickActive() {
previewAbility.onPreviewActiveTick(previewNpc, currentTick);
if (currentTick == 1 && !previewAbility.spawnPreviewDuringWindup()) {
spawnPreviewEntity();
fireEntities();
}
if (currentTick >= activeDuration) {
transitionToExtended();
}
}
private void tickExtended() {
if (currentTick >= EXTENDED_DURATION) {
playing = false;
}
}
private void transitionToActive() {
phase = AbilityPhase.ACTIVE;
currentTick = 0;
previewTelegraph = null;
// Notify ability of execution (for movement abilities like Slam/Charge/Dash)
previewAbility.onPreviewExecute(previewNpc);
fireEntities();
Animation activeAnim = previewAbility.getActiveAnimation();
if (activeAnim != null && previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
data.setAnimation(activeAnim);
data.animation.paused = false;
}
}
private void transitionToExtended() {
phase = AbilityPhase.IDLE;
currentTick = 0;
if (previewNpc != null) {
AnimationData data = previewNpc.display.animationData;
data.setAnimation(new Animation());
}
}
private void spawnPreviewEntity() {
Entity entity = previewAbility.createPreviewEntity(previewNpc);
if (entity != null) {
previewEntities.add(entity);
if (parentGui != null) {
parentGui.addPreviewEntity(entity);
}
}
}
private void fireEntities() {
for (Entity entity : previewEntities) {
if (entity instanceof EntityAbilityOrb) {
((EntityAbilityOrb) entity).startPreviewFiring();
} else if (entity instanceof EntityAbilityBeam) {
((EntityAbilityBeam) entity).startPreviewFiring();
} else if (entity instanceof EntityAbilityDisc) {
((EntityAbilityDisc) entity).startPreviewFiring();
}
}
}
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();
}
}
// ==================== GETTERS ====================
public boolean isPlaying() { return playing; }
public boolean isPaused() { return paused; }
public boolean isActive() { return playing || paused; }
public AbilityPhase getPhase() { return phase; }
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";
} else if (paused) {
return "Paused";
} else if (phase == AbilityPhase.WINDUP) {
return "Windup: " + currentTick + "/" + (previewAbility != null ? previewAbility.getWindUpTicks() : 0);
} else if (phase == AbilityPhase.ACTIVE) {
return "Active: " + currentTick + "/" + activeDuration;
} else if (phase == AbilityPhase.IDLE && playing) {
return "Extended: " + currentTick + "/" + EXTENDED_DURATION;
}
return "";
}
}
@@ -0,0 +1,391 @@
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.client.EntityUtil;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.entity.data.ModelData;
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.
*
* 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 ModelData playerdata;
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) {
super(npc);
this.npc = npc;
this.playerdata = ((EntityCustomNpc) npc).modelData;
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) {
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);
// Get the entity to render (could be transformed player model)
EntityLivingBase renderEntity = playerdata.getEntity(npc);
if (renderEntity == null) {
renderEntity = this.npc;
}
// Sync NPC properties to render entity
EntityUtil.Copy(npc, renderEntity);
// 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, 50F);
// 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)
try {
RenderManager.instance.renderEntityWithPosYaw(renderEntity, npcDeltaX, npcDeltaY, npcDeltaZ, 0.0F, partialTicks);
} catch (Exception e) {
playerdata.setEntityClass(null);
}
// 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) {
super.keyTyped(par1, par2);
if (par2 == 1) {
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();
}
}
}
@@ -18,11 +18,11 @@ import org.lwjgl.opengl.GL12;
public class GuiModelInterface2 extends GuiNPCInterface2 {
public ModelData playerdata;
private static float rotation = 0;
protected static float rotation = 0;
private GuiNpcButton left, right, zoom, unzoom;
private static float zoomed = 60;
protected static float zoomed = 60;
public int xOffset = 0;
public int yOffset = 0;
@@ -7,6 +7,7 @@ public enum EnumScrollData {
DIALOG_GROUP,
QUEST_GROUP,
ABILITY_TYPES,
ABILITIES,
ANIMATIONS,
BUILTIN_ANIMATIONS
}