mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 04:32:39 +00:00
pillar ability
This commit is contained in:
1 parent
d4a89dad1d
commit
0222a4984e
3 files changed
+796
-8
No files matched your search
@@ -32,14 +32,7 @@ import kamkeel.npcs.controllers.data.ability.type.AbilitySlam;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityTeleport;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityTrap;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityVortex;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityBeam;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityDisc;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityDome;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityLaser;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityOrb;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityShield;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilitySweeper;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.AbilityWall;
|
||||
import kamkeel.npcs.controllers.data.ability.type.energy.*;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import noppes.npcs.controllers.data.AbilityScript;
|
||||
import noppes.npcs.controllers.data.ChainedAbilityScript;
|
||||
@@ -177,6 +170,8 @@ public class AbilityController implements IAbilityHandler {
|
||||
registerType(AbilityDome::new);
|
||||
registerType(AbilityWall::new);
|
||||
registerType(AbilityShield::new);
|
||||
|
||||
registerType(AbilityPillar::new);
|
||||
}
|
||||
|
||||
private void registerBuiltinConditionTypes() {
|
||||
|
||||
+542
@@ -0,0 +1,542 @@
|
||||
package kamkeel.npcs.controllers.data.ability.type.energy;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyCombatData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyDisplayData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLifespanData;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.HitType;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
||||
import kamkeel.npcs.entity.EntityEnergyAbility;
|
||||
import kamkeel.npcs.entity.EntityEnergyZone;
|
||||
import kamkeel.npcs.network.packets.data.energycharge.EnergyChargeRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.energycharge.EnergyChargeSpawnPacket;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstract base for all energy zone abilities (Pillar, etc.).
|
||||
* Extends AbilityEnergy for shared visual/lightning data.
|
||||
*
|
||||
* Handles:
|
||||
* - Multi-zone support with staggered spawning via fireDelay
|
||||
* - Charge visual lifecycle via EnergyChargeSpawnPacket + EnergyChargeTracker
|
||||
* - Windup -> execute -> active -> complete lifecycle
|
||||
* - Telegraph infrastructure (subclass defines shape and radius)
|
||||
* - NBT persistence for shared fields
|
||||
*
|
||||
* Subclasses must implement:
|
||||
* - createEntity() — instantiate the zone entity
|
||||
* - setupEntityCharging() — configure entity for charge visual
|
||||
* - setupEntityPreview() — configure entity for GUI preview
|
||||
* - createEntityArray() — typed array creation (generics limitation)
|
||||
* - getZoneTelegraphRadius() — telegraph size
|
||||
* - addTypeDefinitions() — type-specific GUI fields
|
||||
* - writeTypeSpecificNBT()
|
||||
* - readTypeSpecificNBT()
|
||||
*
|
||||
* @param <E> The zone entity type this ability spawns
|
||||
*/
|
||||
public abstract class AbilityEnergyZone<E extends EntityEnergyZone> extends AbilityEnergy {
|
||||
|
||||
protected static final int MAX_ZONES = 8;
|
||||
|
||||
// ==================== ZONE COUNT & STAGGER ====================
|
||||
|
||||
protected int zoneCount = 1;
|
||||
protected int fireDelay = 0;
|
||||
|
||||
// ==================== SHARED DATA ====================
|
||||
|
||||
protected final EnergyCombatData combatData;
|
||||
protected final EnergyLifespanData lifespanData;
|
||||
|
||||
// ==================== RUNTIME STATE ====================
|
||||
|
||||
protected transient E[] entities;
|
||||
protected transient boolean[] zoneSpawned;
|
||||
protected transient int spawnedCount;
|
||||
protected transient String[] chargeVisualIds;
|
||||
protected transient EntityLivingBase chargeVisualCaster;
|
||||
|
||||
protected transient List<double[]> preCalculatedPositions = new ArrayList<>();
|
||||
|
||||
// ==================== CONSTRUCTOR ====================
|
||||
|
||||
protected AbilityEnergyZone(EnergyDisplayData displayData,
|
||||
EnergyCombatData combatData,
|
||||
EnergyLifespanData lifespanData) {
|
||||
super(displayData);
|
||||
this.combatData = combatData;
|
||||
this.lifespanData = lifespanData;
|
||||
this.burstOverlap = true;
|
||||
}
|
||||
|
||||
// ==================== ABSTRACT METHODS ====================
|
||||
|
||||
/**
|
||||
* Instantiate a single zone entity at the given position.
|
||||
* Called when a zone actually spawns.
|
||||
*/
|
||||
protected abstract E createEntity(EntityLivingBase caster, EntityLivingBase target,
|
||||
double x, double y, double z,
|
||||
EnergyDisplayData resolved, int index);
|
||||
|
||||
/**
|
||||
* Configure entity for charge visual during windup (non-preview).
|
||||
*/
|
||||
protected abstract void setupEntityCharging(E entity, int index);
|
||||
|
||||
/**
|
||||
* Configure entity for GUI preview mode.
|
||||
*/
|
||||
protected abstract void setupEntityPreview(E entity, EntityLivingBase caster,
|
||||
EnergyDisplayData resolved, int index);
|
||||
|
||||
/**
|
||||
* Create typed array. Required because Java generics cannot create generic arrays.
|
||||
*/
|
||||
protected abstract E[] createEntityArray(int size);
|
||||
|
||||
/**
|
||||
* Telegraph radius for this zone type.
|
||||
*/
|
||||
protected abstract float getZoneTelegraphRadius();
|
||||
|
||||
/**
|
||||
* Add type-specific GUI field definitions.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
protected abstract void addTypeDefinitions(List<FieldDef> defs);
|
||||
|
||||
/**
|
||||
* Write type-specific fields to NBT.
|
||||
* Shared data classes are written by the base class.
|
||||
*/
|
||||
protected abstract void writeTypeSpecificNBT(NBTTagCompound nbt);
|
||||
|
||||
/**
|
||||
* Read type-specific fields from NBT.
|
||||
* Shared data classes are read by the base class.
|
||||
*/
|
||||
protected abstract void readTypeSpecificNBT(NBTTagCompound nbt);
|
||||
|
||||
// ==================== OVERRIDABLE HOOKS ====================
|
||||
|
||||
/**
|
||||
* Resolve the spawn position for zone index.
|
||||
* Default uses preCalculatedPositions when available, falls back to target position.
|
||||
* Subclasses override for type-specific positioning (e.g. Pillar MOVING mode).
|
||||
*/
|
||||
protected double[] getSpawnPosition(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
if (index < preCalculatedPositions.size()) {
|
||||
return preCalculatedPositions.get(index);
|
||||
}
|
||||
if (target != null) {
|
||||
return new double[]{target.posX, target.posY, target.posZ};
|
||||
}
|
||||
return new double[]{caster.posX, caster.posY, caster.posZ};
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the display data for a specific zone index.
|
||||
* Default returns the shared displayData. Override for per-zone color overrides.
|
||||
*/
|
||||
protected EnergyDisplayData resolveDisplay(int index) {
|
||||
return displayData;
|
||||
}
|
||||
|
||||
// ==================== ZONE COUNT ====================
|
||||
|
||||
public int getZoneCount() {
|
||||
return zoneCount;
|
||||
}
|
||||
|
||||
public void setZoneCount(int count) {
|
||||
this.zoneCount = Math.max(1, Math.min(count, MAX_ZONES));
|
||||
}
|
||||
|
||||
public int getFireDelay() {
|
||||
return fireDelay;
|
||||
}
|
||||
|
||||
public void setFireDelay(int delay) {
|
||||
this.fireDelay = Math.max(0, delay);
|
||||
}
|
||||
|
||||
// ==================== RUNTIME STATE INIT ====================
|
||||
|
||||
protected void initRuntimeState(EntityLivingBase caster) {
|
||||
entities = createEntityArray(zoneCount);
|
||||
zoneSpawned = new boolean[zoneCount];
|
||||
spawnedCount = 0;
|
||||
chargeVisualIds = new String[zoneCount];
|
||||
chargeVisualCaster = caster;
|
||||
}
|
||||
|
||||
// ==================== ENTITY CREATION ====================
|
||||
|
||||
protected E createZoneEntity(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
double[] pos = getSpawnPosition(caster, target, index);
|
||||
EnergyDisplayData resolved = resolveDisplay(index);
|
||||
E entity = createEntity(caster, target, pos[0], pos[1], pos[2], resolved, index);
|
||||
entity.setSourceAbility(this);
|
||||
entity.setIgnoreIFrames(this.isIgnoreIFrames());
|
||||
entity.setEffects(this.effects);
|
||||
noppes.npcs.controllers.data.MagicData resolvedMagic = resolveMagicData(caster);
|
||||
if (resolvedMagic != null) {
|
||||
entity.setMagicData(resolvedMagic.copy());
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
protected void spawnZoneEntity(E entity, int index) {
|
||||
if (entity == null) return;
|
||||
spawnAbilityEntity(entity);
|
||||
entities[index] = entity;
|
||||
if (!zoneSpawned[index]) {
|
||||
zoneSpawned[index] = true;
|
||||
spawnedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
protected void spawnZoneAt(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
if (entities != null && entities[index] != null && !entities[index].isDead) return;
|
||||
E entity = createZoneEntity(caster, target, index);
|
||||
spawnZoneEntity(entity, index);
|
||||
}
|
||||
|
||||
// ==================== CHARGE VISUAL ====================
|
||||
|
||||
protected String getChargeVisualId(EntityLivingBase caster, int index) {
|
||||
return "energy_charge:" + caster.getEntityId() + ":" + executionStartTime + ":" + burstIndex + ":" + index;
|
||||
}
|
||||
|
||||
protected void spawnChargeVisual(EntityLivingBase caster, EntityLivingBase target, int index, int chargeDuration) {
|
||||
if (isPreview() || caster == null || caster.worldObj == null || caster.worldObj.isRemote) return;
|
||||
if (chargeVisualIds == null || index < 0 || index >= chargeVisualIds.length) return;
|
||||
|
||||
E previewEntity = createZoneEntity(caster, target, index);
|
||||
previewEntity.setPreviewMode(true);
|
||||
previewEntity.setPreviewOwner(caster);
|
||||
setupEntityCharging(previewEntity, index);
|
||||
previewEntity.setChargeDuration(Math.max(1, chargeDuration));
|
||||
|
||||
String id = getChargeVisualId(caster, index);
|
||||
chargeVisualIds[index] = id;
|
||||
chargeVisualCaster = caster;
|
||||
EnergyChargeSpawnPacket.sendToTracking(id, previewEntity, caster);
|
||||
|
||||
EnergyChargeTracker.Instance.add(new EnergyChargeTracker.ChargeEntry(
|
||||
id,
|
||||
previewEntity.getClass().getName(),
|
||||
previewEntity.exportSpawnNBT(),
|
||||
caster.getEntityId(),
|
||||
(int) caster.worldObj.getTotalWorldTime()
|
||||
));
|
||||
}
|
||||
|
||||
protected void removeChargeVisual(EntityLivingBase caster, int index) {
|
||||
if (isPreview() || caster == null || caster.worldObj == null || caster.worldObj.isRemote) return;
|
||||
if (chargeVisualIds == null || index < 0 || index >= chargeVisualIds.length) return;
|
||||
|
||||
String id = chargeVisualIds[index];
|
||||
if (id != null && !id.isEmpty()) {
|
||||
EnergyChargeRemovePacket.sendToTracking(id, caster);
|
||||
EnergyChargeTracker.Instance.remove(id, caster.getEntityId());
|
||||
chargeVisualIds[index] = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void removeAllChargeVisuals(EntityLivingBase caster) {
|
||||
if (chargeVisualIds == null || caster == null) return;
|
||||
for (int i = 0; i < chargeVisualIds.length; i++) {
|
||||
removeChargeVisual(caster, i);
|
||||
}
|
||||
if (!isPreview() && caster.worldObj != null && !caster.worldObj.isRemote) {
|
||||
EnergyChargeTracker.Instance.removeAllForCaster(caster.getEntityId());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== LIFECYCLE ====================
|
||||
|
||||
@Override
|
||||
public boolean allowOverlap() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowFreeOnCast() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTargetingModeLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetingMode[] getAllowedTargetingModes() {
|
||||
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadyForBurstCompletion(int activeTick) {
|
||||
return fireDelay <= 0 || activeTick >= fireDelay * (zoneCount - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detach() {
|
||||
entities = null;
|
||||
zoneSpawned = null;
|
||||
spawnedCount = 0;
|
||||
preCalculatedPositions.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, int tick) {
|
||||
if (caster.worldObj.isRemote && !isPreview()) return;
|
||||
|
||||
if (tick == 1) {
|
||||
initRuntimeState(caster);
|
||||
|
||||
if (isPreview()) {
|
||||
for (int i = 0; i < zoneCount; i++) {
|
||||
E previewEntity = createZoneEntity(caster, target, i);
|
||||
setupEntityPreview(previewEntity, caster, resolveDisplay(i), i);
|
||||
spawnAbilityEntity(previewEntity);
|
||||
entities[i] = previewEntity;
|
||||
zoneSpawned[i] = true;
|
||||
spawnedCount++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < zoneCount; i++) {
|
||||
spawnChargeVisual(caster, target, i, windUpTicks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetForBurst() {
|
||||
removeAllChargeVisuals(chargeVisualCaster);
|
||||
if (!burstOverlap) {
|
||||
cleanup();
|
||||
}
|
||||
entities = null;
|
||||
zoneSpawned = null;
|
||||
spawnedCount = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (isPreview()) {
|
||||
if (entities == null) {
|
||||
initRuntimeState(caster);
|
||||
for (int i = 0; i < zoneCount; i++) {
|
||||
E previewEntity = createZoneEntity(caster, target, i);
|
||||
setupEntityPreview(previewEntity, caster, resolveDisplay(i), i);
|
||||
spawnAbilityEntity(previewEntity);
|
||||
entities[i] = previewEntity;
|
||||
zoneSpawned[i] = true;
|
||||
spawnedCount++;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (entities == null || zoneSpawned == null || entities.length != zoneCount) {
|
||||
initRuntimeState(caster);
|
||||
}
|
||||
|
||||
removeAllChargeVisuals(caster);
|
||||
|
||||
spawnZoneAt(caster, target, 0);
|
||||
|
||||
if (fireDelay <= 0) {
|
||||
for (int i = 1; i < zoneCount; i++) {
|
||||
spawnZoneAt(caster, target, i);
|
||||
}
|
||||
} else {
|
||||
for (int i = 1; i < zoneCount; i++) {
|
||||
spawnChargeVisual(caster, target, i, fireDelay * i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, int tick) {
|
||||
if (entities == null || zoneSpawned == null) {
|
||||
signalCompletion();
|
||||
return;
|
||||
}
|
||||
|
||||
if (fireDelay > 0) {
|
||||
for (int i = 1; i < zoneCount; i++) {
|
||||
if (tick == fireDelay * i) {
|
||||
removeChargeVisual(caster, i);
|
||||
spawnZoneAt(caster, target, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isFreeOnCast()) {
|
||||
int lastSpawnTick = fireDelay > 0 ? fireDelay * (zoneCount - 1) : 0;
|
||||
if (tick >= lastSpawnTick) {
|
||||
signalCompletion();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean allDead = spawnedCount >= zoneCount;
|
||||
if (allDead) {
|
||||
for (E entity : entities) {
|
||||
if (entity == null || entity.isDead) continue;
|
||||
if (!isPreview() && tick > 5 && entity.worldObj != null
|
||||
&& entity.worldObj.getEntityByID(entity.getEntityId()) != entity) {
|
||||
entity.setDead();
|
||||
continue;
|
||||
}
|
||||
allDead = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!allDead) {
|
||||
int lastSpawnTick = fireDelay > 0 ? fireDelay * (zoneCount - 1) : 0;
|
||||
int maxLifetime = lifespanData.getMaxLifetime() > 0 ? lifespanData.getMaxLifetime() : 200;
|
||||
if (tick > lastSpawnTick + maxLifetime + 20) {
|
||||
cleanup();
|
||||
allDead = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (allDead) {
|
||||
signalCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(EntityLivingBase caster, EntityLivingBase target) {
|
||||
removeAllChargeVisuals(caster);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInterrupt(EntityLivingBase caster, DamageSource source, float damage) {
|
||||
removeAllChargeVisuals(caster);
|
||||
cleanup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
removeAllChargeVisuals(chargeVisualCaster);
|
||||
if (entities != null) {
|
||||
for (int i = 0; i < entities.length; i++) {
|
||||
if (entities[i] != null && !entities[i].isDead) {
|
||||
entities[i].setDead();
|
||||
}
|
||||
entities[i] = null;
|
||||
}
|
||||
}
|
||||
entities = null;
|
||||
zoneSpawned = null;
|
||||
spawnedCount = 0;
|
||||
chargeVisualIds = null;
|
||||
chargeVisualCaster = null;
|
||||
preCalculatedPositions.clear();
|
||||
}
|
||||
|
||||
// ==================== PREVIEW ====================
|
||||
|
||||
@Override
|
||||
public int getMaxPreviewDuration() {
|
||||
return lifespanData.getMaxLifetime() > 0 ? Math.min(lifespanData.getMaxLifetime(), 100) : 100;
|
||||
}
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
@Override
|
||||
public final void writeTypeNBT(NBTTagCompound nbt) {
|
||||
writeTypeSpecificNBT(nbt);
|
||||
|
||||
nbt.setInteger("zoneCount", zoneCount);
|
||||
nbt.setInteger("fireDelay", fireDelay);
|
||||
|
||||
writeEnergyNBT(nbt);
|
||||
combatData.writeNBT(nbt);
|
||||
lifespanData.writeNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void readTypeNBT(NBTTagCompound nbt) {
|
||||
readTypeSpecificNBT(nbt);
|
||||
|
||||
this.zoneCount = Math.max(1, Math.min(nbt.getInteger("zoneCount"), MAX_ZONES));
|
||||
this.fireDelay = Math.max(0, nbt.getInteger("fireDelay"));
|
||||
|
||||
readEnergyNBT(nbt);
|
||||
combatData.readNBT(nbt);
|
||||
lifespanData.readNBT(nbt);
|
||||
}
|
||||
|
||||
// ==================== GUI ====================
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public final void getAbilityDefinitions(List<FieldDef> defs) {
|
||||
defs.add(FieldDef.enumField("ability.hitType", HitType.class,
|
||||
() -> HitType.fromOrdinal(getHitType()),
|
||||
v -> setHitType(v.ordinal()))
|
||||
.hover("ability.hover.hitType"));
|
||||
defs.add(FieldDef.intField("ability.multiHitDelay", this::getMultiHitDelayTicks, this::setMultiHitDelayTicks)
|
||||
.range(1, 200)
|
||||
.visibleWhen(() -> getHitType() == HitType.MULTI.ordinal())
|
||||
.hover("ability.hover.multiHitDelay"));
|
||||
defs.add(FieldDef.intField("ability.maxHits", this::getMaxHits, this::setMaxHits)
|
||||
.range(1, EnergyCombatData.MAX_HITS)
|
||||
.visibleWhen(() -> getHitType() != HitType.SINGLE.ordinal())
|
||||
.hover("ability.hover.maxHits"));
|
||||
|
||||
defs.add(FieldDef.intField("ability.zoneCount", this::getZoneCount, this::setZoneCount)
|
||||
.range(1, MAX_ZONES));
|
||||
defs.add(FieldDef.intField("ability.fireDelay", this::getFireDelay, this::setFireDelay)
|
||||
.range(0, 200)
|
||||
.visibleWhen(() -> zoneCount > 1));
|
||||
|
||||
addTypeDefinitions(defs);
|
||||
|
||||
addEnergyColorDefinitions(defs);
|
||||
addEnergyEffectDefinitions(defs);
|
||||
}
|
||||
|
||||
// ==================== COMBAT GETTERS & SETTERS ====================
|
||||
|
||||
public float getDamage() { return combatData.getDamage(); }
|
||||
public void setDamage(float damage) { combatData.setDamage(damage); }
|
||||
|
||||
@Override
|
||||
public float getDisplayDamage() { return combatData.getDamage(); }
|
||||
|
||||
public float getKnockback() { return combatData.knockback; }
|
||||
public void setKnockback(float knockback) { combatData.setKnockback(knockback); }
|
||||
|
||||
public int getHitType() { return combatData.hitType.ordinal(); }
|
||||
public void setHitType(int hitType) { combatData.hitType = HitType.fromOrdinal(hitType); }
|
||||
|
||||
public int getMultiHitDelayTicks() { return combatData.multiHitDelayTicks; }
|
||||
public void setMultiHitDelayTicks(int delay) { combatData.multiHitDelayTicks = Math.max(1, delay); }
|
||||
|
||||
public int getMaxHits() { return combatData.getMaxHits(); }
|
||||
public void setMaxHits(int maxHits) { combatData.setMaxHits(maxHits); }
|
||||
|
||||
public int getMaxLifetime() { return lifespanData.getMaxLifetime(); }
|
||||
public void setMaxLifetime(int ticks) { lifespanData.setMaxLifetime(ticks); }
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
package kamkeel.npcs.controllers.data.ability.type.energy;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyCombatData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyDisplayData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyHomingData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyLifespanData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyPillarData;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.LockMode;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.telegraph.Telegraph;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar.PillarMode;
|
||||
import kamkeel.npcs.entity.EntityAbilityPillar.PillarShape;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Vec3;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Pillar zone ability — spawns one or more energy pillars that rise from the ground
|
||||
* or fall from the sky.
|
||||
*
|
||||
* ANCHORED: pillar spawns at the target's position and stays there.
|
||||
* MOVING: pillar spawns in front of the caster and travels forward,
|
||||
* optionally homing toward a target.
|
||||
*
|
||||
* Telegraph shape matches PillarShape (CIRCLE or SQUARE).
|
||||
*/
|
||||
public class AbilityPillar extends AbilityEnergyZone<EntityAbilityPillar> {
|
||||
|
||||
// ==================== PILLAR CONFIG ====================
|
||||
|
||||
private EnergyPillarData pillarData = new EnergyPillarData();
|
||||
private EnergyHomingData homingData = new EnergyHomingData();
|
||||
|
||||
// ==================== CONSTRUCTOR ====================
|
||||
|
||||
public AbilityPillar() {
|
||||
super(
|
||||
new EnergyDisplayData(),
|
||||
new EnergyCombatData(),
|
||||
new EnergyLifespanData()
|
||||
);
|
||||
this.typeId = "ability.cnpc.pillar";
|
||||
this.name = "Pillar";
|
||||
this.targetingMode = TargetingMode.AGGRO_TARGET;
|
||||
this.maxRange = 25.0f;
|
||||
this.minRange = 5.0f;
|
||||
this.cooldownTicks = 0;
|
||||
this.windUpTicks = 30;
|
||||
this.lockMovement = LockMode.WINDUP;
|
||||
this.telegraphType = pillarData.shape.getTelegraphType();
|
||||
this.showTelegraph = true;
|
||||
}
|
||||
|
||||
// ==================== ABSTRACT IMPLEMENTATIONS ====================
|
||||
|
||||
@Override
|
||||
protected EntityAbilityPillar createEntity(EntityLivingBase caster, EntityLivingBase target,
|
||||
double x, double y, double z,
|
||||
EnergyDisplayData resolved, int index) {
|
||||
return new EntityAbilityPillar(
|
||||
caster.worldObj, caster,
|
||||
x, y, z,
|
||||
pillarData,
|
||||
resolved,
|
||||
lightningData,
|
||||
homingData
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupEntityCharging(EntityAbilityPillar entity, int index) {
|
||||
entity.setupCharging(windUpTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupEntityPreview(EntityAbilityPillar entity, EntityLivingBase caster,
|
||||
EnergyDisplayData resolved, int index) {
|
||||
entity.setupPreview(caster, pillarData, resolved, lightningData, windUpTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EntityAbilityPillar[] createEntityArray(int size) {
|
||||
return new EntityAbilityPillar[size];
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getZoneTelegraphRadius() {
|
||||
return pillarData.targetRadius;
|
||||
}
|
||||
|
||||
// ==================== SPAWN POSITION ====================
|
||||
|
||||
@Override
|
||||
protected double[] getSpawnPosition(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
if (pillarData.mode == PillarMode.MOVING) {
|
||||
// Spawn in front of caster along look vector
|
||||
Vec3 look = caster.getLookVec();
|
||||
if (look != null) {
|
||||
float dist = Math.max(1.0f, pillarData.targetRadius);
|
||||
return new double[]{
|
||||
caster.posX + look.xCoord * dist,
|
||||
caster.posY,
|
||||
caster.posZ + look.zCoord * dist
|
||||
};
|
||||
}
|
||||
return new double[]{caster.posX, caster.posY, caster.posZ};
|
||||
}
|
||||
|
||||
// ANCHORED: use pre-calculated position or target position
|
||||
return super.getSpawnPosition(caster, target, index);
|
||||
}
|
||||
|
||||
// ==================== EXECUTE — startGrowing ====================
|
||||
|
||||
@Override
|
||||
protected void spawnZoneAt(EntityLivingBase caster, EntityLivingBase target, int index) {
|
||||
super.spawnZoneAt(caster, target, index);
|
||||
EntityAbilityPillar entity = entities[index];
|
||||
if (entity != null && !entity.isDead) {
|
||||
if (target != null) {
|
||||
entity.setTarget(target);
|
||||
}
|
||||
entity.startGrowing();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== TELEGRAPH ====================
|
||||
|
||||
@Override
|
||||
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (!showTelegraph || telegraphType == TelegraphType.NONE || isPlayerCaster(caster) || target == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Telegraph telegraph;
|
||||
if (pillarData.shape == PillarShape.SQUARE) {
|
||||
telegraph = Telegraph.square(pillarData.targetRadius);
|
||||
} else {
|
||||
telegraph = Telegraph.circle(pillarData.targetRadius);
|
||||
}
|
||||
|
||||
telegraph.setDurationTicks(windUpTicks);
|
||||
telegraph.setColor(windUpColor);
|
||||
telegraph.setWarningColor(activeColor);
|
||||
telegraph.setWarningStartTick(Math.max(5, windUpTicks / 4));
|
||||
telegraph.setHeightOffset(telegraphHeightOffset);
|
||||
|
||||
double groundY = findGroundLevel(caster.worldObj, target.posX, target.posY, target.posZ);
|
||||
|
||||
// Store position for use in getSpawnPosition (ANCHORED mode)
|
||||
preCalculatedPositions.clear();
|
||||
for (int i = 0; i < zoneCount; i++) {
|
||||
preCalculatedPositions.add(new double[]{target.posX, groundY, target.posZ});
|
||||
}
|
||||
|
||||
TelegraphInstance instance = new TelegraphInstance(telegraph, target.posX, groundY, target.posZ, caster.rotationYaw);
|
||||
instance.setCasterEntityId(caster.getEntityId());
|
||||
instance.setEntityIdToFollow(homingData.isHoming() ? target.getEntityId() : -1);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTelegraphRadius() {
|
||||
return pillarData.targetRadius;
|
||||
}
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
@Override
|
||||
protected void writeTypeSpecificNBT(NBTTagCompound nbt) {
|
||||
pillarData.writeNBT(nbt);
|
||||
homingData.writeNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readTypeSpecificNBT(NBTTagCompound nbt) {
|
||||
pillarData.readNBT(nbt);
|
||||
homingData.readNBT(nbt);
|
||||
}
|
||||
|
||||
// ==================== GUI ====================
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
protected void addTypeDefinitions(List<FieldDef> defs) {
|
||||
defs.add(FieldDef.section("ability.section.pillar"));
|
||||
|
||||
defs.add(FieldDef.enumField("ability.pillarMode", PillarMode.class,
|
||||
() -> pillarData.mode,
|
||||
v -> pillarData.mode = v));
|
||||
|
||||
defs.add(FieldDef.enumField("ability.pillarOrigin", EntityAbilityPillar.PillarOrigin.class,
|
||||
() -> pillarData.origin,
|
||||
v -> pillarData.origin = v));
|
||||
|
||||
defs.add(FieldDef.enumField("ability.pillarShape", PillarShape.class,
|
||||
() -> pillarData.shape,
|
||||
v -> pillarData.shape = v));
|
||||
|
||||
defs.add(FieldDef.row(
|
||||
FieldDef.floatField("ability.pillar.targetRadius", () -> pillarData.targetRadius, v -> pillarData.targetRadius = v).range(0.1f, 64f),
|
||||
FieldDef.floatField("ability.pillar.targetHeight", () -> pillarData.targetHeight, v -> pillarData.targetHeight = v).range(0.1f, 64f)
|
||||
));
|
||||
|
||||
defs.add(FieldDef.row(
|
||||
FieldDef.floatField("ability.pillar.radiusGrowSpeed", () -> pillarData.radiusGrowSpeed, v -> pillarData.radiusGrowSpeed = Math.max(0.01f, v)),
|
||||
FieldDef.floatField("ability.pillar.heightGrowSpeed", () -> pillarData.heightGrowSpeed, v -> pillarData.heightGrowSpeed = Math.max(0.01f, v))
|
||||
));
|
||||
|
||||
defs.add(FieldDef.intField("ability.pillar.spawnDelay", () -> pillarData.spawnDelay, v -> pillarData.spawnDelay = Math.max(0, v))
|
||||
.range(0, 200));
|
||||
|
||||
defs.add(FieldDef.section("ability.section.homing")
|
||||
.visibleWhen(() -> pillarData.mode == PillarMode.MOVING));
|
||||
|
||||
defs.add(FieldDef.boolField("ability.homing", () -> homingData.isHoming(), v -> homingData.setHoming(v))
|
||||
.visibleWhen(() -> pillarData.mode == PillarMode.MOVING));
|
||||
|
||||
defs.add(FieldDef.row(
|
||||
FieldDef.floatField("ability.homingStrength", () -> homingData.getHomingStrength(), v -> homingData.setHomingStrength(v)).range(0f, 1f),
|
||||
FieldDef.floatField("ability.homingRange", () -> homingData.getHomingRange(), v -> homingData.setHomingRange(v))
|
||||
).visibleWhen(() -> pillarData.mode == PillarMode.MOVING && homingData.isHoming()));
|
||||
|
||||
defs.add(FieldDef.floatField("ability.speed", () -> homingData.getSpeed(), v -> homingData.setSpeed(v))
|
||||
.visibleWhen(() -> pillarData.mode == PillarMode.MOVING)
|
||||
.range(0.01f, 10f));
|
||||
|
||||
defs.add(FieldDef.section("ability.section.combat"));
|
||||
|
||||
defs.add(FieldDef.floatField("ability.damage", this::getDamage, this::setDamage).range(0f, 1000f));
|
||||
defs.add(FieldDef.floatField("ability.knockback", this::getKnockback, this::setKnockback).range(0f, 10f));
|
||||
defs.add(FieldDef.intField("ability.maxLifetime", this::getMaxLifetime, this::setMaxLifetime).range(1, 1200));
|
||||
}
|
||||
|
||||
// ==================== GETTERS & SETTERS ====================
|
||||
|
||||
public EnergyPillarData getPillarData() { return pillarData; }
|
||||
public void setPillarData(EnergyPillarData data) { this.pillarData = data != null ? data : new EnergyPillarData(); }
|
||||
|
||||
public EnergyHomingData getHomingData() { return homingData; }
|
||||
public void setHomingData(EnergyHomingData data) { this.homingData = data != null ? data : new EnergyHomingData(); }
|
||||
}
|
||||
Reference in new issue
Block a user