mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 20:09:49 +00:00
Merge remote-tracking branch 'origin/syntax-highlighter-unified' into syntax-highlighter-unified
This commit is contained in:
commit
1d1962603b
24 files changed
+667
-300
No files matched your search
@@ -105,7 +105,7 @@ public class TelegraphRenderer {
|
||||
renderLine(telegraph.getLength(), telegraph.getWidth(), red, green, blue, alpha);
|
||||
break;
|
||||
case CONE:
|
||||
renderCone(telegraph.getLength(), telegraph.getAngle(), red, green, blue, alpha);
|
||||
renderCone(telegraph.getLength(), telegraph.getAngle(), telegraph.getInnerRadius(), red, green, blue, alpha);
|
||||
break;
|
||||
case POINT:
|
||||
renderPoint(red, green, blue, alpha);
|
||||
@@ -207,42 +207,98 @@ public class TelegraphRenderer {
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
private void renderCone(float length, float angle, float r, float g, float b, float a) {
|
||||
private void renderCone(float length, float angle, float innerRadius, float r, float g, float b, float a) {
|
||||
float halfAngleRad = (float) Math.toRadians(angle / 2);
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawing(GL11.GL_TRIANGLE_FAN);
|
||||
tessellator.setColorRGBA_F(r, g, b, a);
|
||||
|
||||
// Origin point
|
||||
tessellator.addVertex(0, 0, 0);
|
||||
if (innerRadius <= 0) {
|
||||
// Standard cone: triangle fan from origin
|
||||
tessellator.startDrawing(GL11.GL_TRIANGLE_FAN);
|
||||
tessellator.setColorRGBA_F(r, g, b, a);
|
||||
|
||||
// Arc points
|
||||
for (int i = 0; i <= CONE_SEGMENTS; i++) {
|
||||
float segmentAngle = -halfAngleRad + (halfAngleRad * 2 * i) / CONE_SEGMENTS;
|
||||
double x = Math.sin(segmentAngle) * length;
|
||||
double z = Math.cos(segmentAngle) * length;
|
||||
tessellator.addVertex(x, 0, z);
|
||||
tessellator.addVertex(0, 0, 0);
|
||||
|
||||
for (int i = 0; i <= CONE_SEGMENTS; i++) {
|
||||
float segmentAngle = -halfAngleRad + (halfAngleRad * 2 * i) / CONE_SEGMENTS;
|
||||
double x = Math.sin(segmentAngle) * length;
|
||||
double z = Math.cos(segmentAngle) * length;
|
||||
tessellator.addVertex(x, 0, z);
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
// Border
|
||||
tessellator.startDrawing(GL11.GL_LINE_STRIP);
|
||||
tessellator.setColorRGBA_F(r, g, b, Math.min(1.0f, a * 2));
|
||||
|
||||
tessellator.addVertex(0, 0.01, 0);
|
||||
|
||||
for (int i = 0; i <= CONE_SEGMENTS; i++) {
|
||||
float segmentAngle = -halfAngleRad + (halfAngleRad * 2 * i) / CONE_SEGMENTS;
|
||||
double x = Math.sin(segmentAngle) * length;
|
||||
double z = Math.cos(segmentAngle) * length;
|
||||
tessellator.addVertex(x, 0.01, z);
|
||||
}
|
||||
|
||||
tessellator.addVertex(0, 0.01, 0);
|
||||
|
||||
tessellator.draw();
|
||||
} else {
|
||||
// Truncated cone: strip between inner and outer arcs
|
||||
tessellator.startDrawing(GL11.GL_TRIANGLE_STRIP);
|
||||
tessellator.setColorRGBA_F(r, g, b, a);
|
||||
|
||||
for (int i = 0; i <= CONE_SEGMENTS; i++) {
|
||||
float segmentAngle = -halfAngleRad + (halfAngleRad * 2 * i) / CONE_SEGMENTS;
|
||||
double sinA = Math.sin(segmentAngle);
|
||||
double cosA = Math.cos(segmentAngle);
|
||||
|
||||
tessellator.addVertex(sinA * length, 0, cosA * length);
|
||||
tessellator.addVertex(sinA * innerRadius, 0, cosA * innerRadius);
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
// Border: outer arc
|
||||
float borderAlpha = Math.min(1.0f, a * 2);
|
||||
tessellator.startDrawing(GL11.GL_LINE_STRIP);
|
||||
tessellator.setColorRGBA_F(r, g, b, borderAlpha);
|
||||
|
||||
for (int i = 0; i <= CONE_SEGMENTS; i++) {
|
||||
float segmentAngle = -halfAngleRad + (halfAngleRad * 2 * i) / CONE_SEGMENTS;
|
||||
tessellator.addVertex(Math.sin(segmentAngle) * length, 0.01, Math.cos(segmentAngle) * length);
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
// Border: inner arc
|
||||
tessellator.startDrawing(GL11.GL_LINE_STRIP);
|
||||
tessellator.setColorRGBA_F(r, g, b, borderAlpha);
|
||||
|
||||
for (int i = 0; i <= CONE_SEGMENTS; i++) {
|
||||
float segmentAngle = -halfAngleRad + (halfAngleRad * 2 * i) / CONE_SEGMENTS;
|
||||
tessellator.addVertex(Math.sin(segmentAngle) * innerRadius, 0.01, Math.cos(segmentAngle) * innerRadius);
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
// Border: side edges connecting inner and outer arcs
|
||||
tessellator.startDrawing(GL11.GL_LINES);
|
||||
tessellator.setColorRGBA_F(r, g, b, borderAlpha);
|
||||
|
||||
double sinStart = Math.sin(-halfAngleRad);
|
||||
double cosStart = Math.cos(-halfAngleRad);
|
||||
tessellator.addVertex(sinStart * innerRadius, 0.01, cosStart * innerRadius);
|
||||
tessellator.addVertex(sinStart * length, 0.01, cosStart * length);
|
||||
|
||||
double sinEnd = Math.sin(halfAngleRad);
|
||||
double cosEnd = Math.cos(halfAngleRad);
|
||||
tessellator.addVertex(sinEnd * innerRadius, 0.01, cosEnd * innerRadius);
|
||||
tessellator.addVertex(sinEnd * length, 0.01, cosEnd * length);
|
||||
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
|
||||
// Draw border
|
||||
tessellator.startDrawing(GL11.GL_LINE_STRIP);
|
||||
tessellator.setColorRGBA_F(r, g, b, Math.min(1.0f, a * 2));
|
||||
|
||||
tessellator.addVertex(0, 0.01, 0);
|
||||
|
||||
for (int i = 0; i <= CONE_SEGMENTS; i++) {
|
||||
float segmentAngle = -halfAngleRad + (halfAngleRad * 2 * i) / CONE_SEGMENTS;
|
||||
double x = Math.sin(segmentAngle) * length;
|
||||
double z = Math.cos(segmentAngle) * length;
|
||||
tessellator.addVertex(x, 0.01, z);
|
||||
}
|
||||
|
||||
tessellator.addVertex(0, 0.01, 0);
|
||||
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
private void renderPoint(float r, float g, float b, float a) {
|
||||
@@ -344,7 +400,7 @@ public class TelegraphRenderer {
|
||||
renderLine(telegraph.getLength(), telegraph.getWidth(), red, green, blue, alpha);
|
||||
break;
|
||||
case CONE:
|
||||
renderCone(telegraph.getLength(), telegraph.getAngle(), red, green, blue, alpha);
|
||||
renderCone(telegraph.getLength(), telegraph.getAngle(), telegraph.getInnerRadius(), red, green, blue, alpha);
|
||||
break;
|
||||
case POINT:
|
||||
renderPoint(red, green, blue, alpha);
|
||||
|
||||
@@ -81,6 +81,7 @@ public class AbilityController implements IAbilityHandler {
|
||||
private final List<IAbilityExtender> extenders = new ArrayList<>();
|
||||
private final Map<String, Supplier<AbilityCondition>> conditionTypes = new HashMap<>();
|
||||
private final List<Predicate<EntityPlayer>> flightCheckers = new ArrayList<>();
|
||||
private final List<Predicate<EntityPlayer>> activationCheckers = new ArrayList<>();
|
||||
|
||||
// ── Chained Abilities ──────────────────────────────────────────────────
|
||||
private final Map<String, ChainedAbility> chainedAbilities = new LinkedHashMap<>(); // name → ChainedAbility
|
||||
@@ -1019,6 +1020,17 @@ public class AbilityController implements IAbilityHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void registerActivationChecker(Predicate<EntityPlayer> checker) {
|
||||
activationCheckers.add(checker);
|
||||
}
|
||||
|
||||
public boolean canPlayerActivate(EntityPlayer player) {
|
||||
for (Predicate<EntityPlayer> checker : activationCheckers) {
|
||||
if (!checker.test(player)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire onAbilityStart on all extenders. Returns false if ANY extender cancels.
|
||||
*/
|
||||
|
||||
@@ -64,6 +64,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public abstract class Ability implements IAbility, IAbilityAction {
|
||||
|
||||
@@ -156,6 +157,15 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
protected transient int defaultIconWidth = 48;
|
||||
protected transient int defaultIconHeight = 48;
|
||||
|
||||
/**
|
||||
* Optional player requirement predicate. When set, the ability is only visible
|
||||
* and usable by players for whom this predicate returns true.
|
||||
* Evaluated on-demand (no polling). Null means no requirement (always available).
|
||||
* <p>
|
||||
* This is transient — set programmatically by addons, not saved to NBT.
|
||||
*/
|
||||
protected transient Predicate<EntityPlayer> playerRequirement;
|
||||
|
||||
/**
|
||||
* A single layer of a default ability icon. Each layer has a texture,
|
||||
* an optional dynamic color source, and optional per-state texture variants.
|
||||
@@ -597,6 +607,18 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
return 45.0f;
|
||||
}
|
||||
|
||||
public float getTelegraphInnerRadius() {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to return true if the ability type manages its own telegraph GUI controls.
|
||||
* When true, the base class will skip adding the default telegraph section.
|
||||
*/
|
||||
public boolean hasOwnTelegraphControls() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the caster is a player (not an NPC).
|
||||
* Use this instead of checking {@code target != null} to make NPC/Player
|
||||
@@ -875,7 +897,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
.tab("Effects"));
|
||||
|
||||
TelegraphType tType = getTelegraphType();
|
||||
if (tType != null && tType != TelegraphType.NONE) {
|
||||
if (tType != null && tType != TelegraphType.NONE && !hasOwnTelegraphControls()) {
|
||||
defs.add(FieldDef.section("ability.section.telegraph").tab("Effects")
|
||||
.hover("telegraph." + tType.name().toLowerCase()));
|
||||
defs.add(FieldDef.boolField("ability.showTelegraph", this::isShowTelegraph, this::setShowTelegraph)
|
||||
@@ -1015,13 +1037,13 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
telegraph = Telegraph.circle(getTelegraphRadius());
|
||||
break;
|
||||
case RING:
|
||||
telegraph = Telegraph.ring(getTelegraphRadius(), getTelegraphRadius() * 0.5f);
|
||||
telegraph = Telegraph.ring(getTelegraphRadius(), getTelegraphInnerRadius());
|
||||
break;
|
||||
case LINE:
|
||||
telegraph = Telegraph.line(getTelegraphLength(), getTelegraphWidth());
|
||||
break;
|
||||
case CONE:
|
||||
telegraph = Telegraph.cone(getTelegraphLength(), getTelegraphAngle());
|
||||
telegraph = Telegraph.cone(getTelegraphLength(), getTelegraphAngle(), getTelegraphInnerRadius());
|
||||
break;
|
||||
case POINT:
|
||||
telegraph = new Telegraph("", TelegraphType.POINT);
|
||||
@@ -1762,7 +1784,10 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
}
|
||||
|
||||
public Ability deepCopy() {
|
||||
return AbilityController.Instance.fromNBT(this.writeNBT(false));
|
||||
Ability copy = AbilityController.Instance.fromNBT(this.writeNBT(false));
|
||||
if (copy != null)
|
||||
copy.playerRequirement = this.playerRequirement;
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2346,6 +2371,22 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
this.allowedBy = allowedBy;
|
||||
}
|
||||
|
||||
public Predicate<EntityPlayer> getPlayerRequirement() {
|
||||
return playerRequirement;
|
||||
}
|
||||
|
||||
public void setPlayerRequirement(Predicate<EntityPlayer> requirement) {
|
||||
this.playerRequirement = requirement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this ability is available for the given player.
|
||||
* Returns true if no requirement is set, or if the requirement predicate passes.
|
||||
*/
|
||||
public boolean isAvailableFor(EntityPlayer player) {
|
||||
return playerRequirement == null || playerRequirement.test(player);
|
||||
}
|
||||
|
||||
public boolean isIgnoreCooldown() {
|
||||
return ignoreCooldown;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package kamkeel.npcs.controllers.data.ability;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.LockMode;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.UserType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -28,6 +32,17 @@ public class CustomAbility extends Ability implements ICustomAbility {
|
||||
|
||||
private int durationTicks = 20;
|
||||
|
||||
// Telegraph dimension fields
|
||||
private float tRadius = 5.0f;
|
||||
private float tInnerRadius = 0.0f;
|
||||
private float tLength = 5.0f;
|
||||
private float tWidth = 2.0f;
|
||||
private float tAngle = 45.0f;
|
||||
|
||||
// Telegraph timing
|
||||
private int telegraphActiveTicks = 0;
|
||||
private boolean syncTelegraphWithDuration = true;
|
||||
|
||||
public CustomAbility() {
|
||||
this.typeId = "ability.cnpc.custom";
|
||||
this.name = "Custom";
|
||||
@@ -77,6 +92,139 @@ public class CustomAbility extends Ability implements ICustomAbility {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasOwnTelegraphControls() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// ==================== TELEGRAPH OVERRIDES ====================
|
||||
|
||||
@Override
|
||||
public boolean keepTelegraphDuringActive() {
|
||||
return getResolvedTelegraphActiveTicks() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective telegraph active ticks: synced from duration or manual value.
|
||||
*/
|
||||
public int getResolvedTelegraphActiveTicks() {
|
||||
if (syncTelegraphWithDuration) {
|
||||
return durationTicks;
|
||||
}
|
||||
return telegraphActiveTicks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (!isShowTelegraph() || getTelegraphType() == TelegraphType.NONE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Telegraph telegraph;
|
||||
double x, y, z;
|
||||
float yaw = caster.rotationYaw;
|
||||
TelegraphType tType = getTelegraphType();
|
||||
|
||||
boolean positionAtCaster = targetingMode == TargetingMode.AOE_SELF ||
|
||||
targetingMode == TargetingMode.SELF ||
|
||||
tType == TelegraphType.LINE ||
|
||||
tType == TelegraphType.CONE;
|
||||
|
||||
if (positionAtCaster) {
|
||||
x = caster.posX;
|
||||
y = findGroundLevel(caster.worldObj, caster.posX, caster.posY, caster.posZ);
|
||||
z = caster.posZ;
|
||||
} else if (target != null) {
|
||||
x = target.posX;
|
||||
y = findGroundLevel(caster.worldObj, target.posX, target.posY, target.posZ);
|
||||
z = target.posZ;
|
||||
} else {
|
||||
x = caster.posX;
|
||||
y = findGroundLevel(caster.worldObj, caster.posX, caster.posY, caster.posZ);
|
||||
z = caster.posZ;
|
||||
}
|
||||
|
||||
switch (tType) {
|
||||
case CIRCLE:
|
||||
telegraph = Telegraph.circle(tRadius);
|
||||
break;
|
||||
case RING:
|
||||
telegraph = Telegraph.ring(tRadius, tInnerRadius);
|
||||
break;
|
||||
case LINE:
|
||||
telegraph = Telegraph.line(tLength, tWidth);
|
||||
break;
|
||||
case CONE:
|
||||
telegraph = Telegraph.cone(tLength, tAngle, tInnerRadius);
|
||||
break;
|
||||
case POINT:
|
||||
telegraph = new Telegraph("", TelegraphType.POINT);
|
||||
break;
|
||||
case SQUARE:
|
||||
telegraph = Telegraph.square(tRadius);
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
int activeTicks = getResolvedTelegraphActiveTicks();
|
||||
int totalDuration = windUpTicks + activeTicks;
|
||||
telegraph.setDurationTicks(Math.max(1, totalDuration));
|
||||
telegraph.setColor(windUpColor);
|
||||
telegraph.setWarningColor(activeColor);
|
||||
if (windUpTicks > 0) {
|
||||
telegraph.setWarningStartTick(windUpTicks);
|
||||
} else {
|
||||
telegraph.setWarningStartTick(0);
|
||||
}
|
||||
telegraph.setHeightOffset(telegraphHeightOffset);
|
||||
|
||||
TelegraphInstance instance = new TelegraphInstance(telegraph, x, y, z, yaw);
|
||||
instance.setCasterEntityId(caster.getEntityId());
|
||||
|
||||
if (positionAtCaster) {
|
||||
instance.setEntityIdToFollow(caster.getEntityId());
|
||||
if (tType == TelegraphType.LINE || tType == TelegraphType.CONE) {
|
||||
if (!isRotationLockedDuringWindup()) {
|
||||
if (target != null) {
|
||||
instance.setTargetEntityId(target.getEntityId());
|
||||
} else {
|
||||
instance.setTrackFollowedEntityYaw(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (target != null) {
|
||||
instance.setEntityIdToFollow(target.getEntityId());
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTelegraphRadius() {
|
||||
return tRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTelegraphInnerRadius() {
|
||||
return tInnerRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTelegraphLength() {
|
||||
return tLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTelegraphWidth() {
|
||||
return tWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTelegraphAngle() {
|
||||
return tAngle;
|
||||
}
|
||||
|
||||
// ==================== FIELDS ====================
|
||||
|
||||
@Override
|
||||
@@ -89,6 +237,62 @@ public class CustomAbility extends Ability implements ICustomAbility {
|
||||
this.durationTicks = Math.max(0, ticks);
|
||||
}
|
||||
|
||||
public float getTRadius() {
|
||||
return tRadius;
|
||||
}
|
||||
|
||||
public void setTRadius(float radius) {
|
||||
this.tRadius = Math.max(0, radius);
|
||||
}
|
||||
|
||||
public float getTInnerRadius() {
|
||||
return tInnerRadius;
|
||||
}
|
||||
|
||||
public void setTInnerRadius(float innerRadius) {
|
||||
this.tInnerRadius = Math.max(0, innerRadius);
|
||||
}
|
||||
|
||||
public float getTLength() {
|
||||
return tLength;
|
||||
}
|
||||
|
||||
public void setTLength(float length) {
|
||||
this.tLength = Math.max(0, length);
|
||||
}
|
||||
|
||||
public float getTWidth() {
|
||||
return tWidth;
|
||||
}
|
||||
|
||||
public void setTWidth(float width) {
|
||||
this.tWidth = Math.max(0, width);
|
||||
}
|
||||
|
||||
public float getTAngle() {
|
||||
return tAngle;
|
||||
}
|
||||
|
||||
public void setTAngle(float angle) {
|
||||
this.tAngle = Math.max(0, angle);
|
||||
}
|
||||
|
||||
public int getTelegraphActiveTicks() {
|
||||
return telegraphActiveTicks;
|
||||
}
|
||||
|
||||
public void setTelegraphActiveTicks(int ticks) {
|
||||
this.telegraphActiveTicks = Math.max(0, ticks);
|
||||
}
|
||||
|
||||
public boolean isSyncTelegraphWithDuration() {
|
||||
return syncTelegraphWithDuration;
|
||||
}
|
||||
|
||||
public void setSyncTelegraphWithDuration(boolean sync) {
|
||||
this.syncTelegraphWithDuration = sync;
|
||||
}
|
||||
|
||||
// ==================== ICustomAbility ====================
|
||||
|
||||
@Override
|
||||
@@ -104,6 +308,31 @@ public class CustomAbility extends Ability implements ICustomAbility {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTelegraphRadius(float radius) {
|
||||
this.tRadius = Math.max(0, radius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTelegraphInnerRadius(float innerRadius) {
|
||||
this.tInnerRadius = Math.max(0, innerRadius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTelegraphLength(float length) {
|
||||
this.tLength = Math.max(0, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTelegraphWidth(float width) {
|
||||
this.tWidth = Math.max(0, width);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTelegraphAngle(float angle) {
|
||||
this.tAngle = Math.max(0, angle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTargetingModeType() {
|
||||
return getTargetingMode().ordinal();
|
||||
@@ -122,15 +351,30 @@ public class CustomAbility extends Ability implements ICustomAbility {
|
||||
@Override
|
||||
public void writeTypeNBT(NBTTagCompound nbt) {
|
||||
nbt.setInteger("durationTicks", durationTicks);
|
||||
nbt.setFloat("tRadius", tRadius);
|
||||
nbt.setFloat("tInnerRadius", tInnerRadius);
|
||||
nbt.setFloat("tLength", tLength);
|
||||
nbt.setFloat("tWidth", tWidth);
|
||||
nbt.setFloat("tAngle", tAngle);
|
||||
nbt.setInteger("telegraphActiveTicks", telegraphActiveTicks);
|
||||
nbt.setBoolean("syncTelegraphWithDuration", syncTelegraphWithDuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readTypeNBT(NBTTagCompound nbt) {
|
||||
this.durationTicks = Math.max(0, nbt.getInteger("durationTicks"));
|
||||
this.tRadius = nbt.hasKey("tRadius") ? nbt.getFloat("tRadius") : 5.0f;
|
||||
this.tInnerRadius = nbt.hasKey("tInnerRadius") ? nbt.getFloat("tInnerRadius") : 0.0f;
|
||||
this.tLength = nbt.hasKey("tLength") ? nbt.getFloat("tLength") : 5.0f;
|
||||
this.tWidth = nbt.hasKey("tWidth") ? nbt.getFloat("tWidth") : 2.0f;
|
||||
this.tAngle = nbt.hasKey("tAngle") ? nbt.getFloat("tAngle") : 45.0f;
|
||||
this.telegraphActiveTicks = nbt.hasKey("telegraphActiveTicks") ? nbt.getInteger("telegraphActiveTicks") : 0;
|
||||
this.syncTelegraphWithDuration = nbt.hasKey("syncTelegraphWithDuration") ? nbt.getBoolean("syncTelegraphWithDuration") : true;
|
||||
}
|
||||
|
||||
// ==================== GUI ====================
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void getAbilityDefinitions(List<FieldDef> defs) {
|
||||
// User Type (NPC / Player / Both)
|
||||
@@ -141,10 +385,6 @@ public class CustomAbility extends Ability implements ICustomAbility {
|
||||
defs.add(FieldDef.enumField("ability.targetingMode", TargetingMode.class,
|
||||
this::getTargetingMode, this::setTargetingMode));
|
||||
|
||||
// Telegraph Shape
|
||||
defs.add(FieldDef.enumField("ability.telegraphShape", TelegraphType.class,
|
||||
this::getTelegraphType, this::setTelegraphType));
|
||||
|
||||
// Toggle section
|
||||
defs.add(FieldDef.section("ability.section.toggle"));
|
||||
defs.add(FieldDef.boolField("ability.toggleEnabled",
|
||||
@@ -161,5 +401,86 @@ public class CustomAbility extends Ability implements ICustomAbility {
|
||||
defs.add(FieldDef.intField("ability.duration", this::getDurationTicks, this::setDurationTicks)
|
||||
.range(0, 6000)
|
||||
.visibleWhen(() -> !this.isToggleable()));
|
||||
|
||||
// ── Telegraph Controls (Effects tab) ─────────────────────────
|
||||
defs.add(FieldDef.section("ability.section.telegraph").tab("Effects"));
|
||||
defs.add(FieldDef.enumField("ability.telegraphShape", TelegraphType.class,
|
||||
this::getTelegraphType, this::setTelegraphType).tab("Effects")
|
||||
.hover("ability.hover.telegraphShape"));
|
||||
defs.add(FieldDef.boolField("ability.showTelegraph", this::isShowTelegraph, this::setShowTelegraph)
|
||||
.tab("Effects").visibleWhen(this::hasTelegraphShape)
|
||||
.hover("ability.hover.showTelegraph"));
|
||||
defs.add(FieldDef.colorSubGui("ability.windUpColor", this::getWindUpColor, this::setWindUpColor)
|
||||
.tab("Effects").visibleWhen(this::isTelegraphVisible)
|
||||
.hover("ability.hover.windUpColor"));
|
||||
defs.add(FieldDef.colorSubGui("ability.activeColor", this::getActiveColor, this::setActiveColor)
|
||||
.tab("Effects").visibleWhen(this::isTelegraphVisible)
|
||||
.hover("ability.hover.activeColor"));
|
||||
defs.add(FieldDef.floatField("ability.telegraphHeight", this::getTelegraphHeightOffset, this::setTelegraphHeightOffset)
|
||||
.tab("Effects").visibleWhen(this::isTelegraphVisible)
|
||||
.hover("ability.hover.telegraphHeight"));
|
||||
|
||||
// Telegraph active duration with sync toggle (mirrors windup sync pattern)
|
||||
defs.add(FieldDef.row(
|
||||
FieldDef.intField("ability.telegraphActiveTicks", this::getTelegraphActiveTicks, this::setTelegraphActiveTicks).range(0, 6000)
|
||||
.hover("ability.hover.telegraphActiveTicks"),
|
||||
FieldDef.boolField("ability.syncTelegraph", this::isSyncTelegraphWithDuration, this::setSyncTelegraphWithDuration)
|
||||
.hover("ability.hover.syncTelegraph")
|
||||
).tab("Effects").visibleWhen(() -> isTelegraphVisible() && !isSyncTelegraphWithDuration()));
|
||||
defs.add(FieldDef.row(
|
||||
FieldDef.labelField("ability.telegraphActiveTicks", () -> getResolvedTelegraphActiveTicks() + "t"),
|
||||
FieldDef.boolField("ability.syncTelegraph", this::isSyncTelegraphWithDuration, this::setSyncTelegraphWithDuration)
|
||||
.hover("ability.hover.syncTelegraph")
|
||||
).tab("Effects").visibleWhen(() -> isTelegraphVisible() && isSyncTelegraphWithDuration()));
|
||||
|
||||
// Shape-specific dimension fields
|
||||
defs.add(FieldDef.floatField("ability.telegraphRadius", this::getTRadius, this::setTRadius)
|
||||
.tab("Effects").visibleWhen(() -> isTelegraphVisible() && needsRadius())
|
||||
.hover("ability.hover.telegraphRadius"));
|
||||
defs.add(FieldDef.floatField("ability.telegraphInnerRadius", this::getTInnerRadius, this::setTInnerRadius)
|
||||
.tab("Effects").visibleWhen(() -> isTelegraphVisible() && needsInnerRadius())
|
||||
.hover("ability.hover.telegraphInnerRadius"));
|
||||
defs.add(FieldDef.floatField("ability.telegraphLength", this::getTLength, this::setTLength)
|
||||
.tab("Effects").visibleWhen(() -> isTelegraphVisible() && needsLength())
|
||||
.hover("ability.hover.telegraphLength"));
|
||||
defs.add(FieldDef.floatField("ability.telegraphWidth", this::getTWidth, this::setTWidth)
|
||||
.tab("Effects").visibleWhen(() -> isTelegraphVisible() && needsWidth())
|
||||
.hover("ability.hover.telegraphWidth"));
|
||||
defs.add(FieldDef.floatField("ability.telegraphAngle", this::getTAngle, this::setTAngle)
|
||||
.tab("Effects").visibleWhen(() -> isTelegraphVisible() && needsAngle())
|
||||
.hover("ability.hover.telegraphAngle"));
|
||||
}
|
||||
|
||||
// ==================== TELEGRAPH VISIBILITY HELPERS ====================
|
||||
|
||||
private boolean hasTelegraphShape() {
|
||||
return getTelegraphType() != TelegraphType.NONE;
|
||||
}
|
||||
|
||||
private boolean isTelegraphVisible() {
|
||||
return hasTelegraphShape() && isShowTelegraph();
|
||||
}
|
||||
|
||||
private boolean needsRadius() {
|
||||
TelegraphType t = getTelegraphType();
|
||||
return t == TelegraphType.CIRCLE || t == TelegraphType.RING || t == TelegraphType.SQUARE;
|
||||
}
|
||||
|
||||
private boolean needsInnerRadius() {
|
||||
TelegraphType t = getTelegraphType();
|
||||
return t == TelegraphType.RING || t == TelegraphType.CONE;
|
||||
}
|
||||
|
||||
private boolean needsLength() {
|
||||
TelegraphType t = getTelegraphType();
|
||||
return t == TelegraphType.LINE || t == TelegraphType.CONE;
|
||||
}
|
||||
|
||||
private boolean needsWidth() {
|
||||
return getTelegraphType() == TelegraphType.LINE;
|
||||
}
|
||||
|
||||
private boolean needsAngle() {
|
||||
return getTelegraphType() == TelegraphType.CONE;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
public class ConditionItem extends AbilityCondition {
|
||||
|
||||
public enum UsageType {
|
||||
ARMOR, HOLDING, AMMO, OFFHAND;
|
||||
ARMOR, HOLDING, COUNT, OFFHAND;
|
||||
|
||||
public static UsageType fromOrdinal(int ordinal) {
|
||||
UsageType[] values = values();
|
||||
@@ -40,7 +40,7 @@ public class ConditionItem extends AbilityCondition {
|
||||
private ArmorSlot armorSlot = ArmorSlot.BOOTS;
|
||||
private boolean fullArmorSet = false;
|
||||
|
||||
// AMMO + PLAYER only
|
||||
// COUNT + PLAYER only
|
||||
private int requiredCount = 1;
|
||||
|
||||
public ConditionItem() {
|
||||
@@ -55,8 +55,8 @@ public class ConditionItem extends AbilityCondition {
|
||||
return checkHolding(entity);
|
||||
case ARMOR:
|
||||
return checkArmor(entity);
|
||||
case AMMO:
|
||||
return checkAmmo(entity);
|
||||
case COUNT:
|
||||
return checkCount(entity);
|
||||
case OFFHAND:
|
||||
return checkOffhand(entity);
|
||||
default:
|
||||
@@ -75,17 +75,7 @@ public class ConditionItem extends AbilityCondition {
|
||||
return matchesItem(entity.getEquipmentInSlot(slot));
|
||||
}
|
||||
|
||||
private boolean checkFullArmor(EntityLivingBase entity) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int slot = i + 1;
|
||||
if (!matchesItem(i, entity.getEquipmentInSlot(slot)))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean checkAmmo(EntityLivingBase entity) {
|
||||
private boolean checkCount(EntityLivingBase entity) {
|
||||
if (entity instanceof EntityPlayer) {
|
||||
return checkPlayerInventoryCount((EntityPlayer) entity);
|
||||
}
|
||||
@@ -121,10 +111,6 @@ public class ConditionItem extends AbilityCondition {
|
||||
}
|
||||
|
||||
private boolean matchesItem(ItemStack stack) {
|
||||
return matchesItem(0, stack);
|
||||
}
|
||||
|
||||
private boolean matchesItem(int index, ItemStack stack) {
|
||||
if (stack == null || itemName == null || itemName.isEmpty()) return false;
|
||||
String registryName = net.minecraft.item.Item.itemRegistry.getNameForObject(stack.getItem());
|
||||
return itemName.equals(registryName);
|
||||
@@ -148,7 +134,7 @@ public class ConditionItem extends AbilityCondition {
|
||||
defs.add(FieldDef.intField("condition.item_count",
|
||||
this::getRequiredCount, this::setRequiredCount)
|
||||
.range(1, 64)
|
||||
.visibleWhen(() -> usageType == UsageType.AMMO && userType.allowsPlayer())
|
||||
.visibleWhen(() -> usageType == UsageType.COUNT && userType.allowsPlayer())
|
||||
.hover("condition.hover.required_count"));
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import kamkeel.npcs.controllers.data.ability.AbilityAction;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.UserType;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.List;
|
||||
@@ -40,6 +41,15 @@ public interface IAbilityAction {
|
||||
|
||||
boolean checkConditionsForPlayer(EntityLivingBase caster);
|
||||
|
||||
/**
|
||||
* Check if this action is available for the given player.
|
||||
* Used for visibility filtering (HUD, selection) and activation gating.
|
||||
* Returns true by default (no requirement).
|
||||
*/
|
||||
default boolean isAvailableFor(EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this action is a chained ability (sequence of abilities) vs an individual ability.
|
||||
*/
|
||||
|
||||
@@ -122,7 +122,7 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
|
||||
return null;
|
||||
}
|
||||
|
||||
Telegraph telegraph = Telegraph.cone(getTelegraphLength(), getTelegraphAngle());
|
||||
Telegraph telegraph = Telegraph.cone(getTelegraphLength(), getTelegraphAngle(), getTelegraphInnerRadius());
|
||||
int totalDuration = windUpTicks + getActiveDurationTicks();
|
||||
telegraph.setDurationTicks(totalDuration);
|
||||
telegraph.setColor(windUpColor);
|
||||
@@ -162,6 +162,11 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
|
||||
return arcAngle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTelegraphInnerRadius() {
|
||||
return innerRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(EntityLivingBase caster, EntityLivingBase target) {
|
||||
hitEntities.clear();
|
||||
@@ -456,6 +461,7 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
|
||||
FieldDef.row(
|
||||
FieldDef.floatField("ability.arcAngle", this::getArcAngle, this::setArcAngle),
|
||||
FieldDef.floatField("ability.innerRadius", this::getInnerRadius, this::setInnerRadius)
|
||||
.hover("ability.hover.innerRadius")
|
||||
),
|
||||
FieldDef.floatField("ability.sweepSpeed", this::getSweepSpeed, this::setSweepSpeed),
|
||||
FieldDef.intField("ability.spinDuration", this::getSpinDurationTicks, this::setSpinDurationTicks)
|
||||
|
||||
@@ -111,9 +111,10 @@ public class AbilityDodge extends AbilityDefend implements IAbilityDodge {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
protected void getTypeDefinitions(List<FieldDef> defs) {
|
||||
defs.add(FieldDef.section("ability.section.dodgeAnimations").tab("Effects"));
|
||||
|
||||
FieldDef.insertAfter(defs, "ability.dazedAnimation",
|
||||
FieldDef.section("ability.section.dodgeAnimations").tab("Effects"));
|
||||
|
||||
FieldDef.insertAfter(defs, "ability.section.dodgeAnimations",
|
||||
FieldDef.animSubGui("ability.dodgeAnimation1",
|
||||
this::getDodgeAnimation1Id, this::setDodgeAnimation1Id,
|
||||
this::getDodgeAnimation1Name, this::setDodgeAnimation1Name)
|
||||
|
||||
@@ -152,6 +152,14 @@ public class Telegraph {
|
||||
return t;
|
||||
}
|
||||
|
||||
public static Telegraph cone(float length, float angle, float innerRadius) {
|
||||
Telegraph t = new Telegraph("", TelegraphType.CONE);
|
||||
t.length = length;
|
||||
t.angle = angle;
|
||||
t.innerRadius = innerRadius;
|
||||
return t;
|
||||
}
|
||||
|
||||
public static Telegraph point() {
|
||||
return new Telegraph("", TelegraphType.POINT);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumPlayerPacket;
|
||||
import kamkeel.npcs.network.packets.data.npc.UpdateNpcPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
@@ -17,16 +16,10 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
public class RequestProperSpawnData extends AbstractPacket {
|
||||
public static final String packetName = "Player|SpawnData";
|
||||
private static final int BATCH_LIMIT = 5;
|
||||
|
||||
private static final Set<Integer> entitiesToFix = new HashSet<>();
|
||||
private static long lastBatchAttemptMillis = 0L;
|
||||
private static final long REQUEST_COOLDOWN_MILLIS = 1000L;
|
||||
private int entityId;
|
||||
|
||||
public RequestProperSpawnData() {}
|
||||
@@ -37,8 +30,7 @@ public class RequestProperSpawnData extends AbstractPacket {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clear() {
|
||||
entitiesToFix.clear();
|
||||
lastBatchAttemptMillis = 0L;
|
||||
// No backlog queue to clear.
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,40 +73,24 @@ public class RequestProperSpawnData extends AbstractPacket {
|
||||
if (entityID <= 0)
|
||||
return;
|
||||
|
||||
if (npc.clientFixAttempts++ < 3) {
|
||||
PacketClient.sendClient(new RequestProperSpawnData(entityID));
|
||||
} else {
|
||||
entitiesToFix.add(entityID);
|
||||
}
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - npc.clientFixLastRequestMillis < REQUEST_COOLDOWN_MILLIS)
|
||||
return;
|
||||
if (npc.clientFixAttempts >= 3)
|
||||
return;
|
||||
|
||||
npc.clientFixLastRequestMillis = now;
|
||||
npc.clientFixAttempts++;
|
||||
PacketClient.sendClient(new RequestProperSpawnData(entityID));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static boolean canDoBatchUpdate() {
|
||||
return System.currentTimeMillis() - lastBatchAttemptMillis >= 5000;
|
||||
return false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void handleBacklog() {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc == null || mc.theWorld == null || mc.thePlayer == null)
|
||||
return;
|
||||
|
||||
if (entitiesToFix.isEmpty())
|
||||
return;
|
||||
// Remove entity checks if they're no longer loaded
|
||||
entitiesToFix.removeIf(value -> !(mc.theWorld.getEntityByID(value) instanceof EntityNPCInterface));
|
||||
|
||||
Iterator<Integer> it = entitiesToFix.iterator();
|
||||
int count = 0;
|
||||
|
||||
while (it.hasNext() && count < BATCH_LIMIT) {
|
||||
PacketClient.sendClient(new RequestProperSpawnData(it.next()));
|
||||
it.remove();
|
||||
count++;
|
||||
}
|
||||
|
||||
if (count != 0) {
|
||||
lastBatchAttemptMillis = System.currentTimeMillis();
|
||||
}
|
||||
// No batch backlog. Requests are immediate and throttled in reportMissingData().
|
||||
}
|
||||
}
|
||||
@@ -1021,6 +1021,11 @@ public abstract class AbstractDataAbilities {
|
||||
* Execute an ability immediately (no windup). Called when windUpTicks is 0.
|
||||
*/
|
||||
protected void executeImmediate(Ability ability, EntityLivingBase target) {
|
||||
// Spawn telegraph for abilities that persist during active phase (e.g., Custom Ability)
|
||||
if (ability.keepTelegraphDuringActive()) {
|
||||
spawnTelegraph(ability, target);
|
||||
}
|
||||
|
||||
// Play active sound and animation
|
||||
playAbilitySound(ability.getActiveSound());
|
||||
playAbilityAnimation(ability.getActiveAnimation());
|
||||
|
||||
@@ -124,7 +124,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11-beta13.1")
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11-beta14")
|
||||
public class CustomNpcs {
|
||||
|
||||
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
|
||||
|
||||
@@ -193,8 +193,6 @@ public class ClientTickHandler {
|
||||
return;
|
||||
|
||||
if (mc.theWorld.getTotalWorldTime() % 20 == 0) { // Update every second
|
||||
if (RequestProperSpawnData.canDoBatchUpdate())
|
||||
RequestProperSpawnData.handleBacklog();
|
||||
updateCompassMarks();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,6 +197,14 @@ public class GuiScript extends GuiScriptInterface {
|
||||
addButton(new GuiNpcButton(100, guiLeft + 315, guiTop + 25, 50, 20, "gui.copy"));
|
||||
addButton(new GuiNpcButton(107, guiLeft + 315, guiTop + 70, 80, 20, "script.loadscript"));
|
||||
|
||||
// Disable all buttons until server data arrives
|
||||
if (!serverDataReceived) {
|
||||
for (int btnId : new int[]{100, 101, 102, 107}) {
|
||||
GuiNpcButton btn = getButton(btnId);
|
||||
if (btn != null) btn.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
GuiCustomScroll scroll = new GuiCustomScroll(this, 0).setUnselectable();
|
||||
scroll.setSize(100, 120);
|
||||
scroll.guiLeft = guiLeft + 315;
|
||||
@@ -235,12 +243,18 @@ public class GuiScript extends GuiScriptInterface {
|
||||
addButton(new GuiNpcButton(104, guiLeft + 294, guiTop + 48, 50, 20,
|
||||
new String[]{"gui.no", "gui.yes"}, script.enabled ? 1 : 0));
|
||||
|
||||
// Disable language/enabled controls until server data actually arrives
|
||||
getButton(103).enabled = serverDataReceived && languageOptions.size() > 0;
|
||||
getButton(104).enabled = serverDataReceived;
|
||||
|
||||
if (MinecraftServer.getServer() != null)
|
||||
addButton(new GuiNpcButton(106, guiLeft + 232, guiTop + 71, 150, 20, "script.openfolder"));
|
||||
|
||||
// Disable all buttons until server data arrives
|
||||
if (!serverDataReceived) {
|
||||
for (int btnId : new int[]{100, 102, 103, 104, 105, 106}) {
|
||||
GuiNpcButton btn = getButton(btnId);
|
||||
if (btn != null) btn.enabled = false;
|
||||
}
|
||||
} else {
|
||||
getButton(103).enabled = languageOptions.size() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply editor globals for the active NPC hook.
|
||||
@@ -368,6 +382,11 @@ public class GuiScript extends GuiScriptInterface {
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
// Only process the actual NPCScriptPacket response (has ScriptLanguage + Languages)
|
||||
// Ignore unrelated packets (e.g. script config with ScriptsEnabled/GlobalNPCScriptsEnabled)
|
||||
if (!compound.hasKey("ScriptLanguage") && !compound.hasKey("Languages")) {
|
||||
return;
|
||||
}
|
||||
script.readFromNBT(compound);
|
||||
loadLanguagesData(compound);
|
||||
loaded = true;
|
||||
@@ -375,7 +394,7 @@ public class GuiScript extends GuiScriptInterface {
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
if (loaded) {
|
||||
if (loaded && serverDataReceived) {
|
||||
setScript();
|
||||
NPCScriptPacket.Save(script.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import kamkeel.npcs.controllers.data.ability.data.IAbilityAction;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.player.ability.AbilityHotbarSelectPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import noppes.npcs.client.ClientProxy;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.client.ClientAbilityState;
|
||||
import noppes.npcs.client.KeyPressHandler;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
@@ -527,19 +527,34 @@ public class AbilityHotbarComponent extends HudComponent {
|
||||
PlayerAbilityHotbarData hotbarData = playerData.hotbarData;
|
||||
if (hotbarData == null) return;
|
||||
|
||||
EntityPlayer clientPlayer = Minecraft.getMinecraft().thePlayer;
|
||||
boolean globalBlock = clientPlayer != null && AbilityController.Instance != null
|
||||
&& !AbilityController.Instance.canPlayerActivate(clientPlayer);
|
||||
|
||||
for (int i = 0; i < TOTAL_SLOTS; i++) {
|
||||
AbilityHotbarData slotData = hotbarData.slots[i];
|
||||
String key = slotData.isEmpty() ? null : slotData.abilityKey;
|
||||
Ability ability = null;
|
||||
IAbilityAction action = null;
|
||||
if (key != null && AbilityController.Instance != null) {
|
||||
if (slotData.isChainKey()) {
|
||||
action = AbilityController.Instance.resolveChainedAbility(slotData.getResolveKey());
|
||||
if (globalBlock) {
|
||||
key = null;
|
||||
} else {
|
||||
ability = AbilityController.Instance.resolveAbility(key);
|
||||
action = ability;
|
||||
if (slotData.isChainKey()) {
|
||||
action = AbilityController.Instance.resolveChainedAbility(slotData.getResolveKey());
|
||||
} else {
|
||||
ability = AbilityController.Instance.resolveAbility(key);
|
||||
action = ability;
|
||||
}
|
||||
if (ability == null && action == null) key = null;
|
||||
|
||||
// Hide abilities whose player requirement is not met
|
||||
if (action != null && clientPlayer != null && !action.isAvailableFor(clientPlayer)) {
|
||||
key = null;
|
||||
ability = null;
|
||||
action = null;
|
||||
}
|
||||
}
|
||||
if (ability == null && action == null) key = null;
|
||||
}
|
||||
slots[i].setAbility(key, ability, action);
|
||||
}
|
||||
|
||||
-160
@@ -1,160 +0,0 @@
|
||||
package noppes.npcs.client.gui.player.inventory;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.controllers.data.AbilityHotbarData;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* SubGui for selecting an ability to assign to a hotbar slot.
|
||||
* Uses ability keys internally to avoid duplicate display name collisions.
|
||||
*/
|
||||
public class SubGuiSelectAbilityForSlot extends SubGuiInterface implements ICustomScrollListener, ITextfieldListener {
|
||||
private LinkedHashMap<String, String> keyToDisplay = new LinkedHashMap<>();
|
||||
private List<String> scrollKeys = new ArrayList<>();
|
||||
private GuiCustomScroll scrollAbilities;
|
||||
private int selectedIndex = -1;
|
||||
private String search = "";
|
||||
|
||||
public boolean confirmed = false;
|
||||
public String selectedAbilityKey = null;
|
||||
public int slotIndex;
|
||||
public boolean removeAbility = false;
|
||||
|
||||
public SubGuiSelectAbilityForSlot(int slotIndex) {
|
||||
this.slotIndex = slotIndex;
|
||||
this.closeOnEsc = true;
|
||||
this.drawDefaultBackground = true;
|
||||
xSize = 256 + 10;
|
||||
this.setBackground("menubg.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
guiTop = (this.height - ySize) / 2 + 10;
|
||||
|
||||
if (scrollAbilities == null) {
|
||||
scrollAbilities = new GuiCustomScroll(this, 0, 0);
|
||||
scrollAbilities.setSize(177, 185);
|
||||
}
|
||||
|
||||
scrollAbilities.guiLeft = guiLeft + 4;
|
||||
scrollAbilities.guiTop = guiTop + 4;
|
||||
addScroll(scrollAbilities);
|
||||
|
||||
loadAbilities();
|
||||
scrollAbilities.setList(getSearchList());
|
||||
|
||||
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 4, guiTop + 192, 177, 20, search));
|
||||
|
||||
addButton(new GuiNpcButton(0, guiLeft + 183, guiTop + 4, 79, 20, "gui.add"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 183, guiTop + 26, 79, 20, "gui.cancel"));
|
||||
addButton(new GuiNpcButton(2, guiLeft + 183, guiTop + 88, 79, 20, "gui.remove"));
|
||||
}
|
||||
|
||||
private void loadAbilities() {
|
||||
keyToDisplay.clear();
|
||||
PlayerData playerData = ClientCacheHandler.playerData;
|
||||
if (playerData == null || playerData.abilityData == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> abilities = playerData.abilityData.getUnlockedAbilityList();
|
||||
for (String key : abilities) {
|
||||
String displayName;
|
||||
if (key.startsWith(AbilityHotbarData.CHAIN_PREFIX)) {
|
||||
String chainKey = key.substring(AbilityHotbarData.CHAIN_PREFIX.length());
|
||||
ChainedAbility chain = AbilityController.Instance != null ?
|
||||
AbilityController.Instance.resolveChainedAbility(chainKey) : null;
|
||||
displayName = chain != null ? "\u00A76\u2726 " + chain.getDisplayName() : key;
|
||||
} else {
|
||||
Ability ability = AbilityController.Instance != null ?
|
||||
AbilityController.Instance.resolveAbility(key) : null;
|
||||
displayName = ability != null ? ability.getDisplayName() : key;
|
||||
}
|
||||
keyToDisplay.put(key, displayName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(GuiButton button) {
|
||||
int id = button.id;
|
||||
|
||||
if (id == 0 && selectedIndex >= 0 && selectedIndex < scrollKeys.size()) {
|
||||
confirmed = true;
|
||||
selectedAbilityKey = scrollKeys.get(selectedIndex);
|
||||
this.close();
|
||||
}
|
||||
if (id == 1) {
|
||||
this.close();
|
||||
}
|
||||
if (id == 2) {
|
||||
this.removeAbility = true;
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int i1, int i2, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll == scrollAbilities) {
|
||||
selectedIndex = scrollAbilities.selected;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll guiCustomScroll) {
|
||||
if (guiCustomScroll == scrollAbilities && selectedIndex >= 0 && selectedIndex < scrollKeys.size()) {
|
||||
confirmed = true;
|
||||
selectedAbilityKey = scrollKeys.get(selectedIndex);
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField guiNpcTextField) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
if (getTextField(55) != null) {
|
||||
if (getTextField(55).isFocused()) {
|
||||
if (search.equals(getTextField(55).getText()))
|
||||
return;
|
||||
search = getTextField(55).getText().toLowerCase();
|
||||
scrollAbilities.resetScroll();
|
||||
selectedIndex = -1;
|
||||
scrollAbilities.setList(getSearchList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getSearchList() {
|
||||
scrollKeys.clear();
|
||||
List<String> displayNames = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, String> entry : keyToDisplay.entrySet()) {
|
||||
String displayName = entry.getValue();
|
||||
if (search.isEmpty() || displayName.toLowerCase().contains(search)) {
|
||||
scrollKeys.add(entry.getKey());
|
||||
displayNames.add(displayName);
|
||||
}
|
||||
}
|
||||
return displayNames;
|
||||
}
|
||||
}
|
||||
@@ -317,6 +317,14 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
|
||||
this.addButton(new GuiNpcButton(107, left1, this.guiTop + 66 + yoffset, 80, 20, "script.loadscript"));
|
||||
|
||||
// Disable all buttons until server data arrives
|
||||
if (!serverDataReceived) {
|
||||
for (int btnId : new int[]{100, 101, 102, 105, 107, 113}) {
|
||||
GuiNpcButton btn = getButton(btnId);
|
||||
if (btn != null) btn.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
GuiCustomScroll scroll = (new GuiCustomScroll(this, 0)).setUnselectable();
|
||||
scroll.setSize(100, (int) ((double) this.ySize * 0.54D) - yoffset * 2);
|
||||
scroll.guiLeft = left1;
|
||||
@@ -349,11 +357,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
this.addButton(new GuiNpcButton(104, var9 + 60, this.guiTop + 31, 50, 20,
|
||||
new String[]{"gui.no", "gui.yes"}, this.handler.getEnabled() ? 1 : 0));
|
||||
|
||||
// Disable language/enabled controls until server data actually arrives
|
||||
// (serverDataReceived is only set in loadLanguagesData, not by getLanguageOptions injecting Java)
|
||||
this.getButton(103).enabled = serverDataReceived && languageOptions.size() > 0;
|
||||
this.getButton(104).enabled = serverDataReceived;
|
||||
|
||||
if (this.player.worldObj.isRemote) {
|
||||
this.addButton(new GuiNpcButton(106, var9, this.guiTop + 55, 150, 20, "script.openfolder"));
|
||||
}
|
||||
@@ -362,6 +365,17 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
this.addButton(new GuiNpcButton(112, var9 + 81, this.guiTop + 78, 80, 20, "gui.forum"));
|
||||
this.addButton(new GuiNpcButton(110, var9, this.guiTop + 99, 80, 20, "script.apidoc"));
|
||||
this.addButton(new GuiNpcButton(111, var9 + 81, this.guiTop + 99, 80, 20, "script.apisrc"));
|
||||
|
||||
// Disable all buttons until server data arrives
|
||||
if (!serverDataReceived) {
|
||||
for (int btnId : new int[]{100, 102, 103, 104, 106, 109, 110, 111, 112}) {
|
||||
GuiNpcButton btn = getButton(btnId);
|
||||
if (btn != null) btn.enabled = false;
|
||||
}
|
||||
} else {
|
||||
// Language button requires options to be available
|
||||
this.getButton(103).enabled = languageOptions.size() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public GuiScriptInterface setDimensions(int x, int y) {
|
||||
@@ -774,6 +788,9 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if (handler instanceof IScriptHandlerPacket) {
|
||||
IScriptHandlerPacket.GuiDataResult result = ((IScriptHandlerPacket) handler).setGuiData(compound);
|
||||
if (result == null) {
|
||||
return; // Unrelated packet, ignore
|
||||
}
|
||||
if (result.kind == IScriptHandlerPacket.GuiDataKind.LOAD_COMPLETE) {
|
||||
loaded = true;
|
||||
return;
|
||||
@@ -789,6 +806,10 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
return;
|
||||
}
|
||||
|
||||
// For non-IScriptHandlerPacket handlers, ignore unrelated packets
|
||||
if (!compound.hasKey("ScriptLanguage") && !compound.hasKey("Languages")) {
|
||||
return;
|
||||
}
|
||||
loadLanguagesData(compound);
|
||||
}
|
||||
|
||||
@@ -832,7 +853,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (!loaded)
|
||||
if (!loaded || !serverDataReceived)
|
||||
return;
|
||||
|
||||
this.setScript();
|
||||
|
||||
@@ -609,7 +609,26 @@ public class RenderNPCInterface extends RenderLiving {
|
||||
InputStream inputstream = null;
|
||||
try {
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
texturemanager.deleteTexture(location);
|
||||
|
||||
// Compute the hash-based skin location first
|
||||
ResourceLocation skinLocation = location;
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
byte[] hash = digest.digest(npc.display.texture.getBytes("UTF-8"));
|
||||
StringBuilder sb = new StringBuilder(2 * hash.length);
|
||||
for (byte b : hash) {
|
||||
sb.append(String.format("%02x", b & 0xff));
|
||||
}
|
||||
if (npc.display.modelType == 0) {
|
||||
skinLocation = new ResourceLocation("skin/" + sb.toString());
|
||||
} else {
|
||||
skinLocation = new ResourceLocation("skin64/" + sb.toString());
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// Delete old processed skin texture if cached (prevents GL texture leak)
|
||||
texturemanager.deleteTexture(skinLocation);
|
||||
|
||||
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(location);
|
||||
inputstream = iresource.getInputStream();
|
||||
@@ -625,22 +644,8 @@ public class RenderNPCInterface extends RenderLiving {
|
||||
ImageDownloadAlt object = new ImageDownloadAlt(null, npc.display.texture, SkinManager.field_152793_a, new ImageBufferDownloadAlt(true));
|
||||
object.setBufferedImage(bufferedimage);
|
||||
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
byte[] hash = digest.digest(npc.display.texture.getBytes("UTF-8"));
|
||||
StringBuilder sb = new StringBuilder(2 * hash.length);
|
||||
for (byte b : hash) {
|
||||
sb.append(String.format("%02x", b & 0xff));
|
||||
}
|
||||
if (npc.display.modelType == 0) {
|
||||
location = new ResourceLocation("skin/" + sb.toString());
|
||||
} else {
|
||||
location = new ResourceLocation("skin64/" + sb.toString());
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
texturemanager.loadTexture(location, object);
|
||||
return location;
|
||||
texturemanager.loadTexture(skinLocation, object);
|
||||
return skinLocation;
|
||||
} finally {
|
||||
if (inputstream != null) {
|
||||
inputstream.close();
|
||||
|
||||
@@ -53,6 +53,12 @@ public interface IScriptHandlerPacket extends IScriptHandler {
|
||||
return new GuiDataResult(GuiDataKind.LOAD_COMPLETE, -1);
|
||||
}
|
||||
|
||||
// Ignore unrelated packets (e.g. ScriptInfoPacket config data)
|
||||
// that don't contain any expected keys for this handler
|
||||
if (!compound.hasKey("Tab") && !compound.hasKey("ScriptLanguage") && !compound.hasKey("ScriptEnabled")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!compound.hasKey("Tab")) {
|
||||
setLanguage(compound.getString("ScriptLanguage"));
|
||||
setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
|
||||
@@ -381,6 +381,9 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
public boolean activateAbility(EntityPlayer player, String key) {
|
||||
if (player.worldObj.isRemote || key == null || key.isEmpty()) return false;
|
||||
|
||||
// Global activation check (e.g., addon-registered restrictions)
|
||||
if (!AbilityController.Instance.canPlayerActivate(player)) return false;
|
||||
|
||||
// Can't activate if already executing
|
||||
if (currentAbility != null && currentAbility.isExecuting()) return false;
|
||||
if (isExecutingChain()) return false;
|
||||
@@ -395,6 +398,9 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
// Check conditions (skip target-requiring ones)
|
||||
if (!action.checkConditionsForPlayer(player)) return false;
|
||||
|
||||
// Check player requirement (visibility/availability gate)
|
||||
if (!action.isAvailableFor(player)) return false;
|
||||
|
||||
// Dispatch: chain vs ability
|
||||
if (action.isChain()) {
|
||||
if (isOnCooldown()) return false;
|
||||
|
||||
@@ -236,6 +236,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
|
||||
// For Client-Side Use Only
|
||||
public int clientFixAttempts = 0;
|
||||
public long clientFixLastRequestMillis = 0L;
|
||||
|
||||
public EntityNPCInterface(World world) {
|
||||
super(world);
|
||||
@@ -483,7 +484,14 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
}
|
||||
|
||||
if (wasKilled != isKilled() && wasKilled) {
|
||||
reset();
|
||||
if (!worldObj.isRemote) {
|
||||
reset();
|
||||
} else {
|
||||
// Client-side full reset can create health oscillation when spawn data is being repaired.
|
||||
deathTime = 0;
|
||||
currentAnimation = EnumAnimation.NONE;
|
||||
updateHitbox();
|
||||
}
|
||||
}
|
||||
|
||||
wasKilled = isKilled();
|
||||
@@ -1838,6 +1846,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
display.writeToNBT(compound);
|
||||
compound.setDouble("MaxHealth", stats.maxHealth);
|
||||
compound.setFloat("CurrentHealth", getHealth());
|
||||
compound.setTag("Armor", NBTTags.nbtItemStackList(inventory.getArmor()));
|
||||
compound.setTag("Weapons", NBTTags.nbtItemStackList(inventory.getWeapons()));
|
||||
compound.setInteger("Speed", ais.getWalkingSpeed());
|
||||
@@ -1892,6 +1901,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
return;
|
||||
}
|
||||
|
||||
float preservedHealth = getHealth();
|
||||
stats.maxHealth = compound.getDouble("MaxHealth");
|
||||
ais.setWalkingSpeed(compound.getInteger("Speed"));
|
||||
stats.hideKilledBody = compound.getBoolean("DeadBody");
|
||||
@@ -1916,6 +1926,12 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
ais.bodyOffsetY = compound.getFloat("OffsetY");
|
||||
|
||||
this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(stats.maxHealth);
|
||||
if (compound.hasKey("CurrentHealth", Constants.NBT.TAG_FLOAT)) {
|
||||
setHealth(MathHelper.clamp_float(compound.getFloat("CurrentHealth"), 0.0F, getMaxHealth()));
|
||||
} else {
|
||||
// Keep previous client health if packet came from an older sender format.
|
||||
setHealth(MathHelper.clamp_float(preservedHealth, 0.0F, getMaxHealth()));
|
||||
}
|
||||
inventory.setArmor(NBTTags.getItemStackList(compound.getTagList("Armor", 10)));
|
||||
inventory.setWeapons(NBTTags.getItemStackList(compound.getTagList("Weapons", 10)));
|
||||
advanced.setRole(compound.getInteger("Role"));
|
||||
@@ -1990,6 +2006,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
return true;
|
||||
}
|
||||
clientFixAttempts = 0;
|
||||
clientFixLastRequestMillis = 0L;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user