Default Icon Layer Handling

This commit is contained in:
Kam committed 2026-02-28 16:58:38 -05:00
1 parent eaec10e529
commit 8056640102
54 files changed
+360 -199

No files matched your search

@@ -136,12 +136,33 @@ public abstract class Ability implements IAbility, IAbilityAction {
protected transient boolean builtIn = false;
protected transient String registryKey;
// Default icon (set in subclass constructors, NOT persisted)
protected transient String defaultIconTexture = "";
protected transient java.util.function.IntSupplier defaultIconColorSource = null;
// Default icon layers (set in subclass constructors, NOT persisted)
protected transient DefaultIconLayer[] defaultIconLayers = null;
protected transient int defaultIconWidth = 48;
protected transient int defaultIconHeight = 48;
protected transient String[] defaultIconStateTextures = null;
/**
* A single layer of a default ability icon. Each layer has a texture and
* an optional dynamic color source derived from the ability's properties.
*/
public static class DefaultIconLayer {
public final String texture;
public final java.util.function.IntSupplier colorSource;
public DefaultIconLayer(String texture, java.util.function.IntSupplier colorSource) {
this.texture = texture;
this.colorSource = colorSource;
}
/** Layer with no color tinting (renders as white). */
public DefaultIconLayer(String texture) {
this(texture, null);
}
public int getColor() {
return colorSource != null ? colorSource.getAsInt() : 0xFFFFFF;
}
}
// ═══════════════════════════════════════════════════════════════════
// TOGGLE CONFIGURATION (saved to NBT for custom abilities)
@@ -778,27 +799,23 @@ public abstract class Ability implements IAbility, IAbilityAction {
// ── Icon section (Effects tab) ───────────────────────────
if (!isNpcInlineEdit()) {
AbilityIconData icon = AbilityIconData.fromAbility(this);
java.util.function.BooleanSupplier isCustom = icon::isEnabled;
defs.add(FieldDef.section("ability.section.icon").tab("Effects"));
defs.add(FieldDef.boolField("ability.hasIcon", icon::isEnabled, icon::setEnabled)
.tab("Effects"));
defs.add(FieldDef.stringField("gui.texture", icon::getTexture, icon::setTexture)
.tab("Effects").visibleWhen(icon::isEnabled));
defs.add(FieldDef.section("ability.icon.section.uv").tab("Effects")
.visibleWhen(icon::isEnabled));
defs.add(FieldDef.intField("ability.icon.x", icon::getIconX, icon::setIconX)
.tab("Effects").range(0, 4096).visibleWhen(icon::isEnabled));
defs.add(FieldDef.intField("ability.icon.y", icon::getIconY, icon::setIconY)
.tab("Effects").range(0, 4096).visibleWhen(icon::isEnabled));
defs.add(FieldDef.section("gui.size").tab("Effects")
.visibleWhen(icon::isEnabled));
defs.add(FieldDef.intField("gui.width", icon::getWidth, icon::setWidth)
.tab("Effects").range(1, 256).visibleWhen(icon::isEnabled));
defs.add(FieldDef.intField("gui.height", icon::getHeight, icon::setHeight)
.tab("Effects").range(1, 256).visibleWhen(icon::isEnabled));
defs.add(FieldDef.row(
FieldDef.intField("gui.width", icon::getWidth, icon::setWidth).range(1, 256),
FieldDef.intField("gui.height", icon::getHeight, icon::setHeight).range(1, 256)
).tab("Effects").visibleWhen(isCustom));
defs.add(FieldDef.floatField("gui.scale", icon::getScale, icon::setScale)
.tab("Effects").range(0.1f, 10.0f).visibleWhen(icon::isEnabled));
defs.add(FieldDef.colorSubGui("ability.icon.tint", icon::getTintColor, icon::setTintColor)
.tab("Effects").visibleWhen(icon::isEnabled));
.tab("Effects").range(0.1f, 10.0f).visibleWhen(isCustom));
defs.add(FieldDef.intField("ability.icon.layers", icon::getLayerCount, icon::setLayerCount)
.tab("Effects").range(1, AbilityIconData.MAX_LAYERS).visibleWhen(isCustom));
addIconLayerFields(defs, icon, 0, isCustom);
addIconLayerFields(defs, icon, 1, () -> isCustom.getAsBoolean() && icon.getLayerCount() >= 2);
addIconLayerFields(defs, icon, 2, () -> isCustom.getAsBoolean() && icon.getLayerCount() >= 3);
}
// External field providers (e.g., DBC Addon injecting a "DBC" tab)
@@ -809,6 +826,28 @@ public abstract class Ability implements IAbility, IAbilityAction {
return defs;
}
private void addIconLayerFields(List<FieldDef> defs, AbilityIconData icon, int layerIndex,
java.util.function.BooleanSupplier visible) {
String sectionLabel = StatCollector.translateToLocal("ability.icon.layer") + " " + (layerIndex + 1);
defs.add(FieldDef.section(sectionLabel).tab("Effects").visibleWhen(visible));
defs.add(FieldDef.stringField("gui.texture",
() -> icon.getLayer(layerIndex).texture,
t -> icon.setLayerTexture(layerIndex, t))
.tab("Effects").visibleWhen(visible));
defs.add(FieldDef.row(
FieldDef.intField("ability.icon.x",
() -> icon.getLayer(layerIndex).iconX,
x -> icon.setLayerIconX(layerIndex, x)).range(0, 4096),
FieldDef.intField("ability.icon.y",
() -> icon.getLayer(layerIndex).iconY,
y -> icon.setLayerIconY(layerIndex, y)).range(0, 4096)
).tab("Effects").visibleWhen(visible));
defs.add(FieldDef.colorSubGui("ability.icon.tint",
() -> icon.getLayer(layerIndex).tintColor,
c -> icon.setLayerTintColor(layerIndex, c))
.tab("Effects").visibleWhen(visible));
}
/**
* Creates the GUI for configuring this ability.
* Override this method to provide a custom GUI subclass for type-specific settings.
@@ -1622,24 +1661,8 @@ public abstract class Ability implements IAbility, IAbilityAction {
// DEFAULT ICON
// ═══════════════════════════════════════════════════════════════════
public String getDefaultIconTexture() {
return defaultIconTexture;
}
/**
* Returns the default icon texture for a specific toggle state.
* Falls back to the base defaultIconTexture if no state-specific texture exists.
* @param state 1-indexed toggle state (0 = off/default)
*/
public String getDefaultIconTextureForState(int state) {
if (state > 0 && defaultIconStateTextures != null && state - 1 < defaultIconStateTextures.length) {
return defaultIconStateTextures[state - 1];
}
return defaultIconTexture;
}
public int getDefaultIconColor() {
return defaultIconColorSource != null ? defaultIconColorSource.getAsInt() : 0xFFFFFF;
public DefaultIconLayer[] getDefaultIconLayers() {
return defaultIconLayers;
}
public int getDefaultIconWidth() {
@@ -1650,12 +1673,9 @@ public abstract class Ability implements IAbility, IAbilityAction {
return defaultIconHeight;
}
public String[] getDefaultIconStateTextures() {
return defaultIconStateTextures;
}
public boolean hasDefaultIcon() {
return defaultIconTexture != null && !defaultIconTexture.isEmpty();
return defaultIconLayers != null && defaultIconLayers.length > 0
&& defaultIconLayers[0].texture != null && !defaultIconLayers[0].texture.isEmpty();
}
public Ability deepCopy() {
@@ -6,17 +6,16 @@ import net.minecraft.nbt.NBTTagList;
/**
* Icon data for abilities, stored in the ability's customData NBT under "AbilityIcon".
* Used to render ability icons in the Ability Hotbar, Wheel, and Abilities Tab.
* Supports up to 3 layers, each with its own texture, UV coordinates, and tint color.
* Width, height, and scale are shared across all layers.
*/
public class AbilityIconData {
public static final String NBT_KEY = "AbilityIcon";
public static final int MAX_LAYERS = 3;
private final NBTTagCompound customData;
// Icon properties
public String texture = "";
public int iconX = 0;
public int iconY = 0;
// Shared across all layers
public int width = 32;
public int height = 32;
public float scale = 1.0f;
@@ -24,12 +23,50 @@ public class AbilityIconData {
/** Whether a custom icon override is active. Default false = use type's default icon. */
private boolean enabled = false;
/** Manual tint color for the custom icon (0xRRGGBB). Default white = no tint. */
private int tintColor = 0xFFFFFF;
/** Number of active layers (1-3). */
private int layerCount = 1;
/** Per-state icon UV overrides (0-indexed, maps to toggle states 1, 2, ...). */
/** Layer data (always 3 slots allocated). */
private Layer[] layers = { new Layer(), new Layer(), new Layer() };
/** Per-state icon UV overrides for layer 0 (0-indexed, maps to toggle states 1, 2, ...). */
private int[][] stateIcons = null;
// ═══════════════════════════════════════════════════════════════════
// LAYER INNER CLASS
// ═══════════════════════════════════════════════════════════════════
public static class Layer {
public String texture = "";
public int iconX = 0;
public int iconY = 0;
public int tintColor = 0xFFFFFF;
public Layer() {}
public boolean hasTexture() {
return texture != null && !texture.isEmpty();
}
public void writeToNBT(NBTTagCompound nbt) {
nbt.setString("Texture", texture);
nbt.setInteger("IconX", iconX);
nbt.setInteger("IconY", iconY);
nbt.setInteger("TintColor", tintColor);
}
public void readFromNBT(NBTTagCompound nbt) {
texture = nbt.getString("Texture");
iconX = nbt.getInteger("IconX");
iconY = nbt.getInteger("IconY");
tintColor = nbt.hasKey("TintColor") ? nbt.getInteger("TintColor") : 0xFFFFFF;
}
}
// ═══════════════════════════════════════════════════════════════════
// CONSTRUCTION
// ═══════════════════════════════════════════════════════════════════
private AbilityIconData(NBTTagCompound customData) {
this.customData = customData;
}
@@ -60,6 +97,10 @@ public class AbilityIconData {
return fromCustomData(chain.getCustomData());
}
// ═══════════════════════════════════════════════════════════════════
// NBT SERIALIZATION
// ═══════════════════════════════════════════════════════════════════
/**
* Write current state back to the customData NBT.
*/
@@ -71,13 +112,19 @@ public class AbilityIconData {
public void writeToNBT(NBTTagCompound nbt) {
nbt.setBoolean("Enabled", enabled);
nbt.setString("Texture", texture);
nbt.setInteger("IconX", iconX);
nbt.setInteger("IconY", iconY);
nbt.setInteger("Width", width);
nbt.setInteger("Height", height);
nbt.setFloat("Scale", scale);
nbt.setInteger("TintColor", tintColor);
nbt.setInteger("LayerCount", layerCount);
NBTTagList layerList = new NBTTagList();
for (int i = 0; i < MAX_LAYERS; i++) {
NBTTagCompound layerNBT = new NBTTagCompound();
layers[i].writeToNBT(layerNBT);
layerList.appendTag(layerNBT);
}
nbt.setTag("Layers", layerList);
if (stateIcons != null && stateIcons.length > 0) {
NBTTagList list = new NBTTagList();
for (int[] pair : stateIcons) {
@@ -92,16 +139,27 @@ public class AbilityIconData {
public void readFromNBT(NBTTagCompound nbt) {
enabled = nbt.getBoolean("Enabled");
texture = nbt.getString("Texture");
tintColor = nbt.hasKey("TintColor") ? nbt.getInteger("TintColor") : 0xFFFFFF;
iconX = nbt.getInteger("IconX");
iconY = nbt.getInteger("IconY");
width = nbt.getInteger("Width");
if (width <= 0) width = 32;
height = nbt.getInteger("Height");
if (height <= 0) height = 32;
scale = nbt.getFloat("Scale");
if (scale <= 0) scale = 1.0f;
layerCount = nbt.getInteger("LayerCount");
if (layerCount < 1) layerCount = 1;
if (layerCount > MAX_LAYERS) layerCount = MAX_LAYERS;
if (nbt.hasKey("Layers")) {
NBTTagList layerList = nbt.getTagList("Layers", 10);
for (int i = 0; i < MAX_LAYERS; i++) {
layers[i] = new Layer();
if (i < layerList.tagCount()) {
layers[i].readFromNBT(layerList.getCompoundTagAt(i));
}
}
}
if (nbt.hasKey("StateIcons")) {
NBTTagList list = nbt.getTagList("StateIcons", 10);
stateIcons = new int[list.tagCount()][2];
@@ -113,15 +171,53 @@ public class AbilityIconData {
}
}
/**
* Check if this icon has a valid texture configured.
*/
public boolean hasTexture() {
return texture != null && !texture.isEmpty();
// ═══════════════════════════════════════════════════════════════════
// LAYER API
// ═══════════════════════════════════════════════════════════════════
public int getLayerCount() {
return layerCount;
}
public void setLayerCount(int count) {
this.layerCount = Math.max(1, Math.min(MAX_LAYERS, count));
save();
}
public Layer getLayer(int index) {
return (index >= 0 && index < MAX_LAYERS) ? layers[index] : layers[0];
}
public void setLayerTexture(int index, String tex) {
if (index >= 0 && index < MAX_LAYERS) {
layers[index].texture = tex != null ? tex : "";
save();
}
}
public void setLayerIconX(int index, int x) {
if (index >= 0 && index < MAX_LAYERS) {
layers[index].iconX = Math.max(0, x);
save();
}
}
public void setLayerIconY(int index, int y) {
if (index >= 0 && index < MAX_LAYERS) {
layers[index].iconY = Math.max(0, y);
save();
}
}
public void setLayerTintColor(int index, int color) {
if (index >= 0 && index < MAX_LAYERS) {
layers[index].tintColor = color & 0xFFFFFF;
save();
}
}
// ═══════════════════════════════════════════════════════════════════
// GETTERS AND SETTERS (with auto-save)
// SHARED PROPERTY GETTERS/SETTERS (with auto-save)
// ═══════════════════════════════════════════════════════════════════
public boolean isEnabled() {
@@ -133,42 +229,6 @@ public class AbilityIconData {
save();
}
public int getTintColor() {
return tintColor;
}
public void setTintColor(int tintColor) {
this.tintColor = tintColor & 0xFFFFFF;
save();
}
public String getTexture() {
return texture;
}
public void setTexture(String texture) {
this.texture = texture != null ? texture : "";
save();
}
public int getIconX() {
return iconX;
}
public void setIconX(int iconX) {
this.iconX = Math.max(0, iconX);
save();
}
public int getIconY() {
return iconY;
}
public void setIconY(int iconY) {
this.iconY = Math.max(0, iconY);
save();
}
public int getWidth() {
return width;
}
@@ -197,7 +257,7 @@ public class AbilityIconData {
}
// ═══════════════════════════════════════════════════════════════════
// PER-STATE ICON OVERRIDES
// PER-STATE ICON OVERRIDES (applies to layer 0)
// ═══════════════════════════════════════════════════════════════════
public void setStateIcons(int[][] stateIcons) {
@@ -206,26 +266,26 @@ public class AbilityIconData {
}
/**
* Get iconX for a specific toggle state.
* Falls back to default iconX if no state override exists.
* Get iconX for a specific toggle state (layer 0).
* Falls back to layer 0 iconX if no state override exists.
* @param state 1-indexed toggle state (0 = off/default)
*/
public int getIconXForState(int state) {
if (state > 0 && stateIcons != null && state - 1 < stateIcons.length) {
return stateIcons[state - 1][0];
}
return iconX;
return layers[0].iconX;
}
/**
* Get iconY for a specific toggle state.
* Falls back to default iconY if no state override exists.
* Get iconY for a specific toggle state (layer 0).
* Falls back to layer 0 iconY if no state override exists.
* @param state 1-indexed toggle state (0 = off/default)
*/
public int getIconYForState(int state) {
if (state > 0 && stateIcons != null && state - 1 < stateIcons.length) {
return stateIcons[state - 1][1];
}
return iconY;
return layers[0].iconY;
}
}
@@ -53,6 +53,9 @@ public class AbilityCharge extends AbilityMovement implements IAbilityCharge {
this.activeSound = "mob.zombie.attack";
this.windUpAnimationName = "Ability_Charge_Windup";
this.activeAnimationName = "Ability_Charge_Active";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/charge.png")
};
}
@Override
@@ -79,6 +79,10 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
this.activeSound = "random.break";
this.windUpAnimationName = "Ability_Cutter_Windup";
this.activeAnimationName = "Ability_Cutter_Active";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/cutter.png",
this::getActiveColor)
};
}
@Override
@@ -144,6 +144,9 @@ public class AbilityDash extends AbilityMovement implements IAbilityDash {
this.telegraphType = TelegraphType.NONE;
this.showTelegraph = false;
this.windUpSound = "mob.bat.takeoff";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/dash.png")
};
}
@Override
@@ -78,6 +78,11 @@ public class AbilityEffect extends Ability implements IAbilityEffect {
this.windUpTicks = 30;
this.telegraphType = TelegraphType.NONE;
this.showTelegraph = false;
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/effect.png"),
new DefaultIconLayer("customnpcs:textures/gui/ability/effect_overlay.png",
this::getActiveColor)
};
}
// ==================== ABILITY TYPE OVERRIDES ====================
@@ -64,6 +64,9 @@ public class AbilityGuard extends Ability implements IAbilityGuard {
this.activeAnimationName = "Ability_Guard_Active";
this.counterAnimationName = "Ability_Guard_Counter";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/guard.png")
};
}
@Override
@@ -30,6 +30,12 @@ public class AbilityHazard extends AbilityZone implements IAbilityHazard {
this.windUpTicks = 30;
this.windUpAnimationName = "Ability_Zone_Windup";
this.activeAnimationName = "Ability_Zone_Active";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/hazard.png"),
new DefaultIconLayer("customnpcs:textures/gui/ability/hazard_overlay.png",
this::getActiveColor)
};
}
@Override
@@ -47,6 +47,11 @@ public class AbilityHeavyHit extends Ability implements IAbilityHeavyHit {
this.activeSound = "random.anvil_land";
this.windUpAnimationName = "Ability_HeavyHit_Windup";
this.activeAnimationName = "Ability_HeavyHit_Active";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/heavy_hit.png"),
new DefaultIconLayer("customnpcs:textures/gui/ability/heavy_hit_overlay.png",
this::getActiveColor)
};
}
@Override
@@ -43,6 +43,11 @@ public class AbilityShockwave extends Ability implements IAbilityShockwave {
this.activeSound = "random.explode";
this.windUpAnimationName = "Ability_Shockwave_Windup";
this.activeAnimationName = "Ability_Shockwave_Active";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/shockwave.png"),
new DefaultIconLayer("customnpcs:textures/gui/ability/shockwave_overlay.png",
this::getActiveColor)
};
}
@Override
@@ -83,6 +83,9 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
// Default built-in animations
this.windUpAnimationName = "Ability_Slam_Windup";
this.activeAnimationName = "Ability_Slam_Active";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/slam.png")
};
}
/**
@@ -86,6 +86,9 @@ public class AbilityTeleport extends Ability implements IAbilityTeleport {
this.showTelegraph = false;
this.windUpSound = "mob.endermen.portal";
this.activeSound = "mob.endermen.portal";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/teleport.png")
};
}
@Override
@@ -36,6 +36,11 @@ public class AbilityTrap extends AbilityZone implements IAbilityTrap {
this.windUpTicks = 30;
this.windUpAnimationName = "Ability_Zone_Windup";
this.activeAnimationName = "Ability_Zone_Active";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/trap.png",
this::getActiveColor)
};
}
@Override
@@ -72,6 +72,10 @@ public class AbilityVortex extends Ability implements IAbilityVortex {
this.telegraphType = TelegraphType.CIRCLE;
this.windUpSound = "mob.ghast.charge";
this.activeSound = "mob.ghast.fireball";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/vortex.png",
this::getActiveColor)
};
}
@Override
@@ -56,8 +56,10 @@ public class AbilityBeam extends AbilityEnergyProjectile<EntityAbilityBeam> impl
this.windUpAnimationName = "Ability_Beam_Windup";
this.activeAnimationName = "Ability_Beam_Active";
this.defaultIconTexture = "customnpcs:textures/gui/ability/beam.png";
this.defaultIconColorSource = () -> isOuterColorEnabled() ? getOuterColor() : getInnerColor();
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/beam.png",
() -> isOuterColorEnabled() ? getOuterColor() : getInnerColor())
};
}
// ==================== ABSTRACT IMPLEMENTATIONS ====================
@@ -56,8 +56,11 @@ public class AbilityDisc extends AbilityEnergyProjectile<EntityAbilityDisc> impl
this.windUpAnimationName = "Ability_Disc_Windup";
this.activeAnimationName = "Ability_Disc_Active";
this.defaultIconTexture = "customnpcs:textures/gui/ability/disc.png";
this.defaultIconColorSource = () -> isOuterColorEnabled() ? getOuterColor() : getInnerColor();
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/disc.png"),
new DefaultIconLayer("customnpcs:textures/gui/ability/disc_overlay.png",
() -> isOuterColorEnabled() ? getOuterColor() : getInnerColor())
};
}
// ==================== ABSTRACT IMPLEMENTATIONS ====================
@@ -42,6 +42,11 @@ public class AbilityDome extends AbilityBarrier {
this.showTelegraph = true;
this.windUpAnimationName = "";
this.activeAnimationName = "";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/dome.png",
() -> isOuterColorEnabled() ? getOuterColor() : getInnerColor())
};
}
// ==================== ABSTRACT IMPLEMENTATIONS ====================
@@ -54,8 +54,11 @@ public class AbilityLaser extends AbilityEnergyProjectile<EntityAbilityLaser> im
this.windUpAnimationName = "Ability_Laser_Windup";
this.activeAnimationName = "Ability_Laser_Active";
this.defaultIconTexture = "customnpcs:textures/gui/ability/laser.png";
this.defaultIconColorSource = () -> isOuterColorEnabled() ? getOuterColor() : getInnerColor();
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/laser_shot.png"),
new DefaultIconLayer("customnpcs:textures/gui/ability/laser_shot_overlay.png",
() -> isOuterColorEnabled() ? getOuterColor() : getInnerColor())
};
}
// ==================== OVERRIDES ====================
@@ -50,8 +50,11 @@ public class AbilityOrb extends AbilityEnergyProjectile<EntityAbilityOrb> implem
this.windUpAnimationName = "Ability_Orb_Windup";
this.activeAnimationName = "Ability_Orb_Active";
this.defaultIconTexture = "customnpcs:textures/gui/ability/orb.png";
this.defaultIconColorSource = () -> isOuterColorEnabled() ? getOuterColor() : getInnerColor();
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/orb.png"),
new DefaultIconLayer("customnpcs:textures/gui/ability/orb_overlay.png",
() -> isOuterColorEnabled() ? getOuterColor() : getInnerColor())
};
}
// ==================== ABSTRACT IMPLEMENTATIONS ====================
@@ -45,6 +45,11 @@ public class AbilityShield extends AbilityBarrier {
this.windUpAnimationName = "";
this.activeAnimationName = "";
this.allowedBy = UserType.BOTH;
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/shield.png",
() -> isOuterColorEnabled() ? getOuterColor() : getInnerColor())
};
}
// ==================== ABSTRACT IMPLEMENTATIONS ====================
@@ -55,6 +55,12 @@ public class AbilitySweeper extends AbilityEnergy implements IAbilitySweeper {
// Circle telegraph to show range
this.telegraphType = TelegraphType.CIRCLE;
this.showTelegraph = true;
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/sweeper.png"),
new DefaultIconLayer("customnpcs:textures/gui/ability/sweeper_overlay.png",
() -> isOuterColorEnabled() ? getOuterColor() : getInnerColor())
};
}
@Override
@@ -45,6 +45,12 @@ public class AbilityWall extends AbilityBarrier {
this.showTelegraph = true;
this.windUpAnimationName = "";
this.activeAnimationName = "";
this.defaultIconLayers = new DefaultIconLayer[]{
new DefaultIconLayer("customnpcs:textures/gui/ability/wall.png"),
new DefaultIconLayer("customnpcs:textures/gui/ability/wall_overlay.png",
() -> isOuterColorEnabled() ? getOuterColor() : getInnerColor())
};
}
@Override
@@ -163,14 +163,35 @@ 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));
}
// External field providers (e.g., DBC Addon injecting a "DBC" tab)
if (AbilityController.Instance != null) {
@@ -25,12 +25,10 @@ public class AbilityIcon extends Gui {
public int width;
public int height;
// Default icon info (extracted from ability)
private String defaultTexture = "";
private String[] defaultStateTextures = null;
// Default icon layers (extracted from ability)
private Ability.DefaultIconLayer[] defaultLayers = null;
private int defaultIconWidth = 48;
private int defaultIconHeight = 48;
private Ability sourceAbility = null;
private AbilityIcon(AbilityIconData data) {
this.data = data;
@@ -41,11 +39,9 @@ public class AbilityIcon extends Gui {
public static AbilityIcon fromAbility(Ability ability) {
if (ability != null) {
AbilityIcon icon = new AbilityIcon(AbilityIconData.fromAbility(ability));
icon.defaultTexture = ability.getDefaultIconTexture();
icon.defaultStateTextures = ability.getDefaultIconStateTextures();
icon.defaultLayers = ability.getDefaultIconLayers();
icon.defaultIconWidth = ability.getDefaultIconWidth();
icon.defaultIconHeight = ability.getDefaultIconHeight();
icon.sourceAbility = ability;
return icon;
}
return fromDefaults();
@@ -83,90 +79,70 @@ public class AbilityIcon extends Gui {
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Tessellator t;
if (data.isEnabled() && data.hasTexture()) {
// Path 1: Custom icon enabled with texture — draw with manual tintColor
ImageData imageData = ClientCacheHandler.getImageData(data.texture);
if (imageData != null && imageData.imageLoaded()) {
int tint = data.getTintColor();
float r = ((tint >> 16) & 0xFF) / 255f;
float g = ((tint >> 8) & 0xFF) / 255f;
float b = (tint & 0xFF) / 255f;
GL11.glColor4f(r, g, b, alpha);
GL11.glScalef(data.scale, data.scale, 1);
renderEngine.bindTexture(imageData.getLocation());
t = getTessellator(imageData, state);
t.draw();
} else {
if (data.isEnabled()) {
// Path 1: Custom icon — draw each active layer bottom-to-top
GL11.glScalef(data.scale, data.scale, 1);
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);
t = getFallbackTessellator();
t.draw();
getFallbackTessellator().draw();
}
} else if (hasDefaultTexture()) {
// Path 2: No custom icon, but type has a default icon — draw with auto-color tint
String texturePath = resolveDefaultTexture(state);
ImageData defaultImageData = ClientCacheHandler.getImageData(texturePath);
if (defaultImageData != null && defaultImageData.imageLoaded()) {
int autoColor = sourceAbility != null ? sourceAbility.getDefaultIconColor() : 0xFFFFFF;
float r = ((autoColor >> 16) & 0xFF) / 255f;
float g = ((autoColor >> 8) & 0xFF) / 255f;
float b = (autoColor & 0xFF) / 255f;
GL11.glColor4f(r, g, b, alpha);
renderEngine.bindTexture(defaultImageData.getLocation());
t = getDefaultIconTessellator();
t.draw();
} else {
// Default texture not found — use fallback at default icon dimensions with auto-color tint
int autoColor = sourceAbility != null ? sourceAbility.getDefaultIconColor() : 0xFFFFFF;
float r = ((autoColor >> 16) & 0xFF) / 255f;
float g = ((autoColor >> 8) & 0xFF) / 255f;
float b = (autoColor & 0xFF) / 255f;
GL11.glColor4f(r, g, b, alpha);
renderEngine.bindTexture(FALLBACK_TEXTURE);
t = getDefaultIconTessellator();
t.draw();
} else if (hasDefaultLayers()) {
// Path 2: Default layers — draw each layer with its dynamic color
for (Ability.DefaultIconLayer defLayer : defaultLayers) {
if (defLayer.texture == null || defLayer.texture.isEmpty()) continue;
ImageData imageData = ClientCacheHandler.getImageData(defLayer.texture);
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 icon — generic fallback with auto-color tint if available
int autoColor = sourceAbility != null ? sourceAbility.getDefaultIconColor() : 0xFFFFFF;
float r = ((autoColor >> 16) & 0xFF) / 255f;
float g = ((autoColor >> 8) & 0xFF) / 255f;
float b = (autoColor & 0xFF) / 255f;
GL11.glColor4f(r, g, b, alpha);
// Path 3: No custom icon, no default layers — generic fallback
GL11.glColor4f(1, 1, 1, alpha);
renderEngine.bindTexture(FALLBACK_TEXTURE);
t = getFallbackTessellator();
t.draw();
getFallbackTessellator().draw();
}
GL11.glPopMatrix();
}
/**
* Resolve the default texture path for a given toggle state.
* Falls back to the base defaultTexture if no state-specific texture exists.
*/
private String resolveDefaultTexture(int state) {
if (state > 0 && defaultStateTextures != null && state - 1 < defaultStateTextures.length) {
return defaultStateTextures[state - 1];
}
return defaultTexture;
private boolean hasDefaultLayers() {
return defaultLayers != null && defaultLayers.length > 0;
}
private boolean hasDefaultTexture() {
return defaultTexture != null && !defaultTexture.isEmpty();
}
private Tessellator getTessellator(ImageData imageData, int state) {
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;
float u1 = ix / texW;
float v1 = iy / texH;
@@ -209,7 +185,7 @@ public class AbilityIcon extends Gui {
}
public boolean hasTexture() {
return (data.isEnabled() && data.hasTexture()) || hasDefaultTexture();
return data.isEnabled() || hasDefaultLayers();
}
/**
@@ -217,10 +193,10 @@ public class AbilityIcon extends Gui {
* Custom icon: max(width,height) * scale. Default icon: max(defaultW,defaultH). Fallback: 32.
*/
public float getDrawSize() {
if (data.isEnabled() && data.hasTexture()) {
if (data.isEnabled()) {
return Math.max(width, height) * data.scale;
}
if (hasDefaultTexture()) {
if (hasDefaultLayers()) {
return Math.max(defaultIconWidth, defaultIconHeight);
}
return 32f;