mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 11:09:42 +00:00
Merge remote-tracking branch 'origin/syntax-highlighter-unified' into syntax-highlighter-unified
This commit is contained in:
commit
b4c0859759
158 files changed
+12912
-10170
No files matched your search
@@ -91,6 +91,7 @@ import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
||||
import noppes.npcs.entity.old.EntityNPCDwarfFemale;
|
||||
import noppes.npcs.entity.old.EntityNPCDwarfMale;
|
||||
import noppes.npcs.entity.old.EntityNPCElfFemale;
|
||||
@@ -117,7 +118,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11-beta1")
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11-beta3")
|
||||
public class CustomNpcs {
|
||||
|
||||
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
|
||||
@@ -292,6 +293,7 @@ public class CustomNpcs {
|
||||
registerNewEntity(EntityAbilityLaser.class, "abilitylaser", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityBeam.class, "abilitybeam", 64, 3, true);
|
||||
registerNewEntity(EntityAbilitySweeper.class, "abilitysweeper", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityZone.class, "abilityzone", 64, 3, true);
|
||||
|
||||
new RecipeController();
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class DataAbilities {
|
||||
/**
|
||||
* Whether the ability system is enabled for this NPC
|
||||
*/
|
||||
public boolean enabled = false;
|
||||
public boolean enabled = true;
|
||||
|
||||
/**
|
||||
* Minimum cooldown ticks between abilities (global minimum)
|
||||
@@ -90,6 +90,24 @@ public class DataAbilities {
|
||||
private transient float lockedRenderYawOffset = 0;
|
||||
private transient float lockedPitch = 0;
|
||||
|
||||
/**
|
||||
* Locked position values for movement lock.
|
||||
* Stored when entering a locked phase, applied after super.onLivingUpdate()
|
||||
* to override any position changes from AI/physics.
|
||||
*/
|
||||
private transient boolean positionLocked = false;
|
||||
private transient double lockedPosX = 0;
|
||||
private transient double lockedPosY = 0;
|
||||
private transient double lockedPosZ = 0;
|
||||
|
||||
/**
|
||||
* Hit scan state - forces NPC to face target.
|
||||
* Set during tickCurrentAbility(), applied after super.onLivingUpdate()
|
||||
* to override AI look helper rotation.
|
||||
*/
|
||||
private transient boolean hitScanActive = false;
|
||||
private transient EntityLivingBase hitScanTarget = null;
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CONSTRUCTOR
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -107,10 +125,33 @@ public class DataAbilities {
|
||||
* Should be called every tick from onLivingUpdate().
|
||||
*/
|
||||
public void tick() {
|
||||
if (!enabled || npc.worldObj.isRemote || npc.isKilled()) {
|
||||
if (npc.worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Force-stop any running ability when NPC is killed or abilities are disabled
|
||||
if (!enabled || npc.isKilled()) {
|
||||
if (currentAbility != null) {
|
||||
removeTelegraph(currentAbility);
|
||||
stopAbilityAnimation();
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
currentAbility = null;
|
||||
lastTarget = null;
|
||||
} else {
|
||||
// No ability but locks could be orphaned
|
||||
if (rotationLocked || hitScanActive) releaseRotationControl();
|
||||
if (positionLocked) releaseLockedPosition();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Safety: release orphaned locks if no ability is actively executing
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) {
|
||||
if (rotationLocked || hitScanActive) releaseRotationControl();
|
||||
if (positionLocked) releaseLockedPosition();
|
||||
}
|
||||
|
||||
// Tick current ability if executing
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
tickCurrentAbility();
|
||||
@@ -130,39 +171,75 @@ public class DataAbilities {
|
||||
// Fire tick event for scripts
|
||||
fireTickEvent(currentAbility, target);
|
||||
|
||||
// Fire extender tick hook (e.g., per-tick resource drain)
|
||||
if (!AbilityController.Instance.fireOnAbilityTick(currentAbility, npc, target,
|
||||
currentAbility.getPhase(), currentAbility.getCurrentTick())) {
|
||||
interruptCurrentAbility(null, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle phase-specific logic
|
||||
switch (currentAbility.getPhase()) {
|
||||
case WINDUP:
|
||||
currentAbility.onWindUpTick(npc, target, npc.worldObj, currentAbility.getCurrentTick());
|
||||
if (phaseChanged && oldPhase == AbilityPhase.BURST_DELAY) {
|
||||
// Burst replay: re-enter windup - set up telegraph, sound, animation, locks
|
||||
if (currentAbility.isRotationLockedDuringWindup()) {
|
||||
captureLockedRotation();
|
||||
}
|
||||
if (currentAbility.isMovementLockedDuringWindup() && !currentAbility.hasAbilityMovement()) {
|
||||
captureLockedPosition();
|
||||
}
|
||||
spawnTelegraph(currentAbility, target);
|
||||
playAbilitySound(currentAbility.getWindUpSound());
|
||||
playAbilityAnimation(currentAbility.getWindUpAnimation());
|
||||
}
|
||||
currentAbility.onWindUpTick(npc, target, currentAbility.getCurrentTick());
|
||||
break;
|
||||
|
||||
case ACTIVE:
|
||||
if (phaseChanged && oldPhase == AbilityPhase.WINDUP) {
|
||||
// Just entered ACTIVE phase - lock telegraph position if it was following
|
||||
if (phaseChanged && (oldPhase == AbilityPhase.WINDUP || oldPhase == AbilityPhase.BURST_DELAY)) {
|
||||
// Just entered ACTIVE phase - lock telegraph positions if they were following
|
||||
// This commits the ability to its current target position
|
||||
TelegraphInstance telegraph = currentAbility.getTelegraphInstance();
|
||||
if (telegraph != null) {
|
||||
for (TelegraphInstance telegraph : currentAbility.getTelegraphInstances()) {
|
||||
telegraph.lockPosition();
|
||||
}
|
||||
|
||||
// Remove telegraph - it has served its purpose
|
||||
removeTelegraph(currentAbility);
|
||||
// Remove telegraph unless the ability keeps it during active phase
|
||||
// (e.g., sweeping attacks where the telegraph shows the ongoing danger zone)
|
||||
if (!currentAbility.keepTelegraphDuringActive()) {
|
||||
removeTelegraph(currentAbility);
|
||||
}
|
||||
|
||||
// Handle rotation lock transition from WINDUP to ACTIVE
|
||||
// Handle rotation control transition from WINDUP to ACTIVE
|
||||
if (currentAbility.isRotationLockedDuringActive()) {
|
||||
// ACTIVE or WINDUP_AND_ACTIVE: capture (or keep) rotation lock
|
||||
if (!rotationLocked) {
|
||||
captureLockedRotation();
|
||||
}
|
||||
} else if (rotationLocked) {
|
||||
// WINDUP only: release the lock now that windup is over
|
||||
releaseLockedRotation();
|
||||
releaseRotationControl();
|
||||
}
|
||||
|
||||
// Handle position lock transition from WINDUP to ACTIVE
|
||||
if (currentAbility.isMovementLockedDuringActive() && !currentAbility.hasAbilityMovement()) {
|
||||
if (!positionLocked) {
|
||||
captureLockedPosition();
|
||||
}
|
||||
} else if (positionLocked) {
|
||||
releaseLockedPosition();
|
||||
}
|
||||
|
||||
// Play active sound and animation
|
||||
playAbilitySound(currentAbility.getActiveSound());
|
||||
// Abilities that keep telegraph during active manage their own sound timing
|
||||
if (!currentAbility.keepTelegraphDuringActive()) {
|
||||
playAbilitySound(currentAbility.getActiveSound());
|
||||
}
|
||||
playAbilityAnimation(currentAbility.getActiveAnimation());
|
||||
|
||||
// Snap NPC to face target before execute so startMoving() reads correct rotation
|
||||
if (currentAbility.isHitScanForCurrentPhase() && target != null) {
|
||||
faceTarget(target);
|
||||
}
|
||||
|
||||
// Fire execute event (cancelable)
|
||||
AbilityEvent.ExecuteEvent executeEvent = new AbilityEvent.ExecuteEvent(
|
||||
npc.wrappedNPC, currentAbility, target);
|
||||
@@ -172,7 +249,7 @@ public class DataAbilities {
|
||||
}
|
||||
|
||||
// Call onExecute
|
||||
currentAbility.onExecute(npc, target, npc.worldObj);
|
||||
currentAbility.onExecute(npc, target);
|
||||
|
||||
// Check if ability completed during onExecute (signalCompletion was called)
|
||||
if (currentAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
@@ -180,13 +257,38 @@ public class DataAbilities {
|
||||
return;
|
||||
}
|
||||
}
|
||||
currentAbility.onActiveTick(npc, target, npc.worldObj, currentAbility.getCurrentTick());
|
||||
currentAbility.onActiveTick(npc, target, currentAbility.getCurrentTick());
|
||||
|
||||
// Check if ability completed during onActiveTick (signalCompletion was called)
|
||||
if (currentAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
handleAbilityCompletion(target);
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto-complete for burst overlap mode (entities fly independently)
|
||||
// This allows entity-spawning abilities to immediately chain next burst
|
||||
// without each type needing to check burst state in their onActiveTick()
|
||||
// Wait until all staggered projectiles have been fired before auto-completing
|
||||
if (currentAbility.isBurstEnabled()
|
||||
&& currentAbility.getBurstIndex() < currentAbility.getBurstAmount()
|
||||
&& currentAbility.getPhase() == AbilityPhase.ACTIVE
|
||||
&& currentAbility.isReadyForBurstCompletion(currentAbility.getCurrentTick())) {
|
||||
currentAbility.signalCompletion();
|
||||
}
|
||||
|
||||
// Check if ability entered burst delay during onActiveTick or overlap auto-complete
|
||||
if (currentAbility.getPhase() == AbilityPhase.BURST_DELAY) {
|
||||
// Release all locks - free movement/rotation during delay
|
||||
if (rotationLocked) releaseRotationControl();
|
||||
if (positionLocked) releaseLockedPosition();
|
||||
if (hitScanActive) releaseRotationControl();
|
||||
}
|
||||
break;
|
||||
|
||||
case BURST_DELAY:
|
||||
// Free movement and rotation during burst delay
|
||||
if (rotationLocked) releaseRotationControl();
|
||||
if (positionLocked) releaseLockedPosition();
|
||||
break;
|
||||
|
||||
case DAZED:
|
||||
@@ -199,6 +301,15 @@ public class DataAbilities {
|
||||
break;
|
||||
}
|
||||
|
||||
// Update hit scan state - actual facing is deferred to applyRotationControl()
|
||||
// which runs AFTER super.onLivingUpdate() to override AI look helper
|
||||
if (currentAbility != null && currentAbility.isExecuting()
|
||||
&& currentAbility.isHitScanForCurrentPhase() && target != null) {
|
||||
enableHitScan(target);
|
||||
} else if (hitScanActive) {
|
||||
releaseRotationControl();
|
||||
}
|
||||
|
||||
// Apply movement control if ability is still executing
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
applyMovementControl();
|
||||
@@ -235,6 +346,12 @@ public class DataAbilities {
|
||||
private void handleAbilityCompletion(EntityLivingBase target) {
|
||||
if (currentAbility == null) return;
|
||||
|
||||
// Remove any remaining telegraphs (for abilities that keep telegraph during active)
|
||||
removeTelegraph(currentAbility);
|
||||
|
||||
// Fire extender complete hook
|
||||
AbilityController.Instance.fireOnAbilityComplete(currentAbility, npc, target, false);
|
||||
|
||||
// Call onComplete callback
|
||||
currentAbility.onComplete(npc, target);
|
||||
|
||||
@@ -243,8 +360,9 @@ public class DataAbilities {
|
||||
npc.wrappedNPC, currentAbility, target);
|
||||
NpcAPI.EVENT_BUS.post(completeEvent);
|
||||
|
||||
// Release rotation lock before cleanup
|
||||
releaseLockedRotation();
|
||||
// Release locks before cleanup
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
|
||||
// Clean up and roll cooldown (this sets currentAbility to null)
|
||||
onAbilityComplete();
|
||||
@@ -259,8 +377,9 @@ public class DataAbilities {
|
||||
// Stop any ability animation
|
||||
stopAbilityAnimation();
|
||||
|
||||
// Release rotation lock
|
||||
releaseLockedRotation();
|
||||
// Release locks
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
|
||||
// Calculate cooldown: random(min, max) + ability offset
|
||||
int abilityCooldownOffset = currentAbility.getCooldownTicks();
|
||||
@@ -349,6 +468,11 @@ public class DataAbilities {
|
||||
* Check if a specific ability is eligible for use.
|
||||
*/
|
||||
private boolean isAbilityEligible(Ability ability, EntityLivingBase target) {
|
||||
// Check UserType allows NPCs
|
||||
if (!ability.getAllowedBy().allowsNpc()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check enabled
|
||||
if (!ability.isEnabled()) {
|
||||
return false;
|
||||
@@ -387,6 +511,11 @@ public class DataAbilities {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fire extender start hook (e.g., resource cost checks)
|
||||
if (!AbilityController.Instance.fireOnAbilityStart(ability, npc, target)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
currentAbility = ability;
|
||||
lastTarget = target;
|
||||
ability.start(target);
|
||||
@@ -399,6 +528,9 @@ public class DataAbilities {
|
||||
if (ability.isRotationLockedDuringWindup()) {
|
||||
captureLockedRotation();
|
||||
}
|
||||
if (ability.isMovementLockedDuringWindup() && !ability.hasAbilityMovement()) {
|
||||
captureLockedPosition();
|
||||
}
|
||||
spawnTelegraph(ability, target);
|
||||
playAbilitySound(ability.getWindUpSound());
|
||||
playAbilityAnimation(ability.getWindUpAnimation());
|
||||
@@ -416,6 +548,9 @@ public class DataAbilities {
|
||||
if (ability.isRotationLockedDuringActive()) {
|
||||
captureLockedRotation();
|
||||
}
|
||||
if (ability.isMovementLockedDuringActive() && !ability.hasAbilityMovement()) {
|
||||
captureLockedPosition();
|
||||
}
|
||||
|
||||
// Play active sound and animation
|
||||
playAbilitySound(ability.getActiveSound());
|
||||
@@ -429,7 +564,7 @@ public class DataAbilities {
|
||||
}
|
||||
|
||||
// Call onExecute
|
||||
ability.onExecute(npc, target, npc.worldObj);
|
||||
ability.onExecute(npc, target);
|
||||
|
||||
// Check if ability completed during onExecute
|
||||
if (ability.getPhase() == AbilityPhase.IDLE) {
|
||||
@@ -486,26 +621,27 @@ public class DataAbilities {
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn and send telegraph for an ability.
|
||||
* Spawn and send telegraphs for an ability.
|
||||
*/
|
||||
private void spawnTelegraph(Ability ability, EntityLivingBase target) {
|
||||
TelegraphInstance telegraph = ability.createTelegraph(npc, target);
|
||||
if (telegraph != null) {
|
||||
ability.setTelegraphInstance(telegraph);
|
||||
// Send to all nearby players
|
||||
TelegraphSpawnPacket.sendToTracking(telegraph, npc);
|
||||
List<TelegraphInstance> telegraphs = ability.createTelegraphs(npc, target);
|
||||
if (!telegraphs.isEmpty()) {
|
||||
ability.setTelegraphInstances(telegraphs);
|
||||
for (TelegraphInstance telegraph : telegraphs) {
|
||||
TelegraphSpawnPacket.sendToTracking(telegraph, npc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove telegraph when ability ends or is interrupted.
|
||||
* Remove telegraphs when ability ends or is interrupted.
|
||||
*/
|
||||
private void removeTelegraph(Ability ability) {
|
||||
TelegraphInstance telegraph = ability.getTelegraphInstance();
|
||||
if (telegraph != null) {
|
||||
List<TelegraphInstance> telegraphs = ability.getTelegraphInstances();
|
||||
for (TelegraphInstance telegraph : telegraphs) {
|
||||
TelegraphRemovePacket.sendToTracking(telegraph.getInstanceId(), npc);
|
||||
ability.setTelegraphInstance(null);
|
||||
}
|
||||
ability.setTelegraphInstances(null);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -625,8 +761,12 @@ public class DataAbilities {
|
||||
// Stop any ability animation
|
||||
stopAbilityAnimation();
|
||||
|
||||
// Release rotation lock
|
||||
releaseLockedRotation();
|
||||
// Release locks
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
|
||||
// Fire extender complete hook (interrupted)
|
||||
AbilityController.Instance.fireOnAbilityComplete(currentAbility, npc, lastTarget, true);
|
||||
|
||||
// Fire interrupt event
|
||||
AbilityEvent.InterruptEvent interruptEvent = new AbilityEvent.InterruptEvent(
|
||||
@@ -648,7 +788,8 @@ public class DataAbilities {
|
||||
if (currentAbility != null) {
|
||||
removeTelegraph(currentAbility);
|
||||
stopAbilityAnimation();
|
||||
releaseLockedRotation();
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
currentAbility.interrupt();
|
||||
currentAbility = null;
|
||||
lastTarget = null;
|
||||
@@ -668,6 +809,11 @@ public class DataAbilities {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check UserType allows NPCs
|
||||
if (!ability.getAllowedBy().allowsNpc()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Stop any currently executing ability
|
||||
stopCurrentAbility();
|
||||
|
||||
@@ -940,15 +1086,15 @@ public class DataAbilities {
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// ROTATION LOCKING
|
||||
// ROTATION CONTROL
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/** Bit flag for rotation lock in the existing data watcher slot 15 bitfield */
|
||||
private static final int ROTATION_LOCKED_FLAG = 16;
|
||||
/** Bit flag for rotation control (LOCKED or TRACK) in data watcher slot 15 */
|
||||
private static final int ROTATION_CONTROLLED_FLAG = 16;
|
||||
|
||||
/**
|
||||
* Capture current rotation values to lock NPC's look direction.
|
||||
* Called when entering a locked phase (WINDUP or ACTIVE depending on LockMovementType).
|
||||
* Called when entering a LOCKED rotation phase.
|
||||
*/
|
||||
private void captureLockedRotation() {
|
||||
lockedYaw = npc.rotationYaw;
|
||||
@@ -956,41 +1102,79 @@ public class DataAbilities {
|
||||
lockedRenderYawOffset = npc.renderYawOffset;
|
||||
lockedPitch = npc.rotationPitch;
|
||||
rotationLocked = true;
|
||||
npc.setBoolFlag(true, ROTATION_LOCKED_FLAG);
|
||||
npc.setBoolFlag(true, ROTATION_CONTROLLED_FLAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the rotation lock.
|
||||
* Called when leaving the locked phase or ability completes.
|
||||
* Release rotation control (both locked and hit scan).
|
||||
*/
|
||||
private void releaseLockedRotation() {
|
||||
private void releaseRotationControl() {
|
||||
rotationLocked = false;
|
||||
npc.setBoolFlag(false, ROTATION_LOCKED_FLAG);
|
||||
hitScanActive = false;
|
||||
hitScanTarget = null;
|
||||
npc.setBoolFlag(false, ROTATION_CONTROLLED_FLAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply locked rotation values to the NPC.
|
||||
* Called AFTER super.onLivingUpdate() in EntityNPCInterface to override
|
||||
* any rotation changes made by the look helper, AI tasks, or body smoothing.
|
||||
* Runs on both client and server.
|
||||
* Enable hit scan tracking for the given target.
|
||||
*/
|
||||
public void applyLockedRotation() {
|
||||
private void enableHitScan(EntityLivingBase target) {
|
||||
if (!hitScanActive) {
|
||||
hitScanActive = true;
|
||||
npc.setBoolFlag(true, ROTATION_CONTROLLED_FLAG);
|
||||
}
|
||||
hitScanTarget = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Snap the NPC to face the target instantly.
|
||||
*/
|
||||
private void faceTarget(EntityLivingBase target) {
|
||||
double dx = target.posX - npc.posX;
|
||||
double dz = target.posZ - npc.posZ;
|
||||
double dy = (target.posY + target.getEyeHeight() * 0.5) - (npc.posY + npc.getEyeHeight());
|
||||
double distXZ = Math.sqrt(dx * dx + dz * dz);
|
||||
|
||||
float yaw = (float) (Math.atan2(-dx, dz) * 180.0 / Math.PI);
|
||||
float pitch = (float) (-(Math.atan2(dy, distXZ)) * 180.0 / Math.PI);
|
||||
|
||||
npc.rotationYaw = yaw;
|
||||
npc.rotationYawHead = yaw;
|
||||
npc.renderYawOffset = yaw;
|
||||
npc.rotationPitch = pitch;
|
||||
npc.prevRotationYaw = yaw;
|
||||
npc.prevRotationYawHead = yaw;
|
||||
npc.prevRenderYawOffset = yaw;
|
||||
npc.prevRotationPitch = pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply rotation control after super.onLivingUpdate() and super.onUpdate().
|
||||
* Handles both LOCKED (freeze at captured values) and TRACK (face target) modes.
|
||||
*
|
||||
* Server: computes the correct rotation (locked values or target facing).
|
||||
* Client: trusts the server-synced rotation values and prevents body smoothing override.
|
||||
*/
|
||||
public void applyRotationControl() {
|
||||
if (npc.worldObj.isRemote) {
|
||||
// Client-side: check bit 16 in the existing flags data watcher (slot 15)
|
||||
boolean flagActive = npc.getBoolFlag(ROTATION_LOCKED_FLAG);
|
||||
if (!flagActive) {
|
||||
// Client: check single flag for any rotation control
|
||||
if (!npc.getBoolFlag(ROTATION_CONTROLLED_FLAG)) {
|
||||
rotationLocked = false;
|
||||
return;
|
||||
}
|
||||
// First tick the flag is active: capture current rotation values
|
||||
if (!rotationLocked) {
|
||||
lockedYaw = npc.rotationYaw;
|
||||
lockedYawHead = npc.rotationYawHead;
|
||||
lockedRenderYawOffset = npc.renderYawOffset;
|
||||
lockedPitch = npc.rotationPitch;
|
||||
rotationLocked = true;
|
||||
}
|
||||
// Force all rotation values back to locked state
|
||||
// Trust server rotation, prevent body smoothing from overriding
|
||||
npc.prevRotationYaw = npc.rotationYaw;
|
||||
npc.prevRotationYawHead = npc.rotationYawHead;
|
||||
npc.renderYawOffset = npc.rotationYawHead;
|
||||
npc.prevRenderYawOffset = npc.rotationYawHead;
|
||||
npc.prevRotationPitch = npc.rotationPitch;
|
||||
return;
|
||||
}
|
||||
|
||||
// Server: apply the appropriate rotation
|
||||
if (hitScanActive && hitScanTarget != null && !hitScanTarget.isDead) {
|
||||
faceTarget(hitScanTarget);
|
||||
} else if (rotationLocked) {
|
||||
npc.rotationYaw = lockedYaw;
|
||||
npc.rotationYawHead = lockedYawHead;
|
||||
npc.renderYawOffset = lockedRenderYawOffset;
|
||||
@@ -999,32 +1183,89 @@ public class DataAbilities {
|
||||
npc.prevRotationYawHead = lockedYawHead;
|
||||
npc.prevRenderYawOffset = lockedRenderYawOffset;
|
||||
npc.prevRotationPitch = lockedPitch;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if rotation is currently controlled (locked or tracking target).
|
||||
* Used by AI tasks to determine if they should try to change NPC look direction.
|
||||
*/
|
||||
public boolean isRotationLocked() {
|
||||
return rotationLocked || hitScanActive;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// POSITION LOCKING
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/** Bit flag for position lock in data watcher slot 15 */
|
||||
private static final int POSITION_LOCKED_FLAG = 32;
|
||||
|
||||
/**
|
||||
* Capture current position to lock NPC in place.
|
||||
* Called when entering a phase with movement lock.
|
||||
*/
|
||||
private void captureLockedPosition() {
|
||||
lockedPosX = npc.posX;
|
||||
lockedPosY = npc.posY;
|
||||
lockedPosZ = npc.posZ;
|
||||
positionLocked = true;
|
||||
npc.setBoolFlag(true, POSITION_LOCKED_FLAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the position lock.
|
||||
* Called when leaving the locked phase or ability completes.
|
||||
*/
|
||||
private void releaseLockedPosition() {
|
||||
positionLocked = false;
|
||||
npc.setBoolFlag(false, POSITION_LOCKED_FLAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply locked position values to the NPC.
|
||||
* Called AFTER super.onLivingUpdate() in EntityNPCInterface to override
|
||||
* any position changes from AI pathfinding, physics, or entity collisions.
|
||||
* Runs on both client and server.
|
||||
*/
|
||||
public void applyLockedPosition() {
|
||||
if (npc.worldObj.isRemote) {
|
||||
// Client-side: check flag via data watcher
|
||||
boolean flagActive = npc.getBoolFlag(POSITION_LOCKED_FLAG);
|
||||
if (!flagActive) {
|
||||
positionLocked = false;
|
||||
return;
|
||||
}
|
||||
// First tick the flag is active: capture current position
|
||||
if (!positionLocked) {
|
||||
lockedPosX = npc.posX;
|
||||
lockedPosY = npc.posY;
|
||||
lockedPosZ = npc.posZ;
|
||||
positionLocked = true;
|
||||
}
|
||||
// Snap position back and set prev to prevent interpolation jitter
|
||||
npc.setPosition(lockedPosX, lockedPosY, lockedPosZ);
|
||||
npc.prevPosX = lockedPosX;
|
||||
npc.prevPosY = lockedPosY;
|
||||
npc.prevPosZ = lockedPosZ;
|
||||
npc.motionX = 0;
|
||||
npc.motionY = 0;
|
||||
npc.motionZ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Server-side: use stored locked values
|
||||
if (!rotationLocked) {
|
||||
if (!positionLocked) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Force rotation back to locked values
|
||||
npc.rotationYaw = lockedYaw;
|
||||
npc.rotationYawHead = lockedYawHead;
|
||||
npc.renderYawOffset = lockedRenderYawOffset;
|
||||
npc.rotationPitch = lockedPitch;
|
||||
|
||||
// Also set prev values to prevent interpolation jitter
|
||||
npc.prevRotationYaw = lockedYaw;
|
||||
npc.prevRotationYawHead = lockedYawHead;
|
||||
npc.prevRenderYawOffset = lockedRenderYawOffset;
|
||||
npc.prevRotationPitch = lockedPitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if rotation is currently locked.
|
||||
*/
|
||||
public boolean isRotationLocked() {
|
||||
return rotationLocked;
|
||||
npc.setPosition(lockedPosX, lockedPosY, lockedPosZ);
|
||||
npc.prevPosX = lockedPosX;
|
||||
npc.prevPosY = lockedPosY;
|
||||
npc.prevPosZ = lockedPosZ;
|
||||
npc.motionX = 0;
|
||||
npc.motionY = 0;
|
||||
npc.motionZ = 0;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -20,6 +20,7 @@ public class DataStats {
|
||||
public EnumPotionType potionType = EnumPotionType.None;
|
||||
public int potionDuration = 5; //20 = 1 second
|
||||
public int potionAmp = 0;
|
||||
public int potionManualId = 0;
|
||||
|
||||
public double maxHealth = 20;
|
||||
public int respawnTime = 20;
|
||||
@@ -45,6 +46,7 @@ public class DataStats {
|
||||
public boolean pPhysics = true, pXlr8 = false, pGlows = false, pExplode = false;
|
||||
public boolean pRender3D = false, pSpin = false, pStick = false, pBurnItem = false;
|
||||
public EnumPotionType pEffect = EnumPotionType.None;
|
||||
public int pManualId = 0;
|
||||
public EnumParticleType pTrail = EnumParticleType.None;
|
||||
public ScriptParticle pCustom = new ScriptParticle("");
|
||||
public int pEffAmp = 0;
|
||||
@@ -88,6 +90,8 @@ public class DataStats {
|
||||
compound.setInteger("PotionEffect", potionType.ordinal());
|
||||
compound.setInteger("PotionDuration", potionDuration);
|
||||
compound.setInteger("PotionAmp", potionAmp);
|
||||
if (potionType == EnumPotionType.Manual)
|
||||
compound.setInteger("PotionManualId", potionManualId);
|
||||
|
||||
compound.setInteger("MaxFiringRange", rangedRange);
|
||||
compound.setInteger("FireRate", fireRate);
|
||||
@@ -122,6 +126,8 @@ public class DataStats {
|
||||
compound.setTag("pCustom", pCustom.writeToNBT());
|
||||
if (pEffect == EnumPotionType.Fire)
|
||||
compound.setBoolean("pBurnItem", pBurnItem);
|
||||
if (pEffect == EnumPotionType.Manual)
|
||||
compound.setInteger("pManualId", pManualId);
|
||||
|
||||
compound.setBoolean("ImmuneToFire", immuneToFire);
|
||||
compound.setBoolean("PotionImmune", potionImmune);
|
||||
@@ -145,7 +151,7 @@ public class DataStats {
|
||||
aggroRange = compound.getInteger("AggroRange");
|
||||
respawnTime = compound.getInteger("RespawnTime");
|
||||
spawnCycle = compound.getInteger("SpawnCycle");
|
||||
creatureType = EnumCreatureAttribute.values()[compound.getInteger("CreatureType") % EnumPotionType.values().length];
|
||||
creatureType = EnumCreatureAttribute.values()[compound.getInteger("CreatureType") % EnumCreatureAttribute.values().length];
|
||||
ignoreCobweb = compound.getBoolean("IgnoreCobweb");
|
||||
healthRegen = compound.getFloat("HealthRegen");
|
||||
combatRegen = compound.getFloat("CombatRegen");
|
||||
@@ -155,9 +161,11 @@ public class DataStats {
|
||||
swingWarmUp = ValueUtil.clamp(compound.getInteger("SwingWarmup"), 0, 1000);
|
||||
attackRange = compound.getInteger("AttackRange");
|
||||
knockback = compound.getInteger("KnockBack");
|
||||
potionType = EnumPotionType.values()[compound.getInteger("PotionEffect") % EnumPotionType.values().length];
|
||||
potionType = EnumPotionType.fromOrdinal(compound.getInteger("PotionEffect"));
|
||||
potionDuration = compound.getInteger("PotionDuration");
|
||||
potionAmp = compound.getInteger("PotionAmp");
|
||||
if (potionType == EnumPotionType.Manual)
|
||||
potionManualId = compound.getInteger("PotionManualId");
|
||||
|
||||
rangedRange = compound.getInteger("MaxFiringRange");
|
||||
fireRate = compound.getInteger("FireRate");
|
||||
@@ -180,7 +188,7 @@ public class DataStats {
|
||||
pRender3D = compound.getBoolean("pRender3D");
|
||||
pSpin = compound.getBoolean("pSpin");
|
||||
pStick = compound.getBoolean("pStick");
|
||||
pEffect = EnumPotionType.values()[compound.getInteger("pEffect") % EnumPotionType.values().length];
|
||||
pEffect = EnumPotionType.fromOrdinal(compound.getInteger("pEffect"));
|
||||
pTrail = EnumParticleType.values()[compound.getInteger("pTrail") % EnumParticleType.values().length];
|
||||
pEffAmp = compound.getInteger("pEffAmp");
|
||||
fireSound = compound.getString("FiringSound");
|
||||
@@ -195,6 +203,8 @@ public class DataStats {
|
||||
pCustom = ScriptParticle.fromNBT(compound.getCompoundTag("pCustom"));
|
||||
if (pEffect == EnumPotionType.Fire)
|
||||
pBurnItem = compound.getBoolean("pBurnItem");
|
||||
if (pEffect == EnumPotionType.Manual)
|
||||
pManualId = compound.getInteger("pManualId");
|
||||
|
||||
immuneToFire = compound.getBoolean("ImmuneToFire");
|
||||
potionImmune = compound.getBoolean("PotionImmune");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import kamkeel.npcs.entity.EntityAbilityProjectile;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -16,7 +17,10 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import noppes.npcs.api.IBlock;
|
||||
import noppes.npcs.api.IPos;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.entity.IEnergyProjectile;
|
||||
import noppes.npcs.api.entity.IAnimatable;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
@@ -52,6 +56,7 @@ import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.AnimationEvent;
|
||||
import noppes.npcs.scripted.event.BlockEvent;
|
||||
import noppes.npcs.scripted.event.CustomNPCsEvent;
|
||||
import noppes.npcs.scripted.event.EnergyProjectileEvent;
|
||||
import noppes.npcs.scripted.event.ForgeEvent;
|
||||
import noppes.npcs.scripted.event.ItemEvent;
|
||||
import noppes.npcs.scripted.event.LinkedItemEvent;
|
||||
@@ -448,6 +453,110 @@ public class EventHooks {
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
// ==================== ENERGY PROJECTILE EVENTS ====================
|
||||
|
||||
public static void onEnergyProjectileFired(EntityAbilityProjectile projectile) {
|
||||
IEnergyProjectile wrapped = (IEnergyProjectile) NpcAPI.Instance().getIEntity(projectile);
|
||||
EnergyProjectileEvent.FiredEvent event = new EnergyProjectileEvent.FiredEvent(wrapped);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.ENERGY_PROJECTILE_FIRED, event);
|
||||
|
||||
Entity owner = projectile.worldObj.getEntityByID(projectile.getOwnerEntityId());
|
||||
if (owner instanceof EntityNPCInterface) {
|
||||
((EntityNPCInterface) owner).script.callScript(EnumScriptType.ENERGY_PROJECTILE_FIRED, event);
|
||||
} else if (owner instanceof EntityPlayer) {
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts((EntityPlayer) owner);
|
||||
if (handler != null) {
|
||||
handler.callScript(EnumScriptType.ENERGY_PROJECTILE_FIRED, event);
|
||||
}
|
||||
}
|
||||
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onEnergyProjectileTick(EntityAbilityProjectile projectile) {
|
||||
IEnergyProjectile wrapped = (IEnergyProjectile) NpcAPI.Instance().getIEntity(projectile);
|
||||
EnergyProjectileEvent.UpdateEvent event = new EnergyProjectileEvent.UpdateEvent(wrapped);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.ENERGY_PROJECTILE_TICK, event);
|
||||
|
||||
Entity owner = projectile.worldObj.getEntityByID(projectile.getOwnerEntityId());
|
||||
if (owner instanceof EntityNPCInterface) {
|
||||
((EntityNPCInterface) owner).script.callScript(EnumScriptType.ENERGY_PROJECTILE_TICK, event);
|
||||
} else if (owner instanceof EntityPlayer) {
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts((EntityPlayer) owner);
|
||||
if (handler != null) {
|
||||
handler.callScript(EnumScriptType.ENERGY_PROJECTILE_TICK, event);
|
||||
}
|
||||
}
|
||||
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires the entity impact event. Returns the (possibly modified) damage, or -1 if cancelled.
|
||||
*/
|
||||
public static float onEnergyProjectileEntityImpact(EntityAbilityProjectile projectile, EntityLivingBase target, float damage) {
|
||||
IEnergyProjectile wrapped = (IEnergyProjectile) NpcAPI.Instance().getIEntity(projectile);
|
||||
IEntity wrappedTarget = NpcAPI.Instance().getIEntity(target);
|
||||
EnergyProjectileEvent.EntityImpactEvent event = new EnergyProjectileEvent.EntityImpactEvent(wrapped, wrappedTarget, damage);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.ENERGY_PROJECTILE_ENTITY_IMPACT, event);
|
||||
|
||||
Entity owner = projectile.worldObj.getEntityByID(projectile.getOwnerEntityId());
|
||||
if (owner instanceof EntityNPCInterface) {
|
||||
((EntityNPCInterface) owner).script.callScript(EnumScriptType.ENERGY_PROJECTILE_ENTITY_IMPACT, event);
|
||||
} else if (owner instanceof EntityPlayer) {
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts((EntityPlayer) owner);
|
||||
if (handler != null) {
|
||||
handler.callScript(EnumScriptType.ENERGY_PROJECTILE_ENTITY_IMPACT, event);
|
||||
}
|
||||
}
|
||||
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
|
||||
if (event.isCanceled()) {
|
||||
return -1;
|
||||
}
|
||||
return event.getDamage();
|
||||
}
|
||||
|
||||
public static void onEnergyProjectileBlockImpact(EntityAbilityProjectile projectile, int blockX, int blockY, int blockZ) {
|
||||
IEnergyProjectile wrapped = (IEnergyProjectile) NpcAPI.Instance().getIEntity(projectile);
|
||||
IPos pos = NpcAPI.Instance().getIPos(blockX, blockY, blockZ);
|
||||
IWorld world = NpcAPI.Instance().getIWorld(projectile.worldObj);
|
||||
IBlock block = NpcAPI.Instance().getIBlock(world, pos);
|
||||
EnergyProjectileEvent.BlockImpactEvent event = new EnergyProjectileEvent.BlockImpactEvent(wrapped, block);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.ENERGY_PROJECTILE_BLOCK_IMPACT, event);
|
||||
|
||||
Entity owner = projectile.worldObj.getEntityByID(projectile.getOwnerEntityId());
|
||||
if (owner instanceof EntityNPCInterface) {
|
||||
((EntityNPCInterface) owner).script.callScript(EnumScriptType.ENERGY_PROJECTILE_BLOCK_IMPACT, event);
|
||||
} else if (owner instanceof EntityPlayer) {
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts((EntityPlayer) owner);
|
||||
if (handler != null) {
|
||||
handler.callScript(EnumScriptType.ENERGY_PROJECTILE_BLOCK_IMPACT, event);
|
||||
}
|
||||
}
|
||||
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onEnergyProjectileExpired(EntityAbilityProjectile projectile) {
|
||||
IEnergyProjectile wrapped = (IEnergyProjectile) NpcAPI.Instance().getIEntity(projectile);
|
||||
EnergyProjectileEvent.ExpiredEvent event = new EnergyProjectileEvent.ExpiredEvent(wrapped);
|
||||
ScriptController.Instance.globalNpcScripts.callScript(EnumScriptType.ENERGY_PROJECTILE_EXPIRED, event);
|
||||
|
||||
Entity owner = projectile.worldObj.getEntityByID(projectile.getOwnerEntityId());
|
||||
if (owner instanceof EntityNPCInterface) {
|
||||
((EntityNPCInterface) owner).script.callScript(EnumScriptType.ENERGY_PROJECTILE_EXPIRED, event);
|
||||
} else if (owner instanceof EntityPlayer) {
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts((EntityPlayer) owner);
|
||||
if (handler != null) {
|
||||
handler.callScript(EnumScriptType.ENERGY_PROJECTILE_EXPIRED, event);
|
||||
}
|
||||
}
|
||||
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerInit(PlayerDataScript handler, IPlayer player) {
|
||||
PlayerEvent.InitEvent event = new PlayerEvent.InitEvent(player);
|
||||
handler.callScript(EnumScriptType.INIT, event);
|
||||
@@ -693,6 +802,31 @@ public class EventHooks {
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerAbilityStart(PlayerDataScript handler, PlayerAbilityEvent.StartEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_START, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerAbilityExecute(PlayerDataScript handler, PlayerAbilityEvent.ExecuteEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_EXECUTE, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerAbilityTick(PlayerDataScript handler, PlayerAbilityEvent.TickEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_TICK, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerAbilityInterrupt(PlayerDataScript handler, PlayerAbilityEvent.InterruptEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_INTERRUPT, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onPlayerAbilityComplete(PlayerDataScript handler, PlayerAbilityEvent.CompleteEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_COMPLETE, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerAbilityHit(PlayerDataScript handler, PlayerAbilityEvent.HitEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_HIT, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
|
||||
@@ -2,6 +2,7 @@ package noppes.npcs;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.ParticlePacket;
|
||||
@@ -780,18 +781,38 @@ public class NoppesUtilServer {
|
||||
if (controller != null) {
|
||||
int index = 0;
|
||||
for (String typeId : controller.getTypes()) {
|
||||
// Exclude built-in types from the NPC type list
|
||||
if (controller.isBuiltInType(typeId)) continue;
|
||||
map.put(typeId, index++);
|
||||
}
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.ABILITY_TYPES);
|
||||
}
|
||||
|
||||
public static void sendBuiltInAbilitiesData(EntityPlayerMP player) {
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
AbilityController controller = AbilityController.Instance;
|
||||
if (controller != null) {
|
||||
int index = 0;
|
||||
for (String name : controller.getAbilityNames()) {
|
||||
Ability ability = controller.getAbility(name);
|
||||
if (ability != null) {
|
||||
map.put(ability.getName(), index++);
|
||||
}
|
||||
}
|
||||
}
|
||||
sendScrollData(player, map, EnumScrollData.BUILTIN_ABILITIES);
|
||||
}
|
||||
|
||||
public static void sendCustomAbilitiesData(EntityPlayerMP player) {
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>();
|
||||
kamkeel.npcs.controllers.data.ability.AbilityController controller = kamkeel.npcs.controllers.data.ability.AbilityController.Instance;
|
||||
if (controller != null) {
|
||||
int index = 0;
|
||||
for (String uuid : controller.getCustomAbilityIds()) {
|
||||
Ability ability = controller.getCustomAbility(uuid);
|
||||
if (ability == null || !ability.getAllowedBy().allowsNpc()) continue;
|
||||
|
||||
String name = controller.getCustomAbilityName(uuid);
|
||||
if (name == null || name.isEmpty()) name = uuid;
|
||||
map.put(name + "\t" + uuid, index++);
|
||||
|
||||
@@ -8,6 +8,8 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -100,9 +102,17 @@ public class ScriptPlayerEventHandler {
|
||||
playerData.abilityData.tick(player);
|
||||
|
||||
// Lock player movement during ability phases that require it
|
||||
// Skip zeroing if the ability has its own movement (Charge/Dash/Slam)
|
||||
if (playerData.abilityData.isMovementLocked()) {
|
||||
player.motionX = 0;
|
||||
player.motionZ = 0;
|
||||
Ability current = playerData.abilityData.getCurrentAbility();
|
||||
if (current == null || !current.hasAbilityMovement()) {
|
||||
player.motionX = 0;
|
||||
if (!AbilityController.Instance.isPlayerFlying(player)) {
|
||||
player.motionY = Math.min(player.motionY, 0);
|
||||
}
|
||||
player.motionZ = 0;
|
||||
player.velocityChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (playerData.updateClient) {
|
||||
@@ -322,6 +332,12 @@ public class ScriptPlayerEventHandler {
|
||||
return;
|
||||
|
||||
if (event.player.worldObj instanceof WorldServer && event.player instanceof EntityPlayerMP) {
|
||||
// Cancel any executing ability on dimension change
|
||||
PlayerData playerData = PlayerData.get(event.player);
|
||||
if (playerData != null) {
|
||||
playerData.abilityData.interruptCurrentAbility();
|
||||
}
|
||||
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(event.player);
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.player);
|
||||
EventHooks.onPlayerChangeDim(handler, scriptPlayer, event.fromDim, event.toDim);
|
||||
@@ -472,6 +488,13 @@ public class ScriptPlayerEventHandler {
|
||||
|
||||
if (event.entityLiving.worldObj instanceof WorldServer) {
|
||||
if (event.entityLiving instanceof EntityPlayerMP) {
|
||||
// Cancel jump if movement is locked by an ability
|
||||
PlayerData playerData = PlayerData.get((EntityPlayer) event.entityLiving);
|
||||
if (playerData != null && playerData.abilityData.isMovementLocked()) {
|
||||
event.entityLiving.motionY = 0;
|
||||
event.entityLiving.velocityChanged = true;
|
||||
}
|
||||
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts((EntityPlayer) event.entityLiving);
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.entityLiving);
|
||||
EventHooks.onPlayerJump(handler, scriptPlayer);
|
||||
@@ -526,6 +549,8 @@ public class ScriptPlayerEventHandler {
|
||||
|
||||
EntityPlayer player = (EntityPlayer) event.entityLiving;
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
// Cancel any executing ability on death
|
||||
playerData.abilityData.interruptCurrentAbility();
|
||||
if (ConfigScript.ClearActionsOnDeath)
|
||||
playerData.actionManager.clear();
|
||||
}
|
||||
@@ -596,6 +621,12 @@ public class ScriptPlayerEventHandler {
|
||||
}
|
||||
|
||||
if (event.entityLiving instanceof EntityPlayerMP) {
|
||||
// Handle ability damage interactions (Guard counter, damage reduction)
|
||||
PlayerData pData = PlayerData.get((EntityPlayer) event.entityLiving);
|
||||
if (pData != null && pData.abilityData != null && pData.abilityData.isExecutingAbility()) {
|
||||
event.ammount = pData.abilityData.onDamage(event.source, event.ammount);
|
||||
}
|
||||
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts((EntityPlayer) event.entityLiving);
|
||||
noppes.npcs.scripted.event.player.PlayerEvent.DamagedEvent pevent = new noppes.npcs.scripted.event.player.PlayerEvent.DamagedEvent((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayer) event.entityLiving), source, event.ammount, event.source);
|
||||
cancel = EventHooks.onPlayerDamaged(handler, pevent);
|
||||
@@ -619,6 +650,12 @@ public class ScriptPlayerEventHandler {
|
||||
return;
|
||||
|
||||
if (event.player.worldObj instanceof WorldServer && event.player instanceof EntityPlayerMP) {
|
||||
// Cancel any executing ability on respawn
|
||||
PlayerData playerData = PlayerData.get(event.player);
|
||||
if (playerData != null) {
|
||||
playerData.abilityData.interruptCurrentAbility();
|
||||
}
|
||||
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(event.player);
|
||||
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.player);
|
||||
EventHooks.onPlayerRespawn(handler, scriptPlayer);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package noppes.npcs.client;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilityStatePacket;
|
||||
|
||||
/**
|
||||
* Client-side state holder for player ability lock flags.
|
||||
* Updated by {@link PlayerAbilityStatePacket} from the server.
|
||||
* Read by {@link ClientTickHandler} to suppress WASD input and enforce rotation.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ClientAbilityState {
|
||||
public static boolean movementLocked = false;
|
||||
public static boolean rotationLocked = false;
|
||||
public static boolean hasAbilityMovement = false;
|
||||
public static boolean positionLocked = false;
|
||||
public static float lockedYaw = 0;
|
||||
public static float lockedPitch = 0;
|
||||
|
||||
/**
|
||||
* Update state from a received packet.
|
||||
*/
|
||||
public static void update(byte flags, float yaw, float pitch) {
|
||||
movementLocked = (flags & PlayerAbilityStatePacket.FLAG_MOVEMENT_LOCKED) != 0;
|
||||
rotationLocked = (flags & PlayerAbilityStatePacket.FLAG_ROTATION_LOCKED) != 0;
|
||||
hasAbilityMovement = (flags & PlayerAbilityStatePacket.FLAG_HAS_ABILITY_MOVEMENT) != 0;
|
||||
positionLocked = (flags & PlayerAbilityStatePacket.FLAG_POSITION_LOCKED) != 0;
|
||||
lockedYaw = yaw;
|
||||
lockedPitch = pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether player WASD movement input should be suppressed.
|
||||
* True when movement/position is locked or ability has its own movement.
|
||||
*/
|
||||
public static boolean shouldSuppressMovementInput() {
|
||||
return movementLocked || hasAbilityMovement || positionLocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether player camera rotation should be locked.
|
||||
*/
|
||||
public static boolean shouldLockRotation() {
|
||||
return rotationLocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset all state. Called on world change / disconnect.
|
||||
*/
|
||||
public static void reset() {
|
||||
movementLocked = false;
|
||||
rotationLocked = false;
|
||||
hasAbilityMovement = false;
|
||||
positionLocked = false;
|
||||
lockedYaw = 0;
|
||||
lockedPitch = 0;
|
||||
}
|
||||
}
|
||||
@@ -84,9 +84,20 @@ public class ClientEventHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onMouse(MouseEvent event) {
|
||||
if (Minecraft.getMinecraft().currentScreen != null)
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc.currentScreen != null)
|
||||
return;
|
||||
|
||||
// Block mouse movement during ability rotation lock.
|
||||
// Allow clicks (button >= 0) and scroll (dwheel != 0) to pass through.
|
||||
if (mc.theWorld != null && mc.thePlayer != null
|
||||
&& ClientAbilityState.shouldLockRotation()
|
||||
&& (event.dx != 0 || event.dy != 0)
|
||||
&& event.button == -1 && event.dwheel == 0) {
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<Integer> removeList = new ArrayList<>();
|
||||
for (Map.Entry<Integer, Long> entry : disabledButtonTimes.entrySet()) {
|
||||
if (entry.getValue() > 0) {
|
||||
|
||||
@@ -153,12 +153,14 @@ import kamkeel.npcs.client.renderer.RenderAbilityDisc;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityLaser;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityBeam;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilitySweeper;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityZone;
|
||||
import kamkeel.npcs.client.renderer.lightning.LightningHandler;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
||||
import noppes.npcs.client.renderer.blocks.BlockBannerRenderer;
|
||||
import noppes.npcs.client.renderer.blocks.BlockBarrelRenderer;
|
||||
import noppes.npcs.client.renderer.blocks.BlockBeamRenderer;
|
||||
@@ -272,6 +274,7 @@ public class ClientProxy extends CommonProxy {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityLaser.class, new RenderAbilityLaser());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityBeam.class, new RenderAbilityBeam());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilitySweeper.class, new RenderAbilitySweeper());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityZone.class, new RenderAbilityZone());
|
||||
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityCustomNpc.class, new RenderCustomNpc());
|
||||
|
||||
@@ -511,6 +514,8 @@ public class ClientProxy extends CommonProxy {
|
||||
} else {
|
||||
abilityNpc = new EntityCustomNpc(Minecraft.getMinecraft().theWorld);
|
||||
abilityNpc.display.texture = "customnpcs:textures/entity/humanmale/AnimationBody.png";
|
||||
abilityNpc.height = 1.8f;
|
||||
abilityNpc.width = 0.6f;
|
||||
}
|
||||
return new GuiNpcManageAbilities(abilityNpc, npc != null);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import kamkeel.npcs.client.renderer.lightning.LightningBolt;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.CheckPlayerValue;
|
||||
@@ -13,6 +14,7 @@ import kamkeel.npcs.network.packets.player.InputDevicePacket;
|
||||
import kamkeel.npcs.network.packets.player.ScreenSizePacket;
|
||||
import kamkeel.npcs.network.packets.player.SpecialKeyStatePacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ContainerPlayer;
|
||||
@@ -56,13 +58,16 @@ public class ClientTickHandler {
|
||||
if ((this.prevWorld == null || mc.theWorld == null) && this.prevWorld != mc.theWorld) {
|
||||
if (mc.theWorld == null) {
|
||||
ClientCacheHandler.clearCache();
|
||||
ClientAbilityState.reset();
|
||||
}
|
||||
this.prevWorld = mc.theWorld;
|
||||
}
|
||||
if (event.phase == Phase.START) {
|
||||
EntityPlayer player = mc.thePlayer;
|
||||
if (player != null) {
|
||||
boolean specialKeyDown = ClientProxy.SpecialKey != null && Keyboard.isKeyDown(ClientProxy.SpecialKey.getKeyCode());
|
||||
// Only process special key when no GUI screen is open
|
||||
boolean specialKeyDown = mc.currentScreen == null
|
||||
&& ClientProxy.SpecialKey != null && Keyboard.isKeyDown(ClientProxy.SpecialKey.getKeyCode());
|
||||
if (specialKeyDown != lastSpecialKeyDown) {
|
||||
PlayerData data = CustomNpcs.proxy.getPlayerData(player);
|
||||
if (data != null) {
|
||||
@@ -72,6 +77,33 @@ public class ClientTickHandler {
|
||||
lastSpecialKeyDown = specialKeyDown;
|
||||
}
|
||||
|
||||
// Suppress player input during ability-controlled phases.
|
||||
// Only suppress when no GUI screen is open (screens already capture input).
|
||||
if (mc.currentScreen == null && ClientAbilityState.shouldSuppressMovementInput()) {
|
||||
// Unpress movement keybinds at the source BEFORE updatePlayerMoveState() reads them.
|
||||
// This is more robust than just zeroing movementInput fields, because
|
||||
// updatePlayerMoveState() reads directly from keybind pressed state.
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindForward.getKeyCode(), false);
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindBack.getKeyCode(), false);
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindLeft.getKeyCode(), false);
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindRight.getKeyCode(), false);
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindJump.getKeyCode(), false);
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindSneak.getKeyCode(), false);
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindSprint.getKeyCode(), false);
|
||||
|
||||
// Also zero the movementInput values directly as a safety net
|
||||
mc.thePlayer.movementInput.moveForward = 0;
|
||||
mc.thePlayer.movementInput.moveStrafe = 0;
|
||||
mc.thePlayer.movementInput.jump = false;
|
||||
mc.thePlayer.movementInput.sneak = false;
|
||||
}
|
||||
if (mc.currentScreen == null && ClientAbilityState.shouldLockRotation()) {
|
||||
mc.thePlayer.rotationYaw = ClientAbilityState.lockedYaw;
|
||||
mc.thePlayer.rotationPitch = ClientAbilityState.lockedPitch;
|
||||
mc.thePlayer.prevRotationYaw = ClientAbilityState.lockedYaw;
|
||||
mc.thePlayer.prevRotationPitch = ClientAbilityState.lockedPitch;
|
||||
}
|
||||
|
||||
if (player.ridingEntity instanceof EntityNPCInterface) {
|
||||
EntityNPCInterface mount = (EntityNPCInterface) player.ridingEntity;
|
||||
if (mount.advanced.role == EnumRoleType.Mount && mount.roleInterface instanceof RoleMount) {
|
||||
@@ -84,8 +116,43 @@ public class ClientTickHandler {
|
||||
}
|
||||
}
|
||||
if (event.phase == Phase.END) {
|
||||
if (mc.thePlayer != null && mc.theWorld != null && !mc.isGamePaused() && ClientEventHandler.hasOverlays(mc.thePlayer)) {
|
||||
renderCNPCPlayer.itemRenderer.updateEquippedItem();
|
||||
if (mc.thePlayer != null) {
|
||||
// Re-enforce ability locks AFTER entity update.
|
||||
// EntityPlayerSP.onLivingUpdate() calls updatePlayerMoveState() which
|
||||
// overwrites Phase.START suppression with actual keyboard state, causing
|
||||
// client-predicted movement that fights the server lock. Undo it here.
|
||||
// Skip when a GUI screen is open (screens already capture all input).
|
||||
if (mc.currentScreen == null && ClientAbilityState.shouldSuppressMovementInput()) {
|
||||
mc.thePlayer.movementInput.moveForward = 0;
|
||||
mc.thePlayer.movementInput.moveStrafe = 0;
|
||||
mc.thePlayer.movementInput.jump = false;
|
||||
mc.thePlayer.movementInput.sneak = false;
|
||||
|
||||
// Zero horizontal motion (unless ability provides its own movement)
|
||||
if (!ClientAbilityState.hasAbilityMovement) {
|
||||
mc.thePlayer.motionX = 0;
|
||||
mc.thePlayer.motionZ = 0;
|
||||
}
|
||||
|
||||
// Prevent jumping when locked (allow gravity only if not flying)
|
||||
if ((ClientAbilityState.movementLocked || ClientAbilityState.positionLocked)
|
||||
&& !ClientAbilityState.hasAbilityMovement
|
||||
&& !AbilityController.Instance.isPlayerFlying(mc.thePlayer)) {
|
||||
mc.thePlayer.motionY = Math.min(mc.thePlayer.motionY, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (mc.currentScreen == null && ClientAbilityState.shouldLockRotation()) {
|
||||
mc.thePlayer.rotationYaw = ClientAbilityState.lockedYaw;
|
||||
mc.thePlayer.rotationPitch = ClientAbilityState.lockedPitch;
|
||||
mc.thePlayer.prevRotationYaw = ClientAbilityState.lockedYaw;
|
||||
mc.thePlayer.prevRotationPitch = ClientAbilityState.lockedPitch;
|
||||
mc.thePlayer.rotationYawHead = ClientAbilityState.lockedYaw;
|
||||
}
|
||||
|
||||
if (mc.theWorld != null && !mc.isGamePaused() && ClientEventHandler.hasOverlays(mc.thePlayer)) {
|
||||
renderCNPCPlayer.itemRenderer.updateEquippedItem();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -143,8 +210,9 @@ public class ClientTickHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onKey(InputEvent.KeyInputEvent event) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
if (ClientProxy.NPCButton.isPressed()) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
if (mc.currentScreen == null) {
|
||||
InventoryTabCustomNpc.tabHelper();
|
||||
} else if (mc.currentScreen instanceof GuiCNPCInventory)
|
||||
@@ -155,10 +223,33 @@ public class ClientTickHandler {
|
||||
int key = Keyboard.getEventKey();
|
||||
boolean keyDown = Keyboard.isKeyDown(key);
|
||||
|
||||
// Block movement keys during ability lock (only when no GUI is open and world exists).
|
||||
// Non-movement keys (ESC, chat, inventory, etc.) always pass through.
|
||||
if (mc.theWorld != null && mc.currentScreen == null && keyDown
|
||||
&& ClientAbilityState.shouldSuppressMovementInput() && isMovementKey(key)) {
|
||||
// Unpress the keybind so vanilla doesn't process it
|
||||
KeyBinding.setKeyBindState(key, false);
|
||||
return;
|
||||
}
|
||||
|
||||
InputDevicePacket.sendKeyboard(key, keyDown);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a key code corresponds to a movement keybind (WASD, jump, sneak, sprint).
|
||||
*/
|
||||
private boolean isMovementKey(int keyCode) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
return keyCode == mc.gameSettings.keyBindForward.getKeyCode()
|
||||
|| keyCode == mc.gameSettings.keyBindBack.getKeyCode()
|
||||
|| keyCode == mc.gameSettings.keyBindLeft.getKeyCode()
|
||||
|| keyCode == mc.gameSettings.keyBindRight.getKeyCode()
|
||||
|| keyCode == mc.gameSettings.keyBindJump.getKeyCode()
|
||||
|| keyCode == mc.gameSettings.keyBindSneak.getKeyCode()
|
||||
|| keyCode == mc.gameSettings.keyBindSprint.getKeyCode();
|
||||
}
|
||||
|
||||
private boolean isIgnoredKey(int key) {
|
||||
int[] var2 = this.ignoreKeys;
|
||||
int var3 = var2.length;
|
||||
|
||||
@@ -84,6 +84,10 @@ public class CustomFX extends EntityFX {
|
||||
this.imageData = ClientCacheHandler.getImageData(this.directory);
|
||||
}
|
||||
|
||||
public void setMaxAge(int age) {
|
||||
this.particleMaxAge = age;
|
||||
}
|
||||
|
||||
public static CustomFX fromScriptedParticle(ScriptParticle particle, World worldObj, Entity entity) {
|
||||
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
|
||||
if (entity == player) {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package noppes.npcs.client.fx;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.particle.EntityFX;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Simple particle for zone visual effects (Trap/Hazard styles).
|
||||
* Uses vanilla particle atlas with color tinting. Fades out over lifetime.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class ZoneParticleFX extends EntityFX {
|
||||
|
||||
private final float startAlpha;
|
||||
private final boolean glow;
|
||||
|
||||
public ZoneParticleFX(World world, double x, double y, double z,
|
||||
double motionX, double motionY, double motionZ,
|
||||
float r, float g, float b, float alpha,
|
||||
float scale, int maxAge, float gravity, boolean glow) {
|
||||
super(world, x, y, z, 0, 0, 0);
|
||||
this.motionX = motionX;
|
||||
this.motionY = motionY;
|
||||
this.motionZ = motionZ;
|
||||
this.particleRed = r;
|
||||
this.particleGreen = g;
|
||||
this.particleBlue = b;
|
||||
this.particleAlpha = alpha;
|
||||
this.startAlpha = alpha;
|
||||
this.particleScale = scale;
|
||||
this.particleMaxAge = maxAge;
|
||||
this.particleGravity = gravity;
|
||||
this.glow = glow;
|
||||
this.noClip = true;
|
||||
this.setParticleTextureIndex(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBrightnessForRender(float partialTick) {
|
||||
return glow ? 0xF000F0 : super.getBrightnessForRender(partialTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
this.prevPosX = this.posX;
|
||||
this.prevPosY = this.posY;
|
||||
this.prevPosZ = this.posZ;
|
||||
|
||||
if (this.particleAge++ >= this.particleMaxAge) {
|
||||
this.setDead();
|
||||
return;
|
||||
}
|
||||
|
||||
// Linear fade out
|
||||
float lifeRatio = (float) this.particleAge / (float) this.particleMaxAge;
|
||||
this.particleAlpha = this.startAlpha * (1.0f - lifeRatio);
|
||||
|
||||
// Movement
|
||||
this.motionY -= 0.04D * (double) this.particleGravity;
|
||||
this.posX += this.motionX;
|
||||
this.posY += this.motionY;
|
||||
this.posZ += this.motionZ;
|
||||
}
|
||||
}
|
||||
@@ -198,6 +198,5 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener,
|
||||
}
|
||||
|
||||
public void save() {
|
||||
PacketClient.sendClient(new DialogSavePacket(this.dialogCategoryID, dialog.writeToNBT(new NBTTagCompound()), false));
|
||||
}
|
||||
}
|
||||
@@ -521,8 +521,6 @@ public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiLis
|
||||
|
||||
public void save() {
|
||||
GuiNpcTextField.unfocus();
|
||||
if (dialog.id >= 0)
|
||||
PacketClient.sendClient(new DialogSavePacket(((SubGuiNpcDialog) parent).dialogCategoryID, dialog.writeToNBT(new NBTTagCompound()), false));
|
||||
}
|
||||
|
||||
private DialogImage getSelectedImage() {
|
||||
|
||||
@@ -12,7 +12,6 @@ import noppes.npcs.constants.EnumPotionType;
|
||||
|
||||
public class SubGuiNpcMeleeProperties extends SubGuiInterface implements ITextfieldListener {
|
||||
private DataStats stats;
|
||||
private String[] potionNames = new String[]{"gui.none", "tile.fire.name", "potion.poison", "potion.hunger", "potion.weakness", "potion.moveSlowdown", "potion.confusion", "potion.blindness", "potion.wither"};
|
||||
|
||||
public SubGuiNpcMeleeProperties(DataStats stats) {
|
||||
this.stats = stats;
|
||||
@@ -42,18 +41,28 @@ public class SubGuiNpcMeleeProperties extends SubGuiInterface implements ITextfi
|
||||
getTextField(4).integersOnly = true;
|
||||
getTextField(4).setMinMaxDefault(0, Integer.MAX_VALUE, 0);
|
||||
addLabel(new GuiNpcLabel(5, "stats.meleeeffect", guiLeft + 5, guiTop + 135));
|
||||
addButton(new GuiButtonBiDirectional(5, guiLeft + 85, guiTop + 130, 100, 20, potionNames, stats.potionType.ordinal()));
|
||||
addButton(new GuiButtonBiDirectional(5, guiLeft + 85, guiTop + 130, 100, 20, EnumPotionType.getLangKeys(), stats.potionType.ordinal()));
|
||||
if (stats.potionType == EnumPotionType.Manual) {
|
||||
addLabel(new GuiNpcLabel(8, "effect.potionid", guiLeft + 198, guiTop + 119));
|
||||
addTextField(new GuiNpcTextField(8, this, fontRendererObj, guiLeft + 200, guiTop + 132, 40, 18, stats.potionManualId + ""));
|
||||
getTextField(8).integersOnly = true;
|
||||
getTextField(8).setMinMaxDefault(0, Integer.MAX_VALUE, 0);
|
||||
}
|
||||
|
||||
int y = guiTop + 160;
|
||||
if (stats.potionType != EnumPotionType.None) {
|
||||
addLabel(new GuiNpcLabel(6, "gui.time", guiLeft + 5, guiTop + 165));
|
||||
addTextField(new GuiNpcTextField(6, this, fontRendererObj, guiLeft + 85, guiTop + 160, 40, 18, stats.potionDuration + ""));
|
||||
addLabel(new GuiNpcLabel(6, "gui.time", guiLeft + 5, y + 5));
|
||||
addTextField(new GuiNpcTextField(6, this, fontRendererObj, guiLeft + 85, y, 40, 18, stats.potionDuration + ""));
|
||||
getTextField(6).integersOnly = true;
|
||||
getTextField(6).setMinMaxDefault(1, Integer.MAX_VALUE, 5);
|
||||
if (stats.potionType != EnumPotionType.Fire) {
|
||||
addLabel(new GuiNpcLabel(7, "stats.amplify", guiLeft + 5, guiTop + 195));
|
||||
addButton(new GuiButtonBiDirectional(7, guiLeft + 85, guiTop + 190, 52, 20, new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}, stats.potionAmp));
|
||||
y += 30;
|
||||
addLabel(new GuiNpcLabel(7, "stats.amplify", guiLeft + 5, y + 5));
|
||||
addButton(new GuiButtonBiDirectional(7, guiLeft + 85, y, 52, 20, new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}, stats.potionAmp));
|
||||
}
|
||||
}
|
||||
addButton(new GuiNpcButton(66, guiLeft + 190, guiTop + 190, 60, 20, "gui.done"));
|
||||
|
||||
addButton(new GuiNpcButton(66, guiLeft + 190, guiTop + ySize - 26, 60, 20, "gui.done"));
|
||||
}
|
||||
|
||||
public void unFocused(GuiNpcTextField textfield) {
|
||||
@@ -67,13 +76,15 @@ public class SubGuiNpcMeleeProperties extends SubGuiInterface implements ITextfi
|
||||
stats.knockback = textfield.getInteger();
|
||||
} else if (textfield.id == 6) {
|
||||
stats.potionDuration = textfield.getInteger();
|
||||
} else if (textfield.id == 8) {
|
||||
stats.potionManualId = textfield.getInteger();
|
||||
}
|
||||
}
|
||||
|
||||
protected void actionPerformed(GuiButton guibutton) {
|
||||
GuiNpcButton button = (GuiNpcButton) guibutton;
|
||||
if (button.id == 5) {
|
||||
stats.potionType = EnumPotionType.values()[button.getValue()];
|
||||
stats.potionType = EnumPotionType.fromOrdinal(button.getValue());
|
||||
initGui();
|
||||
}
|
||||
if (button.id == 7) {
|
||||
|
||||
@@ -15,7 +15,6 @@ import noppes.npcs.constants.EnumPotionType;
|
||||
|
||||
public class SubGuiNpcProjectiles extends SubGuiInterface implements ITextfieldListener, ISubGuiListener {
|
||||
private DataStats stats;
|
||||
private String[] potionNames = new String[]{"gui.none", "tile.fire.name", "potion.poison", "potion.hunger", "potion.weakness", "potion.moveSlowdown", "potion.confusion", "potion.blindness", "potion.wither"};
|
||||
private String[] trailNames = new String[]{"gui.none", "trail.smoke", "trail.portal", "trail.redstone",
|
||||
"trail.lightning", "trail.largesmoke", "trail.magic", "trail.enchant", "trail.crit",
|
||||
"trail.explode", "trail.music", "trail.flame", "trail.lava", "trail.splash",
|
||||
@@ -76,22 +75,29 @@ public class SubGuiNpcProjectiles extends SubGuiInterface implements ITextfieldL
|
||||
}
|
||||
|
||||
addLabel(new GuiNpcLabel(7, "stats.rangedeffect", guiLeft + 210, y + 5));
|
||||
addButton(new GuiButtonBiDirectional(4, guiLeft + 280, y, 100, 20, potionNames, stats.pEffect.ordinal()));
|
||||
addButton(new GuiButtonBiDirectional(4, guiLeft + 280, y, 100, 20, EnumPotionType.getLangKeys(), stats.pEffect.ordinal()));
|
||||
|
||||
if (stats.pEffect != EnumPotionType.None) {
|
||||
int internalY = y + 30;
|
||||
if (stats.pEffect == EnumPotionType.Manual) {
|
||||
addLabel(new GuiNpcLabel(110, "effect.potionid", guiLeft + 210, internalY + 5));
|
||||
addTextField(new GuiNpcTextField(11, this, fontRendererObj, guiLeft + 330, internalY, 52, 20, stats.pManualId + ""));
|
||||
getTextField(11).integersOnly = true;
|
||||
getTextField(11).setMinMaxDefault(0, Integer.MAX_VALUE, 0);
|
||||
internalY += 30;
|
||||
}
|
||||
addLabel(new GuiNpcLabel(50, "gui.time", guiLeft + 210, internalY + 5));
|
||||
addTextField(new GuiNpcTextField(5, this, fontRendererObj, guiLeft + 330, internalY, 52, 20, stats.pDur + ""));
|
||||
getTextField(5).integersOnly = true;
|
||||
getTextField(5).setMinMaxDefault(1, Integer.MAX_VALUE, 5);
|
||||
if (stats.pEffect != EnumPotionType.Fire) {
|
||||
internalY += 30;
|
||||
addLabel(new GuiNpcLabel(70, "stats.amplify", guiLeft + 210, internalY + 5));
|
||||
addButton(new GuiButtonBiDirectional(10, guiLeft + 280, internalY, 52, 20, new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}, stats.pEffAmp));
|
||||
} else {
|
||||
if (stats.pEffect == EnumPotionType.Fire) {
|
||||
internalY += 30;
|
||||
addLabel(new GuiNpcLabel(100, "stats.burnItem", guiLeft + 210, internalY + 5));
|
||||
addButton(new GuiNpcButtonYesNo(100, guiLeft + 330, internalY, 52, 20, stats.pBurnItem));
|
||||
} else {
|
||||
internalY += 30;
|
||||
addLabel(new GuiNpcLabel(70, "stats.amplify", guiLeft + 210, internalY + 5));
|
||||
addButton(new GuiButtonBiDirectional(10, guiLeft + 280, internalY, 52, 20, new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}, stats.pEffAmp));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +132,8 @@ public class SubGuiNpcProjectiles extends SubGuiInterface implements ITextfieldL
|
||||
stats.pSpeed = textfield.getInteger();
|
||||
} else if (textfield.id == 5) {
|
||||
stats.pDur = textfield.getInteger();
|
||||
} else if (textfield.id == 11) {
|
||||
stats.pManualId = textfield.getInteger();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +154,7 @@ public class SubGuiNpcProjectiles extends SubGuiInterface implements ITextfieldL
|
||||
stats.pArea = button.getValue();
|
||||
}
|
||||
if (button.id == 4) {
|
||||
stats.pEffect = EnumPotionType.values()[button.getValue()];
|
||||
stats.pEffect = EnumPotionType.fromOrdinal(button.getValue());
|
||||
initGui();
|
||||
}
|
||||
if (button.id == 5) {
|
||||
|
||||
@@ -239,6 +239,5 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener,
|
||||
}
|
||||
|
||||
public void save() {
|
||||
PacketClient.sendClient(new QuestSavePacket(this.questCategoryID, quest.writeToNBT(new NBTTagCompound()), false));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package noppes.npcs.client.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SubGuiTrapPresetSelector extends SubGuiInterface {
|
||||
|
||||
public String selectedPreset = null;
|
||||
|
||||
private static final String[] PRESET_NAMES = {"HIDDEN", "VENOM", "EXPLOSIVE", "CURSED", "SHOCK", "SNARE"};
|
||||
private static final String[] PRESET_LABELS = {
|
||||
"ability.preset.hidden", "ability.preset.venom", "ability.preset.explosive",
|
||||
"ability.preset.cursed", "ability.preset.shock", "ability.preset.snare"
|
||||
};
|
||||
private static final int[] PRESET_COLORS = {0x888888, 0x44DD44, 0xFF6611, 0xAA44FF, 0x4488FF, 0x88CCFF};
|
||||
|
||||
public SubGuiTrapPresetSelector() {
|
||||
xSize = 170;
|
||||
ySize = 135;
|
||||
setBackground("menubg.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
int btnW = 72;
|
||||
int btnH = 20;
|
||||
int gapY = 4;
|
||||
int col1 = guiLeft + 7;
|
||||
int col2 = col1 + btnW + 6;
|
||||
int startY = guiTop + 22;
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int x = (i % 2 == 0) ? col1 : col2;
|
||||
int y = startY + (i / 2) * (btnH + gapY);
|
||||
addButton(new GuiNpcButton(i, x, y, btnW, btnH, PRESET_LABELS[i]));
|
||||
}
|
||||
|
||||
int cancelY = startY + 3 * (btnH + gapY) + 4;
|
||||
addButton(new GuiNpcButton(10, guiLeft + xSize / 2 - 36, cancelY, 72, btnH, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton btn) {
|
||||
super.actionPerformed(btn);
|
||||
if (btn.id >= 0 && btn.id < 6) {
|
||||
selectedPreset = PRESET_NAMES[btn.id];
|
||||
close();
|
||||
} else if (btn.id == 10) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
super.drawScreen(mouseX, mouseY, f);
|
||||
drawCenteredString(fontRendererObj, StatCollector.translateToLocal("gui.applyPreset"), guiLeft + xSize / 2, guiTop + 8, 0xFFFFFF);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
GuiNpcButton btn = getButton(i);
|
||||
if (btn != null && btn.visible) {
|
||||
int x = btn.xPosition + 4;
|
||||
int y = btn.yPosition + 5;
|
||||
drawRect(x, y, x + 10, y + 10, 0xFF000000 | PRESET_COLORS[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package noppes.npcs.client.gui;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SubGuiZonePresetSelector extends SubGuiInterface {
|
||||
|
||||
public String selectedPreset = null;
|
||||
|
||||
private static final String[] PRESET_NAMES = {"DEFAULT", "TOXIC", "INFERNO", "ARCANE", "ELECTRIC", "FROST"};
|
||||
private static final String[] PRESET_LABELS = {
|
||||
"ability.preset.default", "ability.preset.toxic", "ability.preset.inferno",
|
||||
"ability.preset.arcane", "ability.preset.electric", "ability.preset.frost"
|
||||
};
|
||||
private static final int[] PRESET_COLORS = {0xCCCCCC, 0x44DD44, 0xFF6611, 0xAA44FF, 0x4488FF, 0x88CCFF};
|
||||
|
||||
public SubGuiZonePresetSelector() {
|
||||
xSize = 170;
|
||||
ySize = 135;
|
||||
setBackground("menubg.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
int btnW = 72;
|
||||
int btnH = 20;
|
||||
int gapY = 4;
|
||||
int col1 = guiLeft + 7;
|
||||
int col2 = col1 + btnW + 6;
|
||||
int startY = guiTop + 22;
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int x = (i % 2 == 0) ? col1 : col2;
|
||||
int y = startY + (i / 2) * (btnH + gapY);
|
||||
addButton(new GuiNpcButton(i, x, y, btnW, btnH, PRESET_LABELS[i]));
|
||||
}
|
||||
|
||||
int cancelY = startY + 3 * (btnH + gapY) + 4;
|
||||
addButton(new GuiNpcButton(10, guiLeft + xSize / 2 - 36, cancelY, 72, btnH, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton btn) {
|
||||
super.actionPerformed(btn);
|
||||
if (btn.id >= 0 && btn.id < 6) {
|
||||
selectedPreset = PRESET_NAMES[btn.id];
|
||||
close();
|
||||
} else if (btn.id == 10) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
super.drawScreen(mouseX, mouseY, f);
|
||||
drawCenteredString(fontRendererObj, StatCollector.translateToLocal("gui.applyPreset"), guiLeft + xSize / 2, guiTop + 8, 0xFFFFFF);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
GuiNpcButton btn = getButton(i);
|
||||
if (btn != null && btn.visible) {
|
||||
int x = btn.xPosition + 4;
|
||||
int y = btn.yPosition + 5;
|
||||
drawRect(x, y, x + 10, y + 10, 0xFF000000 | PRESET_COLORS[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,12 @@ package noppes.npcs.client.gui.advanced;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilitySlot;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.AbilitiesGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.AbilitiesNpcSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitySavePacket;
|
||||
import kamkeel.npcs.util.Register;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -57,6 +59,12 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
private String search = "";
|
||||
private int selectedAbilityIndex = -1;
|
||||
|
||||
// Existing preset names for duplicate checking
|
||||
private final Set<String> existingPresetNames = new HashSet<>();
|
||||
|
||||
// Pending variant selection
|
||||
private String pendingTypeId = null;
|
||||
|
||||
public static int modIndex = 0;
|
||||
public static ScrollType scrollType = ScrollType.CNPC;
|
||||
|
||||
@@ -64,6 +72,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
super(npc);
|
||||
PacketClient.sendClient(new AbilitiesGetAllPacket());
|
||||
PacketClient.sendClient(new AbilitiesNpcGetPacket());
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
}
|
||||
|
||||
public enum ScrollType {
|
||||
@@ -79,7 +88,9 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
if (Register.isEmpty("ability"))
|
||||
return "modded";
|
||||
|
||||
return Register.REGISTERED_NAMESPACES.get("ability").get(modIndex);
|
||||
String namespace = Register.REGISTERED_NAMESPACES.get("ability").get(modIndex);
|
||||
String displayName = Register.NAMESPACE_DISPLAY_NAMES.get(namespace);
|
||||
return displayName != null ? displayName : namespace;
|
||||
case ALL: return "filter.all";
|
||||
default: return name();
|
||||
}
|
||||
@@ -92,38 +103,38 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
int y = guiTop + 10;
|
||||
|
||||
// Enabled checkbox
|
||||
addLabel(new GuiNpcLabel(100, "gui.enabled", guiLeft + 5, y + 5));
|
||||
addButton(new GuiNpcButton(100, guiLeft + 55, y, 50, 20, new String[]{"gui.no", "gui.yes"}, abilitiesEnabled ? 1 : 0));
|
||||
addButton(new GuiNpcButton(50, guiLeft + 5, y, 140, 20, scrollType.toString()));
|
||||
|
||||
// Cooldown range: Min Cooldown and Max Cooldown (spaced apart more)
|
||||
addLabel(new GuiNpcLabel(101, "ability.minCooldown", guiLeft + 115, y + 5));
|
||||
GuiNpcTextField minField = new GuiNpcTextField(101, this, fontRendererObj, guiLeft + 165, y, 40, 20, "" + minCooldown);
|
||||
addLabel(new GuiNpcLabel(101, "ability.minCooldown", guiLeft + 210, y + 5));
|
||||
GuiNpcTextField minField = new GuiNpcTextField(101, this, fontRendererObj, guiLeft + 260, y, 40, 20, "" + minCooldown);
|
||||
minField.setIntegersOnly();
|
||||
minField.setMinMaxDefault(0, 10000, 20);
|
||||
addTextField(minField);
|
||||
|
||||
addLabel(new GuiNpcLabel(102, "ability.maxCooldown", guiLeft + 260, y + 5));
|
||||
GuiNpcTextField maxField = new GuiNpcTextField(102, this, fontRendererObj, guiLeft + 310, y, 40, 20, "" + maxCooldown);
|
||||
addLabel(new GuiNpcLabel(102, "ability.maxCooldown", guiLeft + 320, y + 5));
|
||||
GuiNpcTextField maxField = new GuiNpcTextField(102, this, fontRendererObj, guiLeft + 370, y, 40, 20, "" + maxCooldown);
|
||||
maxField.setIntegersOnly();
|
||||
maxField.setMinMaxDefault(0, 10000, 60);
|
||||
addTextField(maxField);
|
||||
|
||||
y += 28;
|
||||
|
||||
// Enabled checkbox
|
||||
addButton(new GuiNpcButton(100, guiLeft + 334, y + 145, 76, 20, new String[]{"gui.disabled", "gui.enabled"}, abilitiesEnabled ? 1 : 0));
|
||||
getButton(100).packedFGColour = abilitiesEnabled ? 0x00FF00 : 0xFF0000;
|
||||
|
||||
// Left scroll: available ability types
|
||||
addLabel(new GuiNpcLabel(1, "ability.availableTypes", guiLeft + 5, y));
|
||||
if (availableTypesScroll == null) {
|
||||
availableTypesScroll = new GuiCustomScroll(this, 0);
|
||||
availableTypesScroll.setSize(140, 103);
|
||||
availableTypesScroll.setSize(140, 130);
|
||||
}
|
||||
availableTypesScroll.guiLeft = guiLeft + 5;
|
||||
availableTypesScroll.guiTop = y + 12;
|
||||
availableTypesScroll.setList(getFilteredTypeList());
|
||||
addScroll(availableTypesScroll);
|
||||
|
||||
addButton(new GuiNpcButton(50, guiLeft + 5, y + 120, 140, 20, scrollType.toString()));
|
||||
|
||||
// Search bar for types
|
||||
addTextField(new GuiNpcTextField(4, this, fontRendererObj, guiLeft + 5, y + 145, 140, 18, search));
|
||||
|
||||
@@ -131,9 +142,9 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
addLabel(new GuiNpcLabel(2, "ability.npcAbilities", guiLeft + 210, y));
|
||||
if (npcAbilitiesScroll == null) {
|
||||
npcAbilitiesScroll = new GuiCustomScroll(this, 1);
|
||||
npcAbilitiesScroll.setSize(160, 130);
|
||||
npcAbilitiesScroll.setSize(200, 130);
|
||||
} else {
|
||||
npcAbilitiesScroll.setSize(160, 130);
|
||||
npcAbilitiesScroll.setSize(200, 130);
|
||||
}
|
||||
npcAbilitiesScroll.guiLeft = guiLeft + 210;
|
||||
npcAbilitiesScroll.guiTop = y + 12;
|
||||
@@ -142,11 +153,12 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
// Center buttons: Add/Remove
|
||||
int centerX = guiLeft + 158;
|
||||
addButton(new GuiNpcButton(70, centerX, y + 40, 40, 20, ">>>")); // Add
|
||||
addButton(new GuiNpcButton(71, centerX, y + 62, 40, 20, "<<<")); // Remove
|
||||
addButton(new GuiNpcButton(70, centerX, y + 15, 40, 20, ">>>")); // Add
|
||||
addButton(new GuiNpcButton(71, centerX, y + 37, 40, 20, "<<<")); // Remove
|
||||
getButton(71).setEnabled(selectedAbilityIndex >= 0);
|
||||
|
||||
// Load button (under the add/remove arrows)
|
||||
addButton(new GuiNpcButton(75, centerX, y + 90, 40, 20, "gui.load"));
|
||||
addButton(new GuiNpcButton(75, centerX, y + 60, 40, 20, "gui.load"));
|
||||
|
||||
// On/Off toggle for selected ability (under Load button)
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
@@ -156,9 +168,16 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
addButton(toggleBtn);
|
||||
}
|
||||
|
||||
// Check if selected ability is built-in (non-editable)
|
||||
boolean selectedIsBuiltIn = false;
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
Ability sel = npcSlots.get(selectedAbilityIndex).getAbility();
|
||||
if (sel != null && sel.isBuiltIn()) selectedIsBuiltIn = true;
|
||||
}
|
||||
|
||||
// Right side buttons: Edit and Up/Down carrots with Save button
|
||||
addButton(new GuiNpcButton(72, guiLeft + 210, y + 145, 55, 20, "gui.edit"));
|
||||
getButton(72).setEnabled(selectedAbilityIndex >= 0);
|
||||
getButton(72).setEnabled(selectedAbilityIndex >= 0 && !selectedIsBuiltIn);
|
||||
|
||||
// Up/Down carrot buttons
|
||||
addButton(new GuiNpcButton(73, guiLeft + 270, y + 145, 20, 20, "<"));
|
||||
@@ -167,8 +186,8 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
getButton(74).setEnabled(selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size() - 1);
|
||||
|
||||
// Save button (to the right of carrots, only enabled when ability is selected)
|
||||
addButton(new GuiNpcButton(76, guiLeft + 320, y + 145, 50, 20, "gui.save"));
|
||||
getButton(76).setEnabled(selectedAbilityIndex >= 0);
|
||||
addButton(new GuiNpcButton(76, centerX, y + 82, 40, 20, "gui.save"));
|
||||
getButton(76).setEnabled(selectedAbilityIndex >= 0 && !selectedIsBuiltIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,6 +197,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
// Enabled toggle
|
||||
if (id == 100) {
|
||||
abilitiesEnabled = ((GuiNpcButton) guibutton).getValue() == 1;
|
||||
initGui();
|
||||
save();
|
||||
return;
|
||||
}
|
||||
@@ -188,8 +208,17 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
String displayName = availableTypesScroll.getSelected();
|
||||
String typeId = displayNameToTypeId.get(displayName);
|
||||
if (typeId != null) {
|
||||
java.util.List<AbilityVariant> variants = AbilityController.Instance.getVariantsForType(typeId);
|
||||
if (variants.size() > 1) {
|
||||
pendingTypeId = typeId;
|
||||
setSubGui(new SubGuiAbilityVariantSelect(variants));
|
||||
return;
|
||||
}
|
||||
Ability newAbility = AbilityController.Instance.create(typeId);
|
||||
if (newAbility != null) {
|
||||
if (variants.size() == 1) {
|
||||
variants.get(0).apply(newAbility);
|
||||
}
|
||||
newAbility.setId(UUID.randomUUID().toString());
|
||||
npcSlots.add(AbilitySlot.inline(newAbility));
|
||||
selectedAbilityIndex = npcSlots.size() - 1;
|
||||
@@ -225,6 +254,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
} else {
|
||||
Ability ability = slot.getAbility();
|
||||
if (ability != null) {
|
||||
ability.setNpcInlineEdit(true);
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
}
|
||||
}
|
||||
@@ -274,9 +304,10 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
Ability abilityToSave = npcSlots.get(selectedAbilityIndex).getAbility();
|
||||
if (abilityToSave != null) {
|
||||
if (abilityToSave.getName() == null || abilityToSave.getName().isEmpty()) {
|
||||
abilityToSave.setNpcInlineEdit(true);
|
||||
setSubGui(abilityToSave.createConfigGui(this));
|
||||
} else {
|
||||
setSubGui(new SubGuiAbilitySaveConfirm(abilityToSave));
|
||||
setSubGui(new SubGuiAbilitySaveConfirm(abilityToSave, null, existingPresetNames));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -286,9 +317,11 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
// Toggle selected ability on/off
|
||||
if (id == 77) {
|
||||
if (selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
Ability ability = npcSlots.get(selectedAbilityIndex).getAbility();
|
||||
AbilitySlot slot = npcSlots.get(selectedAbilityIndex);
|
||||
Ability ability = slot.getAbility();
|
||||
if (ability != null) {
|
||||
ability.setEnabled(((GuiNpcButton) guibutton).getValue() == 1);
|
||||
boolean enabled = ((GuiNpcButton) guibutton).getValue() == 1;
|
||||
slot.setEnabled(enabled);
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
initGui();
|
||||
@@ -301,7 +334,12 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
if (id == 50) {
|
||||
if (scrollType != ScrollType.MODDED) {
|
||||
ScrollType[] values = ScrollType.values();
|
||||
scrollType = values[(scrollType.ordinal() + 1) % values.length];
|
||||
ScrollType next = values[(scrollType.ordinal() + 1) % values.length];
|
||||
// Skip MODDED if no namespaces are registered
|
||||
if (next == ScrollType.MODDED && Register.isEmpty("ability")) {
|
||||
next = ScrollType.ALL;
|
||||
}
|
||||
scrollType = next;
|
||||
} else {
|
||||
List<String> list = Register.REGISTERED_NAMESPACES.get("ability");
|
||||
|
||||
@@ -320,8 +358,12 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
Map<String, Integer> dummyMap = new HashMap<>(allAbilityTypes);
|
||||
filteredAbilityTypes.clear();
|
||||
filteredAbilityTypes.putAll(getFilteredData(dummyMap));
|
||||
}
|
||||
|
||||
// Reset scroll position when changing category
|
||||
if (availableTypesScroll != null) {
|
||||
availableTypesScroll.resetScroll();
|
||||
}
|
||||
}
|
||||
|
||||
initGui();
|
||||
}
|
||||
@@ -336,6 +378,16 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
if (availableTypesScroll != null) {
|
||||
availableTypesScroll.setList(getFilteredTypeList());
|
||||
}
|
||||
} else if (type == EnumScrollData.CUSTOM_ABILITIES) {
|
||||
existingPresetNames.clear();
|
||||
for (String key : data.keySet()) {
|
||||
int tabIndex = key.indexOf('\t');
|
||||
if (tabIndex > 0) {
|
||||
existingPresetNames.add(key.substring(0, tabIndex));
|
||||
} else {
|
||||
existingPresetNames.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
@@ -423,6 +475,10 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
String displayName = I18n.format(typeId);
|
||||
// Search matches either the display name or the typeId
|
||||
if (search.isEmpty() || displayName.toLowerCase().contains(search) || typeId.toLowerCase().contains(search)) {
|
||||
// Gray out built-in types to distinguish them from configurable types
|
||||
if (AbilityController.Instance.isBuiltInType(typeId)) {
|
||||
displayName = "\u00A77" + displayName;
|
||||
}
|
||||
list.add(displayName);
|
||||
displayNameToTypeId.put(displayName, typeId);
|
||||
}
|
||||
@@ -435,8 +491,31 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
for (int i = 0; i < npcSlots.size(); i++) {
|
||||
list.add(getAbilityListEntry(i));
|
||||
}
|
||||
|
||||
// Sort: enabled first, then numerically by slot index
|
||||
Collections.sort(list, new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String a, String b) {
|
||||
boolean aEnabled = a.startsWith("\u00A7a");
|
||||
boolean bEnabled = b.startsWith("\u00A7a");
|
||||
if (aEnabled != bEnabled) return aEnabled ? -1 : 1;
|
||||
return extractIndex(a) - extractIndex(b);
|
||||
}
|
||||
|
||||
private int extractIndex(String entry) {
|
||||
String stripped = entry.replaceAll("\u00A7.", "").trim();
|
||||
int dotIndex = stripped.indexOf(".");
|
||||
if (dotIndex > 0) {
|
||||
try {
|
||||
return Integer.parseInt(stripped.substring(0, dotIndex).replaceAll("[^0-9]", ""));
|
||||
} catch (NumberFormatException e) { }
|
||||
}
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
});
|
||||
|
||||
if (npcAbilitiesScroll != null) {
|
||||
npcAbilitiesScroll.setList(list);
|
||||
npcAbilitiesScroll.setUnsortedList(list);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,6 +550,9 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
if (slot.isReference()) {
|
||||
return colorPrefix + (index + 1) + ". \u00A7e> " + nameDisplay + "\u00A7r";
|
||||
}
|
||||
if (ability.isBuiltIn()) {
|
||||
return colorPrefix + (index + 1) + ". \u00A77" + nameDisplay + "\u00A7r";
|
||||
}
|
||||
return colorPrefix + (index + 1) + ". " + nameDisplay;
|
||||
}
|
||||
|
||||
@@ -571,11 +653,13 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (scroll == npcAbilitiesScroll && selectedAbilityIndex >= 0 && selectedAbilityIndex < npcSlots.size()) {
|
||||
AbilitySlot slot = npcSlots.get(selectedAbilityIndex);
|
||||
Ability ability = slot.getAbility();
|
||||
if (ability != null && ability.isBuiltIn()) return;
|
||||
if (slot.isReference()) {
|
||||
setSubGui(new SubGuiAbilityEditMode());
|
||||
} else {
|
||||
Ability ability = slot.getAbility();
|
||||
if (ability != null) {
|
||||
ability.setNpcInlineEdit(true);
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
}
|
||||
}
|
||||
@@ -605,7 +689,24 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiAbilityEditMode) {
|
||||
if (subgui instanceof SubGuiAbilityVariantSelect) {
|
||||
SubGuiAbilityVariantSelect variantGui = (SubGuiAbilityVariantSelect) subgui;
|
||||
int idx = variantGui.getSelectedIndex();
|
||||
if (idx >= 0 && pendingTypeId != null) {
|
||||
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
|
||||
if (newAbility != null) {
|
||||
variantGui.getVariants().get(idx).apply(newAbility);
|
||||
newAbility.setId(UUID.randomUUID().toString());
|
||||
npcSlots.add(AbilitySlot.inline(newAbility));
|
||||
selectedAbilityIndex = npcSlots.size() - 1;
|
||||
updateNpcAbilitiesList();
|
||||
selectAbilityByIndex(selectedAbilityIndex);
|
||||
save();
|
||||
}
|
||||
}
|
||||
pendingTypeId = null;
|
||||
initGui();
|
||||
} else if (subgui instanceof SubGuiAbilityEditMode) {
|
||||
int mode = ((SubGuiAbilityEditMode) subgui).getResult();
|
||||
if (mode < 0) return; // cancelled
|
||||
|
||||
@@ -617,6 +718,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
Ability ability = slot.getAbility();
|
||||
if (ability != null) {
|
||||
ability.setId(UUID.randomUUID().toString());
|
||||
ability.setNpcInlineEdit(true);
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
}
|
||||
updateNpcAbilitiesList();
|
||||
|
||||
@@ -324,7 +324,9 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textField) {
|
||||
if (textField.id < DECLARATIVE_ID_START) return;
|
||||
builder.handleTextFieldEvent(textField.id, textField);
|
||||
if (builder.handleTextFieldEvent(textField.id, textField)) {
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -7,24 +7,29 @@ import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.IAbilityConfigCallback;
|
||||
import noppes.npcs.client.gui.util.ISubGuiListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Confirmation dialog for saving an ability preset.
|
||||
* Uses packet-based communication for proper client-server architecture.
|
||||
*/
|
||||
public class SubGuiAbilitySaveConfirm extends SubGuiInterface {
|
||||
public class SubGuiAbilitySaveConfirm extends SubGuiInterface implements ISubGuiListener {
|
||||
|
||||
private final Ability ability;
|
||||
private final IAbilityConfigCallback callback;
|
||||
private final Set<String> existingNames;
|
||||
|
||||
public SubGuiAbilitySaveConfirm(Ability ability) {
|
||||
this(ability, null);
|
||||
this(ability, null, null);
|
||||
}
|
||||
|
||||
public SubGuiAbilitySaveConfirm(Ability ability, IAbilityConfigCallback callback) {
|
||||
public SubGuiAbilitySaveConfirm(Ability ability, IAbilityConfigCallback callback, Set<String> existingNames) {
|
||||
this.ability = ability;
|
||||
this.callback = callback;
|
||||
this.existingNames = existingNames;
|
||||
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
@@ -52,14 +57,32 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface {
|
||||
int id = guibutton.id;
|
||||
|
||||
if (id == 0) {
|
||||
// Save the ability via packet
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
|
||||
if (callback != null) {
|
||||
callback.onAbilitySaved(ability);
|
||||
if (existingNames != null && existingNames.contains(ability.getName())) {
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return;
|
||||
}
|
||||
close();
|
||||
doSave();
|
||||
} else if (id == 1) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
private void doSave() {
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
|
||||
if (callback != null) {
|
||||
callback.onAbilitySaved(ability);
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiDuplicateNameConfirm) {
|
||||
if (((SubGuiDuplicateNameConfirm) subgui).isConfirmed()) {
|
||||
doSave();
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,22 +5,26 @@ import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* SubGui for selecting an ability type when creating a new ability.
|
||||
*/
|
||||
public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomScrollListener {
|
||||
public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomScrollListener, ITextfieldListener {
|
||||
|
||||
private GuiCustomScroll scroll;
|
||||
private final HashMap<String, String> displayNameToTypeId = new HashMap<>();
|
||||
private final HashMap<String, String> allDisplayNameToTypeId = new HashMap<>();
|
||||
private String selectedTypeId = null;
|
||||
private String search = "";
|
||||
|
||||
public SubGuiAbilityTypeSelect() {
|
||||
setBackground("menubg.png");
|
||||
@@ -32,32 +36,44 @@ public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomS
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
addLabel(new GuiNpcLabel(0, "ability.selectType", guiLeft + 5, guiTop + 5));
|
||||
addTextField(new GuiNpcTextField(10, this, fontRendererObj, guiLeft + 5, guiTop + 5, 190, 18, search));
|
||||
|
||||
if (scroll == null) {
|
||||
scroll = new GuiCustomScroll(this, 0);
|
||||
scroll.setSize(190, 165);
|
||||
scroll.setSize(190, 145);
|
||||
}
|
||||
scroll.guiLeft = guiLeft + 5;
|
||||
scroll.guiTop = guiTop + 16;
|
||||
scroll.guiTop = guiTop + 26;
|
||||
addScroll(scroll);
|
||||
|
||||
List<String> list = buildTypeList();
|
||||
scroll.setList(list);
|
||||
buildAllTypes();
|
||||
scroll.setList(getFilteredTypeList());
|
||||
|
||||
addButton(new GuiNpcButton(0, guiLeft + 5, guiTop + 188, 90, 20, "gui.add"));
|
||||
getButton(0).setEnabled(scroll.hasSelected());
|
||||
addButton(new GuiNpcButton(1, guiLeft + 105, guiTop + 188, 90, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
private List<String> buildTypeList() {
|
||||
List<String> list = new ArrayList<>();
|
||||
displayNameToTypeId.clear();
|
||||
private void buildAllTypes() {
|
||||
allDisplayNameToTypeId.clear();
|
||||
String[] types = AbilityController.Instance.getTypes();
|
||||
for (String typeId : types) {
|
||||
// Exclude built-in types — they cannot be created as custom presets
|
||||
if (AbilityController.Instance.isBuiltInType(typeId)) continue;
|
||||
String displayName = I18n.format(typeId);
|
||||
list.add(displayName);
|
||||
displayNameToTypeId.put(displayName, typeId);
|
||||
allDisplayNameToTypeId.put(displayName, typeId);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getFilteredTypeList() {
|
||||
List<String> list = new ArrayList<>();
|
||||
displayNameToTypeId.clear();
|
||||
for (Map.Entry<String, String> entry : allDisplayNameToTypeId.entrySet()) {
|
||||
String displayName = entry.getKey();
|
||||
if (search.isEmpty() || displayName.toLowerCase().contains(search) || entry.getValue().toLowerCase().contains(search)) {
|
||||
list.add(displayName);
|
||||
displayNameToTypeId.put(displayName, entry.getValue());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -89,6 +105,22 @@ public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomS
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char c, int i) {
|
||||
super.keyTyped(c, i);
|
||||
if (getTextField(10) != null && getTextField(10).isFocused()) {
|
||||
if (!search.equals(getTextField(10).getText())) {
|
||||
search = getTextField(10).getText().toLowerCase();
|
||||
scroll.setList(getFilteredTypeList());
|
||||
scroll.resetScroll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textField) {
|
||||
}
|
||||
|
||||
public String getSelectedTypeId() {
|
||||
return selectedTypeId;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* SubGui for selecting a variant/template when creating a new ability.
|
||||
* Uses a scroll list with group headers for external addon variants.
|
||||
*/
|
||||
public class SubGuiAbilityVariantSelect extends SubGuiInterface implements ICustomScrollListener {
|
||||
|
||||
private final List<AbilityVariant> variants;
|
||||
private int selectedIndex = -1;
|
||||
|
||||
// Maps each scroll list index to a variant list index (-1 for non-selectable entries)
|
||||
private final List<Integer> scrollToVariantIndex = new ArrayList<>();
|
||||
|
||||
public SubGuiAbilityVariantSelect(List<AbilityVariant> variants) {
|
||||
this.variants = variants;
|
||||
setBackground("menubg.png");
|
||||
xSize = 200;
|
||||
ySize = 216;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
addLabel(new GuiNpcLabel(0, "ability.selectVariant", guiLeft + 10, guiTop + 8));
|
||||
|
||||
// Build the unsorted scroll list with group headers
|
||||
List<String> scrollList = new ArrayList<>();
|
||||
scrollToVariantIndex.clear();
|
||||
|
||||
boolean hasBaseVariants = false;
|
||||
boolean hasGroupedVariants = false;
|
||||
|
||||
for (AbilityVariant v : variants) {
|
||||
if (v.getGroup() == null)
|
||||
hasBaseVariants = true;
|
||||
else
|
||||
hasGroupedVariants = true;
|
||||
}
|
||||
|
||||
// Add base (non-grouped) variants first
|
||||
for (int i = 0; i < variants.size(); i++) {
|
||||
if (variants.get(i).getGroup() == null) {
|
||||
scrollList.add(variants.get(i).getDisplayKey());
|
||||
scrollToVariantIndex.add(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Blank separator between base and grouped variants
|
||||
if (hasBaseVariants && hasGroupedVariants) {
|
||||
scrollList.add("");
|
||||
scrollToVariantIndex.add(-1);
|
||||
}
|
||||
|
||||
// Add grouped variants with group headers
|
||||
String lastGroup = null;
|
||||
for (int i = 0; i < variants.size(); i++) {
|
||||
AbilityVariant v = variants.get(i);
|
||||
if (v.getGroup() == null)
|
||||
continue;
|
||||
|
||||
if (!v.getGroup().equals(lastGroup)) {
|
||||
scrollList.add(v.getGroup());
|
||||
scrollToVariantIndex.add(-1);
|
||||
lastGroup = v.getGroup();
|
||||
}
|
||||
|
||||
scrollList.add(v.getDisplayKey());
|
||||
scrollToVariantIndex.add(i);
|
||||
}
|
||||
|
||||
GuiCustomScroll scroll = new GuiCustomScroll(this, 0);
|
||||
scroll.guiLeft = guiLeft + 5;
|
||||
scroll.guiTop = guiTop + 22;
|
||||
scroll.setUnsortedList(scrollList);
|
||||
scroll.setSize(190, 155);
|
||||
|
||||
// Mark blank separators and group headers as non-interactive colored entries
|
||||
scroll.colors.put("", 0x000000);
|
||||
if (lastGroup != null) {
|
||||
for (int i = 0; i < variants.size(); i++) {
|
||||
String group = variants.get(i).getGroup();
|
||||
if (group != null)
|
||||
scroll.colors.put(group, 0xFFFF00); // Yellow
|
||||
}
|
||||
}
|
||||
|
||||
// Restore selection in scroll
|
||||
if (selectedIndex >= 0) {
|
||||
for (int s = 0; s < scrollToVariantIndex.size(); s++) {
|
||||
if (scrollToVariantIndex.get(s) == selectedIndex) {
|
||||
scroll.selected = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addScroll(scroll);
|
||||
|
||||
// Select / Cancel buttons
|
||||
addButton(new GuiNpcButton(0, guiLeft + 5, guiTop + 188, 90, 20, "gui.select"));
|
||||
getButton(0).setEnabled(selectedIndex >= 0);
|
||||
addButton(new GuiNpcButton(1, guiLeft + 105, guiTop + 188, 90, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
|
||||
if (scroll.id == 0 && scroll.selected >= 0 && scroll.selected < scrollToVariantIndex.size()) {
|
||||
int variantIdx = scrollToVariantIndex.get(scroll.selected);
|
||||
if (variantIdx >= 0) {
|
||||
selectedIndex = variantIdx;
|
||||
getButton(0).setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (selectedIndex >= 0) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
if (id == 0 && selectedIndex >= 0) {
|
||||
close();
|
||||
} else if (id == 1) {
|
||||
selectedIndex = -1;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public int getSelectedIndex() {
|
||||
return selectedIndex;
|
||||
}
|
||||
|
||||
public List<AbilityVariant> getVariants() {
|
||||
return variants;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
/**
|
||||
* Confirmation dialog shown when saving an ability preset with a name that already exists.
|
||||
*/
|
||||
public class SubGuiDuplicateNameConfirm extends SubGuiInterface {
|
||||
|
||||
private boolean confirmed = false;
|
||||
|
||||
public SubGuiDuplicateNameConfirm() {
|
||||
setBackground("menubg.png");
|
||||
xSize = 220;
|
||||
ySize = 80;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int y = guiTop + 10;
|
||||
addLabel(new GuiNpcLabel(0, "ability.duplicate.name", guiLeft + 10, y));
|
||||
|
||||
y += 30;
|
||||
addButton(new GuiNpcButton(0, guiLeft + 20, y, 80, 20, "gui.continue"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 120, y, 80, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (guibutton.id == 0) {
|
||||
confirmed = true;
|
||||
close();
|
||||
} else if (guibutton.id == 1) {
|
||||
confirmed = false;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConfirmed() {
|
||||
return confirmed;
|
||||
}
|
||||
}
|
||||
@@ -32,8 +32,8 @@ public class FieldDef {
|
||||
private String hoverText = null;
|
||||
|
||||
// Numeric range
|
||||
private float min = Float.MIN_VALUE;
|
||||
private float max = Float.MAX_VALUE;
|
||||
private float min = 0;
|
||||
private float max = Float.POSITIVE_INFINITY;
|
||||
|
||||
// Enum support
|
||||
private Class<? extends Enum<?>> enumClass;
|
||||
@@ -154,8 +154,8 @@ public class FieldDef {
|
||||
|
||||
public static FieldDef colorSubGui(String label, Supplier<Integer> getter, Consumer<Integer> setter) {
|
||||
return subGuiField(label,
|
||||
() -> new SubGuiColorSelector(getter.get()),
|
||||
gui -> setter.accept(((SubGuiColorSelector) gui).color & 0x00FFFFFF))
|
||||
() -> new SubGuiColorSelector(getter.get() & 0xFFFFFF),
|
||||
gui -> setter.accept((((SubGuiColorSelector) gui).color & 0x00FFFFFF) | (getter.get() & 0xFF000000)))
|
||||
.buttonLabel(() -> String.format("%06X", getter.get() & 0xFFFFFF))
|
||||
.buttonTextColor(() -> getter.get() & 0xFFFFFF);
|
||||
}
|
||||
@@ -272,7 +272,7 @@ public class FieldDef {
|
||||
public String getHoverText() { return hoverText; }
|
||||
public float getMin() { return min; }
|
||||
public float getMax() { return max; }
|
||||
public boolean hasRange() { return min != Float.MIN_VALUE || max != Float.MAX_VALUE; }
|
||||
public boolean hasRange() { return min != Float.NEGATIVE_INFINITY || max != Float.POSITIVE_INFINITY; }
|
||||
public Class<? extends Enum<?>> getEnumClass() { return enumClass; }
|
||||
public String[] getStringEnumValues() { return stringEnumValues; }
|
||||
public Supplier<SubGuiInterface> getSubGuiFactory() { return subGuiFactory; }
|
||||
|
||||
@@ -120,6 +120,9 @@ public class GuiFieldBuilder {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip invisible fields
|
||||
if (!def.isVisible()) continue;
|
||||
|
||||
// Section header
|
||||
if (def.getType() == FieldType.SECTION_HEADER) {
|
||||
y += 3;
|
||||
@@ -391,7 +394,7 @@ public class GuiFieldBuilder {
|
||||
|
||||
/**
|
||||
* Handles text field unfocus events for declarative fields.
|
||||
* Call from parent GUI's unFocused(). Returns true if the event was handled.
|
||||
* Call from parent GUI's unFocused(). Returns true if the value actually changed.
|
||||
*/
|
||||
public boolean handleTextFieldEvent(int textFieldId, GuiNpcTextField field) {
|
||||
FieldDef def = textFieldMap.get(textFieldId);
|
||||
@@ -399,14 +402,36 @@ public class GuiFieldBuilder {
|
||||
|
||||
switch (def.getType()) {
|
||||
case FLOAT:
|
||||
try { def.setValue(Float.parseFloat(field.getText())); } catch (NumberFormatException ignored) {}
|
||||
return true;
|
||||
try {
|
||||
float newVal = Float.parseFloat(field.getText());
|
||||
Object old = def.getValue();
|
||||
float oldVal = old instanceof Number ? ((Number) old).floatValue() : 0f;
|
||||
if (newVal != oldVal) {
|
||||
def.setValue(newVal);
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {}
|
||||
return false;
|
||||
case INT:
|
||||
try { def.setValue(Integer.parseInt(field.getText())); } catch (NumberFormatException ignored) {}
|
||||
return true;
|
||||
try {
|
||||
int newVal = Integer.parseInt(field.getText());
|
||||
Object old = def.getValue();
|
||||
int oldVal = old instanceof Number ? ((Number) old).intValue() : 0;
|
||||
if (newVal != oldVal) {
|
||||
def.setValue(newVal);
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {}
|
||||
return false;
|
||||
case STRING:
|
||||
def.setValue(field.getText());
|
||||
return true;
|
||||
String newVal = field.getText();
|
||||
Object old = def.getValue();
|
||||
String oldVal = old != null ? old.toString() : "";
|
||||
if (!newVal.equals(oldVal)) {
|
||||
def.setValue(newVal);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -65,16 +65,17 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
// Toggle button - added FIRST to maintain stable buttonList index
|
||||
// (prevents double-toggle when initGui() is called from actionPerformed)
|
||||
String toggleLabel = showingBuiltIn ? "gui.builtin" : "gui.custom";
|
||||
this.addButton(new GuiNpcButton(10, guiLeft + 368, guiTop + 56, 45, 20, toggleLabel));
|
||||
|
||||
// Add/Remove buttons - only show for custom animations
|
||||
if (!showingBuiltIn) {
|
||||
this.addButton(new GuiNpcButton(0, guiLeft + 368, guiTop + 8, 45, 20, "gui.add"));
|
||||
this.addButton(new GuiNpcButton(1, guiLeft + 368, guiTop + 32, 45, 20, "gui.remove"));
|
||||
}
|
||||
|
||||
// Toggle button for Custom/Built-in - under Remove button
|
||||
String toggleLabel = showingBuiltIn ? "gui.builtin" : "gui.custom";
|
||||
this.addButton(new GuiNpcButton(10, guiLeft + 368, guiTop + 56, 45, 20, toggleLabel));
|
||||
|
||||
if (scrollAnimations == null) {
|
||||
scrollAnimations = new GuiCustomScroll(this, 0, 0);
|
||||
scrollAnimations.setSize(143, 185);
|
||||
@@ -200,11 +201,15 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
|
||||
// Toggle button
|
||||
if (button.id == 10) {
|
||||
showingBuiltIn = !showingBuiltIn;
|
||||
// Clear selection when switching views
|
||||
// Clear selection and search when switching views
|
||||
selected = null;
|
||||
search = "";
|
||||
animation = new Animation();
|
||||
currentIsBuiltIn = false;
|
||||
playingAnimation = false;
|
||||
scrollAnimations.clear();
|
||||
// Re-request data to ensure both lists are populated
|
||||
PacketClient.sendClient(new AnimationsGetPacket());
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,11 +85,13 @@ public class GuiNPCManageFactions extends GuiNPCInterface2 implements IScrollDat
|
||||
|
||||
addLabel(new GuiNpcLabel(3, "faction.hidden", guiLeft + 8, y + 5));
|
||||
this.addButton(new GuiNpcButton(3, guiLeft + 100, y, 45, 20, new String[]{"gui.no", "gui.yes"}, faction.hideFaction ? 1 : 0));
|
||||
getButton(3).setHoverText("faction.hidden.hover");
|
||||
|
||||
y += 23;
|
||||
|
||||
addLabel(new GuiNpcLabel(4, "faction.attacked", guiLeft + 8, y + 5));
|
||||
this.addButton(new GuiNpcButton(4, guiLeft + 100, y, 45, 20, new String[]{"gui.no", "gui.yes"}, faction.getsAttacked ? 1 : 0));
|
||||
getButton(4).setHoverText("faction.attacked.hover");
|
||||
|
||||
y += 23;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import java.util.UUID;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.ability.BuiltInAbilityGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilityGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.CustomAbilityRemovePacket;
|
||||
@@ -16,7 +17,11 @@ import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityConfig;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityTypeSelect;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiAbilityVariantSelect;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiDuplicateNameConfirm;
|
||||
import noppes.npcs.client.gui.util.AbilityPreviewExecutor;
|
||||
import noppes.npcs.client.gui.util.GuiAbilityInterface;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
@@ -47,6 +52,7 @@ import java.util.Vector;
|
||||
* - Left side: 3D preview of NPC with ability effects
|
||||
* - Right side: Ability list with search
|
||||
* - Play/Pause/Stop buttons to preview abilities
|
||||
* - Toggle between Custom and Built-in ability views
|
||||
*/
|
||||
public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
implements ICustomScrollListener, ISubGuiListener, IAbilityConfigCallback,
|
||||
@@ -54,7 +60,8 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
// ==================== DATA ====================
|
||||
private GuiCustomScroll scroll;
|
||||
private HashMap<String, Integer> abilityData = new HashMap<>();
|
||||
private HashMap<String, Integer> customData = new HashMap<>();
|
||||
private HashMap<String, Integer> builtInData = new HashMap<>();
|
||||
/** Maps display name -> UUID for custom abilities */
|
||||
private final HashMap<String, String> displayToUuid = new HashMap<>();
|
||||
private String selected = null;
|
||||
@@ -62,6 +69,17 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
private String search = "";
|
||||
private Ability selectedAbility = null;
|
||||
|
||||
// ==================== BUILT-IN TOGGLE ====================
|
||||
private boolean showingBuiltIn = false;
|
||||
private boolean currentIsBuiltIn = false;
|
||||
|
||||
// ==================== PENDING SAVE ====================
|
||||
private Ability pendingSaveAbility = null;
|
||||
private boolean pendingNewCreation = false;
|
||||
|
||||
// ==================== PENDING VARIANT ====================
|
||||
private String pendingTypeId = null;
|
||||
|
||||
// ==================== PREVIEW ====================
|
||||
private AbilityPreviewExecutor previewExecutor;
|
||||
private long prevTick = 0;
|
||||
@@ -77,7 +95,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
previewExecutor = new AbilityPreviewExecutor();
|
||||
previewExecutor.setParentGui(this);
|
||||
|
||||
// Request ability data from server
|
||||
// Request ability data from server (sends both custom and built-in)
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
|
||||
// Enable animation data
|
||||
@@ -89,18 +107,26 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
// Add button
|
||||
addButton(new GuiNpcButton(2, guiLeft + 368, guiTop + 8, 45, 20, "gui.add"));
|
||||
// Toggle button — added FIRST to maintain stable buttonList index
|
||||
String toggleLabel = showingBuiltIn ? "gui.builtin" : "gui.custom";
|
||||
addButton(new GuiNpcButton(10, guiLeft + 368, guiTop + 52, 45, 20, toggleLabel));
|
||||
|
||||
// Remove button
|
||||
addButton(new GuiNpcButton(1, guiLeft + 368, guiTop + 30, 45, 20, "gui.remove"));
|
||||
getButton(1).setEnabled(selected != null && !selected.isEmpty() && displayToUuid.containsKey(selected));
|
||||
if (!showingBuiltIn) {
|
||||
// Add button — only for custom view
|
||||
addButton(new GuiNpcButton(2, guiLeft + 368, guiTop + 8, 45, 20, "gui.add"));
|
||||
|
||||
// Edit button
|
||||
addButton(new GuiNpcButton(100, guiLeft + 368, guiTop + 52, 45, 20, "gui.edit"));
|
||||
getButton(100).setEnabled(selected != null && !selected.isEmpty() && selectedAbility != null);
|
||||
// Remove button — only for custom view
|
||||
addButton(new GuiNpcButton(1, guiLeft + 368, guiTop + 30, 45, 20, "gui.remove"));
|
||||
getButton(1).setEnabled(selected != null && !selected.isEmpty() && displayToUuid.containsKey(selected));
|
||||
}
|
||||
|
||||
// Scroll list of saved abilities (right side)
|
||||
// Edit button — hidden when viewing built-in
|
||||
if (!showingBuiltIn && !currentIsBuiltIn) {
|
||||
addButton(new GuiNpcButton(100, guiLeft + 368, guiTop + 74, 45, 20, "gui.edit"));
|
||||
getButton(100).setEnabled(selected != null && !selected.isEmpty() && selectedAbility != null);
|
||||
}
|
||||
|
||||
// Scroll list of abilities (right side)
|
||||
if (scroll == null) {
|
||||
scroll = new GuiCustomScroll(this, 0);
|
||||
scroll.setSize(143, 185);
|
||||
@@ -111,7 +137,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
// Update scroll list
|
||||
scroll.setList(getSearchList());
|
||||
if (selected != null && displayToUuid.containsKey(selected)) {
|
||||
if (selected != null) {
|
||||
scroll.setSelected(selected);
|
||||
}
|
||||
|
||||
@@ -123,9 +149,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
return;
|
||||
}
|
||||
|
||||
// ID/Name label (below search bar)
|
||||
addLabel(new GuiNpcLabel(10, "ID: " + selectedAbility.getId(), guiLeft + 220, guiTop + 215));
|
||||
|
||||
// Play/Pause/Stop buttons (below model preview area)
|
||||
String animTexture = "customnpcs:textures/gui/animation.png";
|
||||
int playButtonOffsetX = 60;
|
||||
@@ -150,17 +173,34 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, Integer> getCurrentData() {
|
||||
return showingBuiltIn ? builtInData : customData;
|
||||
}
|
||||
|
||||
private List<String> getSearchList() {
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<>(displayToUuid.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String name : displayToUuid.keySet()) {
|
||||
if (name.toLowerCase().contains(search.toLowerCase())) {
|
||||
list.add(name);
|
||||
if (showingBuiltIn) {
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<>(builtInData.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String name : builtInData.keySet()) {
|
||||
if (name.toLowerCase().contains(search.toLowerCase())) {
|
||||
list.add(name);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
} else {
|
||||
if (search.isEmpty()) {
|
||||
return new ArrayList<>(displayToUuid.keySet());
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String name : displayToUuid.keySet()) {
|
||||
if (name.toLowerCase().contains(search.toLowerCase())) {
|
||||
list.add(name);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -216,13 +256,30 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
int id = guibutton.id;
|
||||
|
||||
if (id == 2) {
|
||||
// Toggle between custom and built-in views
|
||||
if (id == 10) {
|
||||
showingBuiltIn = !showingBuiltIn;
|
||||
selected = null;
|
||||
selectedUuid = null;
|
||||
selectedAbility = null;
|
||||
currentIsBuiltIn = false;
|
||||
search = "";
|
||||
previewExecutor.stop();
|
||||
if (scroll != null) {
|
||||
scroll.clear();
|
||||
}
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == 2 && !showingBuiltIn) {
|
||||
// Add — open type selection
|
||||
setSubGui(new SubGuiAbilityTypeSelect());
|
||||
} else if (id == 1 && selected != null && selectedUuid != null) {
|
||||
} else if (id == 1 && !showingBuiltIn && selected != null && selectedUuid != null) {
|
||||
GuiYesNo guiyesno = new GuiYesNo(this, selected, StatCollector.translateToLocal("gui.delete"), 1);
|
||||
displayGuiScreen(guiyesno);
|
||||
} else if (id == 100 && selectedAbility != null) {
|
||||
} else if (id == 100 && !showingBuiltIn && !currentIsBuiltIn && selectedAbility != null) {
|
||||
// Edit
|
||||
previewExecutor.stop();
|
||||
setSubGui(selectedAbility.createConfigGui(this));
|
||||
@@ -265,11 +322,20 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
String newSelection = scroll.getSelected();
|
||||
if (newSelection != null && !newSelection.equals(selected)) {
|
||||
previewExecutor.stop();
|
||||
|
||||
selected = newSelection;
|
||||
selectedUuid = displayToUuid.get(selected);
|
||||
if (selectedUuid != null) {
|
||||
PacketClient.sendClient(new CustomAbilityGetPacket(selectedUuid));
|
||||
|
||||
if (showingBuiltIn) {
|
||||
// Fetch built-in ability by display name
|
||||
selectedUuid = null;
|
||||
currentIsBuiltIn = true;
|
||||
PacketClient.sendClient(new BuiltInAbilityGetPacket(selected));
|
||||
} else {
|
||||
// Fetch custom ability by UUID
|
||||
selectedUuid = displayToUuid.get(selected);
|
||||
currentIsBuiltIn = false;
|
||||
if (selectedUuid != null) {
|
||||
PacketClient.sendClient(new CustomAbilityGetPacket(selectedUuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -278,8 +344,8 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
@Override
|
||||
public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) {
|
||||
if (scroll.id == 0 && selection != null && !selection.isEmpty()) {
|
||||
// Double-click to edit
|
||||
if (selectedAbility != null) {
|
||||
// Double-click to edit — only for custom, non-built-in abilities
|
||||
if (!showingBuiltIn && !currentIsBuiltIn && selectedAbility != null) {
|
||||
previewExecutor.stop();
|
||||
setSubGui(selectedAbility.createConfigGui(this));
|
||||
}
|
||||
@@ -290,7 +356,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||
if (type == EnumScrollData.CUSTOM_ABILITIES) {
|
||||
String prevSelected = scroll != null ? scroll.getSelected() : null;
|
||||
this.abilityData = data;
|
||||
this.customData = data;
|
||||
displayToUuid.clear();
|
||||
for (String key : data.keySet()) {
|
||||
// key format: "displayName\tUUID"
|
||||
@@ -303,18 +369,30 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
displayToUuid.put(key, key);
|
||||
}
|
||||
}
|
||||
if (scroll != null) {
|
||||
if (!showingBuiltIn && scroll != null) {
|
||||
scroll.setList(getSearchList());
|
||||
if (prevSelected != null && displayToUuid.containsKey(prevSelected)) {
|
||||
scroll.setSelected(prevSelected);
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
} else if (type == EnumScrollData.BUILTIN_ABILITIES) {
|
||||
this.builtInData = data;
|
||||
if (showingBuiltIn && scroll != null) {
|
||||
scroll.setList(getSearchList());
|
||||
if (selected != null && builtInData.containsKey(selected)) {
|
||||
scroll.setSelected(selected);
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
// Check if this is a built-in ability response
|
||||
currentIsBuiltIn = compound.hasKey("BuiltIn") && compound.getBoolean("BuiltIn");
|
||||
|
||||
// Received ability data from server
|
||||
selectedAbility = AbilityController.Instance.fromNBT(compound);
|
||||
if (selectedAbility != null) {
|
||||
@@ -337,27 +415,111 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiAbilityTypeSelect) {
|
||||
String typeId = ((SubGuiAbilityTypeSelect) subgui).getSelectedTypeId();
|
||||
if (typeId != null) {
|
||||
Ability newAbility = AbilityController.Instance.create(typeId);
|
||||
if (subgui instanceof SubGuiAbilityVariantSelect) {
|
||||
SubGuiAbilityVariantSelect variantGui = (SubGuiAbilityVariantSelect) subgui;
|
||||
int idx = variantGui.getSelectedIndex();
|
||||
if (idx >= 0 && pendingTypeId != null) {
|
||||
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
|
||||
if (newAbility != null) {
|
||||
variantGui.getVariants().get(idx).apply(newAbility);
|
||||
newAbility.setId(UUID.randomUUID().toString());
|
||||
newAbility.setName(newAbility.getTypeId());
|
||||
// Save to server, then open config GUI
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(newAbility.writeNBT()));
|
||||
selectedAbility = newAbility;
|
||||
selected = newAbility.getName();
|
||||
selectedUuid = newAbility.getId();
|
||||
previewExecutor.stop();
|
||||
setSubGui(selectedAbility.createConfigGui(this));
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
pendingNewCreation = true;
|
||||
pendingTypeId = null;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return;
|
||||
}
|
||||
pendingTypeId = null;
|
||||
openConfig(newAbility);
|
||||
return;
|
||||
}
|
||||
}
|
||||
pendingTypeId = null;
|
||||
} else if (subgui instanceof SubGuiAbilityTypeSelect) {
|
||||
String typeId = ((SubGuiAbilityTypeSelect) subgui).getSelectedTypeId();
|
||||
if (typeId != null) {
|
||||
java.util.List<AbilityVariant> variants = AbilityController.Instance.getVariantsForType(typeId);
|
||||
if (variants.size() > 1) {
|
||||
pendingTypeId = typeId;
|
||||
setSubGui(new SubGuiAbilityVariantSelect(variants));
|
||||
return;
|
||||
}
|
||||
Ability newAbility = AbilityController.Instance.create(typeId);
|
||||
if (newAbility != null) {
|
||||
if (variants.size() == 1) {
|
||||
variants.get(0).apply(newAbility);
|
||||
}
|
||||
newAbility.setId(UUID.randomUUID().toString());
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
pendingNewCreation = true;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return;
|
||||
}
|
||||
openConfig(newAbility);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (subgui instanceof SubGuiDuplicateNameConfirm) {
|
||||
SubGuiDuplicateNameConfirm confirm = (SubGuiDuplicateNameConfirm) subgui;
|
||||
if (confirm.isConfirmed() && pendingSaveAbility != null) {
|
||||
if (pendingNewCreation) {
|
||||
openConfig(pendingSaveAbility);
|
||||
pendingSaveAbility = null;
|
||||
pendingNewCreation = false;
|
||||
return;
|
||||
} else {
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
pendingSaveAbility = null;
|
||||
}
|
||||
} else if (pendingSaveAbility != null) {
|
||||
if (pendingNewCreation) {
|
||||
// Cancel new creation - discard
|
||||
pendingSaveAbility = null;
|
||||
pendingNewCreation = false;
|
||||
} else {
|
||||
// Cancel edit save - re-open config GUI to change name
|
||||
Ability ability = pendingSaveAbility;
|
||||
pendingSaveAbility = null;
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if (pendingSaveAbility != null) {
|
||||
// Config GUI closed with a pending save (set by onAbilitySaved)
|
||||
if (hasDuplicateName(pendingSaveAbility)) {
|
||||
pendingNewCreation = false;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return;
|
||||
}
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitiesGetPacket());
|
||||
pendingSaveAbility = null;
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
|
||||
private void openConfig(Ability ability) {
|
||||
selectedAbility = ability;
|
||||
selected = ability.getName();
|
||||
selectedUuid = ability.getId();
|
||||
previewExecutor.stop();
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
}
|
||||
|
||||
private boolean hasDuplicateName(Ability ability) {
|
||||
String name = ability.getName();
|
||||
if (name == null || name.isEmpty()) return false;
|
||||
for (java.util.Map.Entry<String, String> entry : displayToUuid.entrySet()) {
|
||||
if (entry.getKey().equals(name) && !entry.getValue().equals(ability.getId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirmClicked(boolean result, int id) {
|
||||
NoppesUtil.openGUI(player, this);
|
||||
@@ -375,7 +537,8 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
@Override
|
||||
public void onAbilitySaved(Ability ability) {
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
|
||||
// Defer save until subGuiClosed where we can check for duplicate names
|
||||
pendingSaveAbility = ability;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -337,18 +337,45 @@ public class GuiNPCTrader extends GuiContainerNPCInterface implements IGuiData {
|
||||
protected void handleMouseClick(Slot slot, int slotId, int mouseButton, int modifier) {
|
||||
// Client-side balance prediction: immediately subtract currency cost on click
|
||||
// so the displayed balance updates instantly without waiting for server response.
|
||||
// Must mirror ALL server-side checks in ContainerNPCTrader.slotClick() to avoid
|
||||
// predicting a deduction for trades the server will reject.
|
||||
if (slotId >= 0 && slotId < 18 && mouseButton == 0) {
|
||||
long cost = currencyCost[slotId];
|
||||
if (cost > 0 && playerBalance >= cost) {
|
||||
ItemStack sold = role.inventorySold.items.get(slotId);
|
||||
if (sold != null && container.canBuy(slotId, player)) {
|
||||
if (sold != null
|
||||
&& canGivePlayerClient(sold)
|
||||
&& container.isSlotEnabled(slotId, player)
|
||||
&& (!stockEnabled || availableStock[slotId] > 0)
|
||||
&& container.canBuy(slotId, player)) {
|
||||
playerBalance -= cost;
|
||||
if (stockEnabled && availableStock[slotId] < Integer.MAX_VALUE) {
|
||||
availableStock[slotId]--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
super.handleMouseClick(slot, slotId, mouseButton, modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Client-side mirror of ContainerNPCTrader.canGivePlayer.
|
||||
* Checks if the item can be added to the player's cursor stack.
|
||||
*/
|
||||
private boolean canGivePlayerClient(ItemStack item) {
|
||||
ItemStack held = player.inventory.getItemStack();
|
||||
if (held == null) {
|
||||
return true;
|
||||
}
|
||||
if (NoppesUtilPlayer.compareItems(held, item, false, false)) {
|
||||
int k1 = item.stackSize;
|
||||
if (k1 > 0 && k1 + held.stackSize <= held.getMaxStackSize()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
}
|
||||
|
||||
@@ -4,15 +4,10 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.PreviewEntityHandler;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityAbilityProjectile;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.controllers.data.AnimationData;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
@@ -25,38 +20,39 @@ import java.util.List;
|
||||
/**
|
||||
* Client-side executor for previewing abilities in the GUI.
|
||||
*
|
||||
* Lifecycle:
|
||||
* 1. WINDUP phase - plays windup animation, entities spawn and charge
|
||||
* 2. ACTIVE phase - plays active animation, entities fire and move
|
||||
* 3. EXTENDED phase - continues for +100 ticks after animations to see results
|
||||
* 4. IDLE - preview complete
|
||||
* Uses unified execution: calls the REAL ability methods (onWindUpTick, onExecute, onActiveTick)
|
||||
* with previewMode=true. Abilities skip damage/effects/sounds when isPreview() returns true.
|
||||
*
|
||||
* Features:
|
||||
* - Invisible fake target NPC placed in front of the preview NPC for targeting
|
||||
* - NPC movement tracking for abilities that move the NPC (e.g. slam)
|
||||
* Lifecycle:
|
||||
* 1. WINDUP phase - real onWindUpTick() called, telegraph shown, entities may spawn
|
||||
* 2. ACTIVE phase - real onExecute() then onActiveTick() called, physics simulated
|
||||
* 3. EXTENDED phase - 100 extra ticks to observe results (entities continue updating)
|
||||
* 4. IDLE - preview complete
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class AbilityPreviewExecutor {
|
||||
public class AbilityPreviewExecutor implements PreviewEntityHandler {
|
||||
|
||||
// ==================== PREVIEW STATE ====================
|
||||
private Ability previewAbility;
|
||||
private EntityNPCInterface previewNpc;
|
||||
private AbilityPhase phase = AbilityPhase.IDLE;
|
||||
|
||||
/** Executor's own phase tracking (separate from ability.getPhase()) */
|
||||
private enum ExecutorPhase { IDLE, WINDUP, ACTIVE, EXTENDED }
|
||||
private ExecutorPhase executorPhase = ExecutorPhase.IDLE;
|
||||
|
||||
private int currentTick = 0;
|
||||
private boolean playing = false;
|
||||
private boolean paused = false;
|
||||
|
||||
// ==================== TIMING ====================
|
||||
private static final int EXTENDED_DURATION = 100;
|
||||
private int activeDuration = 40;
|
||||
private int maxPreviewDuration = 200;
|
||||
|
||||
// ==================== FAKE TARGET ====================
|
||||
/** Invisible fake target NPC for ability targeting (placed 5 blocks in front of preview NPC) */
|
||||
private EntityNPCInterface fakeTarget;
|
||||
private static final double TARGET_DISTANCE = 5.0;
|
||||
|
||||
// ==================== NPC START POSITION ====================
|
||||
/** Saved NPC position for restoring after movement abilities */
|
||||
private double npcStartX, npcStartY, npcStartZ;
|
||||
|
||||
// ==================== PREVIEW CONTENT ====================
|
||||
@@ -74,7 +70,8 @@ public class AbilityPreviewExecutor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start previewing an ability.
|
||||
* Start previewing an ability using unified execution.
|
||||
* Sets previewMode=true on the ability, then calls its real methods.
|
||||
*/
|
||||
public void startPreview(Ability ability, EntityNPCInterface npc) {
|
||||
stop();
|
||||
@@ -84,31 +81,35 @@ public class AbilityPreviewExecutor {
|
||||
this.currentTick = 0;
|
||||
this.playing = true;
|
||||
this.paused = false;
|
||||
this.activeDuration = ability.getPreviewActiveDuration();
|
||||
this.maxPreviewDuration = ability.getMaxPreviewDuration();
|
||||
|
||||
// Save NPC start position for restoring later
|
||||
this.npcStartX = npc.posX;
|
||||
this.npcStartY = npc.posY;
|
||||
this.npcStartZ = npc.posZ;
|
||||
|
||||
// Enable preview mode on the ability
|
||||
ability.setPreviewMode(true);
|
||||
ability.setPreviewEntityHandler(this);
|
||||
|
||||
// Create invisible fake target NPC for targeting
|
||||
createFakeTarget(npc);
|
||||
|
||||
// Set preview target on the ability
|
||||
ability.setPreviewTarget(fakeTarget);
|
||||
|
||||
// Start tracking NPC movement
|
||||
if (parentGui != null) {
|
||||
parentGui.startTrackingMovement();
|
||||
}
|
||||
|
||||
// Use the ability's real start() method with the fake target
|
||||
ability.start(fakeTarget);
|
||||
|
||||
if (ability.getWindUpTicks() <= 0) {
|
||||
// No windup — go straight to active
|
||||
this.phase = AbilityPhase.ACTIVE;
|
||||
this.executorPhase = ExecutorPhase.ACTIVE;
|
||||
transitionToActive();
|
||||
} else {
|
||||
// Normal windup flow
|
||||
this.phase = AbilityPhase.WINDUP;
|
||||
this.executorPhase = ExecutorPhase.WINDUP;
|
||||
|
||||
// Create telegraph for preview
|
||||
previewTelegraph = ability.createTelegraph(npc, fakeTarget);
|
||||
@@ -121,24 +122,17 @@ public class AbilityPreviewExecutor {
|
||||
data.setAnimation(windUpAnim);
|
||||
data.animation.paused = false;
|
||||
}
|
||||
|
||||
// Spawn preview entity on first tick if ability spawns during windup
|
||||
if (ability.spawnPreviewDuringWindup()) {
|
||||
spawnPreviewEntity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an invisible fake target NPC placed in front of the preview NPC.
|
||||
* This entity is NOT rendered - it only exists for ability targeting logic.
|
||||
*/
|
||||
private void createFakeTarget(EntityNPCInterface npc) {
|
||||
if (npc.worldObj == null) return;
|
||||
|
||||
try {
|
||||
fakeTarget = new EntityCustomNpc(npc.worldObj);
|
||||
// Position target in front of NPC based on its facing direction
|
||||
float facingYaw = GuiAbilityInterface.NPC_FACING_YAW;
|
||||
double yawRad = Math.toRadians(facingYaw);
|
||||
double targetX = npc.posX - Math.sin(yawRad) * TARGET_DISTANCE;
|
||||
@@ -153,15 +147,12 @@ public class AbilityPreviewExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fake target entity for abilities that need a target.
|
||||
*/
|
||||
public EntityLivingBase getFakeTarget() {
|
||||
return fakeTarget;
|
||||
}
|
||||
|
||||
public void play() {
|
||||
if (previewAbility == null || phase == AbilityPhase.IDLE) {
|
||||
if (previewAbility == null || executorPhase == ExecutorPhase.IDLE) {
|
||||
return;
|
||||
}
|
||||
playing = true;
|
||||
@@ -178,6 +169,9 @@ public class AbilityPreviewExecutor {
|
||||
public void pause() {
|
||||
paused = true;
|
||||
|
||||
// Immediately sync prevPos to pos for NPC and all entities to prevent interpolation jitter
|
||||
syncPrevPositions();
|
||||
|
||||
if (previewNpc != null) {
|
||||
AnimationData data = previewNpc.display.animationData;
|
||||
if (data.animation != null) {
|
||||
@@ -186,10 +180,37 @@ public class AbilityPreviewExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync prevPos to pos for the NPC and all preview entities.
|
||||
* Prevents rendering interpolation jitter when standing still or paused.
|
||||
*/
|
||||
private void syncPrevPositions() {
|
||||
if (previewNpc != null) {
|
||||
previewNpc.prevPosX = previewNpc.posX;
|
||||
previewNpc.prevPosY = previewNpc.posY;
|
||||
previewNpc.prevPosZ = previewNpc.posZ;
|
||||
}
|
||||
for (Entity entity : previewEntities) {
|
||||
if (entity != null && !entity.isDead) {
|
||||
entity.prevPosX = entity.posX;
|
||||
entity.prevPosY = entity.posY;
|
||||
entity.prevPosZ = entity.posZ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
// Clean up the ability
|
||||
if (previewAbility != null) {
|
||||
previewAbility.cleanup();
|
||||
previewAbility.setPreviewMode(false);
|
||||
previewAbility.setPreviewEntityHandler(null);
|
||||
previewAbility.reset();
|
||||
}
|
||||
|
||||
playing = false;
|
||||
paused = false;
|
||||
phase = AbilityPhase.IDLE;
|
||||
executorPhase = ExecutorPhase.IDLE;
|
||||
currentTick = 0;
|
||||
|
||||
previewTelegraph = null;
|
||||
@@ -211,9 +232,11 @@ public class AbilityPreviewExecutor {
|
||||
previewNpc.prevPosX = npcStartX;
|
||||
previewNpc.prevPosY = npcStartY;
|
||||
previewNpc.prevPosZ = npcStartZ;
|
||||
previewNpc.motionX = 0;
|
||||
previewNpc.motionY = 0;
|
||||
previewNpc.motionZ = 0;
|
||||
}
|
||||
|
||||
// Remove fake target
|
||||
fakeTarget = null;
|
||||
|
||||
if (previewNpc != null) {
|
||||
@@ -224,13 +247,24 @@ public class AbilityPreviewExecutor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tick the preview forward.
|
||||
* Tick the preview forward. Calls real ability methods.
|
||||
*/
|
||||
public void tick() {
|
||||
if (!playing || paused || previewAbility == null || previewNpc == null) {
|
||||
if (!playing || previewAbility == null || previewNpc == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (paused) {
|
||||
// Sync prevPos to pos for NPC and all entities to prevent interpolation jitter while paused
|
||||
syncPrevPositions();
|
||||
return;
|
||||
}
|
||||
|
||||
// Sync NPC's prevPos to current pos BEFORE any updates to prevent jitter when standing still
|
||||
previewNpc.prevPosX = previewNpc.posX;
|
||||
previewNpc.prevPosY = previewNpc.posY;
|
||||
previewNpc.prevPosZ = previewNpc.posZ;
|
||||
|
||||
currentTick++;
|
||||
|
||||
if (previewTelegraph != null) {
|
||||
@@ -239,14 +273,14 @@ public class AbilityPreviewExecutor {
|
||||
|
||||
tickEntities();
|
||||
|
||||
switch (phase) {
|
||||
switch (executorPhase) {
|
||||
case WINDUP:
|
||||
tickWindup();
|
||||
break;
|
||||
case ACTIVE:
|
||||
tickActive();
|
||||
break;
|
||||
case IDLE:
|
||||
case EXTENDED:
|
||||
tickExtended();
|
||||
break;
|
||||
default:
|
||||
@@ -255,7 +289,8 @@ public class AbilityPreviewExecutor {
|
||||
}
|
||||
|
||||
private void tickWindup() {
|
||||
previewAbility.onPreviewWindUpTick(previewNpc, currentTick);
|
||||
// Call the REAL windup tick method
|
||||
previewAbility.onWindUpTick(previewNpc, fakeTarget, currentTick);
|
||||
|
||||
if (currentTick >= previewAbility.getWindUpTicks()) {
|
||||
transitionToActive();
|
||||
@@ -263,35 +298,41 @@ public class AbilityPreviewExecutor {
|
||||
}
|
||||
|
||||
private void tickActive() {
|
||||
previewAbility.onPreviewActiveTick(previewNpc, currentTick);
|
||||
// Call the REAL active tick method
|
||||
previewAbility.onActiveTick(previewNpc, fakeTarget, currentTick);
|
||||
|
||||
if (currentTick == 1 && !previewAbility.spawnPreviewDuringWindup()) {
|
||||
spawnPreviewEntity();
|
||||
fireEntities();
|
||||
// Simulate physics for movement abilities
|
||||
simulatePhysics();
|
||||
|
||||
// Check if the ability signaled completion (phase went to IDLE)
|
||||
if (previewAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
transitionToExtended();
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentTick >= activeDuration) {
|
||||
// Safety timeout
|
||||
if (currentTick >= maxPreviewDuration) {
|
||||
transitionToExtended();
|
||||
}
|
||||
}
|
||||
|
||||
private void tickExtended() {
|
||||
// Continue ticking entities so they can finish their animations
|
||||
if (currentTick >= EXTENDED_DURATION) {
|
||||
playing = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void transitionToActive() {
|
||||
phase = AbilityPhase.ACTIVE;
|
||||
executorPhase = ExecutorPhase.ACTIVE;
|
||||
currentTick = 0;
|
||||
|
||||
previewTelegraph = null;
|
||||
|
||||
// Notify ability of execution (for movement abilities like Slam/Charge/Dash)
|
||||
previewAbility.onPreviewExecute(previewNpc);
|
||||
|
||||
fireEntities();
|
||||
// Call the REAL onExecute method (fires entities, initiates movement, etc.)
|
||||
previewAbility.onExecute(previewNpc, fakeTarget);
|
||||
|
||||
// Start active animation
|
||||
Animation activeAnim = previewAbility.getActiveAnimation();
|
||||
if (activeAnim != null && previewNpc != null) {
|
||||
AnimationData data = previewNpc.display.animationData;
|
||||
@@ -301,7 +342,7 @@ public class AbilityPreviewExecutor {
|
||||
}
|
||||
|
||||
private void transitionToExtended() {
|
||||
phase = AbilityPhase.IDLE;
|
||||
executorPhase = ExecutorPhase.EXTENDED;
|
||||
currentTick = 0;
|
||||
|
||||
if (previewNpc != null) {
|
||||
@@ -310,26 +351,40 @@ public class AbilityPreviewExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnPreviewEntity() {
|
||||
Entity entity = previewAbility.createPreviewEntity(previewNpc);
|
||||
if (entity != null) {
|
||||
previewEntities.add(entity);
|
||||
if (parentGui != null) {
|
||||
parentGui.addPreviewEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Simulate basic physics for movement abilities (Slam, Charge, Dash).
|
||||
* Applies gravity, drag, and ground clamping to NPC position.
|
||||
*/
|
||||
private void simulatePhysics() {
|
||||
if (!previewAbility.hasAbilityMovement()) return;
|
||||
if (previewNpc == null) return;
|
||||
|
||||
private void fireEntities() {
|
||||
for (Entity entity : previewEntities) {
|
||||
if (entity instanceof EntityAbilityOrb) {
|
||||
((EntityAbilityOrb) entity).startPreviewFiring();
|
||||
} else if (entity instanceof EntityAbilityBeam) {
|
||||
((EntityAbilityBeam) entity).startPreviewFiring();
|
||||
} else if (entity instanceof EntityAbilityDisc) {
|
||||
((EntityAbilityDisc) entity).startPreviewFiring();
|
||||
}
|
||||
// Save previous position for interpolation
|
||||
previewNpc.prevPosX = previewNpc.posX;
|
||||
previewNpc.prevPosY = previewNpc.posY;
|
||||
previewNpc.prevPosZ = previewNpc.posZ;
|
||||
|
||||
// Apply velocity
|
||||
previewNpc.posX += previewNpc.motionX;
|
||||
previewNpc.posY += previewNpc.motionY;
|
||||
previewNpc.posZ += previewNpc.motionZ;
|
||||
|
||||
// Apply gravity
|
||||
previewNpc.motionY -= 0.08;
|
||||
previewNpc.motionY *= 0.98;
|
||||
|
||||
// Apply horizontal drag
|
||||
previewNpc.motionX *= 0.91;
|
||||
previewNpc.motionZ *= 0.91;
|
||||
|
||||
// Ground clamp: if below start position and falling, stop
|
||||
if (previewNpc.posY < npcStartY && previewNpc.motionY < 0) {
|
||||
previewNpc.posY = npcStartY;
|
||||
previewNpc.motionY = 0;
|
||||
previewNpc.onGround = true;
|
||||
}
|
||||
|
||||
previewNpc.fallDistance = 0;
|
||||
}
|
||||
|
||||
private void tickEntities() {
|
||||
@@ -347,12 +402,38 @@ public class AbilityPreviewExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== PreviewEntityHandler ====================
|
||||
|
||||
@Override
|
||||
public void onEntitySpawned(Entity entity) {
|
||||
if (entity == null) return;
|
||||
previewEntities.add(entity);
|
||||
if (parentGui != null) {
|
||||
parentGui.addPreviewEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityRemoved(Entity entity) {
|
||||
if (entity == null) return;
|
||||
previewEntities.remove(entity);
|
||||
if (parentGui != null) {
|
||||
parentGui.removePreviewEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== GETTERS ====================
|
||||
|
||||
public boolean isPlaying() { return playing; }
|
||||
public boolean isPaused() { return paused; }
|
||||
public boolean isActive() { return playing || paused; }
|
||||
public AbilityPhase getPhase() { return phase; }
|
||||
public AbilityPhase getPhase() {
|
||||
switch (executorPhase) {
|
||||
case WINDUP: return AbilityPhase.WINDUP;
|
||||
case ACTIVE: return AbilityPhase.ACTIVE;
|
||||
default: return AbilityPhase.IDLE;
|
||||
}
|
||||
}
|
||||
public int getCurrentTick() { return currentTick; }
|
||||
public TelegraphInstance getTelegraph() { return previewTelegraph; }
|
||||
public List<Entity> getPreviewEntities() { return previewEntities; }
|
||||
@@ -364,11 +445,11 @@ public class AbilityPreviewExecutor {
|
||||
return "Stopped";
|
||||
} else if (paused) {
|
||||
return "Paused";
|
||||
} else if (phase == AbilityPhase.WINDUP) {
|
||||
} else if (executorPhase == ExecutorPhase.WINDUP) {
|
||||
return "Windup: " + currentTick + "/" + (previewAbility != null ? previewAbility.getWindUpTicks() : 0);
|
||||
} else if (phase == AbilityPhase.ACTIVE) {
|
||||
return "Active: " + currentTick + "/" + activeDuration;
|
||||
} else if (phase == AbilityPhase.IDLE && playing) {
|
||||
} else if (executorPhase == ExecutorPhase.ACTIVE) {
|
||||
return "Active: " + currentTick + "/" + maxPreviewDuration;
|
||||
} else if (executorPhase == ExecutorPhase.EXTENDED) {
|
||||
return "Extended: " + currentTick + "/" + EXTENDED_DURATION;
|
||||
}
|
||||
return "";
|
||||
|
||||
@@ -11,10 +11,7 @@ import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.client.ClientEventHandler;
|
||||
import noppes.npcs.client.EntityUtil;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.entity.data.ModelData;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
@@ -50,7 +47,6 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
|
||||
private GuiNpcButton btnLeft, btnRight;
|
||||
|
||||
// ==================== NPC STATE ====================
|
||||
public ModelData playerdata;
|
||||
public EntityNPCInterface npc;
|
||||
|
||||
/** NPC starting position (saved when preview starts, used to track movement) */
|
||||
@@ -85,7 +81,6 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
|
||||
public GuiAbilityInterface(EntityNPCInterface npc, boolean hasMenuNpc) {
|
||||
super(hasMenuNpc ? npc : null);
|
||||
this.npc = npc;
|
||||
this.playerdata = ((EntityCustomNpc) npc).modelData;
|
||||
this.drawDefaultBackground = false;
|
||||
|
||||
CAMERA_ZOOM = 30f;
|
||||
@@ -135,20 +130,17 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
|
||||
* Draw the 3D preview with NPC and entities.
|
||||
*/
|
||||
protected void drawPreview(int mouseX, int mouseY, float partialTicks) {
|
||||
if (hasSubGui())
|
||||
return;
|
||||
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
|
||||
// Enable scissor to clip rendering to preview area
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
setScissorClip(previewX, previewY, previewWidth, previewHeight);
|
||||
|
||||
// Get the entity to render (could be transformed player model)
|
||||
EntityLivingBase renderEntity = playerdata.getEntity(npc);
|
||||
if (renderEntity == null) {
|
||||
renderEntity = this.npc;
|
||||
}
|
||||
|
||||
// Sync NPC properties to render entity
|
||||
EntityUtil.Copy(npc, renderEntity);
|
||||
// Always use the standard NPC animation renderer for ability preview
|
||||
EntityLivingBase renderEntity = this.npc;
|
||||
|
||||
// Set NPC facing direction (affects anchor points and visual facing)
|
||||
npc.prevRenderYawOffset = npc.renderYawOffset = NPC_FACING_YAW;
|
||||
@@ -204,11 +196,7 @@ public class GuiAbilityInterface extends GuiNPCInterface2 {
|
||||
ClientEventHandler.renderingEntityInGUI = true;
|
||||
|
||||
// Render the NPC at its position delta (for movement like slam jumps)
|
||||
try {
|
||||
RenderManager.instance.renderEntityWithPosYaw(renderEntity, npcDeltaX, npcDeltaY, npcDeltaZ, 0.0F, partialTicks);
|
||||
} catch (Exception e) {
|
||||
playerdata.setEntityClass(null);
|
||||
}
|
||||
RenderManager.instance.renderEntityWithPosYaw(renderEntity, npcDeltaX, npcDeltaY, npcDeltaZ, 0.0F, partialTicks);
|
||||
|
||||
// Render preview entities at their positions relative to NPC start position
|
||||
renderPreviewEntities(partialTicks);
|
||||
|
||||
@@ -200,7 +200,8 @@ public class GuiCustomScroll extends GuiScreen {
|
||||
int k = (14 * i + 4) - scrollY;
|
||||
if (k >= 4 && k + 12 < ySize) {
|
||||
int xOffset = scrollHeight < ySize - 8 ? 0 : 10;
|
||||
String displayString = StatCollector.translateToLocal(list.get(i));
|
||||
String rawEntry = list.get(i);
|
||||
String displayString = StatCollector.translateToLocal(rawEntry);
|
||||
|
||||
String text = "";
|
||||
float maxWidth = (xSize + xOffset - 8) * 0.8f;
|
||||
@@ -215,7 +216,13 @@ public class GuiCustomScroll extends GuiScreen {
|
||||
text += "...";
|
||||
} else
|
||||
text = displayString;
|
||||
if ((multipleSelection && selectedList.contains(text)) || (!multipleSelection && selected == i)) {
|
||||
|
||||
// Entries with a custom color are non-interactive (headers/separators)
|
||||
Integer customColor = colors.get(rawEntry);
|
||||
if (customColor != null) {
|
||||
if (!text.isEmpty())
|
||||
fontRendererObj.drawString(text, j, k, customColor);
|
||||
} else if ((multipleSelection && selectedList.contains(text)) || (!multipleSelection && selected == i)) {
|
||||
drawVerticalLine(j - 2, k - 4, k + 10, 0xffffffff);
|
||||
drawVerticalLine(j + xSize - 18 + xOffset, k - 4, k + 10, 0xffffffff);
|
||||
drawHorizontalLine(j - 2, j + xSize - 18 + xOffset, k - 3, 0xffffffff);
|
||||
@@ -239,13 +246,17 @@ public class GuiCustomScroll extends GuiScreen {
|
||||
private int getMouseOver(int i, int j) {
|
||||
i -= guiLeft;
|
||||
j -= guiTop;
|
||||
//fontRenderer.drawString(".", i , j, 0xffffff);
|
||||
if (i >= 4 && i < xSize - 4 && j >= 4 && j < ySize) {
|
||||
for (int j1 = 0; j1 < list.size(); j1++) {
|
||||
if (!mouseInOption(i, j, j1)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip non-interactive entries (colored headers/separators)
|
||||
if (colors.containsKey(list.get(j1))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return j1;
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (GuiNpcTextField tf : new ArrayList<GuiNpcTextField>(textfields.values()))
|
||||
if (tf.enabled)
|
||||
tf.mouseClicked(i, j, k);
|
||||
@@ -415,7 +415,7 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
if (tf.hasHoverText())
|
||||
tf.drawHover(i, j, subGui);
|
||||
}
|
||||
|
||||
|
||||
for (GuiScreen gui : extra.values())
|
||||
gui.drawScreen(i, j, f);
|
||||
|
||||
@@ -439,8 +439,7 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
int bottomHeight = 0;
|
||||
int bottomTextureV = 0;
|
||||
if (ySize < bgTextureHeight) {
|
||||
// Keep bottom border from texture bottom (last 6 pixels of actual content)
|
||||
bottomHeight = 6;
|
||||
bottomHeight = -1;
|
||||
topHeight = ySize - bottomHeight;
|
||||
bottomTextureV = bgTextureHeight - bottomHeight;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
private ITextfieldListener listener;
|
||||
public int id;
|
||||
public int min = 0, max = Integer.MAX_VALUE, def = 0;
|
||||
public double minDouble = 0, maxDouble = Double.MAX_VALUE, defDouble = 0;
|
||||
public float minFloat = 0, maxFloat = Float.MAX_VALUE, defFloat = 0;
|
||||
public double minDouble = Double.NEGATIVE_INFINITY, maxDouble = Double.POSITIVE_INFINITY, defDouble = 0;
|
||||
public float minFloat = Float.NEGATIVE_INFINITY, maxFloat = Float.POSITIVE_INFINITY, defFloat = 0;
|
||||
protected static GuiNpcTextField activeTextfield = null;
|
||||
public boolean canEdit = true;
|
||||
public String hoverableText = "";
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ImageData {
|
||||
|
||||
public ImageData(String directory) {
|
||||
this.location = new ResourceLocation(directory);
|
||||
if (directory.startsWith("https://")) {
|
||||
if (directory.startsWith("https://") || directory.startsWith("http://")) {
|
||||
this.isUrl = true;
|
||||
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
||||
this.imageDownloadAlt = new ImageDownloadAlt(null, directory, new ResourceLocation("customnpcs:textures/gui/invisible.png"), new ImageBufferDownloadAlt(true, false));
|
||||
|
||||
@@ -1,5 +1,83 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
import net.minecraft.potion.Potion;
|
||||
|
||||
public enum EnumPotionType {
|
||||
None, Fire, Poison, Hunger, Weakness, Slowness, Nausea, Blindness, Wither;
|
||||
None("gui.none", -1),
|
||||
Fire("tile.fire.name", -1),
|
||||
Poison("potion.poison", Potion.poison.id),
|
||||
Hunger("potion.hunger", Potion.hunger.id),
|
||||
Weakness("potion.weakness", Potion.weakness.id),
|
||||
Slowness("potion.moveSlowdown", Potion.moveSlowdown.id),
|
||||
Nausea("potion.confusion", Potion.confusion.id),
|
||||
Blindness("potion.blindness", Potion.blindness.id),
|
||||
Wither("potion.wither", Potion.wither.id),
|
||||
MiningFatigue("potion.digSlowDown", Potion.digSlowdown.id),
|
||||
Manual("effect.manual", -1);
|
||||
|
||||
private final String langKey;
|
||||
private final int potionId;
|
||||
|
||||
EnumPotionType(String langKey, int potionId) {
|
||||
this.langKey = langKey;
|
||||
this.potionId = potionId;
|
||||
}
|
||||
|
||||
public String getLangKey() {
|
||||
return langKey;
|
||||
}
|
||||
|
||||
public int getPotionId() {
|
||||
return potionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the actual potion ID to apply.
|
||||
* For Manual type, returns the provided manualId.
|
||||
* For all others, returns the mapped potionId.
|
||||
*/
|
||||
public int getResolvedPotionId(int manualId) {
|
||||
if (this == Manual) return manualId;
|
||||
return potionId;
|
||||
}
|
||||
|
||||
public static String[] getLangKeys() {
|
||||
EnumPotionType[] types = values();
|
||||
String[] keys = new String[types.length];
|
||||
for (int i = 0; i < types.length; i++) keys[i] = types[i].langKey;
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns lang keys excluding None. For use in effect lists where None is not a valid choice.
|
||||
*/
|
||||
public static String[] getLangKeysNoNone() {
|
||||
EnumPotionType[] types = values();
|
||||
String[] keys = new String[types.length - 1];
|
||||
for (int i = 1; i < types.length; i++) keys[i - 1] = types[i].langKey;
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a 0-based index (excluding None) back to the corresponding EnumPotionType.
|
||||
* Index 0 = Fire, 1 = Poison, etc.
|
||||
*/
|
||||
public static EnumPotionType fromIndexNoNone(int index) {
|
||||
return fromOrdinal(index + 1);
|
||||
}
|
||||
|
||||
public static EnumPotionType fromOrdinal(int ordinal) {
|
||||
EnumPotionType[] values = values();
|
||||
if (ordinal >= 0 && ordinal < values.length) {
|
||||
return values[ordinal];
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given potion ID is valid and registered in the Minecraft potion registry.
|
||||
*/
|
||||
public static boolean isValidPotionId(int id) {
|
||||
return id >= 0 && id < Potion.potionTypes.length && Potion.potionTypes[id] != null;
|
||||
}
|
||||
}
|
||||
@@ -125,7 +125,13 @@ public enum EnumScriptType {
|
||||
ABILITY_INTERRUPT("abilityInterrupt"),
|
||||
ABILITY_COMPLETE("abilityComplete"),
|
||||
ABILITY_HIT("abilityHit"),
|
||||
ABILITY_TICK("abilityTick");
|
||||
ABILITY_TICK("abilityTick"),
|
||||
|
||||
ENERGY_PROJECTILE_FIRED("energyProjectileFired"),
|
||||
ENERGY_PROJECTILE_TICK("energyProjectileTick"),
|
||||
ENERGY_PROJECTILE_ENTITY_IMPACT("energyProjectileEntityImpact"),
|
||||
ENERGY_PROJECTILE_BLOCK_IMPACT("energyProjectileBlockImpact"),
|
||||
ENERGY_PROJECTILE_EXPIRED("energyProjectileExpired");
|
||||
|
||||
public String function;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ public enum EnumScrollData {
|
||||
QUEST_GROUP,
|
||||
ABILITY_TYPES,
|
||||
CUSTOM_ABILITIES,
|
||||
BUILTIN_ABILITIES,
|
||||
ANIMATIONS,
|
||||
BUILTIN_ANIMATIONS
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
import noppes.npcs.api.event.IAbilityEvent;
|
||||
import noppes.npcs.api.event.IAnimationEvent;
|
||||
import noppes.npcs.api.event.IBlockEvent;
|
||||
import noppes.npcs.api.event.ICustomGuiEvent;
|
||||
import noppes.npcs.api.event.IDialogEvent;
|
||||
import noppes.npcs.api.event.IEnergyProjectileEvent;
|
||||
import noppes.npcs.api.event.IFactionEvent;
|
||||
import noppes.npcs.api.event.IForgeEvent;
|
||||
import noppes.npcs.api.event.IItemEvent;
|
||||
import noppes.npcs.api.event.INpcEvent;
|
||||
import noppes.npcs.api.event.IPartyEvent;
|
||||
import noppes.npcs.api.event.IPlayerAbilityEvent;
|
||||
import noppes.npcs.api.event.IPlayerEvent;
|
||||
import noppes.npcs.api.event.IProjectileEvent;
|
||||
import noppes.npcs.api.event.IQuestEvent;
|
||||
@@ -52,7 +55,10 @@ public class ScriptContext {
|
||||
|
||||
public static final ScriptContext NPC = register("NPC", "npc",
|
||||
INpcEvent.class,
|
||||
IProjectileEvent.class
|
||||
IProjectileEvent.class,
|
||||
IEnergyProjectileEvent.class,
|
||||
IAbilityEvent.class,
|
||||
IAnimationEvent.class
|
||||
);
|
||||
|
||||
public static final ScriptContext PLAYER = register("PLAYER", "player",
|
||||
@@ -62,7 +68,9 @@ public class ScriptContext {
|
||||
IDialogEvent.class,
|
||||
IQuestEvent.class,
|
||||
IFactionEvent.class,
|
||||
ICustomGuiEvent.class
|
||||
ICustomGuiEvent.class,
|
||||
IEnergyProjectileEvent.class,
|
||||
IPlayerAbilityEvent.class
|
||||
);
|
||||
|
||||
public static final ScriptContext BLOCK = register("BLOCK", "block",
|
||||
|
||||
@@ -2,10 +2,12 @@ package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.api.event.IAbilityEvent;
|
||||
import noppes.npcs.api.event.IAnimationEvent;
|
||||
import noppes.npcs.api.event.IPlayerAbilityEvent;
|
||||
import noppes.npcs.api.event.IBlockEvent;
|
||||
import noppes.npcs.api.event.ICustomGuiEvent;
|
||||
import noppes.npcs.api.event.ICustomNPCsEvent;
|
||||
import noppes.npcs.api.event.IDialogEvent;
|
||||
import noppes.npcs.api.event.IEnergyProjectileEvent;
|
||||
import noppes.npcs.api.event.IFactionEvent;
|
||||
import noppes.npcs.api.event.IForgeEvent;
|
||||
import noppes.npcs.api.event.IItemEvent;
|
||||
@@ -106,6 +108,13 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(NPC, PROJECTILE_TICK, IProjectileEvent.UpdateEvent.class);
|
||||
hook(NPC, PROJECTILE_IMPACT, IProjectileEvent.ImpactEvent.class);
|
||||
|
||||
// Energy Projectile
|
||||
hook(NPC, ENERGY_PROJECTILE_FIRED, IEnergyProjectileEvent.FiredEvent.class);
|
||||
hook(NPC, ENERGY_PROJECTILE_TICK, IEnergyProjectileEvent.UpdateEvent.class);
|
||||
hook(NPC, ENERGY_PROJECTILE_ENTITY_IMPACT, IEnergyProjectileEvent.EntityImpactEvent.class);
|
||||
hook(NPC, ENERGY_PROJECTILE_BLOCK_IMPACT, IEnergyProjectileEvent.BlockImpactEvent.class);
|
||||
hook(NPC, ENERGY_PROJECTILE_EXPIRED, IEnergyProjectileEvent.ExpiredEvent.class);
|
||||
|
||||
// Ability
|
||||
hook(NPC, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(NPC, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
@@ -113,6 +122,12 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(NPC, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(NPC, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(NPC, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
|
||||
// Animation
|
||||
hook(NPC, ANIMATION_START, IAnimationEvent.Started.class);
|
||||
hook(NPC, ANIMATION_END, IAnimationEvent.Ended.class);
|
||||
hook(NPC, ANIMATION_FRAME_ENTER, IAnimationEvent.IFrameEvent.Entered.class);
|
||||
hook(NPC, ANIMATION_FRAME_EXIT, IAnimationEvent.IFrameEvent.Exited.class);
|
||||
}
|
||||
|
||||
private void initializePlayerHooks() {
|
||||
@@ -208,6 +223,21 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(PLAYER, ANIMATION_FRAME_ENTER, IAnimationEvent.IFrameEvent.Entered.class);
|
||||
hook(PLAYER, ANIMATION_FRAME_EXIT, IAnimationEvent.IFrameEvent.Exited.class);
|
||||
|
||||
// Energy Projectile
|
||||
hook(PLAYER, ENERGY_PROJECTILE_FIRED, IEnergyProjectileEvent.FiredEvent.class);
|
||||
hook(PLAYER, ENERGY_PROJECTILE_TICK, IEnergyProjectileEvent.UpdateEvent.class);
|
||||
hook(PLAYER, ENERGY_PROJECTILE_ENTITY_IMPACT, IEnergyProjectileEvent.EntityImpactEvent.class);
|
||||
hook(PLAYER, ENERGY_PROJECTILE_BLOCK_IMPACT, IEnergyProjectileEvent.BlockImpactEvent.class);
|
||||
hook(PLAYER, ENERGY_PROJECTILE_EXPIRED, IEnergyProjectileEvent.ExpiredEvent.class);
|
||||
|
||||
// Ability
|
||||
hook(PLAYER, ABILITY_START, IPlayerAbilityEvent.StartEvent.class);
|
||||
hook(PLAYER, ABILITY_EXECUTE, IPlayerAbilityEvent.ExecuteEvent.class);
|
||||
hook(PLAYER, ABILITY_HIT, IPlayerAbilityEvent.HitEvent.class);
|
||||
hook(PLAYER, ABILITY_TICK, IPlayerAbilityEvent.TickEvent.class);
|
||||
hook(PLAYER, ABILITY_INTERRUPT, IPlayerAbilityEvent.InterruptEvent.class);
|
||||
hook(PLAYER, ABILITY_COMPLETE, IPlayerAbilityEvent.CompleteEvent.class);
|
||||
|
||||
// Profile
|
||||
hook(PLAYER, PROFILE_CHANGE, IPlayerEvent.ProfileEvent.Changed.class);
|
||||
hook(PLAYER, PROFILE_REMOVE, IPlayerEvent.ProfileEvent.Removed.class);
|
||||
|
||||
@@ -4,6 +4,7 @@ import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.UserType;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityGuard;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphSpawnPacket;
|
||||
@@ -14,13 +15,21 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.player.PlayerAbilityEvent;
|
||||
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilityStatePacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilitySyncPacket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -52,6 +61,13 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
*/
|
||||
private int selectedIndex = 0;
|
||||
|
||||
/**
|
||||
* Tracks whether the current animation was started by an ability.
|
||||
* Persisted to NBT so orphaned ability animations can be detected and
|
||||
* cleared on login (ability state is transient, but animation state is not).
|
||||
*/
|
||||
private boolean playingAbilityAnimation = false;
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// RUNTIME STATE (not saved)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -76,6 +92,26 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
*/
|
||||
private transient EntityLivingBase currentTarget;
|
||||
|
||||
/**
|
||||
* Rotation lock state - freezes player yaw/pitch during ability phases.
|
||||
*/
|
||||
private transient boolean rotationLocked = false;
|
||||
private transient float lockedYaw = 0;
|
||||
private transient float lockedPitch = 0;
|
||||
|
||||
/**
|
||||
* Position lock state - freezes player position during ability phases.
|
||||
*/
|
||||
private transient boolean positionLocked = false;
|
||||
private transient double lockedPosX = 0;
|
||||
private transient double lockedPosY = 0;
|
||||
private transient double lockedPosZ = 0;
|
||||
|
||||
/**
|
||||
* Last synced state flags byte for change detection (avoids spamming packets).
|
||||
*/
|
||||
private transient byte lastSyncedFlags = 0;
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CONSTRUCTOR
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -99,6 +135,20 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
tickCurrentAbility(player);
|
||||
|
||||
// Apply rotation and position locks after ability tick
|
||||
applyRotationControl(player);
|
||||
applyPositionLock(player);
|
||||
|
||||
// Sync lock state to client (only sends when flags change)
|
||||
syncAbilityStateIfNeeded(player);
|
||||
} else {
|
||||
// Safety: release orphaned locks if no ability is executing
|
||||
if (rotationLocked || positionLocked) {
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
syncAbilityStateClear(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,38 +161,105 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
// Tick advances time and possibly changes phase
|
||||
boolean phaseChanged = currentAbility.tick();
|
||||
|
||||
// Fire tick event for scripts
|
||||
firePlayerTickEvent(player, currentAbility, currentTarget);
|
||||
|
||||
// Fire extender tick hook (e.g., per-tick resource drain)
|
||||
if (!AbilityController.Instance.fireOnAbilityTick(currentAbility, player, currentTarget,
|
||||
currentAbility.getPhase(), currentAbility.getCurrentTick())) {
|
||||
interruptCurrentAbility();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (currentAbility.getPhase()) {
|
||||
case WINDUP:
|
||||
currentAbility.onWindUpTick(player, currentTarget, player.worldObj, currentAbility.getCurrentTick());
|
||||
if (phaseChanged && oldPhase == AbilityPhase.BURST_DELAY) {
|
||||
// Burst replay: re-enter windup - set up locks
|
||||
if (currentAbility.isRotationLockedDuringWindup()) {
|
||||
captureLockedRotation(player);
|
||||
}
|
||||
if (currentAbility.isMovementLockedDuringWindup() && !currentAbility.hasAbilityMovement()) {
|
||||
captureLockedPosition(player);
|
||||
}
|
||||
spawnTelegraph(currentAbility, player, null);
|
||||
playAbilitySound(player, currentAbility.getWindUpSound());
|
||||
playAbilityAnimation(currentAbility.getWindUpAnimation());
|
||||
}
|
||||
currentAbility.onWindUpTick(player, currentTarget, currentAbility.getCurrentTick());
|
||||
break;
|
||||
|
||||
case ACTIVE:
|
||||
if (phaseChanged && oldPhase == AbilityPhase.WINDUP) {
|
||||
// Just entered ACTIVE phase
|
||||
TelegraphInstance telegraph = currentAbility.getTelegraphInstance();
|
||||
if (telegraph != null) {
|
||||
if (phaseChanged && (oldPhase == AbilityPhase.WINDUP || oldPhase == AbilityPhase.BURST_DELAY)) {
|
||||
// Just entered ACTIVE phase - lock all telegraph positions
|
||||
for (TelegraphInstance telegraph : currentAbility.getTelegraphInstances()) {
|
||||
telegraph.lockPosition();
|
||||
}
|
||||
removeTelegraph(currentAbility, player);
|
||||
// Remove telegraph unless the ability keeps it during active phase
|
||||
if (!currentAbility.keepTelegraphDuringActive()) {
|
||||
removeTelegraph(currentAbility, player);
|
||||
}
|
||||
|
||||
// Handle rotation control transition from WINDUP to ACTIVE
|
||||
if (currentAbility.isRotationLockedDuringActive()) {
|
||||
if (!rotationLocked) {
|
||||
captureLockedRotation(player);
|
||||
}
|
||||
} else if (rotationLocked) {
|
||||
releaseRotationControl();
|
||||
}
|
||||
|
||||
// Handle position lock transition from WINDUP to ACTIVE
|
||||
if (currentAbility.isMovementLockedDuringActive() && !currentAbility.hasAbilityMovement()) {
|
||||
if (!positionLocked) {
|
||||
captureLockedPosition(player);
|
||||
}
|
||||
} else if (positionLocked) {
|
||||
releaseLockedPosition();
|
||||
}
|
||||
|
||||
// Play active sound and animation
|
||||
playAbilitySound(player, currentAbility.getActiveSound());
|
||||
playAbilityAnimation(currentAbility.getActiveAnimation());
|
||||
|
||||
// Fire execute event (cancelable)
|
||||
if (firePlayerExecuteEvent(player, currentAbility, currentTarget)) {
|
||||
return; // Cancelled
|
||||
}
|
||||
|
||||
// Call onExecute
|
||||
currentAbility.onExecute(player, currentTarget, player.worldObj);
|
||||
currentAbility.onExecute(player, currentTarget);
|
||||
|
||||
if (currentAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
handleAbilityCompletion(player);
|
||||
return;
|
||||
}
|
||||
}
|
||||
currentAbility.onActiveTick(player, currentTarget, player.worldObj, currentAbility.getCurrentTick());
|
||||
currentAbility.onActiveTick(player, currentTarget, currentAbility.getCurrentTick());
|
||||
|
||||
if (currentAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
handleAbilityCompletion(player);
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto-complete for burst overlap mode (entities fly independently)
|
||||
if (currentAbility.isBurstEnabled()
|
||||
&& currentAbility.getBurstIndex() < currentAbility.getBurstAmount()
|
||||
&& currentAbility.getPhase() == AbilityPhase.ACTIVE
|
||||
&& currentAbility.isReadyForBurstCompletion(currentAbility.getCurrentTick())) {
|
||||
currentAbility.signalCompletion();
|
||||
}
|
||||
|
||||
// Release locks during burst delay
|
||||
if (currentAbility.getPhase() == AbilityPhase.BURST_DELAY) {
|
||||
if (rotationLocked) releaseRotationControl();
|
||||
if (positionLocked) releaseLockedPosition();
|
||||
}
|
||||
break;
|
||||
|
||||
case BURST_DELAY:
|
||||
// Free movement and rotation during burst delay
|
||||
if (rotationLocked) releaseRotationControl();
|
||||
if (positionLocked) releaseLockedPosition();
|
||||
break;
|
||||
|
||||
case DAZED:
|
||||
@@ -161,8 +278,18 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
private void handleAbilityCompletion(EntityPlayer player) {
|
||||
if (currentAbility == null) return;
|
||||
|
||||
// Fire extender complete hook
|
||||
AbilityController.Instance.fireOnAbilityComplete(currentAbility, player, currentTarget, false);
|
||||
|
||||
currentAbility.onComplete(player, currentTarget);
|
||||
|
||||
// Fire complete event
|
||||
firePlayerCompleteEvent(player, currentAbility, currentTarget);
|
||||
|
||||
// Release all locks
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
|
||||
// Apply universal cooldown (using base cooldownTicks only, not min/max random)
|
||||
if (!currentAbility.isIgnoreCooldown()) {
|
||||
cooldownEndTime = player.worldObj.getTotalWorldTime() + currentAbility.getCooldownTicks();
|
||||
@@ -174,6 +301,9 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
currentAbility = null;
|
||||
currentAbilityKey = null;
|
||||
currentTarget = null;
|
||||
|
||||
// Send cleared state to client
|
||||
syncAbilityStateClear(player);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -223,6 +353,16 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
// Check conditions (skip target-requiring ones)
|
||||
if (!ability.checkConditionsForPlayer(player)) return false;
|
||||
|
||||
// Fire extender start hook (e.g., resource cost checks)
|
||||
if (!AbilityController.Instance.fireOnAbilityStart(ability, player, null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fire start event (cancelable)
|
||||
if (firePlayerStartEvent(player, ability)) {
|
||||
return false; // Cancelled
|
||||
}
|
||||
|
||||
// Start the ability
|
||||
currentAbility = ability;
|
||||
currentAbilityKey = key;
|
||||
@@ -231,9 +371,21 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
|
||||
if (ability.getPhase() == AbilityPhase.ACTIVE) {
|
||||
// Windup was 0 — skip telegraph/windup and go straight to active
|
||||
if (ability.isRotationLockedDuringActive()) {
|
||||
captureLockedRotation(player);
|
||||
}
|
||||
if (ability.isMovementLockedDuringActive() && !ability.hasAbilityMovement()) {
|
||||
captureLockedPosition(player);
|
||||
}
|
||||
executeImmediate(ability, player);
|
||||
} else {
|
||||
// Normal windup flow
|
||||
if (ability.isRotationLockedDuringWindup()) {
|
||||
captureLockedRotation(player);
|
||||
}
|
||||
if (ability.isMovementLockedDuringWindup() && !ability.hasAbilityMovement()) {
|
||||
captureLockedPosition(player);
|
||||
}
|
||||
spawnTelegraph(ability, player, null);
|
||||
playAbilitySound(player, ability.getWindUpSound());
|
||||
playAbilityAnimation(ability.getWindUpAnimation());
|
||||
@@ -251,8 +403,13 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
playAbilitySound(player, ability.getActiveSound());
|
||||
playAbilityAnimation(ability.getActiveAnimation());
|
||||
|
||||
// Fire execute event (cancelable)
|
||||
if (firePlayerExecuteEvent(player, ability, currentTarget)) {
|
||||
return; // Cancelled
|
||||
}
|
||||
|
||||
// Call onExecute
|
||||
ability.onExecute(player, currentTarget, player.worldObj);
|
||||
ability.onExecute(player, currentTarget);
|
||||
|
||||
// Check if ability completed during onExecute
|
||||
if (ability.getPhase() == AbilityPhase.IDLE) {
|
||||
@@ -409,15 +566,75 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
}
|
||||
|
||||
public void interruptCurrentAbility() {
|
||||
interruptCurrentAbility(null, 0);
|
||||
}
|
||||
|
||||
public void interruptCurrentAbility(DamageSource source, float damage) {
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
// Fire extender complete hook (interrupted)
|
||||
AbilityController.Instance.fireOnAbilityComplete(currentAbility, playerData.player, currentTarget, true);
|
||||
|
||||
// Fire interrupt event
|
||||
firePlayerInterruptEvent(playerData.player, currentAbility, currentTarget, source, damage);
|
||||
|
||||
currentAbility.interrupt();
|
||||
stopAbilityAnimation();
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
currentAbility = null;
|
||||
currentAbilityKey = null;
|
||||
currentTarget = null;
|
||||
syncAbilityStateClear(playerData.player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle damage taken while an ability is executing.
|
||||
* Called from LivingHurtEvent BEFORE damage is applied to health.
|
||||
* Triggers Guard counter detection and handles ability interruption.
|
||||
*
|
||||
* @param source The damage source
|
||||
* @param amount The damage amount (post-armor)
|
||||
* @return The modified damage amount (reduced by guard, or 0 if counter absorbs)
|
||||
*/
|
||||
public float onDamage(DamageSource source, float amount) {
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) {
|
||||
return amount;
|
||||
}
|
||||
|
||||
net.minecraft.entity.Entity sourceEntity = source.getEntity();
|
||||
EntityLivingBase attacker = sourceEntity instanceof EntityLivingBase ? (EntityLivingBase) sourceEntity : null;
|
||||
|
||||
// Track counter state before calling onDamageTaken
|
||||
boolean wasCounterTriggered = false;
|
||||
if (currentAbility instanceof AbilityGuard) {
|
||||
wasCounterTriggered = ((AbilityGuard) currentAbility).isCounterTriggered();
|
||||
}
|
||||
|
||||
currentAbility.onDamageTaken(playerData.player, attacker, source, amount);
|
||||
|
||||
// Guard: handle damage reduction and counter absorption
|
||||
if (currentAbility instanceof AbilityGuard) {
|
||||
AbilityGuard guard = (AbilityGuard) currentAbility;
|
||||
if (guard.isGuarding()) {
|
||||
// Counter just triggered — absorb full damage
|
||||
if (!wasCounterTriggered && guard.isCounterTriggered()) {
|
||||
return 0;
|
||||
}
|
||||
// Normal guard — apply flat damage reduction
|
||||
float reduction = guard.getDamageReductionFactor();
|
||||
return Math.max(0, amount - reduction);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for ability interruption
|
||||
if (currentAbility != null && currentAbility.canInterrupt(source)) {
|
||||
interruptCurrentAbility(source, amount);
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnCooldown() {
|
||||
EntityPlayer player = playerData.player;
|
||||
@@ -446,28 +663,154 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
&& currentAbility.isMovementLockedForCurrentPhase();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// ROTATION CONTROL
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Capture current rotation values to lock player's look direction.
|
||||
*/
|
||||
private void captureLockedRotation(EntityPlayer player) {
|
||||
lockedYaw = player.rotationYaw;
|
||||
lockedPitch = player.rotationPitch;
|
||||
rotationLocked = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release rotation lock.
|
||||
*/
|
||||
private void releaseRotationControl() {
|
||||
rotationLocked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply rotation control on the server side.
|
||||
* Enforces locked rotation values on the player entity.
|
||||
*/
|
||||
private void applyRotationControl(EntityPlayer player) {
|
||||
if (!rotationLocked || currentAbility == null) return;
|
||||
|
||||
if (currentAbility.isRotationLockedForCurrentPhase()) {
|
||||
player.rotationYaw = lockedYaw;
|
||||
player.rotationPitch = lockedPitch;
|
||||
player.prevRotationYaw = lockedYaw;
|
||||
player.prevRotationPitch = lockedPitch;
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
player.rotationYawHead = lockedYaw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// POSITION LOCKING
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Capture current position to lock player in place.
|
||||
*/
|
||||
private void captureLockedPosition(EntityPlayer player) {
|
||||
lockedPosX = player.posX;
|
||||
lockedPosY = player.posY;
|
||||
lockedPosZ = player.posZ;
|
||||
positionLocked = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release position lock.
|
||||
*/
|
||||
private void releaseLockedPosition() {
|
||||
positionLocked = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply position lock on the server side.
|
||||
* Snaps player back to locked position and zeroes motion.
|
||||
*/
|
||||
private void applyPositionLock(EntityPlayer player) {
|
||||
if (!positionLocked) return;
|
||||
|
||||
player.setPosition(lockedPosX, lockedPosY, lockedPosZ);
|
||||
player.prevPosX = lockedPosX;
|
||||
player.prevPosY = lockedPosY;
|
||||
player.prevPosZ = lockedPosZ;
|
||||
player.motionX = 0;
|
||||
player.motionY = 0; // Full vertical freeze for position lock
|
||||
player.motionZ = 0;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// ABILITY STATE SYNC
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Build the current ability state flags byte.
|
||||
*/
|
||||
private byte getAbilityStateFlags() {
|
||||
byte flags = 0;
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) return flags;
|
||||
|
||||
if (currentAbility.isMovementLockedForCurrentPhase()) {
|
||||
flags |= PlayerAbilityStatePacket.FLAG_MOVEMENT_LOCKED;
|
||||
}
|
||||
if (rotationLocked && currentAbility.isRotationLockedForCurrentPhase()) {
|
||||
flags |= PlayerAbilityStatePacket.FLAG_ROTATION_LOCKED;
|
||||
}
|
||||
if (currentAbility.hasAbilityMovement() && currentAbility.getPhase() == AbilityPhase.ACTIVE) {
|
||||
flags |= PlayerAbilityStatePacket.FLAG_HAS_ABILITY_MOVEMENT;
|
||||
}
|
||||
if (positionLocked) {
|
||||
flags |= PlayerAbilityStatePacket.FLAG_POSITION_LOCKED;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send ability state to client if flags changed since last sync.
|
||||
*/
|
||||
private void syncAbilityStateIfNeeded(EntityPlayer player) {
|
||||
if (!(player instanceof EntityPlayerMP)) return;
|
||||
byte flags = getAbilityStateFlags();
|
||||
if (flags != lastSyncedFlags) {
|
||||
lastSyncedFlags = flags;
|
||||
PlayerAbilityStatePacket.sendToPlayer((EntityPlayerMP) player, flags, lockedYaw, lockedPitch);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send cleared (all-zero) state to client. Called on ability completion/interrupt.
|
||||
*/
|
||||
private void syncAbilityStateClear(EntityPlayer player) {
|
||||
if (!(player instanceof EntityPlayerMP)) return;
|
||||
if (lastSyncedFlags != 0) {
|
||||
lastSyncedFlags = 0;
|
||||
PlayerAbilityStatePacket.sendToPlayer((EntityPlayerMP) player, (byte) 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// TELEGRAPH
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
private void spawnTelegraph(Ability ability, EntityPlayer player, EntityLivingBase target) {
|
||||
TelegraphInstance telegraph = ability.createTelegraph(player, target);
|
||||
if (telegraph != null) {
|
||||
ability.setTelegraphInstance(telegraph);
|
||||
List<TelegraphInstance> telegraphs = ability.createTelegraphs(player, target);
|
||||
if (!telegraphs.isEmpty()) {
|
||||
ability.setTelegraphInstances(telegraphs);
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
TelegraphSpawnPacket.sendToTracking(telegraph, player);
|
||||
for (TelegraphInstance telegraph : telegraphs) {
|
||||
TelegraphSpawnPacket.sendToTracking(telegraph, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeTelegraph(Ability ability, EntityPlayer player) {
|
||||
TelegraphInstance telegraph = ability.getTelegraphInstance();
|
||||
if (telegraph != null) {
|
||||
List<TelegraphInstance> telegraphs = ability.getTelegraphInstances();
|
||||
for (TelegraphInstance telegraph : telegraphs) {
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
TelegraphRemovePacket.sendToTracking(telegraph.getInstanceId(), player);
|
||||
}
|
||||
ability.setTelegraphInstance(null);
|
||||
}
|
||||
ability.setTelegraphInstances(null);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -479,6 +822,7 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
playerData.animationData.setEnabled(true);
|
||||
playerData.animationData.setAnimation(animation);
|
||||
playerData.animationData.updateClient();
|
||||
playingAbilityAnimation = true;
|
||||
}
|
||||
|
||||
public void playAbilityAnimation(int animation) {
|
||||
@@ -500,6 +844,23 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
private void stopAbilityAnimation() {
|
||||
playerData.animationData.setAnimation(null);
|
||||
playerData.animationData.updateClient();
|
||||
playingAbilityAnimation = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an ability-driven animation is currently playing.
|
||||
* Used by PlayerData.onLogin() to detect orphaned ability animations.
|
||||
*/
|
||||
public boolean isPlayingAbilityAnimation() {
|
||||
return playingAbilityAnimation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears an orphaned ability animation (e.g. after relog when the ability is gone).
|
||||
* Stops the animation and resets the tracking flag.
|
||||
*/
|
||||
public void clearOrphanedAbilityAnimation() {
|
||||
stopAbilityAnimation();
|
||||
}
|
||||
|
||||
private void playAbilitySound(EntityPlayer player, String sound) {
|
||||
@@ -508,6 +869,73 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SCRIPT EVENTS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Fire the ability start event. Returns true if cancelled.
|
||||
*/
|
||||
private boolean firePlayerStartEvent(EntityPlayer player, Ability ability) {
|
||||
if (ScriptController.Instance == null) return false;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return false;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.StartEvent event = new PlayerAbilityEvent.StartEvent(iPlayer, ability, null);
|
||||
return EventHooks.onPlayerAbilityStart(handler, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the ability execute event. Returns true if cancelled.
|
||||
*/
|
||||
private boolean firePlayerExecuteEvent(EntityPlayer player, Ability ability, EntityLivingBase target) {
|
||||
if (ScriptController.Instance == null) return false;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return false;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.ExecuteEvent event = new PlayerAbilityEvent.ExecuteEvent(iPlayer, ability, target);
|
||||
return EventHooks.onPlayerAbilityExecute(handler, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the ability tick event.
|
||||
*/
|
||||
private void firePlayerTickEvent(EntityPlayer player, Ability ability, EntityLivingBase target) {
|
||||
if (ScriptController.Instance == null) return;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.TickEvent event = new PlayerAbilityEvent.TickEvent(
|
||||
iPlayer, ability, target, ability.getPhase().ordinal(), ability.getCurrentTick());
|
||||
EventHooks.onPlayerAbilityTick(handler, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the ability interrupt event.
|
||||
*/
|
||||
private void firePlayerInterruptEvent(EntityPlayer player, Ability ability, EntityLivingBase target,
|
||||
DamageSource source, float damage) {
|
||||
if (ScriptController.Instance == null) return;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.InterruptEvent event = new PlayerAbilityEvent.InterruptEvent(
|
||||
iPlayer, ability, target, source, damage);
|
||||
EventHooks.onPlayerAbilityInterrupt(handler, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the ability complete event.
|
||||
*/
|
||||
private void firePlayerCompleteEvent(EntityPlayer player, Ability ability, EntityLivingBase target) {
|
||||
if (ScriptController.Instance == null) return;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.CompleteEvent event = new PlayerAbilityEvent.CompleteEvent(iPlayer, ability, target);
|
||||
EventHooks.onPlayerAbilityComplete(handler, event);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// NBT SERIALIZATION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -519,6 +947,7 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
}
|
||||
compound.setTag("PlayerAbilities", list);
|
||||
compound.setInteger("PlayerAbilitySelected", selectedIndex);
|
||||
compound.setBoolean("AbilityAnimating", playingAbilityAnimation);
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
@@ -533,8 +962,30 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
}
|
||||
}
|
||||
selectedIndex = compound.getInteger("PlayerAbilitySelected");
|
||||
|
||||
// Prune abilities that no longer exist (deleted custom abilities or removed built-ins)
|
||||
validateUnlockedAbilities();
|
||||
|
||||
if (selectedIndex >= unlockedAbilities.size()) {
|
||||
selectedIndex = Math.max(0, unlockedAbilities.size() - 1);
|
||||
}
|
||||
playingAbilityAnimation = compound.getBoolean("AbilityAnimating");
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any unlocked ability keys that can no longer be resolved.
|
||||
* Called during load to clean up references to deleted abilities.
|
||||
*/
|
||||
private void validateUnlockedAbilities() {
|
||||
if (AbilityController.Instance == null) return;
|
||||
|
||||
Iterator<String> it = unlockedAbilities.iterator();
|
||||
while (it.hasNext()) {
|
||||
String key = it.next();
|
||||
if (!AbilityController.Instance.canResolveAbility(key)) {
|
||||
it.remove();
|
||||
LogWriter.info("Removed invalid ability reference from player data: " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,13 +95,21 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
private boolean specialKeyDown = false;
|
||||
|
||||
public void onLogin() {
|
||||
// Continue playing animation for self when re-logging
|
||||
// Handle animation state from previous session
|
||||
AnimationData animationData = this.animationData;
|
||||
if (animationData != null && animationData.isClientAnimating()) {
|
||||
Animation currentAnimation = animationData.currentClientAnimation;
|
||||
NBTTagCompound compound = currentAnimation.writeToNBT();
|
||||
animationData.viewAnimation(currentAnimation, animationData, compound,
|
||||
animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime);
|
||||
if (abilityData.isPlayingAbilityAnimation()) {
|
||||
// Ability animation was playing when player disconnected.
|
||||
// Ability state is transient (lost on disconnect), so this animation
|
||||
// is orphaned - clear it instead of replaying a stuck animation.
|
||||
abilityData.clearOrphanedAbilityAnimation();
|
||||
} else {
|
||||
// Non-ability animation (e.g. script-driven) - continue playing
|
||||
Animation currentAnimation = animationData.currentClientAnimation;
|
||||
NBTTagCompound compound = currentAnimation.writeToNBT();
|
||||
animationData.viewAnimation(currentAnimation, animationData, compound,
|
||||
animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime);
|
||||
}
|
||||
}
|
||||
|
||||
CustomEffectController controller = CustomEffectController.getInstance();
|
||||
@@ -116,6 +124,8 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
}
|
||||
|
||||
public void onLogout() {
|
||||
// Cancel any executing ability and release all locks
|
||||
abilityData.interruptCurrentAbility();
|
||||
this.partyInvites.clear();
|
||||
this.actionManager.clear();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import noppes.npcs.api.handler.data.IActionQueue;
|
||||
import noppes.npcs.api.handler.data.actions.IConditionalAction;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -344,6 +345,10 @@ public class Action implements IAction {
|
||||
try {
|
||||
onStart.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IAction" + getName() + " onStart threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
manager.LOGGER.error("onStart Task of " + this + " threw an exception:", t);
|
||||
}
|
||||
|
||||
@@ -359,6 +364,11 @@ public class Action implements IAction {
|
||||
task.accept(this);
|
||||
count++;
|
||||
} catch (Throwable t) {
|
||||
String err = "IAction '" + name + "' threw an exception:";
|
||||
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
manager.LOGGER.error("Task of " + this + " threw an exception:", t);
|
||||
markDone();
|
||||
}
|
||||
@@ -374,6 +384,10 @@ public class Action implements IAction {
|
||||
try {
|
||||
onDone.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IAction" + getName() + " onDone threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
manager.LOGGER.error("onDone Task of " + this + " threw an exception:", t);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import noppes.npcs.api.handler.data.IAction;
|
||||
import noppes.npcs.api.handler.data.actions.IConditionalAction;
|
||||
import noppes.npcs.controllers.data.action.Action;
|
||||
import noppes.npcs.controllers.data.action.ActionManager;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
@@ -130,6 +131,10 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
count++;
|
||||
taskExecuted = true;
|
||||
} catch (Throwable t) {
|
||||
String err = "IConditionalAction '" + getName() + "' threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
manager.LOGGER.error("Task of " + this + " threw an exception:", t);
|
||||
markDone();
|
||||
}
|
||||
@@ -146,6 +151,10 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
try {
|
||||
onTermination.accept(this);
|
||||
} catch (Throwable t) {
|
||||
String err = "IConditionalAction" + getName() + " onTermination threw an exception:";
|
||||
if (reportTo != null)
|
||||
reportTo.appendConsole(err + "\n" + ExceptionUtils.getStackTrace(t));
|
||||
|
||||
manager.LOGGER.error("Termination Task of " + this + " threw an exception:", t);
|
||||
}
|
||||
|
||||
|
||||
@@ -308,6 +308,13 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
super.onUpdate();
|
||||
|
||||
// Re-apply locks after super.onUpdate() to override body rotation smoothing
|
||||
// in EntityLivingBase.onUpdate() (func_110146_f) which runs AFTER onLivingUpdate()
|
||||
// and overwrites renderYawOffset, causing a visible twitch each frame.
|
||||
abilities.applyRotationControl();
|
||||
abilities.applyLockedPosition();
|
||||
|
||||
if (!isRemote()) {
|
||||
if (this.ticksExisted % 10 == 0) {
|
||||
EventHooks.onNPCUpdate(this);
|
||||
@@ -377,11 +384,13 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
}
|
||||
}
|
||||
|
||||
if (stats.potionType != EnumPotionType.None) {
|
||||
if (stats.potionType != EnumPotionType.Fire)
|
||||
((EntityLivingBase) receiver).addPotionEffect(new PotionEffect(this.getPotionEffect(stats.potionType), stats.potionDuration * 20, stats.potionAmp));
|
||||
else
|
||||
receiver.setFire(stats.potionDuration);
|
||||
if (stats.potionType == EnumPotionType.Fire) {
|
||||
receiver.setFire(stats.potionDuration);
|
||||
} else if (stats.potionType != EnumPotionType.None) {
|
||||
int potionId = stats.potionType.getResolvedPotionId(stats.potionManualId);
|
||||
if (EnumPotionType.isValidPotionId(potionId)) {
|
||||
((EntityLivingBase) receiver).addPotionEffect(new PotionEffect(potionId, stats.potionDuration * 20, stats.potionAmp));
|
||||
}
|
||||
}
|
||||
return didAttack;
|
||||
}
|
||||
@@ -481,8 +490,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
|
||||
super.onLivingUpdate();
|
||||
|
||||
// Apply locked rotation after super.onLivingUpdate() to override look helper changes
|
||||
abilities.applyLockedRotation();
|
||||
// Apply locks after super.onLivingUpdate() to override AI/physics changes
|
||||
abilities.applyRotationControl();
|
||||
abilities.applyLockedPosition();
|
||||
|
||||
handleMountRiderState();
|
||||
|
||||
@@ -670,6 +680,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
if (entity instanceof EntityLivingBase)
|
||||
attackingEntity = (EntityLivingBase) entity;
|
||||
|
||||
if (faction.isPassive)
|
||||
return false;
|
||||
|
||||
if (attackingEntity != null && attackingEntity == getOwner())
|
||||
return false;
|
||||
else if (attackingEntity instanceof EntityNPCInterface) {
|
||||
@@ -1032,29 +1045,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
return weight;
|
||||
}
|
||||
|
||||
/*
|
||||
* Used for getting the applied potion effect from dataStats.
|
||||
*/
|
||||
private int getPotionEffect(EnumPotionType p) {
|
||||
switch (p) {
|
||||
case Poison:
|
||||
return Potion.poison.id;
|
||||
case Hunger:
|
||||
return Potion.hunger.id;
|
||||
case Weakness:
|
||||
return Potion.weakness.id;
|
||||
case Slowness:
|
||||
return Potion.moveSlowdown.id;
|
||||
case Nausea:
|
||||
return Potion.confusion.id;
|
||||
case Blindness:
|
||||
return Potion.blindness.id;
|
||||
case Wither:
|
||||
return Potion.wither.id;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAir(int air) {
|
||||
|
||||
@@ -94,6 +94,7 @@ public class EntityProjectile extends EntityThrowable {
|
||||
public boolean destroyTerrain = true;
|
||||
public int explosiveRadius = 0;
|
||||
public EnumPotionType effect = EnumPotionType.None;
|
||||
public int manualPotionId = 0;
|
||||
public boolean burnItem = true;
|
||||
public int duration = 5;
|
||||
public int amplify = 0;
|
||||
@@ -508,12 +509,12 @@ public class EntityProjectile extends EntityThrowable {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.effect != EnumPotionType.None && entityliving != null) {
|
||||
if (this.effect != EnumPotionType.Fire) {
|
||||
int p = this.getPotionEffect(effect);
|
||||
entityliving.addPotionEffect(new PotionEffect(p, this.duration * 20, this.amplify));
|
||||
} else {
|
||||
movingobjectposition.entityHit.setFire(duration);
|
||||
if (this.effect == EnumPotionType.Fire && entityliving != null) {
|
||||
movingobjectposition.entityHit.setFire(duration);
|
||||
} else if (this.effect != EnumPotionType.None && entityliving != null) {
|
||||
int potionId = this.effect.getResolvedPotionId(this.manualPotionId);
|
||||
if (EnumPotionType.isValidPotionId(potionId)) {
|
||||
entityliving.addPotionEffect(new PotionEffect(potionId, this.duration * 20, this.amplify));
|
||||
}
|
||||
}
|
||||
} else if (this.hasGravity() && (this.isArrow() || this.sticksToWalls())) {
|
||||
@@ -637,21 +638,23 @@ public class EntityProjectile extends EntityThrowable {
|
||||
d1 = 1.0D;
|
||||
}
|
||||
|
||||
int i = this.getPotionEffect(effect);
|
||||
int potionId = this.effect.getResolvedPotionId(this.manualPotionId);
|
||||
|
||||
if (Potion.potionTypes[i].isInstant()) {
|
||||
Potion.potionTypes[i].affectEntity(this.getThrower(), entitylivingbase, this.amplify, d1);
|
||||
} else {
|
||||
int j = (int) (d1 * (double) this.duration + 0.5D);
|
||||
if (EnumPotionType.isValidPotionId(potionId)) {
|
||||
if (Potion.potionTypes[potionId].isInstant()) {
|
||||
Potion.potionTypes[potionId].affectEntity(this.getThrower(), entitylivingbase, this.amplify, d1);
|
||||
} else {
|
||||
int j = (int) (d1 * (double) this.duration + 0.5D);
|
||||
|
||||
if (j > 20) {
|
||||
entitylivingbase.addPotionEffect(new PotionEffect(i, j, this.amplify));
|
||||
if (j > 20) {
|
||||
entitylivingbase.addPotionEffect(new PotionEffect(potionId, j, this.amplify));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.worldObj.playAuxSFX(2002, (int) Math.round(this.posX), (int) Math.round(this.posY), (int) Math.round(this.posZ), this.getPotionColor(this.effect));
|
||||
this.worldObj.playAuxSFX(2002, (int) Math.round(this.posX), (int) Math.round(this.posY), (int) Math.round(this.posZ), this.getPotionColor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -693,6 +696,8 @@ public class EntityProjectile extends EntityThrowable {
|
||||
par1NBTTagCompound.setBoolean("explosive", explosive);
|
||||
par1NBTTagCompound.setInteger("accuracy", accuracy);
|
||||
par1NBTTagCompound.setInteger("PotionEffect", effect.ordinal());
|
||||
if (effect == EnumPotionType.Manual)
|
||||
par1NBTTagCompound.setInteger("PotionManualId", manualPotionId);
|
||||
par1NBTTagCompound.setString("trail", this.dataWatcher.getWatchableObjectString(22));
|
||||
par1NBTTagCompound.setByte("Render3D", this.dataWatcher.getWatchableObjectByte(28));
|
||||
par1NBTTagCompound.setByte("Spins", this.dataWatcher.getWatchableObjectByte(29));
|
||||
@@ -723,7 +728,9 @@ public class EntityProjectile extends EntityThrowable {
|
||||
this.accelerate = par1NBTTagCompound.getBoolean("accelerate");
|
||||
this.explosive = par1NBTTagCompound.getBoolean("explosive");
|
||||
this.accuracy = par1NBTTagCompound.getInteger("accuracy");
|
||||
this.effect = EnumPotionType.values()[par1NBTTagCompound.getInteger("PotionEffect") % EnumPotionType.values().length];
|
||||
this.effect = EnumPotionType.fromOrdinal(par1NBTTagCompound.getInteger("PotionEffect"));
|
||||
if (effect == EnumPotionType.Manual)
|
||||
this.manualPotionId = par1NBTTagCompound.getInteger("PotionManualId");
|
||||
this.dataWatcher.updateObject(22, par1NBTTagCompound.getString("trail"));
|
||||
this.dataWatcher.updateObject(23, Integer.valueOf(par1NBTTagCompound.getInteger("size")));
|
||||
this.dataWatcher.updateObject(24, Byte.valueOf((byte) (par1NBTTagCompound.getBoolean("glows") ? 1 : 0)));
|
||||
@@ -774,46 +781,12 @@ public class EntityProjectile extends EntityThrowable {
|
||||
return this.thrower;
|
||||
}
|
||||
|
||||
private int getPotionEffect(EnumPotionType p) {
|
||||
switch (p) {
|
||||
case Poison:
|
||||
return Potion.poison.id;
|
||||
case Hunger:
|
||||
return Potion.hunger.id;
|
||||
case Weakness:
|
||||
return Potion.weakness.id;
|
||||
case Slowness:
|
||||
return Potion.moveSlowdown.id;
|
||||
case Nausea:
|
||||
return Potion.confusion.id;
|
||||
case Blindness:
|
||||
return Potion.blindness.id;
|
||||
case Wither:
|
||||
return Potion.wither.id;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private int getPotionColor(EnumPotionType p) {
|
||||
switch (p) {
|
||||
case Poison:
|
||||
return 32660;
|
||||
case Hunger:
|
||||
return 32660;
|
||||
case Weakness:
|
||||
return 32696;
|
||||
case Slowness:
|
||||
return 32698;
|
||||
case Nausea:
|
||||
return 32732;
|
||||
case Blindness:
|
||||
return Potion.blindness.id;
|
||||
case Wither:
|
||||
return 32732;
|
||||
default:
|
||||
return 0;
|
||||
private int getPotionColor() {
|
||||
int potionId = this.effect.getResolvedPotionId(this.manualPotionId);
|
||||
if (EnumPotionType.isValidPotionId(potionId)) {
|
||||
return Potion.potionTypes[potionId].getLiquidColor();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void getStatProperties(DataStats stats) {
|
||||
@@ -823,6 +796,7 @@ public class EntityProjectile extends EntityThrowable {
|
||||
this.explosive = stats.pExplode;
|
||||
this.explosiveRadius = stats.pArea;
|
||||
this.effect = stats.pEffect;
|
||||
this.manualPotionId = stats.pManualId;
|
||||
this.burnItem = stats.pBurnItem;
|
||||
this.duration = stats.pDur;
|
||||
this.amplify = stats.pEffAmp;
|
||||
|
||||
@@ -7,6 +7,10 @@ import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.TelegraphController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.command.CommandHandler;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -119,6 +123,10 @@ import noppes.npcs.items.ItemScripted;
|
||||
import noppes.npcs.scripted.entity.ScriptAnimal;
|
||||
import noppes.npcs.scripted.entity.ScriptArrow;
|
||||
import noppes.npcs.scripted.entity.ScriptDBCPlayer;
|
||||
import noppes.npcs.scripted.entity.ScriptEnergyBeam;
|
||||
import noppes.npcs.scripted.entity.ScriptEnergyDisc;
|
||||
import noppes.npcs.scripted.entity.ScriptEnergyLaser;
|
||||
import noppes.npcs.scripted.entity.ScriptEnergyOrb;
|
||||
import noppes.npcs.scripted.entity.ScriptEntity;
|
||||
import noppes.npcs.scripted.entity.ScriptEntityItem;
|
||||
import noppes.npcs.scripted.entity.ScriptFishHook;
|
||||
@@ -454,6 +462,14 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
data = new ScriptEntityData(new ScriptArrow<>((EntityArrow) entity));
|
||||
else if (entity instanceof EntityFishHook)
|
||||
data = new ScriptEntityData(new ScriptFishHook<>((EntityFishHook) entity));
|
||||
else if (entity instanceof EntityAbilityOrb)
|
||||
data = new ScriptEntityData(new ScriptEnergyOrb<>((EntityAbilityOrb) entity));
|
||||
else if (entity instanceof EntityAbilityBeam)
|
||||
data = new ScriptEntityData(new ScriptEnergyBeam<>((EntityAbilityBeam) entity));
|
||||
else if (entity instanceof EntityAbilityDisc)
|
||||
data = new ScriptEntityData(new ScriptEnergyDisc<>((EntityAbilityDisc) entity));
|
||||
else if (entity instanceof EntityAbilityLaser)
|
||||
data = new ScriptEntityData(new ScriptEnergyLaser<>((EntityAbilityLaser) entity));
|
||||
else
|
||||
data = new ScriptEntityData(new ScriptEntity<>(entity));
|
||||
entity.registerExtendedProperties("ScriptedObject", data);
|
||||
|
||||
@@ -21,6 +21,10 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.api.IBlock;
|
||||
@@ -28,6 +32,10 @@ import noppes.npcs.api.IParticle;
|
||||
import noppes.npcs.api.IPos;
|
||||
import noppes.npcs.api.ITileEntity;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.entity.IEnergyBeam;
|
||||
import noppes.npcs.api.entity.IEnergyDisc;
|
||||
import noppes.npcs.api.entity.IEnergyLaser;
|
||||
import noppes.npcs.api.entity.IEnergyOrb;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.handler.data.ISound;
|
||||
@@ -1242,6 +1250,48 @@ public class ScriptWorld implements IWorld {
|
||||
return "DIM" + this.getDimensionID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergyOrb createEnergyOrb(IEntity owner, double x, double y, double z, float size) {
|
||||
EntityAbilityOrb entity = new EntityAbilityOrb(world);
|
||||
entity.setPosition(x, y, z);
|
||||
entity.setStartPosition(x, y, z);
|
||||
entity.setOwnerEntityId(owner.getMCEntity().getEntityId());
|
||||
entity.setProjectileSize(size);
|
||||
return (IEnergyOrb) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergyBeam createEnergyBeam(IEntity owner, double x, double y, double z, float beamWidth, float headSize) {
|
||||
EntityAbilityBeam entity = new EntityAbilityBeam(world);
|
||||
entity.setPosition(x, y, z);
|
||||
entity.setStartPosition(x, y, z);
|
||||
entity.setOwnerEntityId(owner.getMCEntity().getEntityId());
|
||||
entity.setBeamWidth(beamWidth);
|
||||
entity.setHeadSize(headSize);
|
||||
return (IEnergyBeam) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergyDisc createEnergyDisc(IEntity owner, double x, double y, double z, float radius, float thickness) {
|
||||
EntityAbilityDisc entity = new EntityAbilityDisc(world);
|
||||
entity.setPosition(x, y, z);
|
||||
entity.setStartPosition(x, y, z);
|
||||
entity.setOwnerEntityId(owner.getMCEntity().getEntityId());
|
||||
entity.setDiscRadius(radius);
|
||||
entity.setDiscThickness(thickness);
|
||||
return (IEnergyDisc) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergyLaser createEnergyLaser(IEntity owner, double x, double y, double z, float laserWidth) {
|
||||
EntityAbilityLaser entity = new EntityAbilityLaser(world);
|
||||
entity.setPosition(x, y, z);
|
||||
entity.setStartPosition(x, y, z);
|
||||
entity.setOwnerEntityId(owner.getMCEntity().getEntityId());
|
||||
entity.setLaserWidth(laserWidth);
|
||||
return (IEnergyLaser) NpcAPI.Instance().getIEntity(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(String message) {
|
||||
world.func_73046_m().getConfigurationManager().sendChatMsg(new ChatComponentText(message));
|
||||
|
||||
@@ -15,4 +15,8 @@ public class EntityType {
|
||||
public static final int THROWABLE = 11;
|
||||
public static final int FISH_HOOK = 12;
|
||||
public static final int ENERGY_PROJECTILE = 13;
|
||||
public static final int ENERGY_ORB = 14;
|
||||
public static final int ENERGY_BEAM = 15;
|
||||
public static final int ENERGY_DISC = 16;
|
||||
public static final int ENERGY_LASER = 17;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.api.entity.IEnergyBeam;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
|
||||
public class ScriptEnergyBeam<T extends EntityAbilityBeam> extends ScriptEnergyProjectile<T> implements IEnergyBeam {
|
||||
|
||||
public ScriptEnergyBeam(T entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return EntityType.ENERGY_BEAM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeOf(int type) {
|
||||
return type == EntityType.ENERGY_BEAM || super.typeOf(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyType() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ==================== BEAM-SPECIFIC ====================
|
||||
|
||||
public float getBeamWidth() { return entity.getBeamWidth(); }
|
||||
public void setBeamWidth(float width) { entity.setBeamWidth(width); }
|
||||
|
||||
public float getHeadSize() { return entity.getHeadSize(); }
|
||||
public void setHeadSize(float size) { entity.setHeadSize(size); }
|
||||
|
||||
public boolean isAttachedToOwner() { return entity.isAttachedToOwner(); }
|
||||
public void setAttachedToOwner(boolean attached) { entity.setAttachedToOwner(attached); }
|
||||
|
||||
public boolean shouldRenderTailOrb() { return entity.shouldRenderTailOrb(); }
|
||||
|
||||
// ==================== FIRE ====================
|
||||
|
||||
@Override
|
||||
public void fire(IEntity target) {
|
||||
ensureSpawned();
|
||||
EntityLivingBase mcTarget = null;
|
||||
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
|
||||
mcTarget = (EntityLivingBase) target.getMCEntity();
|
||||
}
|
||||
entity.startFiring(mcTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(double x, double y, double z) {
|
||||
ensureSpawned();
|
||||
double dx = x - entity.posX;
|
||||
double dy = y - entity.posY;
|
||||
double dz = z - entity.posZ;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (len > 0) {
|
||||
entity.motionX = (dx / len) * entity.getSpeed();
|
||||
entity.motionY = (dy / len) * entity.getSpeed();
|
||||
entity.motionZ = (dz / len) * entity.getSpeed();
|
||||
}
|
||||
entity.startFiring(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.api.entity.IEnergyDisc;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
|
||||
public class ScriptEnergyDisc<T extends EntityAbilityDisc> extends ScriptEnergyProjectile<T> implements IEnergyDisc {
|
||||
|
||||
public ScriptEnergyDisc(T entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return EntityType.ENERGY_DISC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeOf(int type) {
|
||||
return type == EntityType.ENERGY_DISC || super.typeOf(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyType() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
// ==================== DISC-SPECIFIC ====================
|
||||
|
||||
public float getDiscRadius() { return entity.getDiscRadius(); }
|
||||
public void setDiscRadius(float radius) { entity.setDiscRadius(radius); }
|
||||
|
||||
public float getDiscThickness() { return entity.getDiscThickness(); }
|
||||
public void setDiscThickness(float thickness) { entity.setDiscThickness(thickness); }
|
||||
|
||||
public boolean isVertical() { return entity.isVertical(); }
|
||||
public void setVertical(boolean vertical) { entity.setVertical(vertical); }
|
||||
|
||||
public boolean isBoomerang() { return entity.isBoomerang(); }
|
||||
public void setBoomerang(boolean boomerang) { entity.setBoomerang(boomerang); }
|
||||
|
||||
public int getBoomerangDelay() { return entity.getBoomerangDelay(); }
|
||||
public void setBoomerangDelay(int ticks) { entity.setBoomerangDelay(ticks); }
|
||||
|
||||
public boolean isReturning() { return entity.isReturning(); }
|
||||
|
||||
// ==================== FIRE ====================
|
||||
|
||||
@Override
|
||||
public void fire(IEntity target) {
|
||||
ensureSpawned();
|
||||
EntityLivingBase mcTarget = null;
|
||||
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
|
||||
mcTarget = (EntityLivingBase) target.getMCEntity();
|
||||
}
|
||||
entity.startMoving(mcTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(double x, double y, double z) {
|
||||
ensureSpawned();
|
||||
double dx = x - entity.posX;
|
||||
double dy = y - entity.posY;
|
||||
double dz = z - entity.posZ;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (len > 0) {
|
||||
entity.motionX = (dx / len) * entity.getSpeed();
|
||||
entity.motionY = (dy / len) * entity.getSpeed();
|
||||
entity.motionZ = (dz / len) * entity.getSpeed();
|
||||
}
|
||||
entity.startMoving(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.api.entity.IEnergyLaser;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
|
||||
public class ScriptEnergyLaser<T extends EntityAbilityLaser> extends ScriptEnergyProjectile<T> implements IEnergyLaser {
|
||||
|
||||
public ScriptEnergyLaser(T entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return EntityType.ENERGY_LASER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeOf(int type) {
|
||||
return type == EntityType.ENERGY_LASER || super.typeOf(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyType() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
// ==================== LASER-SPECIFIC ====================
|
||||
|
||||
public float getLaserWidth() { return entity.getLaserWidth(); }
|
||||
public void setLaserWidth(float width) { entity.setLaserWidth(width); }
|
||||
|
||||
public float getExpansionSpeed() { return entity.getExpansionSpeed(); }
|
||||
public void setExpansionSpeed(float speed) { entity.setExpansionSpeed(speed); }
|
||||
|
||||
public int getLingerTicks() { return entity.getLingerTicks(); }
|
||||
public void setLingerTicks(int ticks) { entity.setLingerTicks(ticks); }
|
||||
|
||||
public float getCurrentLength() { return entity.getCurrentLength(); }
|
||||
public boolean isFullyExtended() { return entity.isFullyExtended(); }
|
||||
|
||||
public double getDirX() { return entity.getDirX(); }
|
||||
public double getDirY() { return entity.getDirY(); }
|
||||
public double getDirZ() { return entity.getDirZ(); }
|
||||
public void setDirection(double x, double y, double z) { entity.setDirection(x, y, z); }
|
||||
|
||||
public double getEndX() { return entity.getEndX(); }
|
||||
public double getEndY() { return entity.getEndY(); }
|
||||
public double getEndZ() { return entity.getEndZ(); }
|
||||
|
||||
public float getLingerAlpha() { return entity.getLingerAlpha(); }
|
||||
|
||||
public boolean isLockVerticalDirection() { return entity.isLockVerticalDirection(); }
|
||||
public void setLockVerticalDirection(boolean lock) { entity.setLockVerticalDirection(lock); }
|
||||
|
||||
// ==================== FIRE ====================
|
||||
|
||||
@Override
|
||||
public void fire(IEntity target) {
|
||||
ensureSpawned();
|
||||
EntityLivingBase mcTarget = null;
|
||||
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
|
||||
mcTarget = (EntityLivingBase) target.getMCEntity();
|
||||
}
|
||||
entity.startMoving(mcTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(double x, double y, double z) {
|
||||
ensureSpawned();
|
||||
double dx = x - entity.posX;
|
||||
double dy = y - entity.posY;
|
||||
double dz = z - entity.posZ;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (len > 0) {
|
||||
entity.setDirection(dx / len, dy / len, dz / len);
|
||||
}
|
||||
entity.startMoving(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.api.entity.IEnergyOrb;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
|
||||
public class ScriptEnergyOrb<T extends EntityAbilityOrb> extends ScriptEnergyProjectile<T> implements IEnergyOrb {
|
||||
|
||||
public ScriptEnergyOrb(T entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return EntityType.ENERGY_ORB;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeOf(int type) {
|
||||
return type == EntityType.ENERGY_ORB || super.typeOf(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyType() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(IEntity target) {
|
||||
ensureSpawned();
|
||||
EntityLivingBase mcTarget = null;
|
||||
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
|
||||
mcTarget = (EntityLivingBase) target.getMCEntity();
|
||||
}
|
||||
entity.startMoving(mcTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(double x, double y, double z) {
|
||||
ensureSpawned();
|
||||
double dx = x - entity.posX;
|
||||
double dy = y - entity.posY;
|
||||
double dz = z - entity.posZ;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (len > 0) {
|
||||
entity.motionX = (dx / len) * entity.getSpeed();
|
||||
entity.motionY = (dy / len) * entity.getSpeed();
|
||||
entity.motionZ = (dz / len) * entity.getSpeed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilityProjectile;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.api.entity.IEnergyProjectile;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
|
||||
public class ScriptEnergyProjectile<T extends EntityAbilityProjectile> extends ScriptEntity<T> implements IEnergyProjectile {
|
||||
protected T entity;
|
||||
|
||||
public ScriptEnergyProjectile(T entity) {
|
||||
super(entity);
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
// ==================== TYPE ====================
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return EntityType.ENERGY_PROJECTILE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean typeOf(int type) {
|
||||
return type == EntityType.ENERGY_PROJECTILE || super.typeOf(type);
|
||||
}
|
||||
|
||||
public int getEnergyType() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ==================== OWNER & TARGET ====================
|
||||
|
||||
public int getOwnerEntityId() {
|
||||
return entity.getOwnerEntityId();
|
||||
}
|
||||
|
||||
public IEntity getOwner() {
|
||||
return entity.getOwner();
|
||||
}
|
||||
|
||||
public void setOwner(IEntity owner) {
|
||||
if (owner != null) {
|
||||
entity.setOwnerEntityId(owner.getMCEntity().getEntityId());
|
||||
}
|
||||
}
|
||||
|
||||
public int getTargetEntityId() {
|
||||
return entity.getTargetEntityId();
|
||||
}
|
||||
|
||||
public IEntity getTarget() {
|
||||
return entity.getTarget();
|
||||
}
|
||||
|
||||
public void setTarget(IEntity target) {
|
||||
if (target != null) {
|
||||
entity.setTargetEntityId(target.getMCEntity().getEntityId());
|
||||
} else {
|
||||
entity.setTargetEntityId(-1);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== SIZE ====================
|
||||
|
||||
public float getSize() {
|
||||
return entity.getSize();
|
||||
}
|
||||
|
||||
public void setSize(float size) {
|
||||
entity.setProjectileSize(size);
|
||||
}
|
||||
|
||||
// ==================== DISPLAY ====================
|
||||
|
||||
public int getInnerColor() { return entity.getInnerColor(); }
|
||||
public void setInnerColor(int color) { entity.setInnerColor(color); }
|
||||
|
||||
public int getOuterColor() { return entity.getOuterColor(); }
|
||||
public void setOuterColor(int color) { entity.setOuterColor(color); }
|
||||
|
||||
public boolean isOuterColorEnabled() { return entity.isOuterColorEnabled(); }
|
||||
public void setOuterColorEnabled(boolean enabled) { entity.setOuterColorEnabled(enabled); }
|
||||
|
||||
public float getOuterColorWidth() { return entity.getOuterColorWidth(); }
|
||||
public void setOuterColorWidth(float width) { entity.setOuterColorWidth(width); }
|
||||
|
||||
public float getOuterColorAlpha() { return entity.getOuterColorAlpha(); }
|
||||
public void setOuterColorAlpha(float alpha) { entity.setOuterColorAlpha(alpha); }
|
||||
|
||||
public float getRotationSpeed() { return entity.getRotationSpeed(); }
|
||||
public void setRotationSpeed(float speed) { entity.setRotationSpeed(speed); }
|
||||
|
||||
// ==================== INTERPOLATION ====================
|
||||
|
||||
public float getInterpolatedRotationX(float partialTicks) { return entity.getInterpolatedRotationX(partialTicks); }
|
||||
public float getInterpolatedRotationY(float partialTicks) { return entity.getInterpolatedRotationY(partialTicks); }
|
||||
public float getInterpolatedRotationZ(float partialTicks) { return entity.getInterpolatedRotationZ(partialTicks); }
|
||||
public float getInterpolatedSize(float partialTicks) { return entity.getInterpolatedSize(partialTicks); }
|
||||
|
||||
// ==================== LIGHTNING ====================
|
||||
|
||||
public boolean hasLightningEffect() { return entity.hasLightningEffect(); }
|
||||
public void setLightningEffect(boolean enabled) { entity.setLightningEffect(enabled); }
|
||||
|
||||
public float getLightningDensity() { return entity.getLightningDensity(); }
|
||||
public void setLightningDensity(float density) { entity.setLightningDensity(density); }
|
||||
|
||||
public float getLightningRadius() { return entity.getLightningRadius(); }
|
||||
public void setLightningRadius(float radius) { entity.setLightningRadius(radius); }
|
||||
|
||||
public int getLightningFadeTime() { return entity.getLightningFadeTime(); }
|
||||
public void setLightningFadeTime(int ticks) { entity.setLightningFadeTime(ticks); }
|
||||
|
||||
// ==================== LIFESPAN ====================
|
||||
|
||||
public float getMaxDistance() { return entity.getMaxDistance(); }
|
||||
public void setMaxDistance(float distance) { entity.setMaxDistance(distance); }
|
||||
|
||||
public int getMaxLifetime() { return entity.getMaxLifetime(); }
|
||||
public void setMaxLifetime(int ticks) { entity.setMaxLifetime(ticks); }
|
||||
|
||||
// ==================== COMBAT ====================
|
||||
|
||||
public float getDamage() { return entity.getDamage(); }
|
||||
public void setDamage(float damage) { entity.setCombatDamage(damage); }
|
||||
|
||||
public float getKnockback() { return entity.getKnockback(); }
|
||||
public void setKnockback(float knockback) { entity.setCombatKnockback(knockback); }
|
||||
|
||||
public float getKnockbackUp() { return entity.getKnockbackUp(); }
|
||||
public void setKnockbackUp(float knockbackUp) { entity.setCombatKnockbackUp(knockbackUp); }
|
||||
|
||||
public boolean isExplosive() { return entity.isExplosive(); }
|
||||
public void setExplosive(boolean explosive) { entity.setExplosive(explosive); }
|
||||
|
||||
public float getExplosionRadius() { return entity.getExplosionRadius(); }
|
||||
public void setExplosionRadius(float radius) { entity.setExplosionRadius(radius); }
|
||||
|
||||
public float getExplosionDamageFalloff() { return entity.getExplosionDamageFalloff(); }
|
||||
public void setExplosionDamageFalloff(float falloff) { entity.setExplosionDamageFalloff(falloff); }
|
||||
|
||||
// ==================== MOVEMENT ====================
|
||||
|
||||
public float getSpeed() { return entity.getSpeed(); }
|
||||
public void setSpeed(float speed) { entity.setSpeed(speed); }
|
||||
|
||||
public boolean isHoming() { return entity.isHoming(); }
|
||||
public void setHoming(boolean homing) { entity.setHomingEnabled(homing); }
|
||||
|
||||
public float getHomingStrength() { return entity.getHomingStrength(); }
|
||||
public void setHomingStrength(float strength) { entity.setHomingStrength(strength); }
|
||||
|
||||
public float getHomingRange() { return entity.getHomingRange(); }
|
||||
public void setHomingRange(float range) { entity.setHomingRange(range); }
|
||||
|
||||
// ==================== ANCHOR ====================
|
||||
|
||||
public int getAnchor() { return entity.getAnchor(); }
|
||||
public float getAnchorOffsetX() { return entity.getAnchorOffsetX(); }
|
||||
public float getAnchorOffsetY() { return entity.getAnchorOffsetY(); }
|
||||
public float getAnchorOffsetZ() { return entity.getAnchorOffsetZ(); }
|
||||
|
||||
// ==================== POSITION ====================
|
||||
|
||||
public double getStartX() { return entity.getStartX(); }
|
||||
public double getStartY() { return entity.getStartY(); }
|
||||
public double getStartZ() { return entity.getStartZ(); }
|
||||
|
||||
// ==================== STATE ====================
|
||||
|
||||
public boolean hasHit() { return entity.getHasHit(); }
|
||||
public boolean isCharging() { return entity.isCharging(); }
|
||||
public float getChargeProgress() { return entity.getChargeProgress(); }
|
||||
|
||||
// ==================== FIRE ====================
|
||||
|
||||
public void fire(IEntity target) {
|
||||
if (target != null) {
|
||||
Entity mcTarget = target.getMCEntity();
|
||||
setMotionToward(mcTarget.posX, mcTarget.posY + mcTarget.getEyeHeight(), mcTarget.posZ);
|
||||
}
|
||||
ensureSpawned();
|
||||
}
|
||||
|
||||
public void fire(double x, double y, double z) {
|
||||
setMotionToward(x, y, z);
|
||||
ensureSpawned();
|
||||
}
|
||||
|
||||
public void fire(float yaw, float pitch) {
|
||||
float yawRad = (float) Math.toRadians(yaw);
|
||||
float pitchRad = (float) Math.toRadians(pitch);
|
||||
entity.motionX = -Math.sin(yawRad) * Math.cos(pitchRad) * entity.getSpeed();
|
||||
entity.motionY = -Math.sin(pitchRad) * entity.getSpeed();
|
||||
entity.motionZ = Math.cos(yawRad) * Math.cos(pitchRad) * entity.getSpeed();
|
||||
ensureSpawned();
|
||||
}
|
||||
|
||||
public void fire(IEntityLivingBase caster) {
|
||||
if (caster == null) return;
|
||||
initFromCaster(caster);
|
||||
fire(caster.getRotation(), caster.getPitch());
|
||||
}
|
||||
|
||||
public void fire(IEntityLivingBase caster, IEntity target) {
|
||||
if (caster == null) return;
|
||||
initFromCaster(caster);
|
||||
fire(target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets owner from caster and positions projectile at caster's eye level.
|
||||
*/
|
||||
private void initFromCaster(IEntityLivingBase caster) {
|
||||
EntityLivingBase mc = (EntityLivingBase) caster.getMCEntity();
|
||||
entity.setOwnerEntityId(mc.getEntityId());
|
||||
double eyeY = mc.posY + mc.getEyeHeight();
|
||||
entity.setPosition(mc.posX, eyeY, mc.posZ);
|
||||
entity.setStartPosition(mc.posX, eyeY, mc.posZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates and sets motion from the projectile's current position toward a target point.
|
||||
*/
|
||||
private void setMotionToward(double x, double y, double z) {
|
||||
double dx = x - entity.posX;
|
||||
double dy = y - entity.posY;
|
||||
double dz = z - entity.posZ;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (len > 0) {
|
||||
entity.motionX = (dx / len) * entity.getSpeed();
|
||||
entity.motionY = (dy / len) * entity.getSpeed();
|
||||
entity.motionZ = (dz / len) * entity.getSpeed();
|
||||
}
|
||||
}
|
||||
|
||||
protected void ensureSpawned() {
|
||||
if (!entity.addedToChunk && entity.worldObj != null) {
|
||||
entity.worldObj.spawnEntityInWorld(entity);
|
||||
if (!entity.worldObj.isRemote) {
|
||||
EventHooks.onEnergyProjectileFired(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityAbilityProjectile;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
@@ -526,6 +531,16 @@ public class ScriptEntity<T extends Entity> implements IEntity {
|
||||
cls = EntityMob.class;
|
||||
else if (type == EntityType.NPC)
|
||||
cls = EntityNPCInterface.class;
|
||||
else if (type == EntityType.ENERGY_PROJECTILE)
|
||||
cls = EntityAbilityProjectile.class;
|
||||
else if (type == EntityType.ENERGY_ORB)
|
||||
cls = EntityAbilityOrb.class;
|
||||
else if (type == EntityType.ENERGY_BEAM)
|
||||
cls = EntityAbilityBeam.class;
|
||||
else if (type == EntityType.ENERGY_DISC)
|
||||
cls = EntityAbilityDisc.class;
|
||||
else if (type == EntityType.ENERGY_LASER)
|
||||
cls = EntityAbilityLaser.class;
|
||||
|
||||
List<Entity> entities = entity.worldObj.getEntitiesWithinAABB(cls, entity.boundingBox.expand(range, range, range));
|
||||
List<IEntity> list = new ArrayList<IEntity>();
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.potion.Potion;
|
||||
import net.minecraft.potion.PotionEffect;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EntityDamageSource;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.Vec3;
|
||||
import noppes.npcs.api.IBlock;
|
||||
import noppes.npcs.api.IDamageSource;
|
||||
@@ -380,4 +381,53 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
|
||||
this.entity.hurtResistantTime = time;
|
||||
this.entity.hurtTime = time;
|
||||
}
|
||||
|
||||
public void applyKnockback(float strength, IEntity source) {
|
||||
double dirX = entity.posX - source.getX();
|
||||
double dirZ = entity.posZ - source.getZ();
|
||||
applyKnockbackInternal(strength, dirX, dirZ, false);
|
||||
}
|
||||
|
||||
public void applyKnockback(float strength, double dirX, double dirZ) {
|
||||
applyKnockbackInternal(strength, dirX, dirZ, false);
|
||||
}
|
||||
|
||||
public void forceKnockback(float strength, IEntity source) {
|
||||
double dirX = entity.posX - source.getX();
|
||||
double dirZ = entity.posZ - source.getZ();
|
||||
applyKnockbackInternal(strength, dirX, dirZ, true);
|
||||
}
|
||||
|
||||
public void forceKnockback(float strength, double dirX, double dirZ) {
|
||||
applyKnockbackInternal(strength, dirX, dirZ, true);
|
||||
}
|
||||
|
||||
private void applyKnockbackInternal(float strength, double dirX, double dirZ, boolean ignoreResistance) {
|
||||
if (!ignoreResistance) {
|
||||
double resistance = entity.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).getAttributeValue();
|
||||
if (entity.worldObj.rand.nextDouble() < resistance) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
double len = MathHelper.sqrt_double(dirX * dirX + dirZ * dirZ);
|
||||
if (len <= 0.0D) {
|
||||
return;
|
||||
}
|
||||
|
||||
entity.isAirBorne = true;
|
||||
float base = 0.4F * strength;
|
||||
entity.motionX /= 2.0D;
|
||||
entity.motionY /= 2.0D;
|
||||
entity.motionZ /= 2.0D;
|
||||
entity.motionX -= (dirX / len) * base;
|
||||
entity.motionY += base;
|
||||
entity.motionZ -= (dirZ / len) * base;
|
||||
|
||||
if (entity.motionY > 0.4D) {
|
||||
entity.motionY = 0.4D;
|
||||
}
|
||||
|
||||
entity.velocityChanged = true;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import noppes.npcs.api.IPos;
|
||||
import noppes.npcs.api.ITimers;
|
||||
import noppes.npcs.api.ability.IDataAbilities;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.entity.IEnergyProjectile;
|
||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.entity.data.IModelData;
|
||||
@@ -28,6 +29,7 @@ import noppes.npcs.constants.EnumMovingType;
|
||||
import noppes.npcs.constants.EnumNavType;
|
||||
import noppes.npcs.constants.EnumRoleType;
|
||||
import noppes.npcs.constants.EnumStandingType;
|
||||
import kamkeel.npcs.entity.EntityAbilityProjectile;
|
||||
import noppes.npcs.controllers.FactionController;
|
||||
import noppes.npcs.controllers.data.DialogOption;
|
||||
import noppes.npcs.controllers.data.Line;
|
||||
@@ -1463,4 +1465,13 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
public IDataAbilities getAbilityData() {
|
||||
return new ScriptDataAbilities(npc);
|
||||
}
|
||||
|
||||
public IEnergyProjectile[] getActiveEnergyProjectiles() {
|
||||
java.util.List<EntityAbilityProjectile> entities = EntityAbilityProjectile.getActiveProjectiles(npc.getEntityId());
|
||||
IEnergyProjectile[] result = new IEnergyProjectile[entities.size()];
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
result[i] = (IEnergyProjectile) NpcAPI.Instance().getIEntity(entities.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.entity.EntityAbilityProjectile;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
@@ -31,6 +32,7 @@ import noppes.npcs.api.IPos;
|
||||
import noppes.npcs.api.IScreenSize;
|
||||
import noppes.npcs.api.ITimers;
|
||||
import noppes.npcs.api.IWorld;
|
||||
import noppes.npcs.api.entity.IEnergyProjectile;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.gui.ICustomGui;
|
||||
@@ -933,4 +935,13 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
public String getFormattedCurrencyBalance() {
|
||||
return getData().tradeData.formatBalance();
|
||||
}
|
||||
|
||||
public IEnergyProjectile[] getActiveEnergyProjectiles() {
|
||||
List<EntityAbilityProjectile> entities = EntityAbilityProjectile.getActiveProjectiles(player.getEntityId());
|
||||
IEnergyProjectile[] result = new IEnergyProjectile[entities.size()];
|
||||
for (int i = 0; i < entities.size(); i++) {
|
||||
result[i] = (IEnergyProjectile) NpcAPI.Instance().getIEntity(entities.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package noppes.npcs.scripted.event;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import noppes.npcs.api.IBlock;
|
||||
import noppes.npcs.api.entity.IEnergyProjectile;
|
||||
import noppes.npcs.api.entity.IEntity;
|
||||
import noppes.npcs.api.event.IEnergyProjectileEvent;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
|
||||
public class EnergyProjectileEvent extends CustomNPCsEvent implements IEnergyProjectileEvent {
|
||||
public final IEnergyProjectile projectile;
|
||||
public final IEntity owner;
|
||||
|
||||
public EnergyProjectileEvent(IEnergyProjectile projectile) {
|
||||
this.projectile = projectile;
|
||||
this.owner = projectile.getOwner();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEnergyProjectile getProjectile() {
|
||||
return projectile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntity getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "energyProjectileEvent";
|
||||
}
|
||||
|
||||
/**
|
||||
* energyProjectileFired
|
||||
*/
|
||||
public static class FiredEvent extends EnergyProjectileEvent implements IEnergyProjectileEvent.FiredEvent {
|
||||
public FiredEvent(IEnergyProjectile projectile) {
|
||||
super(projectile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ENERGY_PROJECTILE_FIRED.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* energyProjectileTick
|
||||
*/
|
||||
public static class UpdateEvent extends EnergyProjectileEvent implements IEnergyProjectileEvent.UpdateEvent {
|
||||
public UpdateEvent(IEnergyProjectile projectile) {
|
||||
super(projectile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ENERGY_PROJECTILE_TICK.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* energyProjectileEntityImpact
|
||||
*/
|
||||
@Cancelable
|
||||
public static class EntityImpactEvent extends EnergyProjectileEvent implements IEnergyProjectileEvent.EntityImpactEvent {
|
||||
private final IEntity target;
|
||||
private float damage;
|
||||
|
||||
public EntityImpactEvent(IEnergyProjectile projectile, IEntity target, float damage) {
|
||||
super(projectile);
|
||||
this.target = target;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntity getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(float damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ENERGY_PROJECTILE_ENTITY_IMPACT.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* energyProjectileBlockImpact
|
||||
*/
|
||||
public static class BlockImpactEvent extends EnergyProjectileEvent implements IEnergyProjectileEvent.BlockImpactEvent {
|
||||
private final IBlock block;
|
||||
|
||||
public BlockImpactEvent(IEnergyProjectile projectile, IBlock block) {
|
||||
super(projectile);
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlock getBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ENERGY_PROJECTILE_BLOCK_IMPACT.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* energyProjectileExpired
|
||||
*/
|
||||
public static class ExpiredEvent extends EnergyProjectileEvent implements IEnergyProjectileEvent.ExpiredEvent {
|
||||
public ExpiredEvent(IEnergyProjectile projectile) {
|
||||
super(projectile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ENERGY_PROJECTILE_EXPIRED.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package noppes.npcs.scripted.event.player;
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.api.IDamageSource;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
@@ -38,6 +40,108 @@ public class PlayerAbilityEvent extends PlayerEvent implements IPlayerAbilityEve
|
||||
return "playerAbilityEvent";
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a player's ability starts executing (enters WINDUP phase).
|
||||
*/
|
||||
@Cancelable
|
||||
public static class StartEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.StartEvent {
|
||||
public StartEvent(IPlayer player, Ability ability, EntityLivingBase target) {
|
||||
super(player, ability, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_START.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a player's ability enters the ACTIVE phase and performs its effect.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ExecuteEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.ExecuteEvent {
|
||||
public ExecuteEvent(IPlayer player, Ability ability, EntityLivingBase target) {
|
||||
super(player, ability, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_EXECUTE.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a player's ability is interrupted by damage.
|
||||
*/
|
||||
public static class InterruptEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.InterruptEvent {
|
||||
private final IDamageSource damageSource;
|
||||
private final float damage;
|
||||
|
||||
public InterruptEvent(IPlayer player, Ability ability, EntityLivingBase target, DamageSource source, float damage) {
|
||||
super(player, ability, target);
|
||||
this.damageSource = source != null ? NpcAPI.Instance().getIDamageSource(source) : null;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDamageSource getDamageSource() {
|
||||
return damageSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_INTERRUPT.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a player's ability completes its full execution cycle.
|
||||
*/
|
||||
public static class CompleteEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.CompleteEvent {
|
||||
public CompleteEvent(IPlayer player, Ability ability, EntityLivingBase target) {
|
||||
super(player, ability, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_COMPLETE.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired every tick while a player's ability is executing.
|
||||
*/
|
||||
public static class TickEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.TickEvent {
|
||||
private final int abilityPhase;
|
||||
private final int tick;
|
||||
|
||||
public TickEvent(IPlayer player, Ability ability, EntityLivingBase target, int phase, int tick) {
|
||||
super(player, ability, target);
|
||||
this.abilityPhase = phase;
|
||||
this.tick = tick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAbilityPhase() {
|
||||
return abilityPhase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTick() {
|
||||
return tick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_TICK.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a player's ability hits an entity with damage.
|
||||
* Canceling prevents the damage from being applied.
|
||||
|
||||
@@ -42,12 +42,25 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
@Override
|
||||
public void addAbility(IAbility ability) {
|
||||
if (ability instanceof Ability) {
|
||||
data.addAbility((Ability) ability);
|
||||
Ability a = (Ability) ability;
|
||||
// Validate ability allows NPCs
|
||||
if (!a.getAllowedBy().allowsNpc()) {
|
||||
return; // Ability is PLAYER_ONLY
|
||||
}
|
||||
data.addAbility(a);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAbilityReference(String key) {
|
||||
// Validate ability exists and allows NPCs
|
||||
Ability ability = AbilityController.Instance.resolveAbility(key);
|
||||
if (ability == null) {
|
||||
return; // Ability doesn't exist
|
||||
}
|
||||
if (!ability.getAllowedBy().allowsNpc()) {
|
||||
return; // Ability is PLAYER_ONLY
|
||||
}
|
||||
data.addAbilityReference(key);
|
||||
}
|
||||
|
||||
@@ -158,6 +171,14 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
|
||||
@Override
|
||||
public boolean executeAbility(String key, Object target) {
|
||||
// Validate ability exists and allows NPCs
|
||||
Ability ability = AbilityController.Instance.resolveAbility(key);
|
||||
if (ability == null) {
|
||||
return false; // Ability doesn't exist
|
||||
}
|
||||
if (!ability.getAllowedBy().allowsNpc()) {
|
||||
return false; // Ability is PLAYER_ONLY
|
||||
}
|
||||
EntityLivingBase targetEntity = resolveTarget(target);
|
||||
return data.executeAbility(key, targetEntity);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package noppes.npcs.scripted.wrapper;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
@@ -26,7 +28,17 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
|
||||
|
||||
@Override
|
||||
public void unlockAbility(String key) {
|
||||
data.unlockAbility(key);
|
||||
// Validate ability exists and allows players
|
||||
Ability ability = AbilityController.Instance.resolveAbility(key);
|
||||
if (ability == null) {
|
||||
return; // Ability doesn't exist
|
||||
}
|
||||
if (!ability.getAllowedBy().allowsPlayer()) {
|
||||
return; // Ability is NPC-only
|
||||
}
|
||||
// Use canonical key (registry key for built-in, UUID for custom)
|
||||
String canonicalKey = ability.getId() != null ? ability.getId() : key;
|
||||
data.unlockAbility(canonicalKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user