Merge remote-tracking branch 'origin/syntax-highlighter-unified' into syntax-highlighter-unified

This commit is contained in:
bigguy345 committed 2026-03-02 00:20:45 +02:00
commit e1be96412d
163 files changed
+4345 -2135

No files matched your search

@@ -7,14 +7,14 @@ import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import kamkeel.npcs.addon.client.DBCClient;
import kamkeel.npcs.client.command.CommandCNPCDebugger;
import kamkeel.npcs.client.renderer.RenderAbilityBeam;
import kamkeel.npcs.client.renderer.RenderAbilityDisc;
import kamkeel.npcs.client.renderer.RenderAbilityLaser;
import kamkeel.npcs.client.renderer.RenderAbilityOrb;
import kamkeel.npcs.client.renderer.RenderAbilitySweeper;
import kamkeel.npcs.client.renderer.RenderAbilityZone;
import kamkeel.npcs.client.renderer.RenderAbilityDome;
import kamkeel.npcs.client.renderer.RenderAbilityPanel;
import kamkeel.npcs.client.renderer.RenderEnergyBeam;
import kamkeel.npcs.client.renderer.RenderEnergyDisc;
import kamkeel.npcs.client.renderer.RenderEnergyLaser;
import kamkeel.npcs.client.renderer.RenderEnergyOrb;
import kamkeel.npcs.client.renderer.RenderSweeper;
import kamkeel.npcs.client.renderer.RenderZone;
import kamkeel.npcs.client.renderer.RenderEnergyDome;
import kamkeel.npcs.client.renderer.RenderEnergyPanel;
import kamkeel.npcs.client.renderer.EnergyChargePreviewRenderer;
import kamkeel.npcs.client.renderer.RenderEnergyExplosion;
import kamkeel.npcs.client.renderer.RenderEnergySlicer;
@@ -26,10 +26,10 @@ import kamkeel.npcs.entity.EntityAbilityBeam;
import kamkeel.npcs.entity.EntityAbilityDisc;
import kamkeel.npcs.entity.EntityAbilityLaser;
import kamkeel.npcs.entity.EntityAbilityOrb;
import kamkeel.npcs.entity.EntityAbilitySweeper;
import kamkeel.npcs.entity.EntityEnergySweeper;
import kamkeel.npcs.entity.EntityAbilityZone;
import kamkeel.npcs.entity.EntityAbilityDome;
import kamkeel.npcs.entity.EntityAbilityPanel;
import kamkeel.npcs.entity.EntityEnergyDome;
import kamkeel.npcs.entity.EntityEnergyPanel;
import kamkeel.npcs.entity.EntityEnergyExplosion;
import kamkeel.npcs.entity.EntityEnergySlicer;
import net.minecraft.client.Minecraft;
@@ -282,14 +282,14 @@ public class ClientProxy extends CommonProxy {
RenderingRegistry.registerEntityRenderingHandler(EntityNpcDragon.class, new RenderNpcDragon(new ModelNpcDragon(0.0F), 0.5F));
RenderingRegistry.registerEntityRenderingHandler(EntityNpcSlime.class, new RenderNpcSlime(new ModelNpcSlime(16), new ModelNpcSlime(0), 0.25F));
RenderingRegistry.registerEntityRenderingHandler(EntityProjectile.class, new RenderProjectile());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityOrb.class, new RenderAbilityOrb());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityDisc.class, new RenderAbilityDisc());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityLaser.class, new RenderAbilityLaser());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityBeam.class, new RenderAbilityBeam());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilitySweeper.class, new RenderAbilitySweeper());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityZone.class, new RenderAbilityZone());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityDome.class, new RenderAbilityDome());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityPanel.class, new RenderAbilityPanel());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityOrb.class, new RenderEnergyOrb());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityDisc.class, new RenderEnergyDisc());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityLaser.class, new RenderEnergyLaser());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityBeam.class, new RenderEnergyBeam());
RenderingRegistry.registerEntityRenderingHandler(EntityEnergySweeper.class, new RenderSweeper());
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityZone.class, new RenderZone());
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyDome.class, new RenderEnergyDome());
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyPanel.class, new RenderEnergyPanel());
RenderingRegistry.registerEntityRenderingHandler(EntityEnergySlicer.class, new RenderEnergySlicer());
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyExplosion.class, new RenderEnergyExplosion());
@@ -8,6 +8,7 @@ import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.config.ConfigClient;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -101,18 +102,10 @@ public class ImageDownloadAlt extends SimpleTexture {
HttpURLConnection connection = null;
try {
URL url = new URL(ImageDownloadAlt.this.imageUrl);
connection = (HttpURLConnection) (url).openConnection(Minecraft.getMinecraft().getProxy());
connection.setDoInput(true);
connection.setDoOutput(false);
connection.setRequestProperty("Content-Type", "image/png");
connection.setRequestProperty("Expect", "100-continue");
//connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0");
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
// Modify Accept Redirect
if (isImgurLink(url)) {
connection.setRequestProperty("Accept", "*/*");
}
// Adding a config so people can switch back if needed.
// TODO: Remove config option if improved works better
connection = ConfigClient.ImprovedImageDownloadConnection ? setupConnectionImproved(url) : setupConnectionOld(url);
connection.connect();
@@ -152,6 +145,44 @@ public class ImageDownloadAlt extends SimpleTexture {
this.imageThread.start();
}
private HttpURLConnection setupConnectionOld(URL url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) (url).openConnection(Minecraft.getMinecraft().getProxy());
// setups stuff which basically tells the browser if this a get or post request
connection.setDoInput(true);
connection.setDoOutput(false);
// ??? I believe these are used to tell the receiver what you are sending to them
// Not what you expect to receive from them.
connection.setRequestProperty("Content-Type", "image/png");
connection.setRequestProperty("Expect", "100-continue");
//connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0");
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
// Modify Accept Redirect
if (isImgurLink(url)) {
connection.setRequestProperty("Accept", "*/*");
}
return connection;
}
private HttpURLConnection setupConnectionImproved(URL url) throws IOException {
HttpURLConnection connection = (HttpURLConnection) (url).openConnection(Minecraft.getMinecraft().getProxy());
connection.setRequestMethod("GET");
// Basically redundant because I set it as a GET request?
// Better safe than sorry ig.
connection.setDoInput(true);
connection.setDoOutput(false);
// Random ass user agent I grabbed from my snooping on imgur
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0");
// I tell the server what I want to receive.
// TODO: Should this just accept PNGs?
connection.setRequestProperty("Accept", "image/png,image/*");
return connection;
}
// Check if the URL is an Imgur link
private static boolean isImgurLink(URL url) {
@@ -8,6 +8,7 @@ import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.gui.global.GuiNPCManageEffects;
import noppes.npcs.client.gui.script.GuiScriptInterface;
import noppes.npcs.client.renderer.AnimationHelper;
import noppes.npcs.client.gui.util.GuiMenuTopButton;
import noppes.npcs.client.gui.util.GuiNpcButtonYesNo;
import noppes.npcs.client.gui.util.GuiNpcLabel;
@@ -129,6 +130,12 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi
int width = data.getTotalWidth();
int height = data.getTotalHeight();
// Animation V offset for preview
if (data.isAnimated()) {
iconY += (int) (data.getCurrentFrameVOffset() * height);
} else if (effect.animated && effect.frameCount > 1) {
iconY += (int) (AnimationHelper.getFrameVOffset(height, effect.frameCount, effect.frametime) * height);
}
func_152125_a(x, y, iconX, iconY, iconWidth, iconHeight, iconRenderSize, iconRenderSize, width, height);
@@ -183,6 +190,33 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi
effect.height
));
scrollWindow.addLabel(new GuiNpcLabel(9, "effect.editor.height", scrollWindow.getTextField(9).xPosition - 43, y + 6, 0xFFFFFF));
y += 25;
// Animation controls
scrollWindow.addLabel(new GuiNpcLabel(11, "gui.animated", x, y + 5, 0xFFFFFF));
GuiNpcButtonYesNo animBtn = new GuiNpcButtonYesNo(11, x + 70, y, 50, 20, effect.animated);
animBtn.setHoverText("gui.animated.hover");
scrollWindow.addButton(animBtn);
if (effect.animated) {
y += 23;
scrollWindow.addLabel(new GuiNpcLabel(12, "gui.frameCount", x, y + 6, 0xFFFFFF));
scrollWindow.addTextField(setIntegerOnly(
new GuiNpcTextField(12, this, x + 80, y, 60, 20, "" + effect.frameCount),
1,
256,
effect.frameCount
));
y += 23;
scrollWindow.addLabel(new GuiNpcLabel(13, "gui.frameTime", x, y + 6, 0xFFFFFF));
scrollWindow.addTextField(setIntegerOnly(
new GuiNpcTextField(13, this, x + 80, y, 60, 20, "" + effect.frametime),
1,
100,
effect.frametime
));
}
}
@@ -209,6 +243,11 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi
GuiNpcButtonYesNo button = (GuiNpcButtonYesNo) guibutton;
effect.lossOnDeath = button.getBoolean();
}
if (id == 11) {
GuiNpcButtonYesNo button = (GuiNpcButtonYesNo) guibutton;
effect.animated = button.getBoolean();
initGui();
}
}
@Override
@@ -248,6 +287,12 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi
case 9:
effect.height = guiNpcTextField.getInteger();
break;
case 12:
effect.frameCount = Math.max(1, guiNpcTextField.getInteger());
break;
case 13:
effect.frametime = Math.max(1, guiNpcTextField.getInteger());
break;
}
}
@@ -649,9 +649,9 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
// Search matches either the display name or the typeId (strip color codes for matching)
String stripped = displayName.replaceAll("\u00A7.", "");
if (search.isEmpty() || stripped.toLowerCase().contains(search) || typeId.toLowerCase().contains(search)) {
// Yellow for concurrent-capable types, gray for other built-in types
// Lime green for concurrent-capable types, gray for other built-in types
if (AbilityController.Instance.isConcurrentCapableType(typeId)) {
displayName = "\u00A7e" + displayName;
displayName = "\u00A7a" + displayName;
} else if (AbilityController.Instance.isBuiltInType(typeId)) {
displayName = "\u00A77" + displayName;
}
@@ -787,7 +787,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
NBTTagList actionList = new NBTTagList();
for (AbilityAction slot : npcSlots) {
actionList.appendTag(slot.writeNBT());
actionList.appendTag(slot.writeNBT(false));
}
compound.setTag("AbilityActions", actionList);
@@ -1105,7 +1105,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
public void onAbilitySaved(Ability ability) {
// Editing a global parent ability via "Modify Parent" on a chain entry
if (editingChainEntryParent) {
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT(false)));
return;
}
@@ -1119,7 +1119,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
AbilityAction slot = npcSlots.get(selectedAbilityIndex);
if (slot.isReference()) {
// Modify Parent on standalone reference — save to global preset
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT(false)));
} else {
// Inline ability — update slot data
npcSlots.set(selectedAbilityIndex, AbilityAction.inline(ability));
@@ -3,6 +3,8 @@ package noppes.npcs.client.gui.advanced;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldBuilder;
import noppes.npcs.client.gui.script.GuiScriptInterface;
import noppes.npcs.controllers.data.AbilityScript;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
@@ -143,6 +145,9 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
GuiMenuTopButton closeBtn = new GuiMenuTopButton(-1000, guiLeft + xSize - 22, guiTop - 17, "X");
addTopButton(closeBtn);
GuiMenuTopButton scriptBtn = new GuiMenuTopButton(-999, "script.scripts", closeBtn);
addTopButton(scriptBtn);
// Build scroll window dimensions
int swX = guiLeft + 4;
int swY = guiTop + 5;
@@ -152,9 +157,12 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
int y = 5;
int labelCounter = LABEL_ID_START;
// General tab: type label + optional concurrent label at top — reserve space
// General tab: type label + optional info labels at top — reserve space
if (activeTab == TAB_GENERAL) {
y += ROW_H;
if ("ability.cnpc.custom".equals(ability.getTypeId())) {
y += 15;
}
if (ability.isConcurrentCapable()) {
y += 15;
}
@@ -168,14 +176,20 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
GuiScrollWindow sw = builder.buildScrollWindow(tabFields, swX, swY, swW, swH);
// General tab: add type label + optional concurrent label at top of scroll window
// General tab: add type label + optional info labels at top of scroll window
if (activeTab == TAB_GENERAL) {
int baseId = builder.getNextLabelId();
int infoY = 25;
sw.addLabel(new GuiNpcLabel(baseId, "gui.type", 5, 10, 0xFFFFFF));
sw.addLabel(new GuiNpcLabel(baseId + 1, ability.getTypeId(), 55, 10, 0xFFFFFF));
if (ability.isConcurrentCapable()) {
if ("ability.cnpc.custom".equals(ability.getTypeId())) {
sw.addLabel(new GuiNpcLabel(baseId + 2,
StatCollector.translateToLocal("ability.concurrentInfo"), 5, 25, 0x55FF55));
StatCollector.translateToLocal("ability.customScriptInfo"), 5, infoY, 0xFF55FF));
infoY += 15;
}
if (ability.isConcurrentCapable()) {
sw.addLabel(new GuiNpcLabel(baseId + 3,
StatCollector.translateToLocal("ability.concurrentInfo"), 5, infoY, 0x55FF55));
}
}
@@ -302,6 +316,13 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
initGui();
return;
}
if (id == -999) {
GuiNpcTextField.unfocus();
applyToAbility();
callback.onAbilitySaved(ability);
GuiScriptInterface.open(parent, new AbilityScript(ability.getId()));
return;
}
if (id == -1000) {
close();
return;
@@ -405,7 +426,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
public void loadAbility(Ability loadedAbility) {
if (loadedAbility == null) return;
NBTTagCompound nbt = loadedAbility.writeNBT();
NBTTagCompound nbt = loadedAbility.writeNBT(false);
nbt.setString("typeId", ability.getTypeId());
ability.readNBT(nbt);
@@ -70,7 +70,7 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface implements ISubGui
private void doSave() {
saved = true;
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT(false)));
if (callback != null) {
callback.onAbilitySaved(ability);
}
@@ -83,8 +83,10 @@ public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomS
continue;
String displayName = I18n.format(typeId);
if (AbilityController.Instance.isConcurrentCapableType(typeId)) {
displayName = "\u00A7e" + displayName;
if (typeId.equals("ability.cnpc.custom")) {
displayName = "\u00A7d" + displayName;
} else if (AbilityController.Instance.isConcurrentCapableType(typeId)) {
displayName = "\u00A7a" + displayName;
}
allDisplayNameToTypeId.put(displayName, typeId);
}
@@ -122,6 +124,21 @@ public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomS
}
Collections.sort(list, (a, b) -> String.CASE_INSENSITIVE_ORDER.compare(
a.replaceAll("\u00A7.", ""), b.replaceAll("\u00A7.", "")));
// Pin Custom Ability to top of list
String customEntry = null;
for (String name : list) {
String tid = displayNameToTypeId.get(name);
if (tid != null && tid.equals("ability.cnpc.custom")) {
customEntry = name;
break;
}
}
if (customEntry != null) {
list.remove(customEntry);
list.add(0, customEntry);
}
return list;
}
@@ -5,6 +5,8 @@ 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.data.ChainedAbility;
import noppes.npcs.client.gui.script.GuiScriptInterface;
import noppes.npcs.controllers.data.ChainedAbilityScript;
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;
@@ -57,6 +59,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
private static final int BTN_TAB_ENTRIES = 91;
private static final int BTN_TAB_TARGET = 92;
private static final int BTN_TAB_EXTRA_BASE = 93;
private static final int BTN_SCRIPT = -999;
private static final int BTN_CLOSE = -1000;
// ── Entries tab: per-entry ID encoding ─────────────────────────────────────
@@ -160,14 +163,43 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
// ── Icon tab ──────────────────────────────────────────────
AbilityIconData chainIcon = AbilityIconData.fromChainedAbility(chain);
fieldDefs.add(FieldDef.stringField("gui.texture", chainIcon::getTexture, chainIcon::setTexture).tab("Icon"));
fieldDefs.add(FieldDef.section("ability.icon.section.uv").tab("Icon"));
fieldDefs.add(FieldDef.intField("ability.icon.x", chainIcon::getIconX, chainIcon::setIconX).tab("Icon").range(0, 4096));
fieldDefs.add(FieldDef.intField("ability.icon.y", chainIcon::getIconY, chainIcon::setIconY).tab("Icon").range(0, 4096));
fieldDefs.add(FieldDef.section("gui.size").tab("Icon"));
fieldDefs.add(FieldDef.intField("gui.width", chainIcon::getWidth, chainIcon::setWidth).tab("Icon").range(1, 256));
fieldDefs.add(FieldDef.intField("gui.height", chainIcon::getHeight, chainIcon::setHeight).tab("Icon").range(1, 256));
fieldDefs.add(FieldDef.row(
FieldDef.intField("gui.width", chainIcon::getWidth, chainIcon::setWidth).range(1, 256),
FieldDef.intField("gui.height", chainIcon::getHeight, chainIcon::setHeight).range(1, 256)
).tab("Icon"));
fieldDefs.add(FieldDef.floatField("gui.scale", chainIcon::getScale, chainIcon::setScale).tab("Icon").range(0.1f, 10.0f));
fieldDefs.add(FieldDef.intField("ability.icon.layers", chainIcon::getLayerCount, chainIcon::setLayerCount)
.tab("Icon").range(1, AbilityIconData.MAX_LAYERS));
for (int i = 0; i < AbilityIconData.MAX_LAYERS; i++) {
final int idx = i;
java.util.function.BooleanSupplier layerVisible = () -> chainIcon.getLayerCount() > idx;
String sectionLabel = net.minecraft.util.StatCollector.translateToLocal("ability.icon.layer") + " " + (idx + 1);
fieldDefs.add(FieldDef.section(sectionLabel).tab("Icon").visibleWhen(layerVisible));
fieldDefs.add(FieldDef.stringField("gui.texture",
() -> chainIcon.getLayer(idx).texture,
t -> chainIcon.setLayerTexture(idx, t))
.tab("Icon").visibleWhen(layerVisible));
fieldDefs.add(FieldDef.row(
FieldDef.intField("ability.icon.x",
() -> chainIcon.getLayer(idx).iconX,
x -> chainIcon.setLayerIconX(idx, x)).range(0, 4096),
FieldDef.intField("ability.icon.y",
() -> chainIcon.getLayer(idx).iconY,
y -> chainIcon.setLayerIconY(idx, y)).range(0, 4096)
).tab("Icon").visibleWhen(layerVisible));
fieldDefs.add(FieldDef.colorSubGui("ability.icon.tint",
() -> chainIcon.getLayer(idx).tintColor,
c -> chainIcon.setLayerTintColor(idx, c))
.tab("Icon").visibleWhen(layerVisible));
}
// Animation
fieldDefs.add(FieldDef.section("Animation").tab("Icon"));
fieldDefs.add(FieldDef.boolField("gui.animated", chainIcon::isAnimated, chainIcon::setAnimated).tab("Icon").hover("gui.animated.hover"));
fieldDefs.add(FieldDef.intField("gui.frameCount", chainIcon::getFrameCount, chainIcon::setFrameCount)
.tab("Icon").range(1, 256).visibleWhen(chainIcon::isAnimated));
fieldDefs.add(FieldDef.intField("gui.frameTime", chainIcon::getFrameTime, chainIcon::setFrameTime)
.tab("Icon").range(1, 100).visibleWhen(chainIcon::isAnimated));
// External field providers (e.g., DBC Addon injecting a "DBC" tab)
if (AbilityController.Instance != null) {
@@ -258,6 +290,9 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
GuiMenuTopButton closeBtn = new GuiMenuTopButton(BTN_CLOSE, guiLeft + xSize - 22, guiTop - 17, "X");
addTopButton(closeBtn);
GuiMenuTopButton scriptBtn = new GuiMenuTopButton(BTN_SCRIPT, "script.scripts", closeBtn);
addTopButton(scriptBtn);
// Scroll window dimensions
int swX = guiLeft + 4;
int swY = guiTop + 5;
@@ -487,6 +522,10 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
initGui();
return;
}
if (id == BTN_SCRIPT) {
GuiScriptInterface.open(parent, new ChainedAbilityScript(chain.getId()));
return;
}
if (id == BTN_CLOSE) {
saveOnClose = true;
close();
@@ -853,7 +892,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
public void onAbilitySaved(Ability ability) {
if (editingParentAbility) {
// Persist the global parent ability to the server
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT(false)));
editingParentAbility = false;
return;
}
@@ -187,19 +187,27 @@ public class FieldDef {
idSetter.accept(-1);
} else {
idSetter.accept(sel.selectedAnimationId);
nameSetter.accept("");
String customName = sel.getSelectedName();
nameSetter.accept(customName != null ? customName : "");
}
})
.buttonLabel(() -> {
String name = nameGetter.get();
if (name != null && !name.isEmpty()) return name;
int id = idGetter.get();
if (id < 0 && name != null && !name.isEmpty()) {
// Built-in animation: show just the name
return name;
}
if (id >= 0) {
// Custom animation: show (X) Name
if (name != null && !name.isEmpty()) {
return "(" + id + ") " + name;
}
Animation anim = AnimationController.Instance != null
? (Animation) AnimationController.Instance.get(id) : null;
String animName = anim != null ? anim.getName() : "";
return animName != null && !animName.isEmpty()
? "(ID: " + id + ") " + animName : "ID: " + id;
? "(" + id + ") " + animName : String.valueOf(id);
}
return "gui.none";
})
@@ -347,9 +347,14 @@ public class GuiFieldBuilder {
String translated = StatCollector.translateToLocal(def.getLabel());
int labelW = fontRenderer.getStringWidth(translated);
int fieldX = colLLabel + labelW + labelPadding;
// Clamp field width so it doesn't extend under the scrollbar
// Available width before the scrollbar
int maxW = contentRight - fieldX - 15;
if (maxW > 0 && fieldW > maxW) fieldW = maxW;
if (def.getType() == FieldType.SUB_GUI && maxW > 0) {
// SUB_GUI fields fill all available width up to the scrollbar
fieldW = maxW;
} else if (maxW > 0 && fieldW > maxW) {
fieldW = maxW;
}
renderFieldAt(def, colLLabel, fieldX, fieldW, y);
}
@@ -7,6 +7,7 @@ import noppes.npcs.api.gui.ICustomGuiComponent;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.gui.custom.GuiCustom;
import noppes.npcs.client.gui.custom.interfaces.IGuiComponent;
import noppes.npcs.client.renderer.AnimationHelper;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.scripted.gui.ScriptGuiTexturedRect;
import org.lwjgl.opengl.GL11;
@@ -30,6 +31,11 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
float alpha;
float rotation;
// Animation
boolean animated;
int frameCount = 1;
int frametime = 2;
public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) {
this(id, texture, x, y, width, height, 0, 0);
}
@@ -64,10 +70,18 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
int totalWidth = this.imageData.getTotalWidth();
int totalHeight = this.imageData.getTotalHeight();
// Animation V offset
float vOff = 0f;
if (this.imageData.isAnimated()) {
vOff = this.imageData.getCurrentFrameVOffset();
} else if (this.animated && this.frameCount > 1) {
vOff = AnimationHelper.getFrameVOffset(totalHeight, this.frameCount, this.frametime);
}
float u1 = (float) textureX / (float) totalWidth;
float u2 = u1 + (float) width / (float) totalWidth;
float v1 = (float) textureY / (float) totalHeight;
float v2 = v1 + (float) height / (float) totalHeight;
float v1 = vOff + (float) textureY / (float) totalHeight;
float v2 = vOff + ((float) textureY + (float) height) / (float) totalHeight;
GL11.glPushMatrix();
float red = (color >> 16 & 255) / 255f;
@@ -104,6 +118,9 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
component.setColor(color);
component.setAlpha(alpha);
component.setRotation(rotation);
if (this.animated && this.frameCount > 1) {
component.setAnimation(this.frameCount, this.frametime);
}
return component;
}
@@ -124,6 +141,12 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
rect.alpha = component.getAlpha();
rect.rotation = component.getRotation();
if (component.isAnimated()) {
rect.animated = true;
rect.frameCount = component.getFrameCount();
rect.frametime = component.getFrameTime();
}
return rect;
}
}
@@ -5,6 +5,8 @@ import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
import kamkeel.npcs.network.PacketClient;
import java.util.UUID;
import kamkeel.npcs.network.packets.request.ability.BuiltInAbilityGetPacket;
import kamkeel.npcs.network.packets.request.ability.ChainedAbilitiesGetPacket;
import kamkeel.npcs.network.packets.request.ability.ChainedAbilityGetPacket;
@@ -495,7 +497,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
private void handleChainConfigClosed() {
if (pendingSaveChain != null) {
PacketClient.sendClient(new ChainedAbilitySavePacket(pendingSaveChain.writeNBT()));
PacketClient.sendClient(new ChainedAbilitySavePacket(pendingSaveChain.writeNBT(false)));
selected = pendingSaveChain.getName();
pendingSaveChain = null;
}
@@ -510,6 +512,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
if (newAbility != null) {
gui.getVariants().get(idx).apply(newAbility);
newAbility.setId(UUID.randomUUID().toString());
pendingTypeId = null;
openConfig(newAbility);
return true;
@@ -536,6 +539,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
if (variants.size() == 1) {
variants.get(0).apply(newAbility);
}
newAbility.setId(UUID.randomUUID().toString());
openConfig(newAbility);
return true;
}
@@ -550,7 +554,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
if (pendingSaveAbility == null) return false;
if (gui.isConfirmed()) {
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT(false)));
pendingSaveAbility = null;
return false;
}
@@ -574,7 +578,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
setSubGui(new SubGuiDuplicateNameConfirm());
return true;
}
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT(false)));
pendingSaveAbility = null;
return false;
}
@@ -13,6 +13,7 @@ import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.renderer.AnimationHelper;
import noppes.npcs.client.renderer.ImageData;
import org.lwjgl.opengl.GL11;
@@ -25,6 +26,11 @@ public class AbilityIcon extends Gui {
public int width;
public int height;
// Default icon layers (extracted from ability)
private Ability.DefaultIconLayer[] defaultLayers = null;
private int defaultIconWidth = 48;
private int defaultIconHeight = 48;
private AbilityIcon(AbilityIconData data) {
this.data = data;
this.width = data.width;
@@ -33,7 +39,11 @@ public class AbilityIcon extends Gui {
public static AbilityIcon fromAbility(Ability ability) {
if (ability != null) {
return new AbilityIcon(AbilityIconData.fromAbility(ability));
AbilityIcon icon = new AbilityIcon(AbilityIconData.fromAbility(ability));
icon.defaultLayers = ability.getDefaultIconLayers();
icon.defaultIconWidth = ability.getDefaultIconWidth();
icon.defaultIconHeight = ability.getDefaultIconHeight();
return icon;
}
return fromDefaults();
}
@@ -66,44 +76,88 @@ public class AbilityIcon extends Gui {
public void draw(int state, float alpha) {
TextureManager renderEngine = Minecraft.getMinecraft().renderEngine;
ImageData imageData = null;
if (data.hasTexture()) {
imageData = ClientCacheHandler.getImageData(data.texture);
}
GL11.glPushMatrix();
GL11.glColor4f(1, 1, 1, alpha);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Tessellator t;
if (imageData == null || !imageData.imageLoaded()) {
GL11.glScalef(1.0f, 1.0f, 1);
renderEngine.bindTexture(FALLBACK_TEXTURE);
t = getFallbackTessellator();
} else {
if (data.isEnabled()) {
// Path 1: Custom icon — draw each active layer bottom-to-top
GL11.glScalef(data.scale, data.scale, 1);
renderEngine.bindTexture(imageData.getLocation());
t = getTessellator(imageData, state);
boolean drewAny = false;
for (int i = 0; i < data.getLayerCount(); i++) {
AbilityIconData.Layer layer = data.getLayer(i);
if (!layer.hasTexture()) continue;
ImageData imageData = ClientCacheHandler.getImageData(layer.texture);
if (imageData != null && imageData.imageLoaded()) {
int tint = layer.tintColor;
float r = ((tint >> 16) & 0xFF) / 255f;
float g = ((tint >> 8) & 0xFF) / 255f;
float b = (tint & 0xFF) / 255f;
GL11.glColor4f(r, g, b, alpha);
renderEngine.bindTexture(imageData.getLocation());
Tessellator t = getLayerTessellator(imageData, layer, i == 0 ? state : 0);
t.draw();
drewAny = true;
}
}
if (!drewAny) {
GL11.glColor4f(1, 1, 1, alpha);
renderEngine.bindTexture(FALLBACK_TEXTURE);
getFallbackTessellator().draw();
}
} else if (hasDefaultLayers()) {
// Path 2: Default layers — draw each layer with its dynamic color
for (Ability.DefaultIconLayer defLayer : defaultLayers) {
String texPath = defLayer.getTextureForState(state);
if (texPath == null || texPath.isEmpty()) continue;
ImageData imageData = ClientCacheHandler.getImageData(texPath);
if (imageData != null && imageData.imageLoaded()) {
int color = defLayer.getColor();
float r = ((color >> 16) & 0xFF) / 255f;
float g = ((color >> 8) & 0xFF) / 255f;
float b = (color & 0xFF) / 255f;
GL11.glColor4f(r, g, b, alpha);
renderEngine.bindTexture(imageData.getLocation());
getDefaultIconTessellator().draw();
}
}
} else {
// Path 3: No custom icon, no default layers — generic fallback
GL11.glColor4f(1, 1, 1, alpha);
renderEngine.bindTexture(FALLBACK_TEXTURE);
getFallbackTessellator().draw();
}
t.draw();
GL11.glPopMatrix();
}
private Tessellator getTessellator(ImageData imageData, int state) {
private boolean hasDefaultLayers() {
return defaultLayers != null && defaultLayers.length > 0;
}
private Tessellator getLayerTessellator(ImageData imageData, AbilityIconData.Layer layer, int state) {
float hw = data.width / 2f;
float hh = data.height / 2f;
float texW = imageData.getTotalWidth();
float texH = imageData.getTotalHeight();
int ix = data.getIconXForState(state);
int iy = data.getIconYForState(state);
// State UV overrides only apply to layer 0
int ix = (state > 0) ? data.getIconXForState(state) : layer.iconX;
int iy = (state > 0) ? data.getIconYForState(state) : layer.iconY;
// Animation V offset
float vOff = 0f;
if (imageData.isAnimated()) {
vOff = imageData.getCurrentFrameVOffset();
} else if (data.isAnimated()) {
vOff = AnimationHelper.getFrameVOffset((int) texH, data.getFrameCount(), data.getFrameTime());
}
float u1 = ix / texW;
float v1 = iy / texH;
float v1 = vOff + iy / texH;
float u2 = (ix + data.width) / texW;
float v2 = (iy + data.height) / texH;
float v2 = vOff + (iy + data.height) / texH;
Tessellator t = Tessellator.instance;
t.startDrawingQuads();
@@ -114,6 +168,19 @@ public class AbilityIcon extends Gui {
return t;
}
private Tessellator getDefaultIconTessellator() {
float hw = defaultIconWidth / 2f;
float hh = defaultIconHeight / 2f;
Tessellator t = Tessellator.instance;
t.startDrawingQuads();
t.addVertexWithUV(-hw, hh, zLevel, 0, 1);
t.addVertexWithUV(hw, hh, zLevel, 1, 1);
t.addVertexWithUV(hw, -hh, zLevel, 1, 0);
t.addVertexWithUV(-hw, -hh, zLevel, 0, 0);
return t;
}
private Tessellator getFallbackTessellator() {
float hw = 16f;
float hh = 16f;
@@ -128,17 +195,20 @@ public class AbilityIcon extends Gui {
}
public boolean hasTexture() {
return data.hasTexture();
return data.isEnabled() || hasDefaultLayers();
}
/**
* Returns the approximate visual size (max dimension) that draw() produces.
* Textured: max(width,height) * scale. Fallback: 32.
* Custom icon: max(width,height) * scale. Default icon: max(defaultW,defaultH). Fallback: 32.
*/
public float getDrawSize() {
if (data.hasTexture()) {
if (data.isEnabled()) {
return Math.max(width, height) * data.scale;
}
if (hasDefaultLayers()) {
return Math.max(defaultIconWidth, defaultIconHeight);
}
return 32f;
}
}
@@ -10,6 +10,7 @@ import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.CustomNpcResourceListener;
import noppes.npcs.client.renderer.AnimationHelper;
import noppes.npcs.client.gui.SubGuiColorSelector;
import noppes.npcs.client.gui.global.GuiNPCManageLinked;
import noppes.npcs.client.gui.script.GuiScriptInterface;
@@ -286,6 +287,31 @@ public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListe
scrollWindow.addLabel(new GuiNpcLabel(70, "display.durabilityShow", x, localY + 5, 0xFFFFFF));
GuiNpcButtonYesNo durabilityButton = new GuiNpcButtonYesNo(26, x + 120, localY, linkedItem.display.durabilityShow);
scrollWindow.addButton(durabilityButton);
localY += 30;
// Animation controls
scrollWindow.addLabel(new GuiNpcLabel(80, "gui.animated", x, localY + 5, 0xFFFFFF));
boolean isAnim = linkedItem.display.animated != null && linkedItem.display.animated;
GuiNpcButtonYesNo animBtn = new GuiNpcButtonYesNo(29, x + 120, localY, isAnim);
animBtn.setHoverText("gui.animated.hover");
scrollWindow.addButton(animBtn);
localY += 25;
if (isAnim) {
scrollWindow.addLabel(new GuiNpcLabel(81, "gui.frameCount", x, localY + 5, 0xFFFFFF));
GuiNpcTextField fcField = new GuiNpcTextField(71, this, x + 120, localY, 60, 20,
"" + (linkedItem.display.frameCount != null ? linkedItem.display.frameCount : 1));
fcField.setIntegersOnly().setMinMaxDefault(1, 256, 1);
scrollWindow.addTextField(fcField);
localY += 25;
scrollWindow.addLabel(new GuiNpcLabel(82, "gui.frameTime", x, localY + 5, 0xFFFFFF));
GuiNpcTextField ftField = new GuiNpcTextField(72, this, x + 120, localY, 60, 20,
"" + (linkedItem.display.frametime != null ? linkedItem.display.frametime : 2));
ftField.setIntegersOnly().setMinMaxDefault(1, 100, 2);
scrollWindow.addTextField(ftField);
localY += 25;
}
scrollWindow.scrollY = 0;
scrollWindow.maxScrollY = Math.max(localY - scrollWindow.clipHeight, 0);
@@ -381,6 +407,9 @@ public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListe
linkedItem.isNormalItem = ((GuiNpcButtonYesNo) guibutton).getBoolean();
} else if (id == 26 && guibutton instanceof GuiNpcButtonYesNo) {
linkedItem.display.durabilityShow = ((GuiNpcButtonYesNo) guibutton).getBoolean();
} else if (id == 29 && guibutton instanceof GuiNpcButtonYesNo) {
linkedItem.display.animated = ((GuiNpcButtonYesNo) guibutton).getBoolean();
initGui();
}
}
@@ -429,6 +458,10 @@ public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListe
linkedItem.display.translateY = textField.getFloat();
} else if (id == 63) {
linkedItem.display.translateZ = textField.getFloat();
} else if (id == 71) {
linkedItem.display.frameCount = Math.max(1, textField.getInteger());
} else if (id == 72) {
linkedItem.display.frametime = Math.max(1, textField.getInteger());
}
}
@@ -472,7 +505,20 @@ public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListe
int iconWidth = data.getTotalWidth();
int iconHeight = data.getTotalWidth();
int width = data.getTotalWidth();
int height = data.getTotalWidth();
int height = data.getTotalHeight();
// Animation V offset for preview
if (data.isAnimated()) {
iconY += (int) (data.getCurrentFrameVOffset() * height);
iconHeight = data.getFrameHeight();
} else if (linkedItem.display.animated != null && linkedItem.display.animated
&& linkedItem.display.frameCount != null && linkedItem.display.frameCount > 1) {
iconY += (int) (AnimationHelper.getFrameVOffset(height, linkedItem.display.frameCount, linkedItem.display.frametime) * height);
iconHeight = height / linkedItem.display.frameCount;
} else {
iconHeight = data.getTotalWidth();
height = data.getTotalWidth();
}
float[] colors = ColorUtil.hexToRGB(linkedItem.display.itemColor);
GL11.glColor3f(colors[0], colors[1], colors[2]);
@@ -145,11 +145,12 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL
scrollSounds.resetScroll();
getTextField(66).setText("");
soundSearch = "";
initGui();
}
if (guiCustomScroll.id == 1) {
selectedResource = new ResourceLocation(selectedDomain, guiCustomScroll.getSelected());
getButton(1).enabled = true;
}
initGui();
}
@Override
@@ -6,6 +6,7 @@ import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.texture.TextureManager;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.renderer.AnimationHelper;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.controllers.data.CustomEffect;
import noppes.npcs.controllers.data.PlayerEffect;
@@ -82,6 +83,13 @@ public class GuiEffectBar extends GuiScreen {
int texWidth = imageData.getTotalWidth();
int texHeight = imageData.getTotalHeight();
// Animation V offset
if (imageData.isAnimated()) {
iconV += (int) (imageData.getCurrentFrameVOffset() * texHeight);
} else if (entry.effect.animated && entry.effect.frameCount > 1) {
iconV += (int) (AnimationHelper.getFrameVOffset(texHeight, entry.effect.frameCount, entry.effect.frametime) * texHeight);
}
// Use iconYOffset to vertically center the icon
func_152125_a(x + 2, drawY + iconYOffset, iconU, iconV, iconWidth, iconHeight, iconRenderSize, iconRenderSize, texWidth, texHeight);
@@ -191,7 +199,14 @@ public class GuiEffectBar extends GuiScreen {
if (imageData != null && imageData.imageLoaded()) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
imageData.bindTexture();
func_152125_a(tooltipX + (maxWidth - iconSize) / 2, textY + 4, hoveredEffect.iconX, hoveredEffect.iconY, hoveredEffect.getWidth(), hoveredEffect.getHeight(), iconSize, iconSize, imageData.getTotalWidth(), imageData.getTotalHeight());
int tooltipIconV = hoveredEffect.iconY;
int tooltipTexH = imageData.getTotalHeight();
if (imageData.isAnimated()) {
tooltipIconV += (int) (imageData.getCurrentFrameVOffset() * tooltipTexH);
} else if (hoveredEffect.animated && hoveredEffect.frameCount > 1) {
tooltipIconV += (int) (AnimationHelper.getFrameVOffset(tooltipTexH, hoveredEffect.frameCount, hoveredEffect.frametime) * tooltipTexH);
}
func_152125_a(tooltipX + (maxWidth - iconSize) / 2, textY + 4, hoveredEffect.iconX, tooltipIconV, hoveredEffect.getWidth(), hoveredEffect.getHeight(), iconSize, iconSize, imageData.getTotalWidth(), tooltipTexH);
}
textureManager.bindTexture(specialIcons);
@@ -0,0 +1,49 @@
package noppes.npcs.client.renderer;
import net.minecraft.client.Minecraft;
/**
* Static utility for computing animated texture UV offsets.
* Used by renderers when animation parameters come from data class fields
* rather than .mcmeta auto-detection on ImageData.
*/
public class AnimationHelper {
/**
* Returns the V-coordinate offset (0.0-1.0) for the current animation frame.
* Based on system time for consistent sync across all animated textures.
*
* @param totalHeight Total pixel height of the sprite strip
* @param frameCount Number of frames in the strip
* @param frametime Ticks per frame (1 tick = 50ms)
* @return V offset in 0.0-1.0 range, or 0.0 if not animated
*/
public static float getFrameVOffset(int totalHeight, int frameCount, int frametime) {
if (frameCount <= 1 || totalHeight <= 0) {
return 0f;
}
frametime = Math.max(1, frametime);
long millis = Minecraft.getSystemTime();
int tick = (int) (millis / 50L);
int frameIdx = (tick / frametime) % frameCount;
int frameHeight = totalHeight / frameCount;
return (float) (frameIdx * frameHeight) / (float) totalHeight;
}
/**
* Returns the V-coordinate size of a single frame in 0.0-1.0 range.
*
* @param totalHeight Total pixel height of the sprite strip
* @param frameCount Number of frames in the strip
* @return V size of one frame, or 1.0 if not animated
*/
public static float getFrameVSize(int totalHeight, int frameCount) {
if (frameCount <= 1 || totalHeight <= 0) {
return 1f;
}
int frameHeight = totalHeight / frameCount;
return (float) frameHeight / (float) totalHeight;
}
}
@@ -1,5 +1,8 @@
package noppes.npcs.client.renderer;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IResource;
@@ -11,6 +14,7 @@ import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class ImageData {
private final ResourceLocation location;
@@ -23,6 +27,14 @@ public class ImageData {
private boolean gotWidthHeight;
private boolean invalid;
// Animation fields
private boolean animated = false;
private int frameCount = 1;
private int frametime = 2;
private int[] frames = null;
private boolean interpolate = false;
private boolean mcmetaChecked = false;
public ImageData(String directory) {
this.location = new ResourceLocation(directory);
if (directory.startsWith("https://") || directory.startsWith("http://")) {
@@ -141,6 +153,11 @@ public class ImageData {
private void correctWidthHeight() {
this.totalWidth = Math.max(this.totalWidth, 1);
this.totalHeight = Math.max(this.totalHeight, 1);
if (!this.isUrl && !this.mcmetaChecked) {
this.mcmetaChecked = true;
tryLoadMcmeta();
}
}
public int getTotalWidth() {
@@ -150,4 +167,112 @@ public class ImageData {
public int getTotalHeight() {
return this.gotWidthHeight ? this.totalHeight : -1;
}
// ═══════════════════════════════════════════════════════════════════
// ANIMATION
// ═══════════════════════════════════════════════════════════════════
private void tryLoadMcmeta() {
try {
ResourceLocation mcmetaLoc = new ResourceLocation(
location.getResourceDomain(),
location.getResourcePath() + ".mcmeta"
);
IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(mcmetaLoc);
InputStream stream = resource.getInputStream();
try {
InputStreamReader reader = new InputStreamReader(stream);
JsonObject root = new JsonParser().parse(reader).getAsJsonObject();
if (root.has("animation")) {
JsonObject anim = root.getAsJsonObject("animation");
this.animated = true;
if (anim.has("frametime")) {
this.frametime = Math.max(1, anim.get("frametime").getAsInt());
}
if (anim.has("interpolate")) {
this.interpolate = anim.get("interpolate").getAsBoolean();
}
if (anim.has("frames")) {
JsonArray framesArray = anim.getAsJsonArray("frames");
this.frames = new int[framesArray.size()];
int maxFrame = 0;
for (int i = 0; i < framesArray.size(); i++) {
this.frames[i] = framesArray.get(i).getAsInt();
if (this.frames[i] > maxFrame) {
maxFrame = this.frames[i];
}
}
this.frameCount = maxFrame + 1;
} else if (this.totalWidth > 0) {
this.frameCount = Math.max(1, this.totalHeight / this.totalWidth);
}
}
} finally {
stream.close();
}
} catch (Exception ignored) {
// No .mcmeta found or parse error — not animated
}
}
/**
* Programmatically enable animation on this ImageData.
* Used when animation settings come from data class fields rather than .mcmeta files.
*/
public void setAnimation(int frameCount, int frametime) {
if (frameCount > 1) {
this.animated = true;
this.frameCount = Math.max(1, frameCount);
this.frametime = Math.max(1, frametime);
}
}
public boolean isAnimated() {
return this.animated && this.frameCount > 1;
}
public int getFrameCount() {
return this.frameCount;
}
public int getFrameTime() {
return this.frametime;
}
/**
* Returns the pixel height of a single animation frame.
* For non-animated textures, returns the total height.
*/
public int getFrameHeight() {
if (this.animated && this.frameCount > 1) {
return Math.max(1, this.totalHeight / this.frameCount);
}
return this.gotWidthHeight ? this.totalHeight : -1;
}
/**
* Returns the V-coordinate offset (0.0-1.0) for the current animation frame.
* Based on system time so all instances of the same texture animate in sync.
* Returns 0.0 for non-animated textures.
*/
public float getCurrentFrameVOffset() {
if (!this.animated || this.frameCount <= 1 || this.totalHeight <= 0) {
return 0f;
}
long millis = Minecraft.getSystemTime();
int tick = (int) (millis / 50L);
int frameIdx;
if (this.frames != null && this.frames.length > 0) {
frameIdx = (tick / this.frametime) % this.frames.length;
frameIdx = this.frames[frameIdx];
} else {
frameIdx = (tick / this.frametime) % this.frameCount;
}
int frameHeight = this.totalHeight / this.frameCount;
return (float) (frameIdx * frameHeight) / (float) this.totalHeight;
}
}
@@ -17,6 +17,7 @@ import net.minecraftforge.client.IItemRenderer;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.renderer.AnimationHelper;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.items.ItemCustomizable;
import noppes.npcs.scripted.NpcAPI;
@@ -222,7 +223,8 @@ public class ItemCustomRenderer implements IItemRenderer {
int pass = 0;
GL11.glPushMatrix();
ClientCacheHandler.getImageData(scriptCustomItem.getTexture()).bindTexture();
ImageData entityImageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
entityImageData.bindTexture();
if (renderInFrame) {
GL11.glTranslatef(0.0F, -0.05F, 0.0F);
@@ -233,10 +235,22 @@ public class ItemCustomRenderer implements IItemRenderer {
Tessellator tessellator = Tessellator.instance;
// Animation V offset for entity rendering
float entityVOff = 0f;
float entityVEnd = 1f;
if (entityImageData.isAnimated()) {
entityVOff = entityImageData.getCurrentFrameVOffset();
entityVEnd = entityVOff + (float) entityImageData.getFrameHeight() / entityImageData.getTotalHeight();
} else if (scriptCustomItem.isTextureAnimated() != null && scriptCustomItem.isTextureAnimated()
&& scriptCustomItem.getFrameCount() != null && scriptCustomItem.getFrameCount() > 1) {
entityVOff = AnimationHelper.getFrameVOffset(entityImageData.getTotalHeight(), scriptCustomItem.getFrameCount(), scriptCustomItem.getFrameTime());
entityVEnd = entityVOff + AnimationHelper.getFrameVSize(entityImageData.getTotalHeight(), scriptCustomItem.getFrameCount());
}
float f14 = 0.0F;
float f15 = 1.0F;
float f4 = 0.0F;
float f5 = 1.0F;
float f4 = entityVOff;
float f5 = entityVEnd;
float f6 = 1.0F;
float f7 = 0.5F;
float f8 = 0.25F;
@@ -272,8 +286,11 @@ public class ItemCustomRenderer implements IItemRenderer {
GL11.glRotatef(-90.0F, 0.0F, 0.0F, 1.0F);
}*/
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
ItemRenderer.renderItemIn2D(tessellator, f15, f4, f14, f5, imageData.getTotalWidth(), imageData.getTotalHeight(), f9);
ImageData loopImageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
int entityFrameH = loopImageData.isAnimated() ? loopImageData.getFrameHeight()
: (scriptCustomItem.isTextureAnimated() != null && scriptCustomItem.isTextureAnimated() && scriptCustomItem.getFrameCount() != null && scriptCustomItem.getFrameCount() > 1
? loopImageData.getTotalHeight() / scriptCustomItem.getFrameCount() : loopImageData.getTotalHeight());
ItemRenderer.renderItemIn2D(tessellator, f15, f4, f14, f5, loopImageData.getTotalWidth(), entityFrameH, f9);
if (itemStack.hasEffect(pass)) {
GL11.glDepthFunc(GL11.GL_EQUAL);
@@ -359,8 +376,20 @@ public class ItemCustomRenderer implements IItemRenderer {
GL11.glDisable(GL11.GL_LIGHTING); //Forge: Make sure that render states are reset, a renderEffect can derp them up.
GL11.glEnable(GL11.GL_ALPHA_TEST);
ClientCacheHandler.getImageData(scriptCustomItem.getTexture()).bindTexture();
renderCustomItemSlot(0, 0, 16, 16, itemRed, itemGreen, itemBlue);
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
imageData.bindTexture();
float vOff = 0f;
float vEnd = 1f;
if (imageData.isAnimated()) {
vOff = imageData.getCurrentFrameVOffset();
vEnd = vOff + (float) imageData.getFrameHeight() / imageData.getTotalHeight();
} else if (scriptCustomItem.isTextureAnimated() != null && scriptCustomItem.isTextureAnimated()
&& scriptCustomItem.getFrameCount() != null && scriptCustomItem.getFrameCount() > 1) {
vOff = AnimationHelper.getFrameVOffset(imageData.getTotalHeight(), scriptCustomItem.getFrameCount(), scriptCustomItem.getFrameTime());
vEnd = vOff + AnimationHelper.getFrameVSize(imageData.getTotalHeight(), scriptCustomItem.getFrameCount());
}
renderCustomItemSlot(0, 0, 16, 16, itemRed, itemGreen, itemBlue, vOff, vEnd);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_ALPHA_TEST);
@@ -412,13 +441,17 @@ public class ItemCustomRenderer implements IItemRenderer {
}
public void renderCustomItemSlot(int posX, int posY, int imageWidth, int imageHeight, float itemRed, float itemGreen, float itemBlue) {
renderCustomItemSlot(posX, posY, imageWidth, imageHeight, itemRed, itemGreen, itemBlue, 0f, 1f);
}
public void renderCustomItemSlot(int posX, int posY, int imageWidth, int imageHeight, float itemRed, float itemGreen, float itemBlue, float vOff, float vEnd) {
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(itemRed, itemGreen, itemBlue, 1.0F);
tessellator.addVertexWithUV((double) (posX), (double) (posY + imageHeight), 0, 0, 1);
tessellator.addVertexWithUV((double) (posX + imageWidth), (double) (posY + imageHeight), 0, 1, 1);
tessellator.addVertexWithUV((double) (posX + imageWidth), (double) (posY), 0, 1, 0);
tessellator.addVertexWithUV((double) (posX), (double) (posY), 0, 0, 0);
tessellator.addVertexWithUV((double) (posX), (double) (posY + imageHeight), 0, 0, vEnd);
tessellator.addVertexWithUV((double) (posX + imageWidth), (double) (posY + imageHeight), 0, 1, vEnd);
tessellator.addVertexWithUV((double) (posX + imageWidth), (double) (posY), 0, 1, vOff);
tessellator.addVertexWithUV((double) (posX), (double) (posY), 0, 0, vOff);
tessellator.draw();
}
@@ -429,7 +462,8 @@ public class ItemCustomRenderer implements IItemRenderer {
TextureManager texturemanager = mc.getTextureManager();
int par3 = 0;
ClientCacheHandler.getImageData(scriptCustomItem.getTexture()).bindTexture();
ImageData item3dImageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
item3dImageData.bindTexture();
Tessellator tessellator = Tessellator.instance;
IIcon icon = entityLivingBase.getItemIcon(itemStack, par3);
@@ -447,7 +481,19 @@ public class ItemCustomRenderer implements IItemRenderer {
GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
renderCustomItemIn2D(scriptCustomItem, tessellator, 1.0F, 0.0F, 0.0F, 1.0F, 0.0625F);
// Animation V offset for 3D handheld rendering
float item3dVOff = 0f;
float item3dVEnd = 1f;
if (item3dImageData.isAnimated()) {
item3dVOff = item3dImageData.getCurrentFrameVOffset();
item3dVEnd = item3dVOff + (float) item3dImageData.getFrameHeight() / item3dImageData.getTotalHeight();
} else if (scriptCustomItem.isTextureAnimated() != null && scriptCustomItem.isTextureAnimated()
&& scriptCustomItem.getFrameCount() != null && scriptCustomItem.getFrameCount() > 1) {
item3dVOff = AnimationHelper.getFrameVOffset(item3dImageData.getTotalHeight(), scriptCustomItem.getFrameCount(), scriptCustomItem.getFrameTime());
item3dVEnd = item3dVOff + AnimationHelper.getFrameVSize(item3dImageData.getTotalHeight(), scriptCustomItem.getFrameCount());
}
renderCustomItemIn2D(scriptCustomItem, tessellator, 1.0F, item3dVOff, 0.0F, item3dVEnd, 0.0625F);
if (itemStack.hasEffect(par3)) {
GL11.glDepthFunc(GL11.GL_EQUAL);
@@ -485,7 +531,10 @@ public class ItemCustomRenderer implements IItemRenderer {
public static void renderCustomItemIn2D(IItemCustomizable wrapper, Tessellator p_78439_0_, float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, float p_78439_7_) {
ImageData imageData = ClientCacheHandler.getImageData(wrapper.getTexture());
int width = imageData.getTotalWidth();
int height = imageData.getTotalHeight();
// Use frame height for edge pixel calculations so animated strips render correctly
int height = imageData.isAnimated() ? imageData.getFrameHeight()
: (wrapper.isTextureAnimated() != null && wrapper.isTextureAnimated() && wrapper.getFrameCount() != null && wrapper.getFrameCount() > 1
? imageData.getTotalHeight() / wrapper.getFrameCount() : imageData.getTotalHeight());
p_78439_0_.startDrawingQuads();
p_78439_0_.setNormal(0.0F, 0.0F, 1.0F);