mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 16:59:43 +00:00
Merge remote-tracking branch 'origin/syntax-highlighter-unified' into syntax-highlighter-unified
This commit is contained in:
commit
e1be96412d
163 files changed
+4345
-2135
No files matched your search
@@ -2,6 +2,7 @@ package noppes.npcs;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDefend;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.data.entry.ChainedAbilityEntry;
|
||||
@@ -11,6 +12,7 @@ import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.scripted.event.AbilityEvent;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -124,28 +126,53 @@ public abstract class AbstractDataAbilities {
|
||||
*/
|
||||
protected abstract long getWorldTime();
|
||||
|
||||
// -- Event Firing --
|
||||
// -- Event Firing (unified via EventHooks) --
|
||||
|
||||
/**
|
||||
* Fire tick event. Implementation differs between NPC (NpcAPI) and Player (ScriptController).
|
||||
*/
|
||||
protected abstract void fireTickEvent(Ability ability, EntityLivingBase target);
|
||||
protected void fireTickEvent(Ability ability, EntityLivingBase target) {
|
||||
EventHooks.onAbilityTick(ability, getEntity(), target, ability.getPhase().ordinal(), ability.getCurrentTick());
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire execute event. Returns true if cancelled.
|
||||
*/
|
||||
protected abstract boolean fireExecuteEvent(Ability ability, EntityLivingBase target);
|
||||
protected boolean fireExecuteEvent(Ability ability, EntityLivingBase target) {
|
||||
return EventHooks.onAbilityExecute(ability, getEntity(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire complete event.
|
||||
*/
|
||||
protected abstract void fireCompleteEvent(Ability ability, EntityLivingBase target);
|
||||
protected void fireCompleteEvent(Ability ability, EntityLivingBase target) {
|
||||
EventHooks.onAbilityComplete(ability, getEntity(), target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire interrupt event.
|
||||
*/
|
||||
protected abstract void fireInterruptEvent(Ability ability, EntityLivingBase target,
|
||||
DamageSource source, float damage);
|
||||
protected void fireInterruptEvent(Ability ability, EntityLivingBase target,
|
||||
DamageSource source, float damage) {
|
||||
EventHooks.onAbilityInterrupt(ability, getEntity(), target, source, damage);
|
||||
}
|
||||
|
||||
protected boolean fireToggleEvent(Ability ability, int oldState, int newState) {
|
||||
return EventHooks.onAbilityToggle(ability, getEntity(), oldState, newState);
|
||||
}
|
||||
|
||||
protected boolean fireToggleUpdateEvent(Ability ability, int tick, int state) {
|
||||
AbilityEvent.ToggleUpdateEvent event = new AbilityEvent.ToggleUpdateEvent(getEntity(), ability, tick, state);
|
||||
EventHooks.onAbilityToggleUpdate(ability, event);
|
||||
return event.isEnabled();
|
||||
}
|
||||
|
||||
// -- Chain Events (unified via EventHooks) --
|
||||
|
||||
protected void fireChainStartEvent(ChainedAbility chain, int entryIndex, EntityLivingBase target) {
|
||||
EventHooks.onChainStart(chain, getEntity(), entryIndex, target);
|
||||
}
|
||||
|
||||
protected void fireChainNextEvent(ChainedAbility chain, int entryIndex, EntityLivingBase target) {
|
||||
EventHooks.onChainNext(chain, getEntity(), entryIndex, target);
|
||||
}
|
||||
|
||||
protected void fireChainCompleteEvent(ChainedAbility chain, int entryIndex, EntityLivingBase target) {
|
||||
EventHooks.onChainComplete(chain, getEntity(), entryIndex, target);
|
||||
}
|
||||
|
||||
protected void fireChainInterruptEvent(ChainedAbility chain, int entryIndex, EntityLivingBase target,
|
||||
DamageSource source, float damage) {
|
||||
EventHooks.onChainInterrupt(chain, getEntity(), entryIndex, target, source, damage);
|
||||
}
|
||||
|
||||
// -- Telegraph --
|
||||
|
||||
@@ -291,6 +318,19 @@ public abstract class AbstractDataAbilities {
|
||||
return currentAbility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active defend ability if one is currently defending.
|
||||
*/
|
||||
public AbilityDefend getActiveDefend() {
|
||||
if (currentAbility instanceof AbilityDefend) {
|
||||
AbilityDefend defend = (AbilityDefend) currentAbility;
|
||||
if (defend.isDefending()) {
|
||||
return defend;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a chained ability is currently executing.
|
||||
*/
|
||||
@@ -391,8 +431,7 @@ public abstract class AbstractDataAbilities {
|
||||
|
||||
AbilityToggleEntry entry = new AbilityToggleEntry(ability, state);
|
||||
activeToggles.put(key, entry);
|
||||
ability.onToggleOn(getEntity());
|
||||
ability.onToggleStateChanged(getEntity(), 0, state);
|
||||
ability.onToggle(getEntity(), 0, state);
|
||||
onToggleStateChanged(key, true, state);
|
||||
return true;
|
||||
}
|
||||
@@ -404,7 +443,7 @@ public abstract class AbstractDataAbilities {
|
||||
if (fireToggleEvent(ability, oldState, newState)) return oldState;
|
||||
|
||||
entry.setState(newState);
|
||||
ability.onToggleStateChanged(getEntity(), oldState, newState);
|
||||
ability.onToggle(getEntity(), oldState, newState);
|
||||
onToggleStateChanged(key, true, newState);
|
||||
return newState;
|
||||
}
|
||||
@@ -417,8 +456,7 @@ public abstract class AbstractDataAbilities {
|
||||
if (fireToggleEvent(entry.getAbility(), oldState, 0)) return;
|
||||
|
||||
activeToggles.remove(key);
|
||||
entry.getAbility().onToggleOff(getEntity());
|
||||
entry.getAbility().onToggleStateChanged(getEntity(), oldState, 0);
|
||||
entry.getAbility().onToggle(getEntity(), oldState, 0);
|
||||
onToggleStateChanged(key, false, 0);
|
||||
}
|
||||
|
||||
@@ -460,8 +498,7 @@ public abstract class AbstractDataAbilities {
|
||||
AbilityToggleEntry entry = activeToggles.remove(key);
|
||||
if (entry != null) {
|
||||
int oldState = entry.getState();
|
||||
entry.getAbility().onToggleOff(entity);
|
||||
entry.getAbility().onToggleStateChanged(entity, oldState, 0);
|
||||
entry.getAbility().onToggle(entity, oldState, 0);
|
||||
onToggleStateChanged(key, false, 0);
|
||||
}
|
||||
}
|
||||
@@ -474,41 +511,23 @@ public abstract class AbstractDataAbilities {
|
||||
protected void onToggleStateChanged(String key, boolean active, int state) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire a toggle event before state change.
|
||||
* @param oldState Previous state (0 = off)
|
||||
* @param newState Target state (0 = off)
|
||||
* @return true if the event was canceled
|
||||
*/
|
||||
protected boolean fireToggleEvent(Ability ability, int oldState, int newState) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire a toggle update event every 10 ticks.
|
||||
* @return true if the toggle should remain active, false to force-deactivate
|
||||
*/
|
||||
protected boolean fireToggleUpdateEvent(Ability ability, int tick, int state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all active toggles (e.g., on death/reset).
|
||||
* Calls onToggleOff and onToggleStateChanged for each active toggle.
|
||||
* Calls onToggle for each active toggle to signal deactivation.
|
||||
*/
|
||||
protected void clearActiveToggles() {
|
||||
if (activeToggles.isEmpty()) return;
|
||||
EntityLivingBase entity = getEntity();
|
||||
for (Map.Entry<String, AbilityToggleEntry> mapEntry : activeToggles.entrySet()) {
|
||||
AbilityToggleEntry entry = mapEntry.getValue();
|
||||
entry.getAbility().onToggleOff(entity);
|
||||
entry.getAbility().onToggleStateChanged(entity, entry.getState(), 0);
|
||||
entry.getAbility().onToggle(entity, entry.getState(), 0);
|
||||
}
|
||||
activeToggles.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a toggle entry directly without calling onToggleOn.
|
||||
* Add a toggle entry directly without calling onToggle.
|
||||
* Used for client-side sync and NBT restoration.
|
||||
* @param key The ability key
|
||||
* @param state The toggle state (0 = remove, 1+ = set at state)
|
||||
@@ -747,6 +766,7 @@ public abstract class AbstractDataAbilities {
|
||||
}
|
||||
}
|
||||
if (startChainEntry(chainTarget)) {
|
||||
fireChainNextEvent(currentChain, chainEntryIndex, chainTarget);
|
||||
launchConsecutiveConcurrentEntries(chainTarget);
|
||||
}
|
||||
}
|
||||
@@ -849,6 +869,24 @@ public abstract class AbstractDataAbilities {
|
||||
|
||||
currentAbility.onActiveTick(entity, target, currentAbility.getCurrentTick());
|
||||
|
||||
// Play pending defend reaction animation + sound (counter strike, dodge roll, etc.)
|
||||
if (currentAbility instanceof AbilityDefend) {
|
||||
AbilityDefend defend = (AbilityDefend) currentAbility;
|
||||
Animation defendAnim = defend.consumeDefendAnimation();
|
||||
if (defendAnim != null) {
|
||||
playAbilityAnimation(defendAnim);
|
||||
playAbilitySound(currentAbility.getActiveSound());
|
||||
defend.scheduleReturnToActive(currentAbility.getCurrentTick(), defendAnim);
|
||||
}
|
||||
// Return to active animation after defend animation finishes (Counter → guard stance)
|
||||
if (defend.shouldReturnToActiveAnimation(currentAbility.getCurrentTick())) {
|
||||
Animation activeAnim = currentAbility.getActiveAnimation();
|
||||
if (activeAnim != null) {
|
||||
playAbilityAnimation(activeAnim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if ability completed during onActiveTick
|
||||
if (currentAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
handleAbilityCompletion(target);
|
||||
@@ -1036,10 +1074,11 @@ public abstract class AbstractDataAbilities {
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
|
||||
// If chain was active, roll chain cooldown and clear chain state
|
||||
// If chain was active, fire interrupt event, roll cooldown and clear chain state
|
||||
if (currentChain != null) {
|
||||
rollChainCooldown(currentChain);
|
||||
interruptCooldownRolled = true;
|
||||
fireChainInterruptEvent(currentChain, chainEntryIndex, getTarget(), source, damage);
|
||||
currentChain = null;
|
||||
chainEntryIndex = -1;
|
||||
chainDelayRemaining = -1;
|
||||
@@ -1116,6 +1155,25 @@ public abstract class AbstractDataAbilities {
|
||||
onAbilityComplete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanly complete the currently executing ability.
|
||||
* Unlike cancel/interrupt, this triggers the normal completion path
|
||||
* (fires abilityComplete event, rolls cooldown, advances chains).
|
||||
* Only works during the ACTIVE phase.
|
||||
*/
|
||||
public void completeCurrentAbility() {
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) return;
|
||||
if (currentAbility.getPhase() != AbilityPhase.ACTIVE) return;
|
||||
|
||||
// Signal completion on the ability (handles cleanup, detach/freeOnCast, burst logic)
|
||||
if (!currentAbility.signalCompletion()) return;
|
||||
|
||||
// If signalCompletion moved to IDLE, handle the clean completion path
|
||||
if (currentAbility.getPhase() == AbilityPhase.IDLE) {
|
||||
handleAbilityCompletion(getTarget());
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CHAINED ABILITY EXECUTION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -1137,6 +1195,7 @@ public abstract class AbstractDataAbilities {
|
||||
// AFTER semantics: no delay before first entry (delay applies after each entry completes)
|
||||
boolean started = startChainEntry(target);
|
||||
if (started) {
|
||||
fireChainStartEvent(currentChain, 0, target);
|
||||
launchConsecutiveConcurrentEntries(target);
|
||||
}
|
||||
return started;
|
||||
@@ -1253,7 +1312,7 @@ public abstract class AbstractDataAbilities {
|
||||
chainEntryIndex++;
|
||||
|
||||
// Deep copy the ability so it has its own state
|
||||
Ability concurrentCopy = AbilityController.Instance.fromNBT(resolved.writeNBT());
|
||||
Ability concurrentCopy = AbilityController.Instance.fromNBT(resolved.writeNBT(true));
|
||||
if (concurrentCopy == null) continue;
|
||||
|
||||
ConcurrentSlot slot = new ConcurrentSlot(concurrentCopy);
|
||||
@@ -1279,6 +1338,7 @@ public abstract class AbstractDataAbilities {
|
||||
protected void completeChain() {
|
||||
if (currentChain != null) {
|
||||
rollChainCooldown(currentChain);
|
||||
fireChainCompleteEvent(currentChain, chainEntryIndex, getTarget());
|
||||
}
|
||||
currentChain = null;
|
||||
chainEntryIndex = -1;
|
||||
|
||||
@@ -29,15 +29,15 @@ import kamkeel.npcs.controllers.TelegraphController;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
||||
import kamkeel.npcs.controllers.data.profile.CNPCData;
|
||||
import kamkeel.npcs.developer.Developer;
|
||||
import kamkeel.npcs.entity.EntityAbilityBarrier;
|
||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityAbilityPanel;
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
||||
import kamkeel.npcs.entity.EntityEnergySweeper;
|
||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
||||
import kamkeel.npcs.entity.EntityAbilityDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
@@ -124,7 +124,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11-beta10")
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11-beta11")
|
||||
public class CustomNpcs {
|
||||
|
||||
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
|
||||
@@ -298,10 +298,10 @@ public class CustomNpcs {
|
||||
registerNewEntity(EntityAbilityDisc.class, "abilitydisc", 64, 1, true);
|
||||
registerNewEntity(EntityAbilityLaser.class, "abilitylaser", 64, 1, true);
|
||||
registerNewEntity(EntityAbilityBeam.class, "abilitybeam", 160, 1, true);
|
||||
registerNewEntity(EntityAbilitySweeper.class, "abilitysweeper", 64, 3, true);
|
||||
registerNewEntity(EntityEnergySweeper.class, "abilitysweeper", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityZone.class, "abilityzone", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityDome.class, "energydome", 64, 3, true);
|
||||
registerNewEntity(EntityAbilityPanel.class, "energypanel", 64, 3, true);
|
||||
registerNewEntity(EntityEnergyDome.class, "energydome", 64, 3, true);
|
||||
registerNewEntity(EntityEnergyPanel.class, "energypanel", 64, 3, true);
|
||||
registerNewEntity(EntityEnergySlicer.class, "energyslicer", 64, 1, true);
|
||||
|
||||
new RecipeController();
|
||||
@@ -433,7 +433,7 @@ public class CustomNpcs {
|
||||
}
|
||||
|
||||
EntityEnergyProjectile.clearAllProjectiles();
|
||||
EntityAbilityBarrier.clearAllBarriers();
|
||||
EntityEnergyBarrier.clearAllBarriers();
|
||||
EnergyChargeTracker.Instance.clear();
|
||||
|
||||
if (FMLCommonHandler.instance().getSide().isClient())
|
||||
|
||||
@@ -7,18 +7,19 @@ import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.data.IAbilityAction;
|
||||
import kamkeel.npcs.controllers.data.ability.data.entry.AbilityToggleEntry;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityGuard;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDefend;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphRemovePacket;
|
||||
import kamkeel.npcs.network.packets.data.telegraph.TelegraphSpawnPacket;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.AbilityEvent;
|
||||
import noppes.npcs.EventHooks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -124,51 +125,6 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
return npc.worldObj.getTotalWorldTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fireTickEvent(Ability ability, EntityLivingBase target) {
|
||||
AbilityEvent.TickEvent event = new AbilityEvent.TickEvent(
|
||||
npc.wrappedNPC, ability, target,
|
||||
ability.getPhase().ordinal(), ability.getCurrentTick());
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireExecuteEvent(Ability ability, EntityLivingBase target) {
|
||||
AbilityEvent.ExecuteEvent executeEvent = new AbilityEvent.ExecuteEvent(
|
||||
npc.wrappedNPC, ability, target);
|
||||
return NpcAPI.EVENT_BUS.post(executeEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fireCompleteEvent(Ability ability, EntityLivingBase target) {
|
||||
AbilityEvent.CompleteEvent completeEvent = new AbilityEvent.CompleteEvent(
|
||||
npc.wrappedNPC, ability, target);
|
||||
NpcAPI.EVENT_BUS.post(completeEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fireInterruptEvent(Ability ability, EntityLivingBase target,
|
||||
DamageSource source, float damage) {
|
||||
AbilityEvent.InterruptEvent interruptEvent = new AbilityEvent.InterruptEvent(
|
||||
npc.wrappedNPC, ability, target, source, damage);
|
||||
NpcAPI.EVENT_BUS.post(interruptEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireToggleEvent(Ability ability, int oldState, int newState) {
|
||||
AbilityEvent.ToggleEvent event = new AbilityEvent.ToggleEvent(
|
||||
npc.wrappedNPC, ability, oldState, newState);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireToggleUpdateEvent(Ability ability, int tick, int state) {
|
||||
AbilityEvent.ToggleUpdateEvent event = new AbilityEvent.ToggleUpdateEvent(
|
||||
npc.wrappedNPC, ability, tick, state);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
return event.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void spawnTelegraph(Ability ability, EntityLivingBase target) {
|
||||
List<TelegraphInstance> telegraphs = ability.createTelegraphs(npc, target);
|
||||
@@ -502,10 +458,7 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
*/
|
||||
private boolean startAbility(Ability ability, EntityLivingBase target) {
|
||||
// Fire start event (cancelable)
|
||||
AbilityEvent.StartEvent startEvent = new AbilityEvent.StartEvent(
|
||||
npc.wrappedNPC, ability, target);
|
||||
if (NpcAPI.EVENT_BUS.post(startEvent)) {
|
||||
// Event was cancelled - don't start the ability
|
||||
if (EventHooks.onAbilityStart(ability, npc, target)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -564,11 +517,6 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
|
||||
// Track hit for hit count condition
|
||||
recordHit();
|
||||
|
||||
net.minecraft.entity.Entity sourceEntity = source.getEntity();
|
||||
EntityLivingBase attacker = sourceEntity instanceof EntityLivingBase ? (EntityLivingBase) sourceEntity : null;
|
||||
currentAbility.onDamageTaken(npc, attacker, source, amount);
|
||||
|
||||
if (currentAbility.canInterrupt(source)) {
|
||||
interruptCurrentAbility(source, amount);
|
||||
return true;
|
||||
@@ -577,18 +525,6 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the damage reduction factor if a Guard ability is currently active.
|
||||
*
|
||||
* @return The damage reduction factor (0.0 = no reduction, 1.0 = full immunity), or 0 if not guarding
|
||||
*/
|
||||
public float getGuardDamageReduction() {
|
||||
if (currentAbility instanceof AbilityGuard) {
|
||||
return ((AbilityGuard) currentAbility).getDamageReductionFactor();
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a hit for the hit count condition.
|
||||
* Includes periodic cleanup to prevent memory leak.
|
||||
@@ -698,29 +634,6 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
// SCRIPT EVENTS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Fire an ability hit event. Called by abilities when they hit an entity.
|
||||
* Returns null if the event was cancelled, otherwise returns the (possibly modified) event.
|
||||
*
|
||||
* @param ability The ability doing the hit
|
||||
* @param target The original target of the ability
|
||||
* @param hitEntity The entity being hit
|
||||
* @param damage The damage amount
|
||||
* @param knockback The horizontal knockback
|
||||
* @param knockbackUp The vertical knockback
|
||||
* @return The event (with possibly modified values), or null if cancelled
|
||||
*/
|
||||
public AbilityEvent.HitEvent fireHitEvent(Ability ability, EntityLivingBase target,
|
||||
EntityLivingBase hitEntity, float damage,
|
||||
float knockback, float knockbackUp) {
|
||||
AbilityEvent.HitEvent event = new AbilityEvent.HitEvent(
|
||||
npc.wrappedNPC, ability, target, hitEntity, damage, knockback, knockbackUp);
|
||||
if (NpcAPI.EVENT_BUS.post(event)) {
|
||||
return null; // Cancelled
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the NPC this DataAbilities belongs to.
|
||||
*/
|
||||
@@ -1091,7 +1004,7 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
|
||||
NBTTagList actionList = new NBTTagList();
|
||||
for (AbilityAction slot : actionSlots) {
|
||||
actionList.appendTag(slot.writeNBT());
|
||||
actionList.appendTag(slot.writeNBT(true));
|
||||
}
|
||||
compound.setTag("AbilityActions", actionList);
|
||||
|
||||
@@ -1146,7 +1059,7 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
}
|
||||
}
|
||||
|
||||
// Active toggles - restore state directly (no onToggleOn callback during load)
|
||||
// Active toggles - restore state directly (no onToggle callback during load)
|
||||
activeToggles.clear();
|
||||
if (compound.hasKey("ActiveToggles")) {
|
||||
NBTTagList toggleNbt = compound.getTagList("ActiveToggles", 10); // 10 = TAG_COMPOUND
|
||||
|
||||
@@ -53,7 +53,16 @@ import noppes.npcs.controllers.data.RecipeScript;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.entity.EntityProjectile;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||
import noppes.npcs.api.event.IAbilityEvent;
|
||||
import noppes.npcs.api.event.IChainEvent;
|
||||
import noppes.npcs.controllers.data.AbilityScript;
|
||||
import noppes.npcs.controllers.data.ChainedAbilityScript;
|
||||
import noppes.npcs.scripted.event.AbilityEvent;
|
||||
import noppes.npcs.scripted.event.AnimationEvent;
|
||||
import noppes.npcs.scripted.event.ChainEvent;
|
||||
import noppes.npcs.scripted.event.BlockEvent;
|
||||
import noppes.npcs.scripted.event.CustomNPCsEvent;
|
||||
import noppes.npcs.scripted.event.EnergyProjectileEvent;
|
||||
@@ -68,7 +77,6 @@ import noppes.npcs.scripted.event.player.AuctionEvent;
|
||||
import noppes.npcs.scripted.event.player.CustomGuiEvent;
|
||||
import noppes.npcs.scripted.event.player.DialogEvent;
|
||||
import noppes.npcs.scripted.event.player.FactionEvent;
|
||||
import noppes.npcs.scripted.event.player.PlayerAbilityEvent;
|
||||
import noppes.npcs.scripted.event.player.PlayerEvent;
|
||||
import noppes.npcs.scripted.event.player.PlayerEvent.ChatEvent;
|
||||
import noppes.npcs.scripted.event.player.PlayerEvent.ContainerOpen;
|
||||
@@ -851,44 +859,146 @@ public class EventHooks {
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerAbilityStart(PlayerDataScript handler, PlayerAbilityEvent.StartEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_START, event);
|
||||
// ==================== ABILITY EVENTS (Unified NPC/Player) ====================
|
||||
|
||||
private static IScriptHandler getEntityScriptHandler(IEntityLivingBase entity) {
|
||||
if (entity instanceof ICustomNpc<?>) {
|
||||
return ((EntityNPCInterface) ((ICustomNpc<?>) entity).getMCEntity()).script;
|
||||
} else if (entity instanceof IPlayer && ScriptController.Instance != null) {
|
||||
return ScriptController.Instance.getPlayerScripts(
|
||||
(EntityPlayer) ((IPlayer) entity).getMCEntity());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches an ability event through the three-tier routing chain:
|
||||
* <ol>
|
||||
* <li><b>AbilityScript</b> — fires for BOTH NPC and Player casters</li>
|
||||
* <li><b>Entity script handler</b> — routes to the caster's own handler:
|
||||
* NPC casters fire on the NPC script handler only,
|
||||
* Player casters fire on the Player script handler only</li>
|
||||
* <li><b>EVENT_BUS</b> — global event bus, fires last</li>
|
||||
* </ol>
|
||||
*
|
||||
* @return true if the event was cancelled (for @Cancelable events)
|
||||
*/
|
||||
private static boolean postAbilityEvent(Ability ability, Event event) {
|
||||
IAbilityEvent abilityEvent = (IAbilityEvent) event;
|
||||
|
||||
// 1. Internal ability script (fires for ALL — both NPC and Player)
|
||||
AbilityScript abScript = ability.getScriptHandler();
|
||||
if (abScript != null) {
|
||||
abScript.callScript(abilityEvent.getHookName(), event);
|
||||
}
|
||||
|
||||
// Short-circuit if cancelled by ability script
|
||||
if (event.isCancelable() && event.isCanceled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 2. Entity script handler (NPC → NPC handler, Player → Player handler, never cross-fires)
|
||||
IScriptHandler handler = getEntityScriptHandler(abilityEvent.getEntity());
|
||||
if (handler != null && !handler.isClient()) {
|
||||
handler.callScript(abilityEvent.getHookName(), event);
|
||||
}
|
||||
|
||||
// Short-circuit if cancelled by entity script
|
||||
if (event.isCancelable() && event.isCanceled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. EVENT_BUS (global — fires last)
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onPlayerAbilityExecute(PlayerDataScript handler, PlayerAbilityEvent.ExecuteEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_EXECUTE, event);
|
||||
private static boolean postChainEvent(ChainedAbility chain, Event event) {
|
||||
IChainEvent chainEvent = (IChainEvent) event;
|
||||
|
||||
// 1. Internal chain script (fires first)
|
||||
ChainedAbilityScript chainScript = chain.getScriptHandler();
|
||||
if (chainScript != null) {
|
||||
chainScript.callScript(chainEvent.getHookName(), event);
|
||||
}
|
||||
|
||||
// Short-circuit if cancelled by chain script
|
||||
if (event.isCancelable() && event.isCanceled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 2. Entity script handler (NPC or Player)
|
||||
IScriptHandler handler = getEntityScriptHandler(chainEvent.getEntity());
|
||||
if (handler != null && !handler.isClient()) {
|
||||
handler.callScript(chainEvent.getHookName(), event);
|
||||
}
|
||||
|
||||
// Short-circuit if cancelled by entity script
|
||||
if (event.isCancelable() && event.isCanceled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. EVENT_BUS (global — fires last)
|
||||
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 boolean onAbilityStart(Ability ability, EntityLivingBase entity, EntityLivingBase target) {
|
||||
if (ability == null || entity == null) return false;
|
||||
return postAbilityEvent(ability, new AbilityEvent.StartEvent(entity, ability, target));
|
||||
}
|
||||
|
||||
public static void onPlayerAbilityInterrupt(PlayerDataScript handler, PlayerAbilityEvent.InterruptEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_INTERRUPT, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
public static boolean onAbilityExecute(Ability ability, EntityLivingBase entity, EntityLivingBase target) {
|
||||
if (ability == null || entity == null) return false;
|
||||
return postAbilityEvent(ability, new AbilityEvent.ExecuteEvent(entity, ability, target));
|
||||
}
|
||||
|
||||
public static void onPlayerAbilityComplete(PlayerDataScript handler, PlayerAbilityEvent.CompleteEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_COMPLETE, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
public static boolean onAbilityTick(Ability ability, EntityLivingBase entity, EntityLivingBase target, int phase, int tick) {
|
||||
if (ability == null || entity == null) return false;
|
||||
return postAbilityEvent(ability, new AbilityEvent.TickEvent(entity, ability, target, phase, tick));
|
||||
}
|
||||
|
||||
public static boolean onPlayerAbilityHit(PlayerDataScript handler, PlayerAbilityEvent.HitEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_HIT, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
public static boolean onAbilityComplete(Ability ability, EntityLivingBase entity, EntityLivingBase target) {
|
||||
if (ability == null || entity == null) return false;
|
||||
return postAbilityEvent(ability, new AbilityEvent.CompleteEvent(entity, ability, target));
|
||||
}
|
||||
|
||||
public static boolean onPlayerAbilityToggle(PlayerDataScript handler, PlayerAbilityEvent.ToggleEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_TOGGLE, event);
|
||||
return NpcAPI.EVENT_BUS.post(event);
|
||||
public static boolean onAbilityInterrupt(Ability ability, EntityLivingBase entity, EntityLivingBase target,
|
||||
DamageSource source, float damage) {
|
||||
if (ability == null || entity == null) return false;
|
||||
return postAbilityEvent(ability, new AbilityEvent.InterruptEvent(entity, ability, target, source, damage));
|
||||
}
|
||||
|
||||
public static void onPlayerAbilityToggleUpdate(PlayerDataScript handler, PlayerAbilityEvent.ToggleUpdateEvent event) {
|
||||
handler.callScript(EnumScriptType.ABILITY_TOGGLE_UPDATE, event);
|
||||
NpcAPI.EVENT_BUS.post(event);
|
||||
public static boolean onAbilityHit(Ability ability, AbilityEvent.HitEvent event) {
|
||||
if (ability == null || event == null) return false;
|
||||
return postAbilityEvent(ability, event);
|
||||
}
|
||||
|
||||
public static boolean onAbilityToggle(Ability ability, EntityLivingBase entity, int oldState, int newState) {
|
||||
if (ability == null || entity == null) return false;
|
||||
return postAbilityEvent(ability, new AbilityEvent.ToggleEvent(entity, ability, oldState, newState));
|
||||
}
|
||||
|
||||
public static boolean onAbilityToggleUpdate(Ability ability, AbilityEvent.ToggleUpdateEvent event) {
|
||||
if (ability == null || event == null) return false;
|
||||
return postAbilityEvent(ability, event);
|
||||
}
|
||||
|
||||
// Chain events
|
||||
|
||||
public static void onChainStart(ChainedAbility chain, EntityLivingBase entity, int entryIndex, EntityLivingBase target) {
|
||||
postChainEvent(chain, new ChainEvent.StartEvent(entity, chain, entryIndex, target));
|
||||
}
|
||||
|
||||
public static void onChainNext(ChainedAbility chain, EntityLivingBase entity, int entryIndex, EntityLivingBase target) {
|
||||
postChainEvent(chain, new ChainEvent.NextEvent(entity, chain, entryIndex, target));
|
||||
}
|
||||
|
||||
public static void onChainComplete(ChainedAbility chain, EntityLivingBase entity, int entryIndex, EntityLivingBase target) {
|
||||
postChainEvent(chain, new ChainEvent.CompleteEvent(entity, chain, entryIndex, target));
|
||||
}
|
||||
|
||||
public static void onChainInterrupt(ChainedAbility chain, EntityLivingBase entity, int entryIndex,
|
||||
EntityLivingBase target, DamageSource source, float damage) {
|
||||
postChainEvent(chain, new ChainEvent.InterruptEvent(entity, chain, entryIndex, target, source, damage));
|
||||
}
|
||||
|
||||
public static void onPlayerChangeDim(PlayerDataScript handler, IPlayer player, int fromDim, int toDim) {
|
||||
|
||||
@@ -10,10 +10,15 @@ import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityCounter;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDefend;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDodge;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityGuard;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilitySyncPacket;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
||||
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.ContainerPlayer;
|
||||
@@ -596,6 +601,7 @@ public class ScriptPlayerEventHandler {
|
||||
if (event.entityLiving.worldObj instanceof WorldServer) {
|
||||
boolean cancel = event.isCanceled();
|
||||
Entity source = NoppesUtilServer.GetDamageSource(event.source);
|
||||
|
||||
if (event.entityLiving instanceof EntityPlayerMP) {
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts((EntityPlayer) event.entityLiving);
|
||||
noppes.npcs.scripted.event.player.PlayerEvent.AttackedEvent pevent = new noppes.npcs.scripted.event.player.PlayerEvent.AttackedEvent((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayer) event.entityLiving), source, event.ammount, event.source);
|
||||
@@ -623,6 +629,22 @@ public class ScriptPlayerEventHandler {
|
||||
noppes.npcs.scripted.event.player.PlayerEvent.AttackEvent pevent1 = new noppes.npcs.scripted.event.player.PlayerEvent.AttackEvent((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayer) event.source.getEntity()), event.entityLiving, attackAmount, event.source);
|
||||
cancel = cancel || EventHooks.onPlayerAttack(handler, pevent1);
|
||||
}
|
||||
|
||||
// Dodge & Counter: cancel attack entirely
|
||||
if (!cancel && event.entityLiving instanceof EntityPlayerMP) {
|
||||
PlayerData pData = PlayerData.get((EntityPlayer) event.entityLiving);
|
||||
if (pData != null && pData.abilityData != null) {
|
||||
AbilityDefend defend = pData.abilityData.getActiveDefend();
|
||||
if (defend instanceof AbilityDodge || defend instanceof AbilityCounter) {
|
||||
EntityLivingBase attacker = source instanceof EntityLivingBase ? (EntityLivingBase) source : null;
|
||||
float result = defend.onDefend(attacker, event.source, event.ammount);
|
||||
if (result != event.ammount) {
|
||||
cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event.setCanceled(cancel);
|
||||
}
|
||||
}
|
||||
@@ -645,20 +667,28 @@ public class ScriptPlayerEventHandler {
|
||||
}
|
||||
|
||||
if (event.entityLiving instanceof EntityPlayerMP) {
|
||||
// Handle ability damage interactions (Guard counter, damage reduction)
|
||||
// Handle ability damage interactions
|
||||
PlayerData pData = PlayerData.get((EntityPlayer) event.entityLiving);
|
||||
if (pData != null && pData.abilityData != null && pData.abilityData.isExecutingAbility()) {
|
||||
if (pData.abilityData.isCurrentAbilityInvulnerable()) {
|
||||
event.ammount = 0;
|
||||
cancel = true;
|
||||
} else {
|
||||
event.ammount = pData.abilityData.onDamage(event.source, event.ammount);
|
||||
// Guard: reduce damage
|
||||
AbilityDefend defend = pData.abilityData.getActiveDefend();
|
||||
if (defend instanceof AbilityGuard) {
|
||||
EntityLivingBase attacker = source instanceof EntityLivingBase ? (EntityLivingBase) source : null;
|
||||
event.ammount = defend.onDefend(attacker, event.source, event.ammount);
|
||||
}
|
||||
|
||||
float modified = pData.abilityData.onDamage(event.source, event.ammount);
|
||||
event.ammount = modified;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
cancel = cancel || EventHooks.onPlayerDamaged(handler, pevent);
|
||||
event.ammount = pevent.damage;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.data.energycharge.EnergyChargeTracker;
|
||||
import kamkeel.npcs.entity.EntityAbilityBarrier;
|
||||
import kamkeel.npcs.entity.EntityAbilityDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumSoundOperation;
|
||||
import kamkeel.npcs.network.enums.EnumSyncAction;
|
||||
@@ -159,7 +159,7 @@ public class ServerEventsHandler {
|
||||
if (event.entityLiving == null || event.entityLiving.worldObj == null || event.entityLiving.worldObj.isRemote)
|
||||
return;
|
||||
|
||||
EntityAbilityBarrier barrier = EntityAbilityBarrier.getAbsorbingBarrier(event.entityLiving);
|
||||
EntityEnergyBarrier barrier = EntityEnergyBarrier.getAbsorbingBarrier(event.entityLiving);
|
||||
if (barrier != null) {
|
||||
// Redirect the caster's damage to their barrier
|
||||
barrier.absorbDamage(event.ammount);
|
||||
@@ -191,9 +191,9 @@ public class ServerEventsHandler {
|
||||
}
|
||||
if (!blacklisted) return;
|
||||
|
||||
List<EntityAbilityBarrier> barriers = EntityAbilityBarrier.getActiveBarriers(player.worldObj);
|
||||
for (EntityAbilityBarrier barrier : barriers) {
|
||||
if (barrier instanceof EntityAbilityDome && barrier.isEntityInside(player)) {
|
||||
List<EntityEnergyBarrier> barriers = EntityEnergyBarrier.getActiveBarriers(player.worldObj);
|
||||
for (EntityEnergyBarrier barrier : barriers) {
|
||||
if (barrier instanceof EntityEnergyDome && barrier.isEntityInside(player)) {
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,16 +79,6 @@ public class CombatHandler {
|
||||
aggressors.put(el, f + damageAmount);
|
||||
}
|
||||
|
||||
// Handle guard counter before interruption
|
||||
|
||||
// if (npc.abilities.getCurrentAbility() instanceof AbilityGuard) {
|
||||
// AbilityGuard guard =
|
||||
// (AbilityGuard) npc.abilities.getCurrentAbility();
|
||||
// if (guard.isGuarding() && e instanceof EntityLivingBase) {
|
||||
// guard.onDamageTaken(npc, (EntityLivingBase) e, source, damageAmount);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Check for ability interruption
|
||||
npc.abilities.onDamage(source, damageAmount);
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import kamkeel.npcs.addon.client.DBCClient;
|
||||
import kamkeel.npcs.client.command.CommandCNPCDebugger;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityBeam;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityDisc;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityLaser;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityOrb;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilitySweeper;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityZone;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityDome;
|
||||
import kamkeel.npcs.client.renderer.RenderAbilityPanel;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyBeam;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyDisc;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyLaser;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyOrb;
|
||||
import kamkeel.npcs.client.renderer.RenderSweeper;
|
||||
import kamkeel.npcs.client.renderer.RenderZone;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyDome;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyPanel;
|
||||
import kamkeel.npcs.client.renderer.EnergyChargePreviewRenderer;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergyExplosion;
|
||||
import kamkeel.npcs.client.renderer.RenderEnergySlicer;
|
||||
@@ -26,10 +26,10 @@ import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
import kamkeel.npcs.entity.EntityEnergySweeper;
|
||||
import kamkeel.npcs.entity.EntityAbilityZone;
|
||||
import kamkeel.npcs.entity.EntityAbilityDome;
|
||||
import kamkeel.npcs.entity.EntityAbilityPanel;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
||||
import kamkeel.npcs.entity.EntityEnergyExplosion;
|
||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -282,14 +282,14 @@ public class ClientProxy extends CommonProxy {
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityNpcDragon.class, new RenderNpcDragon(new ModelNpcDragon(0.0F), 0.5F));
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityNpcSlime.class, new RenderNpcSlime(new ModelNpcSlime(16), new ModelNpcSlime(0), 0.25F));
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityProjectile.class, new RenderProjectile());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityOrb.class, new RenderAbilityOrb());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityDisc.class, new RenderAbilityDisc());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityLaser.class, new RenderAbilityLaser());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityBeam.class, new RenderAbilityBeam());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilitySweeper.class, new RenderAbilitySweeper());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityZone.class, new RenderAbilityZone());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityDome.class, new RenderAbilityDome());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityPanel.class, new RenderAbilityPanel());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityOrb.class, new RenderEnergyOrb());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityDisc.class, new RenderEnergyDisc());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityLaser.class, new RenderEnergyLaser());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityBeam.class, new RenderEnergyBeam());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergySweeper.class, new RenderSweeper());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityAbilityZone.class, new RenderZone());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyDome.class, new RenderEnergyDome());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyPanel.class, new RenderEnergyPanel());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergySlicer.class, new RenderEnergySlicer());
|
||||
RenderingRegistry.registerEntityRenderingHandler(EntityEnergyExplosion.class, new RenderEnergyExplosion());
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.client.renderer.texture.SimpleTexture;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.config.ConfigClient;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -101,18 +102,10 @@ public class ImageDownloadAlt extends SimpleTexture {
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
URL url = new URL(ImageDownloadAlt.this.imageUrl);
|
||||
connection = (HttpURLConnection) (url).openConnection(Minecraft.getMinecraft().getProxy());
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(false);
|
||||
connection.setRequestProperty("Content-Type", "image/png");
|
||||
connection.setRequestProperty("Expect", "100-continue");
|
||||
//connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0");
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
|
||||
// Modify Accept Redirect
|
||||
if (isImgurLink(url)) {
|
||||
connection.setRequestProperty("Accept", "*/*");
|
||||
}
|
||||
// Adding a config so people can switch back if needed.
|
||||
// TODO: Remove config option if improved works better
|
||||
connection = ConfigClient.ImprovedImageDownloadConnection ? setupConnectionImproved(url) : setupConnectionOld(url);
|
||||
|
||||
connection.connect();
|
||||
|
||||
@@ -152,6 +145,44 @@ public class ImageDownloadAlt extends SimpleTexture {
|
||||
this.imageThread.start();
|
||||
}
|
||||
|
||||
private HttpURLConnection setupConnectionOld(URL url) throws IOException {
|
||||
HttpURLConnection connection = (HttpURLConnection) (url).openConnection(Minecraft.getMinecraft().getProxy());
|
||||
// setups stuff which basically tells the browser if this a get or post request
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(false);
|
||||
|
||||
// ??? I believe these are used to tell the receiver what you are sending to them
|
||||
// Not what you expect to receive from them.
|
||||
connection.setRequestProperty("Content-Type", "image/png");
|
||||
connection.setRequestProperty("Expect", "100-continue");
|
||||
//connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0");
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
|
||||
// Modify Accept Redirect
|
||||
if (isImgurLink(url)) {
|
||||
connection.setRequestProperty("Accept", "*/*");
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
private HttpURLConnection setupConnectionImproved(URL url) throws IOException {
|
||||
HttpURLConnection connection = (HttpURLConnection) (url).openConnection(Minecraft.getMinecraft().getProxy());
|
||||
|
||||
connection.setRequestMethod("GET");
|
||||
// Basically redundant because I set it as a GET request?
|
||||
// Better safe than sorry ig.
|
||||
connection.setDoInput(true);
|
||||
connection.setDoOutput(false);
|
||||
|
||||
// Random ass user agent I grabbed from my snooping on imgur
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0");
|
||||
// I tell the server what I want to receive.
|
||||
// TODO: Should this just accept PNGs?
|
||||
connection.setRequestProperty("Accept", "image/png,image/*");
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
// Check if the URL is an Imgur link
|
||||
private static boolean isImgurLink(URL url) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageEffects;
|
||||
import noppes.npcs.client.gui.script.GuiScriptInterface;
|
||||
import noppes.npcs.client.renderer.AnimationHelper;
|
||||
import noppes.npcs.client.gui.util.GuiMenuTopButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButtonYesNo;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
@@ -129,6 +130,12 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi
|
||||
int width = data.getTotalWidth();
|
||||
int height = data.getTotalHeight();
|
||||
|
||||
// Animation V offset for preview
|
||||
if (data.isAnimated()) {
|
||||
iconY += (int) (data.getCurrentFrameVOffset() * height);
|
||||
} else if (effect.animated && effect.frameCount > 1) {
|
||||
iconY += (int) (AnimationHelper.getFrameVOffset(height, effect.frameCount, effect.frametime) * height);
|
||||
}
|
||||
|
||||
func_152125_a(x, y, iconX, iconY, iconWidth, iconHeight, iconRenderSize, iconRenderSize, width, height);
|
||||
|
||||
@@ -183,6 +190,33 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi
|
||||
effect.height
|
||||
));
|
||||
scrollWindow.addLabel(new GuiNpcLabel(9, "effect.editor.height", scrollWindow.getTextField(9).xPosition - 43, y + 6, 0xFFFFFF));
|
||||
y += 25;
|
||||
|
||||
// Animation controls
|
||||
scrollWindow.addLabel(new GuiNpcLabel(11, "gui.animated", x, y + 5, 0xFFFFFF));
|
||||
GuiNpcButtonYesNo animBtn = new GuiNpcButtonYesNo(11, x + 70, y, 50, 20, effect.animated);
|
||||
animBtn.setHoverText("gui.animated.hover");
|
||||
scrollWindow.addButton(animBtn);
|
||||
|
||||
if (effect.animated) {
|
||||
y += 23;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(12, "gui.frameCount", x, y + 6, 0xFFFFFF));
|
||||
scrollWindow.addTextField(setIntegerOnly(
|
||||
new GuiNpcTextField(12, this, x + 80, y, 60, 20, "" + effect.frameCount),
|
||||
1,
|
||||
256,
|
||||
effect.frameCount
|
||||
));
|
||||
|
||||
y += 23;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(13, "gui.frameTime", x, y + 6, 0xFFFFFF));
|
||||
scrollWindow.addTextField(setIntegerOnly(
|
||||
new GuiNpcTextField(13, this, x + 80, y, 60, 20, "" + effect.frametime),
|
||||
1,
|
||||
100,
|
||||
effect.frametime
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -209,6 +243,11 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi
|
||||
GuiNpcButtonYesNo button = (GuiNpcButtonYesNo) guibutton;
|
||||
effect.lossOnDeath = button.getBoolean();
|
||||
}
|
||||
if (id == 11) {
|
||||
GuiNpcButtonYesNo button = (GuiNpcButtonYesNo) guibutton;
|
||||
effect.animated = button.getBoolean();
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -248,6 +287,12 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi
|
||||
case 9:
|
||||
effect.height = guiNpcTextField.getInteger();
|
||||
break;
|
||||
case 12:
|
||||
effect.frameCount = Math.max(1, guiNpcTextField.getInteger());
|
||||
break;
|
||||
case 13:
|
||||
effect.frametime = Math.max(1, guiNpcTextField.getInteger());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -649,9 +649,9 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
// Search matches either the display name or the typeId (strip color codes for matching)
|
||||
String stripped = displayName.replaceAll("\u00A7.", "");
|
||||
if (search.isEmpty() || stripped.toLowerCase().contains(search) || typeId.toLowerCase().contains(search)) {
|
||||
// Yellow for concurrent-capable types, gray for other built-in types
|
||||
// Lime green for concurrent-capable types, gray for other built-in types
|
||||
if (AbilityController.Instance.isConcurrentCapableType(typeId)) {
|
||||
displayName = "\u00A7e" + displayName;
|
||||
displayName = "\u00A7a" + displayName;
|
||||
} else if (AbilityController.Instance.isBuiltInType(typeId)) {
|
||||
displayName = "\u00A77" + displayName;
|
||||
}
|
||||
@@ -787,7 +787,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
|
||||
NBTTagList actionList = new NBTTagList();
|
||||
for (AbilityAction slot : npcSlots) {
|
||||
actionList.appendTag(slot.writeNBT());
|
||||
actionList.appendTag(slot.writeNBT(false));
|
||||
}
|
||||
compound.setTag("AbilityActions", actionList);
|
||||
|
||||
@@ -1105,7 +1105,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
public void onAbilitySaved(Ability ability) {
|
||||
// Editing a global parent ability via "Modify Parent" on a chain entry
|
||||
if (editingChainEntryParent) {
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT(false)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1119,7 +1119,7 @@ public class GuiNPCAbilities extends GuiNPCInterface2 implements IScrollData, IC
|
||||
AbilityAction slot = npcSlots.get(selectedAbilityIndex);
|
||||
if (slot.isReference()) {
|
||||
// Modify Parent on standalone reference — save to global preset
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT(false)));
|
||||
} else {
|
||||
// Inline ability — update slot data
|
||||
npcSlots.set(selectedAbilityIndex, AbilityAction.inline(ability));
|
||||
|
||||
@@ -3,6 +3,8 @@ package noppes.npcs.client.gui.advanced;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
|
||||
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldBuilder;
|
||||
import noppes.npcs.client.gui.script.GuiScriptInterface;
|
||||
import noppes.npcs.controllers.data.AbilityScript;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
@@ -143,6 +145,9 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
GuiMenuTopButton closeBtn = new GuiMenuTopButton(-1000, guiLeft + xSize - 22, guiTop - 17, "X");
|
||||
addTopButton(closeBtn);
|
||||
|
||||
GuiMenuTopButton scriptBtn = new GuiMenuTopButton(-999, "script.scripts", closeBtn);
|
||||
addTopButton(scriptBtn);
|
||||
|
||||
// Build scroll window dimensions
|
||||
int swX = guiLeft + 4;
|
||||
int swY = guiTop + 5;
|
||||
@@ -152,9 +157,12 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
int y = 5;
|
||||
int labelCounter = LABEL_ID_START;
|
||||
|
||||
// General tab: type label + optional concurrent label at top — reserve space
|
||||
// General tab: type label + optional info labels at top — reserve space
|
||||
if (activeTab == TAB_GENERAL) {
|
||||
y += ROW_H;
|
||||
if ("ability.cnpc.custom".equals(ability.getTypeId())) {
|
||||
y += 15;
|
||||
}
|
||||
if (ability.isConcurrentCapable()) {
|
||||
y += 15;
|
||||
}
|
||||
@@ -168,14 +176,20 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
|
||||
GuiScrollWindow sw = builder.buildScrollWindow(tabFields, swX, swY, swW, swH);
|
||||
|
||||
// General tab: add type label + optional concurrent label at top of scroll window
|
||||
// General tab: add type label + optional info labels at top of scroll window
|
||||
if (activeTab == TAB_GENERAL) {
|
||||
int baseId = builder.getNextLabelId();
|
||||
int infoY = 25;
|
||||
sw.addLabel(new GuiNpcLabel(baseId, "gui.type", 5, 10, 0xFFFFFF));
|
||||
sw.addLabel(new GuiNpcLabel(baseId + 1, ability.getTypeId(), 55, 10, 0xFFFFFF));
|
||||
if (ability.isConcurrentCapable()) {
|
||||
if ("ability.cnpc.custom".equals(ability.getTypeId())) {
|
||||
sw.addLabel(new GuiNpcLabel(baseId + 2,
|
||||
StatCollector.translateToLocal("ability.concurrentInfo"), 5, 25, 0x55FF55));
|
||||
StatCollector.translateToLocal("ability.customScriptInfo"), 5, infoY, 0xFF55FF));
|
||||
infoY += 15;
|
||||
}
|
||||
if (ability.isConcurrentCapable()) {
|
||||
sw.addLabel(new GuiNpcLabel(baseId + 3,
|
||||
StatCollector.translateToLocal("ability.concurrentInfo"), 5, infoY, 0x55FF55));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,6 +316,13 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (id == -999) {
|
||||
GuiNpcTextField.unfocus();
|
||||
applyToAbility();
|
||||
callback.onAbilitySaved(ability);
|
||||
GuiScriptInterface.open(parent, new AbilityScript(ability.getId()));
|
||||
return;
|
||||
}
|
||||
if (id == -1000) {
|
||||
close();
|
||||
return;
|
||||
@@ -405,7 +426,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
|
||||
public void loadAbility(Ability loadedAbility) {
|
||||
if (loadedAbility == null) return;
|
||||
NBTTagCompound nbt = loadedAbility.writeNBT();
|
||||
NBTTagCompound nbt = loadedAbility.writeNBT(false);
|
||||
nbt.setString("typeId", ability.getTypeId());
|
||||
ability.readNBT(nbt);
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface implements ISubGui
|
||||
|
||||
private void doSave() {
|
||||
saved = true;
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT(false)));
|
||||
if (callback != null) {
|
||||
callback.onAbilitySaved(ability);
|
||||
}
|
||||
|
||||
@@ -83,8 +83,10 @@ public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomS
|
||||
continue;
|
||||
|
||||
String displayName = I18n.format(typeId);
|
||||
if (AbilityController.Instance.isConcurrentCapableType(typeId)) {
|
||||
displayName = "\u00A7e" + displayName;
|
||||
if (typeId.equals("ability.cnpc.custom")) {
|
||||
displayName = "\u00A7d" + displayName;
|
||||
} else if (AbilityController.Instance.isConcurrentCapableType(typeId)) {
|
||||
displayName = "\u00A7a" + displayName;
|
||||
}
|
||||
allDisplayNameToTypeId.put(displayName, typeId);
|
||||
}
|
||||
@@ -122,6 +124,21 @@ public class SubGuiAbilityTypeSelect extends SubGuiInterface implements ICustomS
|
||||
}
|
||||
Collections.sort(list, (a, b) -> String.CASE_INSENSITIVE_ORDER.compare(
|
||||
a.replaceAll("\u00A7.", ""), b.replaceAll("\u00A7.", "")));
|
||||
|
||||
// Pin Custom Ability to top of list
|
||||
String customEntry = null;
|
||||
for (String name : list) {
|
||||
String tid = displayNameToTypeId.get(name);
|
||||
if (tid != null && tid.equals("ability.cnpc.custom")) {
|
||||
customEntry = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (customEntry != null) {
|
||||
list.remove(customEntry);
|
||||
list.add(0, customEntry);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityAction;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import noppes.npcs.client.gui.script.GuiScriptInterface;
|
||||
import noppes.npcs.controllers.data.ChainedAbilityScript;
|
||||
import kamkeel.npcs.controllers.data.ability.data.entry.ChainedAbilityEntry;
|
||||
import kamkeel.npcs.controllers.data.ability.data.AbilityIconData;
|
||||
import kamkeel.npcs.controllers.data.ability.gui.IChainedAbilityFieldProvider;
|
||||
@@ -57,6 +59,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
|
||||
private static final int BTN_TAB_ENTRIES = 91;
|
||||
private static final int BTN_TAB_TARGET = 92;
|
||||
private static final int BTN_TAB_EXTRA_BASE = 93;
|
||||
private static final int BTN_SCRIPT = -999;
|
||||
private static final int BTN_CLOSE = -1000;
|
||||
|
||||
// ── Entries tab: per-entry ID encoding ─────────────────────────────────────
|
||||
@@ -160,14 +163,43 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
|
||||
|
||||
// ── Icon tab ──────────────────────────────────────────────
|
||||
AbilityIconData chainIcon = AbilityIconData.fromChainedAbility(chain);
|
||||
fieldDefs.add(FieldDef.stringField("gui.texture", chainIcon::getTexture, chainIcon::setTexture).tab("Icon"));
|
||||
fieldDefs.add(FieldDef.section("ability.icon.section.uv").tab("Icon"));
|
||||
fieldDefs.add(FieldDef.intField("ability.icon.x", chainIcon::getIconX, chainIcon::setIconX).tab("Icon").range(0, 4096));
|
||||
fieldDefs.add(FieldDef.intField("ability.icon.y", chainIcon::getIconY, chainIcon::setIconY).tab("Icon").range(0, 4096));
|
||||
fieldDefs.add(FieldDef.section("gui.size").tab("Icon"));
|
||||
fieldDefs.add(FieldDef.intField("gui.width", chainIcon::getWidth, chainIcon::setWidth).tab("Icon").range(1, 256));
|
||||
fieldDefs.add(FieldDef.intField("gui.height", chainIcon::getHeight, chainIcon::setHeight).tab("Icon").range(1, 256));
|
||||
fieldDefs.add(FieldDef.row(
|
||||
FieldDef.intField("gui.width", chainIcon::getWidth, chainIcon::setWidth).range(1, 256),
|
||||
FieldDef.intField("gui.height", chainIcon::getHeight, chainIcon::setHeight).range(1, 256)
|
||||
).tab("Icon"));
|
||||
fieldDefs.add(FieldDef.floatField("gui.scale", chainIcon::getScale, chainIcon::setScale).tab("Icon").range(0.1f, 10.0f));
|
||||
fieldDefs.add(FieldDef.intField("ability.icon.layers", chainIcon::getLayerCount, chainIcon::setLayerCount)
|
||||
.tab("Icon").range(1, AbilityIconData.MAX_LAYERS));
|
||||
for (int i = 0; i < AbilityIconData.MAX_LAYERS; i++) {
|
||||
final int idx = i;
|
||||
java.util.function.BooleanSupplier layerVisible = () -> chainIcon.getLayerCount() > idx;
|
||||
String sectionLabel = net.minecraft.util.StatCollector.translateToLocal("ability.icon.layer") + " " + (idx + 1);
|
||||
fieldDefs.add(FieldDef.section(sectionLabel).tab("Icon").visibleWhen(layerVisible));
|
||||
fieldDefs.add(FieldDef.stringField("gui.texture",
|
||||
() -> chainIcon.getLayer(idx).texture,
|
||||
t -> chainIcon.setLayerTexture(idx, t))
|
||||
.tab("Icon").visibleWhen(layerVisible));
|
||||
fieldDefs.add(FieldDef.row(
|
||||
FieldDef.intField("ability.icon.x",
|
||||
() -> chainIcon.getLayer(idx).iconX,
|
||||
x -> chainIcon.setLayerIconX(idx, x)).range(0, 4096),
|
||||
FieldDef.intField("ability.icon.y",
|
||||
() -> chainIcon.getLayer(idx).iconY,
|
||||
y -> chainIcon.setLayerIconY(idx, y)).range(0, 4096)
|
||||
).tab("Icon").visibleWhen(layerVisible));
|
||||
fieldDefs.add(FieldDef.colorSubGui("ability.icon.tint",
|
||||
() -> chainIcon.getLayer(idx).tintColor,
|
||||
c -> chainIcon.setLayerTintColor(idx, c))
|
||||
.tab("Icon").visibleWhen(layerVisible));
|
||||
}
|
||||
|
||||
// Animation
|
||||
fieldDefs.add(FieldDef.section("Animation").tab("Icon"));
|
||||
fieldDefs.add(FieldDef.boolField("gui.animated", chainIcon::isAnimated, chainIcon::setAnimated).tab("Icon").hover("gui.animated.hover"));
|
||||
fieldDefs.add(FieldDef.intField("gui.frameCount", chainIcon::getFrameCount, chainIcon::setFrameCount)
|
||||
.tab("Icon").range(1, 256).visibleWhen(chainIcon::isAnimated));
|
||||
fieldDefs.add(FieldDef.intField("gui.frameTime", chainIcon::getFrameTime, chainIcon::setFrameTime)
|
||||
.tab("Icon").range(1, 100).visibleWhen(chainIcon::isAnimated));
|
||||
|
||||
// External field providers (e.g., DBC Addon injecting a "DBC" tab)
|
||||
if (AbilityController.Instance != null) {
|
||||
@@ -258,6 +290,9 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
|
||||
GuiMenuTopButton closeBtn = new GuiMenuTopButton(BTN_CLOSE, guiLeft + xSize - 22, guiTop - 17, "X");
|
||||
addTopButton(closeBtn);
|
||||
|
||||
GuiMenuTopButton scriptBtn = new GuiMenuTopButton(BTN_SCRIPT, "script.scripts", closeBtn);
|
||||
addTopButton(scriptBtn);
|
||||
|
||||
// Scroll window dimensions
|
||||
int swX = guiLeft + 4;
|
||||
int swY = guiTop + 5;
|
||||
@@ -487,6 +522,10 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (id == BTN_SCRIPT) {
|
||||
GuiScriptInterface.open(parent, new ChainedAbilityScript(chain.getId()));
|
||||
return;
|
||||
}
|
||||
if (id == BTN_CLOSE) {
|
||||
saveOnClose = true;
|
||||
close();
|
||||
@@ -853,7 +892,7 @@ public class SubGuiChainedAbilityConfig extends SubGuiInterface implements IText
|
||||
public void onAbilitySaved(Ability ability) {
|
||||
if (editingParentAbility) {
|
||||
// Persist the global parent ability to the server
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(ability.writeNBT(false)));
|
||||
editingParentAbility = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -187,19 +187,27 @@ public class FieldDef {
|
||||
idSetter.accept(-1);
|
||||
} else {
|
||||
idSetter.accept(sel.selectedAnimationId);
|
||||
nameSetter.accept("");
|
||||
String customName = sel.getSelectedName();
|
||||
nameSetter.accept(customName != null ? customName : "");
|
||||
}
|
||||
})
|
||||
.buttonLabel(() -> {
|
||||
String name = nameGetter.get();
|
||||
if (name != null && !name.isEmpty()) return name;
|
||||
int id = idGetter.get();
|
||||
if (id < 0 && name != null && !name.isEmpty()) {
|
||||
// Built-in animation: show just the name
|
||||
return name;
|
||||
}
|
||||
if (id >= 0) {
|
||||
// Custom animation: show (X) Name
|
||||
if (name != null && !name.isEmpty()) {
|
||||
return "(" + id + ") " + name;
|
||||
}
|
||||
Animation anim = AnimationController.Instance != null
|
||||
? (Animation) AnimationController.Instance.get(id) : null;
|
||||
String animName = anim != null ? anim.getName() : "";
|
||||
return animName != null && !animName.isEmpty()
|
||||
? "(ID: " + id + ") " + animName : "ID: " + id;
|
||||
? "(" + id + ") " + animName : String.valueOf(id);
|
||||
}
|
||||
return "gui.none";
|
||||
})
|
||||
|
||||
@@ -347,9 +347,14 @@ public class GuiFieldBuilder {
|
||||
String translated = StatCollector.translateToLocal(def.getLabel());
|
||||
int labelW = fontRenderer.getStringWidth(translated);
|
||||
int fieldX = colLLabel + labelW + labelPadding;
|
||||
// Clamp field width so it doesn't extend under the scrollbar
|
||||
// Available width before the scrollbar
|
||||
int maxW = contentRight - fieldX - 15;
|
||||
if (maxW > 0 && fieldW > maxW) fieldW = maxW;
|
||||
if (def.getType() == FieldType.SUB_GUI && maxW > 0) {
|
||||
// SUB_GUI fields fill all available width up to the scrollbar
|
||||
fieldW = maxW;
|
||||
} else if (maxW > 0 && fieldW > maxW) {
|
||||
fieldW = maxW;
|
||||
}
|
||||
renderFieldAt(def, colLLabel, fieldX, fieldW, y);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import noppes.npcs.api.gui.ICustomGuiComponent;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.gui.custom.GuiCustom;
|
||||
import noppes.npcs.client.gui.custom.interfaces.IGuiComponent;
|
||||
import noppes.npcs.client.renderer.AnimationHelper;
|
||||
import noppes.npcs.client.renderer.ImageData;
|
||||
import noppes.npcs.scripted.gui.ScriptGuiTexturedRect;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -30,6 +31,11 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
|
||||
float alpha;
|
||||
float rotation;
|
||||
|
||||
// Animation
|
||||
boolean animated;
|
||||
int frameCount = 1;
|
||||
int frametime = 2;
|
||||
|
||||
public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) {
|
||||
this(id, texture, x, y, width, height, 0, 0);
|
||||
}
|
||||
@@ -64,10 +70,18 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
|
||||
int totalWidth = this.imageData.getTotalWidth();
|
||||
int totalHeight = this.imageData.getTotalHeight();
|
||||
|
||||
// Animation V offset
|
||||
float vOff = 0f;
|
||||
if (this.imageData.isAnimated()) {
|
||||
vOff = this.imageData.getCurrentFrameVOffset();
|
||||
} else if (this.animated && this.frameCount > 1) {
|
||||
vOff = AnimationHelper.getFrameVOffset(totalHeight, this.frameCount, this.frametime);
|
||||
}
|
||||
|
||||
float u1 = (float) textureX / (float) totalWidth;
|
||||
float u2 = u1 + (float) width / (float) totalWidth;
|
||||
float v1 = (float) textureY / (float) totalHeight;
|
||||
float v2 = v1 + (float) height / (float) totalHeight;
|
||||
float v1 = vOff + (float) textureY / (float) totalHeight;
|
||||
float v2 = vOff + ((float) textureY + (float) height) / (float) totalHeight;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
float red = (color >> 16 & 255) / 255f;
|
||||
@@ -104,6 +118,9 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
|
||||
component.setColor(color);
|
||||
component.setAlpha(alpha);
|
||||
component.setRotation(rotation);
|
||||
if (this.animated && this.frameCount > 1) {
|
||||
component.setAnimation(this.frameCount, this.frametime);
|
||||
}
|
||||
return component;
|
||||
}
|
||||
|
||||
@@ -124,6 +141,12 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
|
||||
rect.alpha = component.getAlpha();
|
||||
rect.rotation = component.getRotation();
|
||||
|
||||
if (component.isAnimated()) {
|
||||
rect.animated = true;
|
||||
rect.frameCount = component.getFrameCount();
|
||||
rect.frametime = component.getFrameTime();
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityVariant;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
|
||||
import java.util.UUID;
|
||||
import kamkeel.npcs.network.packets.request.ability.BuiltInAbilityGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.ChainedAbilitiesGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.ability.ChainedAbilityGetPacket;
|
||||
@@ -495,7 +497,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
private void handleChainConfigClosed() {
|
||||
if (pendingSaveChain != null) {
|
||||
PacketClient.sendClient(new ChainedAbilitySavePacket(pendingSaveChain.writeNBT()));
|
||||
PacketClient.sendClient(new ChainedAbilitySavePacket(pendingSaveChain.writeNBT(false)));
|
||||
selected = pendingSaveChain.getName();
|
||||
pendingSaveChain = null;
|
||||
}
|
||||
@@ -510,6 +512,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
|
||||
if (newAbility != null) {
|
||||
gui.getVariants().get(idx).apply(newAbility);
|
||||
newAbility.setId(UUID.randomUUID().toString());
|
||||
pendingTypeId = null;
|
||||
openConfig(newAbility);
|
||||
return true;
|
||||
@@ -536,6 +539,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
if (variants.size() == 1) {
|
||||
variants.get(0).apply(newAbility);
|
||||
}
|
||||
newAbility.setId(UUID.randomUUID().toString());
|
||||
openConfig(newAbility);
|
||||
return true;
|
||||
}
|
||||
@@ -550,7 +554,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
if (pendingSaveAbility == null) return false;
|
||||
|
||||
if (gui.isConfirmed()) {
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT(false)));
|
||||
pendingSaveAbility = null;
|
||||
return false;
|
||||
}
|
||||
@@ -574,7 +578,7 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return true;
|
||||
}
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT(false)));
|
||||
pendingSaveAbility = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.renderer.AnimationHelper;
|
||||
import noppes.npcs.client.renderer.ImageData;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@@ -25,6 +26,11 @@ public class AbilityIcon extends Gui {
|
||||
public int width;
|
||||
public int height;
|
||||
|
||||
// Default icon layers (extracted from ability)
|
||||
private Ability.DefaultIconLayer[] defaultLayers = null;
|
||||
private int defaultIconWidth = 48;
|
||||
private int defaultIconHeight = 48;
|
||||
|
||||
private AbilityIcon(AbilityIconData data) {
|
||||
this.data = data;
|
||||
this.width = data.width;
|
||||
@@ -33,7 +39,11 @@ public class AbilityIcon extends Gui {
|
||||
|
||||
public static AbilityIcon fromAbility(Ability ability) {
|
||||
if (ability != null) {
|
||||
return new AbilityIcon(AbilityIconData.fromAbility(ability));
|
||||
AbilityIcon icon = new AbilityIcon(AbilityIconData.fromAbility(ability));
|
||||
icon.defaultLayers = ability.getDefaultIconLayers();
|
||||
icon.defaultIconWidth = ability.getDefaultIconWidth();
|
||||
icon.defaultIconHeight = ability.getDefaultIconHeight();
|
||||
return icon;
|
||||
}
|
||||
return fromDefaults();
|
||||
}
|
||||
@@ -66,44 +76,88 @@ public class AbilityIcon extends Gui {
|
||||
public void draw(int state, float alpha) {
|
||||
TextureManager renderEngine = Minecraft.getMinecraft().renderEngine;
|
||||
|
||||
ImageData imageData = null;
|
||||
if (data.hasTexture()) {
|
||||
imageData = ClientCacheHandler.getImageData(data.texture);
|
||||
}
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glColor4f(1, 1, 1, alpha);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
Tessellator t;
|
||||
|
||||
if (imageData == null || !imageData.imageLoaded()) {
|
||||
GL11.glScalef(1.0f, 1.0f, 1);
|
||||
renderEngine.bindTexture(FALLBACK_TEXTURE);
|
||||
t = getFallbackTessellator();
|
||||
} else {
|
||||
if (data.isEnabled()) {
|
||||
// Path 1: Custom icon — draw each active layer bottom-to-top
|
||||
GL11.glScalef(data.scale, data.scale, 1);
|
||||
renderEngine.bindTexture(imageData.getLocation());
|
||||
t = getTessellator(imageData, state);
|
||||
boolean drewAny = false;
|
||||
for (int i = 0; i < data.getLayerCount(); i++) {
|
||||
AbilityIconData.Layer layer = data.getLayer(i);
|
||||
if (!layer.hasTexture()) continue;
|
||||
ImageData imageData = ClientCacheHandler.getImageData(layer.texture);
|
||||
if (imageData != null && imageData.imageLoaded()) {
|
||||
int tint = layer.tintColor;
|
||||
float r = ((tint >> 16) & 0xFF) / 255f;
|
||||
float g = ((tint >> 8) & 0xFF) / 255f;
|
||||
float b = (tint & 0xFF) / 255f;
|
||||
GL11.glColor4f(r, g, b, alpha);
|
||||
renderEngine.bindTexture(imageData.getLocation());
|
||||
Tessellator t = getLayerTessellator(imageData, layer, i == 0 ? state : 0);
|
||||
t.draw();
|
||||
drewAny = true;
|
||||
}
|
||||
}
|
||||
if (!drewAny) {
|
||||
GL11.glColor4f(1, 1, 1, alpha);
|
||||
renderEngine.bindTexture(FALLBACK_TEXTURE);
|
||||
getFallbackTessellator().draw();
|
||||
}
|
||||
} else if (hasDefaultLayers()) {
|
||||
// Path 2: Default layers — draw each layer with its dynamic color
|
||||
for (Ability.DefaultIconLayer defLayer : defaultLayers) {
|
||||
String texPath = defLayer.getTextureForState(state);
|
||||
if (texPath == null || texPath.isEmpty()) continue;
|
||||
ImageData imageData = ClientCacheHandler.getImageData(texPath);
|
||||
if (imageData != null && imageData.imageLoaded()) {
|
||||
int color = defLayer.getColor();
|
||||
float r = ((color >> 16) & 0xFF) / 255f;
|
||||
float g = ((color >> 8) & 0xFF) / 255f;
|
||||
float b = (color & 0xFF) / 255f;
|
||||
GL11.glColor4f(r, g, b, alpha);
|
||||
renderEngine.bindTexture(imageData.getLocation());
|
||||
getDefaultIconTessellator().draw();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Path 3: No custom icon, no default layers — generic fallback
|
||||
GL11.glColor4f(1, 1, 1, alpha);
|
||||
renderEngine.bindTexture(FALLBACK_TEXTURE);
|
||||
getFallbackTessellator().draw();
|
||||
}
|
||||
|
||||
t.draw();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private Tessellator getTessellator(ImageData imageData, int state) {
|
||||
private boolean hasDefaultLayers() {
|
||||
return defaultLayers != null && defaultLayers.length > 0;
|
||||
}
|
||||
|
||||
private Tessellator getLayerTessellator(ImageData imageData, AbilityIconData.Layer layer, int state) {
|
||||
float hw = data.width / 2f;
|
||||
float hh = data.height / 2f;
|
||||
|
||||
float texW = imageData.getTotalWidth();
|
||||
float texH = imageData.getTotalHeight();
|
||||
|
||||
int ix = data.getIconXForState(state);
|
||||
int iy = data.getIconYForState(state);
|
||||
// State UV overrides only apply to layer 0
|
||||
int ix = (state > 0) ? data.getIconXForState(state) : layer.iconX;
|
||||
int iy = (state > 0) ? data.getIconYForState(state) : layer.iconY;
|
||||
|
||||
// Animation V offset
|
||||
float vOff = 0f;
|
||||
if (imageData.isAnimated()) {
|
||||
vOff = imageData.getCurrentFrameVOffset();
|
||||
} else if (data.isAnimated()) {
|
||||
vOff = AnimationHelper.getFrameVOffset((int) texH, data.getFrameCount(), data.getFrameTime());
|
||||
}
|
||||
|
||||
float u1 = ix / texW;
|
||||
float v1 = iy / texH;
|
||||
float v1 = vOff + iy / texH;
|
||||
float u2 = (ix + data.width) / texW;
|
||||
float v2 = (iy + data.height) / texH;
|
||||
float v2 = vOff + (iy + data.height) / texH;
|
||||
|
||||
Tessellator t = Tessellator.instance;
|
||||
t.startDrawingQuads();
|
||||
@@ -114,6 +168,19 @@ public class AbilityIcon extends Gui {
|
||||
return t;
|
||||
}
|
||||
|
||||
private Tessellator getDefaultIconTessellator() {
|
||||
float hw = defaultIconWidth / 2f;
|
||||
float hh = defaultIconHeight / 2f;
|
||||
|
||||
Tessellator t = Tessellator.instance;
|
||||
t.startDrawingQuads();
|
||||
t.addVertexWithUV(-hw, hh, zLevel, 0, 1);
|
||||
t.addVertexWithUV(hw, hh, zLevel, 1, 1);
|
||||
t.addVertexWithUV(hw, -hh, zLevel, 1, 0);
|
||||
t.addVertexWithUV(-hw, -hh, zLevel, 0, 0);
|
||||
return t;
|
||||
}
|
||||
|
||||
private Tessellator getFallbackTessellator() {
|
||||
float hw = 16f;
|
||||
float hh = 16f;
|
||||
@@ -128,17 +195,20 @@ public class AbilityIcon extends Gui {
|
||||
}
|
||||
|
||||
public boolean hasTexture() {
|
||||
return data.hasTexture();
|
||||
return data.isEnabled() || hasDefaultLayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the approximate visual size (max dimension) that draw() produces.
|
||||
* Textured: max(width,height) * scale. Fallback: 32.
|
||||
* Custom icon: max(width,height) * scale. Default icon: max(defaultW,defaultH). Fallback: 32.
|
||||
*/
|
||||
public float getDrawSize() {
|
||||
if (data.hasTexture()) {
|
||||
if (data.isEnabled()) {
|
||||
return Math.max(width, height) * data.scale;
|
||||
}
|
||||
if (hasDefaultLayers()) {
|
||||
return Math.max(defaultIconWidth, defaultIconHeight);
|
||||
}
|
||||
return 32f;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.renderer.AnimationHelper;
|
||||
import noppes.npcs.client.gui.SubGuiColorSelector;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageLinked;
|
||||
import noppes.npcs.client.gui.script.GuiScriptInterface;
|
||||
@@ -286,6 +287,31 @@ public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListe
|
||||
scrollWindow.addLabel(new GuiNpcLabel(70, "display.durabilityShow", x, localY + 5, 0xFFFFFF));
|
||||
GuiNpcButtonYesNo durabilityButton = new GuiNpcButtonYesNo(26, x + 120, localY, linkedItem.display.durabilityShow);
|
||||
scrollWindow.addButton(durabilityButton);
|
||||
localY += 30;
|
||||
|
||||
// Animation controls
|
||||
scrollWindow.addLabel(new GuiNpcLabel(80, "gui.animated", x, localY + 5, 0xFFFFFF));
|
||||
boolean isAnim = linkedItem.display.animated != null && linkedItem.display.animated;
|
||||
GuiNpcButtonYesNo animBtn = new GuiNpcButtonYesNo(29, x + 120, localY, isAnim);
|
||||
animBtn.setHoverText("gui.animated.hover");
|
||||
scrollWindow.addButton(animBtn);
|
||||
localY += 25;
|
||||
|
||||
if (isAnim) {
|
||||
scrollWindow.addLabel(new GuiNpcLabel(81, "gui.frameCount", x, localY + 5, 0xFFFFFF));
|
||||
GuiNpcTextField fcField = new GuiNpcTextField(71, this, x + 120, localY, 60, 20,
|
||||
"" + (linkedItem.display.frameCount != null ? linkedItem.display.frameCount : 1));
|
||||
fcField.setIntegersOnly().setMinMaxDefault(1, 256, 1);
|
||||
scrollWindow.addTextField(fcField);
|
||||
localY += 25;
|
||||
|
||||
scrollWindow.addLabel(new GuiNpcLabel(82, "gui.frameTime", x, localY + 5, 0xFFFFFF));
|
||||
GuiNpcTextField ftField = new GuiNpcTextField(72, this, x + 120, localY, 60, 20,
|
||||
"" + (linkedItem.display.frametime != null ? linkedItem.display.frametime : 2));
|
||||
ftField.setIntegersOnly().setMinMaxDefault(1, 100, 2);
|
||||
scrollWindow.addTextField(ftField);
|
||||
localY += 25;
|
||||
}
|
||||
|
||||
scrollWindow.scrollY = 0;
|
||||
scrollWindow.maxScrollY = Math.max(localY - scrollWindow.clipHeight, 0);
|
||||
@@ -381,6 +407,9 @@ public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListe
|
||||
linkedItem.isNormalItem = ((GuiNpcButtonYesNo) guibutton).getBoolean();
|
||||
} else if (id == 26 && guibutton instanceof GuiNpcButtonYesNo) {
|
||||
linkedItem.display.durabilityShow = ((GuiNpcButtonYesNo) guibutton).getBoolean();
|
||||
} else if (id == 29 && guibutton instanceof GuiNpcButtonYesNo) {
|
||||
linkedItem.display.animated = ((GuiNpcButtonYesNo) guibutton).getBoolean();
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,6 +458,10 @@ public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListe
|
||||
linkedItem.display.translateY = textField.getFloat();
|
||||
} else if (id == 63) {
|
||||
linkedItem.display.translateZ = textField.getFloat();
|
||||
} else if (id == 71) {
|
||||
linkedItem.display.frameCount = Math.max(1, textField.getInteger());
|
||||
} else if (id == 72) {
|
||||
linkedItem.display.frametime = Math.max(1, textField.getInteger());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,7 +505,20 @@ public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListe
|
||||
int iconWidth = data.getTotalWidth();
|
||||
int iconHeight = data.getTotalWidth();
|
||||
int width = data.getTotalWidth();
|
||||
int height = data.getTotalWidth();
|
||||
int height = data.getTotalHeight();
|
||||
|
||||
// Animation V offset for preview
|
||||
if (data.isAnimated()) {
|
||||
iconY += (int) (data.getCurrentFrameVOffset() * height);
|
||||
iconHeight = data.getFrameHeight();
|
||||
} else if (linkedItem.display.animated != null && linkedItem.display.animated
|
||||
&& linkedItem.display.frameCount != null && linkedItem.display.frameCount > 1) {
|
||||
iconY += (int) (AnimationHelper.getFrameVOffset(height, linkedItem.display.frameCount, linkedItem.display.frametime) * height);
|
||||
iconHeight = height / linkedItem.display.frameCount;
|
||||
} else {
|
||||
iconHeight = data.getTotalWidth();
|
||||
height = data.getTotalWidth();
|
||||
}
|
||||
|
||||
float[] colors = ColorUtil.hexToRGB(linkedItem.display.itemColor);
|
||||
GL11.glColor3f(colors[0], colors[1], colors[2]);
|
||||
|
||||
@@ -145,11 +145,12 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL
|
||||
scrollSounds.resetScroll();
|
||||
getTextField(66).setText("");
|
||||
soundSearch = "";
|
||||
initGui();
|
||||
}
|
||||
if (guiCustomScroll.id == 1) {
|
||||
selectedResource = new ResourceLocation(selectedDomain, guiCustomScroll.getSelected());
|
||||
getButton(1).enabled = true;
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.renderer.AnimationHelper;
|
||||
import noppes.npcs.client.renderer.ImageData;
|
||||
import noppes.npcs.controllers.data.CustomEffect;
|
||||
import noppes.npcs.controllers.data.PlayerEffect;
|
||||
@@ -82,6 +83,13 @@ public class GuiEffectBar extends GuiScreen {
|
||||
int texWidth = imageData.getTotalWidth();
|
||||
int texHeight = imageData.getTotalHeight();
|
||||
|
||||
// Animation V offset
|
||||
if (imageData.isAnimated()) {
|
||||
iconV += (int) (imageData.getCurrentFrameVOffset() * texHeight);
|
||||
} else if (entry.effect.animated && entry.effect.frameCount > 1) {
|
||||
iconV += (int) (AnimationHelper.getFrameVOffset(texHeight, entry.effect.frameCount, entry.effect.frametime) * texHeight);
|
||||
}
|
||||
|
||||
// Use iconYOffset to vertically center the icon
|
||||
func_152125_a(x + 2, drawY + iconYOffset, iconU, iconV, iconWidth, iconHeight, iconRenderSize, iconRenderSize, texWidth, texHeight);
|
||||
|
||||
@@ -191,7 +199,14 @@ public class GuiEffectBar extends GuiScreen {
|
||||
if (imageData != null && imageData.imageLoaded()) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
imageData.bindTexture();
|
||||
func_152125_a(tooltipX + (maxWidth - iconSize) / 2, textY + 4, hoveredEffect.iconX, hoveredEffect.iconY, hoveredEffect.getWidth(), hoveredEffect.getHeight(), iconSize, iconSize, imageData.getTotalWidth(), imageData.getTotalHeight());
|
||||
int tooltipIconV = hoveredEffect.iconY;
|
||||
int tooltipTexH = imageData.getTotalHeight();
|
||||
if (imageData.isAnimated()) {
|
||||
tooltipIconV += (int) (imageData.getCurrentFrameVOffset() * tooltipTexH);
|
||||
} else if (hoveredEffect.animated && hoveredEffect.frameCount > 1) {
|
||||
tooltipIconV += (int) (AnimationHelper.getFrameVOffset(tooltipTexH, hoveredEffect.frameCount, hoveredEffect.frametime) * tooltipTexH);
|
||||
}
|
||||
func_152125_a(tooltipX + (maxWidth - iconSize) / 2, textY + 4, hoveredEffect.iconX, tooltipIconV, hoveredEffect.getWidth(), hoveredEffect.getHeight(), iconSize, iconSize, imageData.getTotalWidth(), tooltipTexH);
|
||||
}
|
||||
|
||||
textureManager.bindTexture(specialIcons);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package noppes.npcs.client.renderer;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
/**
|
||||
* Static utility for computing animated texture UV offsets.
|
||||
* Used by renderers when animation parameters come from data class fields
|
||||
* rather than .mcmeta auto-detection on ImageData.
|
||||
*/
|
||||
public class AnimationHelper {
|
||||
|
||||
/**
|
||||
* Returns the V-coordinate offset (0.0-1.0) for the current animation frame.
|
||||
* Based on system time for consistent sync across all animated textures.
|
||||
*
|
||||
* @param totalHeight Total pixel height of the sprite strip
|
||||
* @param frameCount Number of frames in the strip
|
||||
* @param frametime Ticks per frame (1 tick = 50ms)
|
||||
* @return V offset in 0.0-1.0 range, or 0.0 if not animated
|
||||
*/
|
||||
public static float getFrameVOffset(int totalHeight, int frameCount, int frametime) {
|
||||
if (frameCount <= 1 || totalHeight <= 0) {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
frametime = Math.max(1, frametime);
|
||||
long millis = Minecraft.getSystemTime();
|
||||
int tick = (int) (millis / 50L);
|
||||
int frameIdx = (tick / frametime) % frameCount;
|
||||
int frameHeight = totalHeight / frameCount;
|
||||
|
||||
return (float) (frameIdx * frameHeight) / (float) totalHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the V-coordinate size of a single frame in 0.0-1.0 range.
|
||||
*
|
||||
* @param totalHeight Total pixel height of the sprite strip
|
||||
* @param frameCount Number of frames in the strip
|
||||
* @return V size of one frame, or 1.0 if not animated
|
||||
*/
|
||||
public static float getFrameVSize(int totalHeight, int frameCount) {
|
||||
if (frameCount <= 1 || totalHeight <= 0) {
|
||||
return 1f;
|
||||
}
|
||||
int frameHeight = totalHeight / frameCount;
|
||||
return (float) frameHeight / (float) totalHeight;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package noppes.npcs.client.renderer;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
@@ -11,6 +14,7 @@ import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class ImageData {
|
||||
private final ResourceLocation location;
|
||||
@@ -23,6 +27,14 @@ public class ImageData {
|
||||
private boolean gotWidthHeight;
|
||||
private boolean invalid;
|
||||
|
||||
// Animation fields
|
||||
private boolean animated = false;
|
||||
private int frameCount = 1;
|
||||
private int frametime = 2;
|
||||
private int[] frames = null;
|
||||
private boolean interpolate = false;
|
||||
private boolean mcmetaChecked = false;
|
||||
|
||||
public ImageData(String directory) {
|
||||
this.location = new ResourceLocation(directory);
|
||||
if (directory.startsWith("https://") || directory.startsWith("http://")) {
|
||||
@@ -141,6 +153,11 @@ public class ImageData {
|
||||
private void correctWidthHeight() {
|
||||
this.totalWidth = Math.max(this.totalWidth, 1);
|
||||
this.totalHeight = Math.max(this.totalHeight, 1);
|
||||
|
||||
if (!this.isUrl && !this.mcmetaChecked) {
|
||||
this.mcmetaChecked = true;
|
||||
tryLoadMcmeta();
|
||||
}
|
||||
}
|
||||
|
||||
public int getTotalWidth() {
|
||||
@@ -150,4 +167,112 @@ public class ImageData {
|
||||
public int getTotalHeight() {
|
||||
return this.gotWidthHeight ? this.totalHeight : -1;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// ANIMATION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
private void tryLoadMcmeta() {
|
||||
try {
|
||||
ResourceLocation mcmetaLoc = new ResourceLocation(
|
||||
location.getResourceDomain(),
|
||||
location.getResourcePath() + ".mcmeta"
|
||||
);
|
||||
IResource resource = Minecraft.getMinecraft().getResourceManager().getResource(mcmetaLoc);
|
||||
InputStream stream = resource.getInputStream();
|
||||
try {
|
||||
InputStreamReader reader = new InputStreamReader(stream);
|
||||
JsonObject root = new JsonParser().parse(reader).getAsJsonObject();
|
||||
if (root.has("animation")) {
|
||||
JsonObject anim = root.getAsJsonObject("animation");
|
||||
this.animated = true;
|
||||
|
||||
if (anim.has("frametime")) {
|
||||
this.frametime = Math.max(1, anim.get("frametime").getAsInt());
|
||||
}
|
||||
if (anim.has("interpolate")) {
|
||||
this.interpolate = anim.get("interpolate").getAsBoolean();
|
||||
}
|
||||
if (anim.has("frames")) {
|
||||
JsonArray framesArray = anim.getAsJsonArray("frames");
|
||||
this.frames = new int[framesArray.size()];
|
||||
int maxFrame = 0;
|
||||
for (int i = 0; i < framesArray.size(); i++) {
|
||||
this.frames[i] = framesArray.get(i).getAsInt();
|
||||
if (this.frames[i] > maxFrame) {
|
||||
maxFrame = this.frames[i];
|
||||
}
|
||||
}
|
||||
this.frameCount = maxFrame + 1;
|
||||
} else if (this.totalWidth > 0) {
|
||||
this.frameCount = Math.max(1, this.totalHeight / this.totalWidth);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// No .mcmeta found or parse error — not animated
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Programmatically enable animation on this ImageData.
|
||||
* Used when animation settings come from data class fields rather than .mcmeta files.
|
||||
*/
|
||||
public void setAnimation(int frameCount, int frametime) {
|
||||
if (frameCount > 1) {
|
||||
this.animated = true;
|
||||
this.frameCount = Math.max(1, frameCount);
|
||||
this.frametime = Math.max(1, frametime);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAnimated() {
|
||||
return this.animated && this.frameCount > 1;
|
||||
}
|
||||
|
||||
public int getFrameCount() {
|
||||
return this.frameCount;
|
||||
}
|
||||
|
||||
public int getFrameTime() {
|
||||
return this.frametime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pixel height of a single animation frame.
|
||||
* For non-animated textures, returns the total height.
|
||||
*/
|
||||
public int getFrameHeight() {
|
||||
if (this.animated && this.frameCount > 1) {
|
||||
return Math.max(1, this.totalHeight / this.frameCount);
|
||||
}
|
||||
return this.gotWidthHeight ? this.totalHeight : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the V-coordinate offset (0.0-1.0) for the current animation frame.
|
||||
* Based on system time so all instances of the same texture animate in sync.
|
||||
* Returns 0.0 for non-animated textures.
|
||||
*/
|
||||
public float getCurrentFrameVOffset() {
|
||||
if (!this.animated || this.frameCount <= 1 || this.totalHeight <= 0) {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
long millis = Minecraft.getSystemTime();
|
||||
int tick = (int) (millis / 50L);
|
||||
int frameIdx;
|
||||
|
||||
if (this.frames != null && this.frames.length > 0) {
|
||||
frameIdx = (tick / this.frametime) % this.frames.length;
|
||||
frameIdx = this.frames[frameIdx];
|
||||
} else {
|
||||
frameIdx = (tick / this.frametime) % this.frameCount;
|
||||
}
|
||||
|
||||
int frameHeight = this.totalHeight / this.frameCount;
|
||||
return (float) (frameIdx * frameHeight) / (float) this.totalHeight;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import net.minecraftforge.client.IItemRenderer;
|
||||
import noppes.npcs.api.item.IItemCustomizable;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.client.ClientCacheHandler;
|
||||
import noppes.npcs.client.renderer.AnimationHelper;
|
||||
import noppes.npcs.client.renderer.ImageData;
|
||||
import noppes.npcs.items.ItemCustomizable;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
@@ -222,7 +223,8 @@ public class ItemCustomRenderer implements IItemRenderer {
|
||||
int pass = 0;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
ClientCacheHandler.getImageData(scriptCustomItem.getTexture()).bindTexture();
|
||||
ImageData entityImageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
|
||||
entityImageData.bindTexture();
|
||||
|
||||
if (renderInFrame) {
|
||||
GL11.glTranslatef(0.0F, -0.05F, 0.0F);
|
||||
@@ -233,10 +235,22 @@ public class ItemCustomRenderer implements IItemRenderer {
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
// Animation V offset for entity rendering
|
||||
float entityVOff = 0f;
|
||||
float entityVEnd = 1f;
|
||||
if (entityImageData.isAnimated()) {
|
||||
entityVOff = entityImageData.getCurrentFrameVOffset();
|
||||
entityVEnd = entityVOff + (float) entityImageData.getFrameHeight() / entityImageData.getTotalHeight();
|
||||
} else if (scriptCustomItem.isTextureAnimated() != null && scriptCustomItem.isTextureAnimated()
|
||||
&& scriptCustomItem.getFrameCount() != null && scriptCustomItem.getFrameCount() > 1) {
|
||||
entityVOff = AnimationHelper.getFrameVOffset(entityImageData.getTotalHeight(), scriptCustomItem.getFrameCount(), scriptCustomItem.getFrameTime());
|
||||
entityVEnd = entityVOff + AnimationHelper.getFrameVSize(entityImageData.getTotalHeight(), scriptCustomItem.getFrameCount());
|
||||
}
|
||||
|
||||
float f14 = 0.0F;
|
||||
float f15 = 1.0F;
|
||||
float f4 = 0.0F;
|
||||
float f5 = 1.0F;
|
||||
float f4 = entityVOff;
|
||||
float f5 = entityVEnd;
|
||||
float f6 = 1.0F;
|
||||
float f7 = 0.5F;
|
||||
float f8 = 0.25F;
|
||||
@@ -272,8 +286,11 @@ public class ItemCustomRenderer implements IItemRenderer {
|
||||
GL11.glRotatef(-90.0F, 0.0F, 0.0F, 1.0F);
|
||||
}*/
|
||||
|
||||
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
|
||||
ItemRenderer.renderItemIn2D(tessellator, f15, f4, f14, f5, imageData.getTotalWidth(), imageData.getTotalHeight(), f9);
|
||||
ImageData loopImageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
|
||||
int entityFrameH = loopImageData.isAnimated() ? loopImageData.getFrameHeight()
|
||||
: (scriptCustomItem.isTextureAnimated() != null && scriptCustomItem.isTextureAnimated() && scriptCustomItem.getFrameCount() != null && scriptCustomItem.getFrameCount() > 1
|
||||
? loopImageData.getTotalHeight() / scriptCustomItem.getFrameCount() : loopImageData.getTotalHeight());
|
||||
ItemRenderer.renderItemIn2D(tessellator, f15, f4, f14, f5, loopImageData.getTotalWidth(), entityFrameH, f9);
|
||||
|
||||
if (itemStack.hasEffect(pass)) {
|
||||
GL11.glDepthFunc(GL11.GL_EQUAL);
|
||||
@@ -359,8 +376,20 @@ public class ItemCustomRenderer implements IItemRenderer {
|
||||
GL11.glDisable(GL11.GL_LIGHTING); //Forge: Make sure that render states are reset, a renderEffect can derp them up.
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
|
||||
ClientCacheHandler.getImageData(scriptCustomItem.getTexture()).bindTexture();
|
||||
renderCustomItemSlot(0, 0, 16, 16, itemRed, itemGreen, itemBlue);
|
||||
ImageData imageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
|
||||
imageData.bindTexture();
|
||||
|
||||
float vOff = 0f;
|
||||
float vEnd = 1f;
|
||||
if (imageData.isAnimated()) {
|
||||
vOff = imageData.getCurrentFrameVOffset();
|
||||
vEnd = vOff + (float) imageData.getFrameHeight() / imageData.getTotalHeight();
|
||||
} else if (scriptCustomItem.isTextureAnimated() != null && scriptCustomItem.isTextureAnimated()
|
||||
&& scriptCustomItem.getFrameCount() != null && scriptCustomItem.getFrameCount() > 1) {
|
||||
vOff = AnimationHelper.getFrameVOffset(imageData.getTotalHeight(), scriptCustomItem.getFrameCount(), scriptCustomItem.getFrameTime());
|
||||
vEnd = vOff + AnimationHelper.getFrameVSize(imageData.getTotalHeight(), scriptCustomItem.getFrameCount());
|
||||
}
|
||||
renderCustomItemSlot(0, 0, 16, 16, itemRed, itemGreen, itemBlue, vOff, vEnd);
|
||||
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
@@ -412,13 +441,17 @@ public class ItemCustomRenderer implements IItemRenderer {
|
||||
}
|
||||
|
||||
public void renderCustomItemSlot(int posX, int posY, int imageWidth, int imageHeight, float itemRed, float itemGreen, float itemBlue) {
|
||||
renderCustomItemSlot(posX, posY, imageWidth, imageHeight, itemRed, itemGreen, itemBlue, 0f, 1f);
|
||||
}
|
||||
|
||||
public void renderCustomItemSlot(int posX, int posY, int imageWidth, int imageHeight, float itemRed, float itemGreen, float itemBlue, float vOff, float vEnd) {
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setColorRGBA_F(itemRed, itemGreen, itemBlue, 1.0F);
|
||||
tessellator.addVertexWithUV((double) (posX), (double) (posY + imageHeight), 0, 0, 1);
|
||||
tessellator.addVertexWithUV((double) (posX + imageWidth), (double) (posY + imageHeight), 0, 1, 1);
|
||||
tessellator.addVertexWithUV((double) (posX + imageWidth), (double) (posY), 0, 1, 0);
|
||||
tessellator.addVertexWithUV((double) (posX), (double) (posY), 0, 0, 0);
|
||||
tessellator.addVertexWithUV((double) (posX), (double) (posY + imageHeight), 0, 0, vEnd);
|
||||
tessellator.addVertexWithUV((double) (posX + imageWidth), (double) (posY + imageHeight), 0, 1, vEnd);
|
||||
tessellator.addVertexWithUV((double) (posX + imageWidth), (double) (posY), 0, 1, vOff);
|
||||
tessellator.addVertexWithUV((double) (posX), (double) (posY), 0, 0, vOff);
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
@@ -429,7 +462,8 @@ public class ItemCustomRenderer implements IItemRenderer {
|
||||
TextureManager texturemanager = mc.getTextureManager();
|
||||
int par3 = 0;
|
||||
|
||||
ClientCacheHandler.getImageData(scriptCustomItem.getTexture()).bindTexture();
|
||||
ImageData item3dImageData = ClientCacheHandler.getImageData(scriptCustomItem.getTexture());
|
||||
item3dImageData.bindTexture();
|
||||
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
IIcon icon = entityLivingBase.getItemIcon(itemStack, par3);
|
||||
@@ -447,7 +481,19 @@ public class ItemCustomRenderer implements IItemRenderer {
|
||||
GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
|
||||
GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
|
||||
|
||||
renderCustomItemIn2D(scriptCustomItem, tessellator, 1.0F, 0.0F, 0.0F, 1.0F, 0.0625F);
|
||||
// Animation V offset for 3D handheld rendering
|
||||
float item3dVOff = 0f;
|
||||
float item3dVEnd = 1f;
|
||||
if (item3dImageData.isAnimated()) {
|
||||
item3dVOff = item3dImageData.getCurrentFrameVOffset();
|
||||
item3dVEnd = item3dVOff + (float) item3dImageData.getFrameHeight() / item3dImageData.getTotalHeight();
|
||||
} else if (scriptCustomItem.isTextureAnimated() != null && scriptCustomItem.isTextureAnimated()
|
||||
&& scriptCustomItem.getFrameCount() != null && scriptCustomItem.getFrameCount() > 1) {
|
||||
item3dVOff = AnimationHelper.getFrameVOffset(item3dImageData.getTotalHeight(), scriptCustomItem.getFrameCount(), scriptCustomItem.getFrameTime());
|
||||
item3dVEnd = item3dVOff + AnimationHelper.getFrameVSize(item3dImageData.getTotalHeight(), scriptCustomItem.getFrameCount());
|
||||
}
|
||||
|
||||
renderCustomItemIn2D(scriptCustomItem, tessellator, 1.0F, item3dVOff, 0.0F, item3dVEnd, 0.0625F);
|
||||
|
||||
if (itemStack.hasEffect(par3)) {
|
||||
GL11.glDepthFunc(GL11.GL_EQUAL);
|
||||
@@ -485,7 +531,10 @@ public class ItemCustomRenderer implements IItemRenderer {
|
||||
public static void renderCustomItemIn2D(IItemCustomizable wrapper, Tessellator p_78439_0_, float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, float p_78439_7_) {
|
||||
ImageData imageData = ClientCacheHandler.getImageData(wrapper.getTexture());
|
||||
int width = imageData.getTotalWidth();
|
||||
int height = imageData.getTotalHeight();
|
||||
// Use frame height for edge pixel calculations so animated strips render correctly
|
||||
int height = imageData.isAnimated() ? imageData.getFrameHeight()
|
||||
: (wrapper.isTextureAnimated() != null && wrapper.isTextureAnimated() && wrapper.getFrameCount() != null && wrapper.getFrameCount() > 1
|
||||
? imageData.getTotalHeight() / wrapper.getFrameCount() : imageData.getTotalHeight());
|
||||
|
||||
p_78439_0_.startDrawingQuads();
|
||||
p_78439_0_.setNormal(0.0F, 0.0F, 1.0F);
|
||||
|
||||
@@ -157,6 +157,7 @@ public class ConfigClient {
|
||||
public static boolean LegacyTallLamp = false;
|
||||
public static boolean LegacyPedestal = false;
|
||||
public static boolean LegacyMailbox = false;
|
||||
public static boolean ImprovedImageDownloadConnection = true;
|
||||
|
||||
public static void init(File configFile) {
|
||||
config = new Configuration(configFile);
|
||||
@@ -303,6 +304,7 @@ public class ConfigClient {
|
||||
BannerAlerts = BannerAlertsProperty.getBoolean(true);
|
||||
|
||||
WoodTextures = config.get(TEXTURE, "Wood Textures", false, "Models like Chairs and Stools will use default MC Wood Textures").getBoolean(false);
|
||||
ImprovedImageDownloadConnection = config.get(TEXTURE, "DEBUG: Better handling of image downloads: ", true).getBoolean(true);
|
||||
|
||||
LegacyCampfire = config.get(MODEL, "Legacy Campfire Model", false).getBoolean(false);
|
||||
LegacyBanner = config.get(MODEL, "Legacy Banner Model", false).getBoolean(false);
|
||||
@@ -333,6 +335,7 @@ public class ConfigClient {
|
||||
FontSize = LegacyConfig.FontSize;
|
||||
FontSizeProperty.set(FontSize);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
FMLLog.log(Level.ERROR, e, "CNPC+ has had a problem loading its client configuration");
|
||||
} finally {
|
||||
|
||||
@@ -127,7 +127,12 @@ public enum EnumScriptType {
|
||||
ABILITY_HIT("abilityHit"),
|
||||
ABILITY_TICK("abilityTick"),
|
||||
ABILITY_TOGGLE("abilityToggle"),
|
||||
ABILITY_TOGGLE_UPDATE("abilityToggleUpdate"),
|
||||
ABILITY_TOGGLE_TICK("abilityToggleTick"),
|
||||
|
||||
CHAIN_START("chainStart"),
|
||||
CHAIN_NEXT("chainNext"),
|
||||
CHAIN_COMPLETE("chainComplete"),
|
||||
CHAIN_INTERRUPT("chainInterrupt"),
|
||||
|
||||
ENERGY_PROJECTILE_FIRED("energyProjectileFired"),
|
||||
ENERGY_PROJECTILE_TICK("energyProjectileTick"),
|
||||
|
||||
@@ -13,7 +13,7 @@ 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.IChainEvent;
|
||||
import noppes.npcs.api.event.IPlayerEvent;
|
||||
import noppes.npcs.api.event.IProjectileEvent;
|
||||
import noppes.npcs.api.event.IQuestEvent;
|
||||
@@ -61,6 +61,7 @@ public class ScriptContext {
|
||||
IEnergyProjectileEvent.class,
|
||||
IEnergyBarrierEvent.class,
|
||||
IAbilityEvent.class,
|
||||
IChainEvent.class,
|
||||
IAnimationEvent.class
|
||||
);
|
||||
|
||||
@@ -74,7 +75,8 @@ public class ScriptContext {
|
||||
ICustomGuiEvent.class,
|
||||
IEnergyProjectileEvent.class,
|
||||
IEnergyBarrierEvent.class,
|
||||
IPlayerAbilityEvent.class,
|
||||
IAbilityEvent.class,
|
||||
IChainEvent.class,
|
||||
IAuctionEvent.class
|
||||
);
|
||||
|
||||
@@ -102,6 +104,14 @@ public class ScriptContext {
|
||||
"Effect"
|
||||
);
|
||||
|
||||
public static final ScriptContext ABILITY = register("ABILITY", "ability",
|
||||
"Ability"
|
||||
);
|
||||
|
||||
public static final ScriptContext CHAINED_ABILITY = register("CHAINED_ABILITY", "chained_ability",
|
||||
"ChainedAbility"
|
||||
);
|
||||
|
||||
public static final ScriptContext GLOBAL = register("GLOBAL", "",
|
||||
"Global" // Special case: Global namespace doesn't have a corresponding event class
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.data.profile.Profile;
|
||||
import kamkeel.npcs.network.packets.data.AchievementPacket;
|
||||
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -91,7 +92,9 @@ public class PlayerQuestController {
|
||||
questData.finishedQuests.put(quest.id, completeTime);
|
||||
}
|
||||
|
||||
if (ConfigMain.ProfilesEnabled && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared)
|
||||
if (ConfigMain.ProfilesEnabled && quest.profileOptions.enableOptions
|
||||
&& (quest.profileOptions.completeControl == EnumProfileSync.Shared
|
||||
|| quest.profileOptions.cooldownControl == EnumProfileSync.Shared))
|
||||
ProfileController.Instance.shareQuestCompletion(player, quest.id, completeTime);
|
||||
}
|
||||
|
||||
@@ -125,27 +128,29 @@ public class PlayerQuestController {
|
||||
if (data.activeQuests.containsKey(quest.id))
|
||||
return false;
|
||||
|
||||
if (!data.finishedQuests.containsKey(quest.id) || quest.repeat == EnumQuestRepeat.REPEATABLE)
|
||||
boolean finishedLocally = data.finishedQuests.containsKey(quest.id);
|
||||
boolean completedShared = false;
|
||||
boolean hasCooldownShared = false;
|
||||
if (ConfigMain.ProfilesEnabled && quest.profileOptions.enableOptions) {
|
||||
Profile profile = ProfileController.Instance.getProfile(player);
|
||||
if (profile != null && profile.sharedQuestTimestamps.containsKey(quest.id)) {
|
||||
if (quest.profileOptions.completeControl == EnumProfileSync.Shared)
|
||||
completedShared = true;
|
||||
if (quest.profileOptions.cooldownControl == EnumProfileSync.Shared)
|
||||
hasCooldownShared = true;
|
||||
}
|
||||
}
|
||||
|
||||
boolean isFinished = finishedLocally || completedShared;
|
||||
|
||||
if (!isFinished && !hasCooldownShared)
|
||||
return true;
|
||||
if (quest.repeat == EnumQuestRepeat.REPEATABLE)
|
||||
return true;
|
||||
if (quest.repeat == EnumQuestRepeat.NONE)
|
||||
return false;
|
||||
return !isFinished;
|
||||
|
||||
long questTime = data.finishedQuests.get(quest.id);
|
||||
|
||||
if (quest.repeat == EnumQuestRepeat.MCDAILY) {
|
||||
return player.worldObj.getTotalWorldTime() - questTime >= 24000;
|
||||
} else if (quest.repeat == EnumQuestRepeat.MCWEEKLY) {
|
||||
return player.worldObj.getTotalWorldTime() - questTime >= 168000;
|
||||
} else if (quest.repeat == EnumQuestRepeat.MCCUSTOM) {
|
||||
return player.worldObj.getTotalWorldTime() - questTime >= quest.customCooldown;
|
||||
} else if (quest.repeat == EnumQuestRepeat.RLDAILY) {
|
||||
return System.currentTimeMillis() - questTime >= 86400000;
|
||||
} else if (quest.repeat == EnumQuestRepeat.RLWEEKLY) {
|
||||
return System.currentTimeMillis() - questTime >= 604800000;
|
||||
} else if (quest.repeat == EnumQuestRepeat.RLCUSTOM) {
|
||||
return System.currentTimeMillis() - questTime >= quest.customCooldown;
|
||||
}
|
||||
return false;
|
||||
return quest.getTimeUntilRepeat(player) <= 0;
|
||||
}
|
||||
|
||||
public static Vector<Quest> getActiveQuests(EntityPlayer player) {
|
||||
|
||||
@@ -80,7 +80,9 @@ public class QuestController implements IQuestHandler {
|
||||
ite.remove();
|
||||
} else {
|
||||
quests.put(id, quest);
|
||||
if (quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared) {
|
||||
if (quest.profileOptions.enableOptions
|
||||
&& (quest.profileOptions.completeControl == EnumProfileSync.Shared
|
||||
|| quest.profileOptions.cooldownControl == EnumProfileSync.Shared)) {
|
||||
sharedQuests.put(id, quest);
|
||||
}
|
||||
}
|
||||
@@ -225,7 +227,9 @@ public class QuestController implements IQuestHandler {
|
||||
category.quests.put(quest.id, quest);
|
||||
|
||||
sharedQuests.remove(quest.id);
|
||||
if (quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared) {
|
||||
if (quest.profileOptions.enableOptions
|
||||
&& (quest.profileOptions.completeControl == EnumProfileSync.Shared
|
||||
|| quest.profileOptions.cooldownControl == EnumProfileSync.Shared)) {
|
||||
sharedQuests.put(quest.id, quest);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.api.event.IAbilityEvent;
|
||||
import noppes.npcs.api.event.IChainEvent;
|
||||
import noppes.npcs.api.event.IAnimationEvent;
|
||||
import noppes.npcs.api.event.IAuctionEvent;
|
||||
import noppes.npcs.api.event.IBlockEvent;
|
||||
@@ -15,7 +16,6 @@ import noppes.npcs.api.event.IItemEvent;
|
||||
import noppes.npcs.api.event.ILinkedItemEvent;
|
||||
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;
|
||||
@@ -41,6 +41,8 @@ import static noppes.npcs.constants.ScriptContext.ITEM;
|
||||
import static noppes.npcs.constants.ScriptContext.LINKED_ITEM;
|
||||
import static noppes.npcs.constants.ScriptContext.NPC;
|
||||
import static noppes.npcs.constants.ScriptContext.PLAYER;
|
||||
import static noppes.npcs.constants.ScriptContext.ABILITY;
|
||||
import static noppes.npcs.constants.ScriptContext.CHAINED_ABILITY;
|
||||
import static noppes.npcs.constants.ScriptContext.RECIPE;
|
||||
|
||||
/**
|
||||
@@ -81,6 +83,7 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
initializeLinkedItemHooks();
|
||||
initializeRecipeHooks();
|
||||
initializeEffectHooks();
|
||||
initializeAbilityHooks();
|
||||
initializeForgeHooks();
|
||||
}
|
||||
|
||||
@@ -124,6 +127,14 @@ 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);
|
||||
hook(NPC, ABILITY_TOGGLE, IAbilityEvent.ToggleEvent.class);
|
||||
hook(NPC, ABILITY_TOGGLE_TICK, IAbilityEvent.ToggleUpdateEvent.class);
|
||||
|
||||
// Chain
|
||||
hook(NPC, CHAIN_START, IChainEvent.StartEvent.class);
|
||||
hook(NPC, CHAIN_NEXT, IChainEvent.NextEvent.class);
|
||||
hook(NPC, CHAIN_COMPLETE, IChainEvent.CompleteEvent.class);
|
||||
hook(NPC, CHAIN_INTERRUPT, IChainEvent.InterruptEvent.class);
|
||||
|
||||
// Energy Barrier
|
||||
hook(NPC, ENERGY_BARRIER_SPAWNED, IEnergyBarrierEvent.SpawnedEvent.class);
|
||||
@@ -245,12 +256,20 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(PLAYER, ENERGY_BARRIER_DESTROYED, IEnergyBarrierEvent.DestroyedEvent.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);
|
||||
hook(PLAYER, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(PLAYER, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
hook(PLAYER, ABILITY_HIT, IAbilityEvent.HitEvent.class);
|
||||
hook(PLAYER, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(PLAYER, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(PLAYER, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
hook(PLAYER, ABILITY_TOGGLE, IAbilityEvent.ToggleEvent.class);
|
||||
hook(PLAYER, ABILITY_TOGGLE_TICK, IAbilityEvent.ToggleUpdateEvent.class);
|
||||
|
||||
// Chain
|
||||
hook(PLAYER, CHAIN_START, IChainEvent.StartEvent.class);
|
||||
hook(PLAYER, CHAIN_NEXT, IChainEvent.NextEvent.class);
|
||||
hook(PLAYER, CHAIN_COMPLETE, IChainEvent.CompleteEvent.class);
|
||||
hook(PLAYER, CHAIN_INTERRUPT, IChainEvent.InterruptEvent.class);
|
||||
|
||||
// Auction
|
||||
hook(PLAYER, AUCTION_CREATE, IAuctionEvent.CreateEvent.class);
|
||||
@@ -333,6 +352,24 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(EFFECT, ON_EFFECT_REMOVE, IPlayerEvent.EffectEvent.Removed.class);
|
||||
}
|
||||
|
||||
private void initializeAbilityHooks() {
|
||||
// Ability context (internal per-ability scripts)
|
||||
hook(ABILITY, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(ABILITY, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
hook(ABILITY, ABILITY_HIT, IAbilityEvent.HitEvent.class);
|
||||
hook(ABILITY, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(ABILITY, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(ABILITY, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
hook(ABILITY, ABILITY_TOGGLE, IAbilityEvent.ToggleEvent.class);
|
||||
hook(ABILITY, ABILITY_TOGGLE_TICK, IAbilityEvent.ToggleUpdateEvent.class);
|
||||
|
||||
// Chained ability context (chain-level lifecycle hooks)
|
||||
hook(CHAINED_ABILITY, CHAIN_START, IChainEvent.StartEvent.class);
|
||||
hook(CHAINED_ABILITY, CHAIN_NEXT, IChainEvent.NextEvent.class);
|
||||
hook(CHAINED_ABILITY, CHAIN_COMPLETE, IChainEvent.CompleteEvent.class);
|
||||
hook(CHAINED_ABILITY, CHAIN_INTERRUPT, IChainEvent.InterruptEvent.class);
|
||||
}
|
||||
|
||||
private void initializeForgeHooks() {
|
||||
hook(FORGE, INIT, IForgeEvent.InitEvent.class);
|
||||
hook(FORGE, FORGE_WORLD, IForgeEvent.WorldEvent.class);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.network.packets.request.script.AbilityScriptPacket;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.ScriptContext;
|
||||
|
||||
/**
|
||||
* Script handler for ability scripts.
|
||||
* Manages a single script container for ability hooks (abilityStart, abilityTick, abilityComplete, etc.).
|
||||
*/
|
||||
public class AbilityScript extends SingleScriptHandler implements IScriptHandlerPacket {
|
||||
|
||||
/**
|
||||
* The ability ID (UUID) for packet communication. Empty if not bound.
|
||||
*/
|
||||
private String abilityId = "";
|
||||
|
||||
/**
|
||||
* Create an unbound AbilityScript (for server-side use).
|
||||
*/
|
||||
public AbilityScript() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an AbilityScript bound to a specific ability (for GUI use).
|
||||
*
|
||||
* @param abilityId The UUID of the ability
|
||||
*/
|
||||
public AbilityScript(String abilityId) {
|
||||
this.abilityId = abilityId != null ? abilityId : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptContext getContext() {
|
||||
return ScriptContext.ABILITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
return !abilityId.isEmpty() ? "Ability[" + abilityId + "]" : "Ability";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestData() {
|
||||
if (!abilityId.isEmpty())
|
||||
AbilityScriptPacket.Get(abilityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSavePacket(int index, int totalCount, NBTTagCompound nbt) {
|
||||
if (!abilityId.isEmpty())
|
||||
AbilityScriptPacket.Save(abilityId, index, totalCount, nbt);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import kamkeel.npcs.network.packets.request.script.ChainedAbilityScriptPacket;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.constants.ScriptContext;
|
||||
|
||||
/**
|
||||
* Script handler for chained ability scripts.
|
||||
* Manages a single script container for chained ability hooks.
|
||||
*/
|
||||
public class ChainedAbilityScript extends SingleScriptHandler implements IScriptHandlerPacket {
|
||||
|
||||
/**
|
||||
* The chained ability ID (UUID) for packet communication. Empty if not bound.
|
||||
*/
|
||||
private String chainId = "";
|
||||
|
||||
/**
|
||||
* Create an unbound ChainedAbilityScript (for server-side use).
|
||||
*/
|
||||
public ChainedAbilityScript() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ChainedAbilityScript bound to a specific chained ability (for GUI use).
|
||||
*
|
||||
* @param chainId The UUID of the chained ability
|
||||
*/
|
||||
public ChainedAbilityScript(String chainId) {
|
||||
this.chainId = chainId != null ? chainId : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptContext getContext() {
|
||||
return ScriptContext.CHAINED_ABILITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
return !chainId.isEmpty() ? "ChainedAbility[" + chainId + "]" : "ChainedAbility";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestData() {
|
||||
if (!chainId.isEmpty())
|
||||
ChainedAbilityScriptPacket.Get(chainId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSavePacket(int index, int totalCount, NBTTagCompound nbt) {
|
||||
if (!chainId.isEmpty())
|
||||
ChainedAbilityScriptPacket.Save(chainId, index, totalCount, nbt);
|
||||
}
|
||||
}
|
||||
@@ -26,15 +26,14 @@ public class CustomEffect implements ICustomEffect {
|
||||
public String icon = "";
|
||||
public int iconX = 0, iconY = 0;
|
||||
|
||||
/**
|
||||
* Experimental script stuff.
|
||||
*/
|
||||
public Consumer<PlayerEvent.EffectEvent.Added> onAddedConsumer;
|
||||
public Consumer<PlayerEvent.EffectEvent.Ticked> onTickConsumer;
|
||||
public Consumer<PlayerEvent.EffectEvent.Removed> onRemovedConsumer;
|
||||
public String menuName = "§aNEW EFFECT";
|
||||
public int width = 16, height = 16;
|
||||
|
||||
// Animation
|
||||
public boolean animated = false;
|
||||
public int frameCount = 1;
|
||||
public int frametime = 2;
|
||||
|
||||
public int index = 0;
|
||||
|
||||
public CustomEffect() {
|
||||
@@ -143,6 +142,36 @@ public class CustomEffect implements ICustomEffect {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnimated() {
|
||||
return animated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnimated(boolean animated) {
|
||||
this.animated = animated;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFrameCount() {
|
||||
return frameCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFrameCount(int frameCount) {
|
||||
this.frameCount = Math.max(1, frameCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFrameTime() {
|
||||
return frametime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFrameTime(int frametime) {
|
||||
this.frametime = Math.max(1, frametime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLossOnDeath() {
|
||||
return lossOnDeath;
|
||||
@@ -169,26 +198,10 @@ public class CustomEffect implements ICustomEffect {
|
||||
}
|
||||
|
||||
|
||||
public void onAdded(Consumer<PlayerEvent.EffectEvent.Added> function) {
|
||||
onAddedConsumer = function;
|
||||
}
|
||||
|
||||
public void onTick(Consumer<PlayerEvent.EffectEvent.Ticked> function) {
|
||||
onTickConsumer = function;
|
||||
}
|
||||
|
||||
public void onRemoved(Consumer<PlayerEvent.EffectEvent.Removed> function) {
|
||||
onRemovedConsumer = function;
|
||||
}
|
||||
|
||||
public void onAdded(EntityPlayer player, PlayerEffect playerEffect) {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
if (playerEffect.index == 0) {
|
||||
PlayerEvent.EffectEvent.Added event = new PlayerEvent.EffectEvent.Added(iPlayer, playerEffect);
|
||||
|
||||
if (onAddedConsumer != null)
|
||||
onAddedConsumer.accept(event);
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
@@ -204,11 +217,6 @@ public class CustomEffect implements ICustomEffect {
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
if (playerEffect.index == 0) {
|
||||
PlayerEvent.EffectEvent.Ticked event = new PlayerEvent.EffectEvent.Ticked(iPlayer, playerEffect);
|
||||
|
||||
if (onTickConsumer != null) {
|
||||
onTickConsumer.accept(event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
@@ -225,11 +233,6 @@ public class CustomEffect implements ICustomEffect {
|
||||
|
||||
if (playerEffect.index == 0) {
|
||||
PlayerEvent.EffectEvent.Removed event = new PlayerEvent.EffectEvent.Removed(iPlayer, playerEffect, type);
|
||||
|
||||
if (onRemovedConsumer != null) {
|
||||
onRemovedConsumer.accept(event);
|
||||
}
|
||||
|
||||
EffectScript script = getScriptHandler();
|
||||
if (script == null) {
|
||||
return;
|
||||
@@ -254,6 +257,9 @@ public class CustomEffect implements ICustomEffect {
|
||||
compound.setInteger("iconHeight", height);
|
||||
compound.setString("icon", icon);
|
||||
compound.setBoolean("lossOnDeath", lossOnDeath);
|
||||
compound.setBoolean("iconAnimated", animated);
|
||||
compound.setInteger("iconFrameCount", frameCount);
|
||||
compound.setInteger("iconFrameTime", frametime);
|
||||
|
||||
if (saveScripts) {
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
@@ -296,6 +302,13 @@ public class CustomEffect implements ICustomEffect {
|
||||
icon = compound.getString("icon");
|
||||
lossOnDeath = compound.getBoolean("lossOnDeath");
|
||||
|
||||
if (compound.hasKey("iconAnimated"))
|
||||
animated = compound.getBoolean("iconAnimated");
|
||||
if (compound.hasKey("iconFrameCount"))
|
||||
frameCount = Math.max(1, compound.getInteger("iconFrameCount"));
|
||||
if (compound.hasKey("iconFrameTime"))
|
||||
frametime = Math.max(1, compound.getInteger("iconFrameTime"));
|
||||
|
||||
if (compound.hasKey("ScriptData", Constants.NBT.TAG_COMPOUND)) {
|
||||
EffectScript handler = new EffectScript();
|
||||
handler.readFromNBT(compound.getCompoundTag("ScriptData"));
|
||||
|
||||
@@ -12,6 +12,11 @@ public class ItemDisplayData {
|
||||
public Boolean durabilityShow = false;
|
||||
public Integer durabilityColor = -1;
|
||||
|
||||
// Animation
|
||||
public Boolean animated = false;
|
||||
public Integer frameCount = 1;
|
||||
public Integer frametime = 2;
|
||||
|
||||
public NBTTagCompound writeToNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.writeToNBT(compound);
|
||||
@@ -42,6 +47,10 @@ public class ItemDisplayData {
|
||||
this.setFloat(compound, "TranslateY", this.translateY);
|
||||
this.setFloat(compound, "TranslateZ", this.translateZ);
|
||||
|
||||
this.setBoolean(compound, "Animated", this.animated);
|
||||
this.setInteger(compound, "FrameCount", this.frameCount);
|
||||
this.setInteger(compound, "FrameTime", this.frametime);
|
||||
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -97,6 +106,16 @@ public class ItemDisplayData {
|
||||
if (compound.hasKey("TranslateZ")) {
|
||||
this.translateZ = compound.getFloat("TranslateZ");
|
||||
}
|
||||
|
||||
if (compound.hasKey("Animated")) {
|
||||
this.animated = compound.getBoolean("Animated");
|
||||
}
|
||||
if (compound.hasKey("FrameCount")) {
|
||||
this.frameCount = Math.max(1, compound.getInteger("FrameCount"));
|
||||
}
|
||||
if (compound.hasKey("FrameTime")) {
|
||||
this.frametime = Math.max(1, compound.getInteger("FrameTime"));
|
||||
}
|
||||
}
|
||||
|
||||
private void setBoolean(NBTTagCompound compound, String key, Boolean value) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.data.IAbilityAction;
|
||||
import kamkeel.npcs.controllers.data.ability.data.entry.AbilityToggleEntry;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityGuard;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.network.packets.data.ability.AbilityCooldownSyncPacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilityStatePacket;
|
||||
@@ -25,10 +24,6 @@ import noppes.npcs.AbstractDataAbilities;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.player.PlayerAbilityEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -129,53 +124,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
return player != null ? player.worldObj.getTotalWorldTime() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fireTickEvent(Ability ability, EntityLivingBase target) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireExecuteEvent(Ability ability, EntityLivingBase target) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fireCompleteEvent(Ability ability, EntityLivingBase target) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fireInterruptEvent(Ability ability, EntityLivingBase target,
|
||||
DamageSource source, float damage) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void spawnTelegraph(Ability ability, EntityLivingBase target) {
|
||||
EntityPlayer player = playerData.player;
|
||||
@@ -423,7 +371,7 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
|
||||
// Fire start event (cancelable)
|
||||
if (firePlayerStartEvent(player, ability)) {
|
||||
if (EventHooks.onAbilityStart(ability, player, null)) {
|
||||
return false; // Cancelled
|
||||
}
|
||||
|
||||
@@ -491,29 +439,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
protected void onToggleStateChanged(String key, boolean active, int state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireToggleEvent(Ability ability, int oldState, int newState) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == null) return false;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return false;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.ToggleEvent event = new PlayerAbilityEvent.ToggleEvent(iPlayer, ability, oldState, newState);
|
||||
return EventHooks.onPlayerAbilityToggle(handler, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fireToggleUpdateEvent(Ability ability, int tick, int state) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (ScriptController.Instance == null || player == null) return true;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return true;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.ToggleUpdateEvent event = new PlayerAbilityEvent.ToggleUpdateEvent(iPlayer, ability, tick, state);
|
||||
EventHooks.onPlayerAbilityToggleUpdate(handler, event);
|
||||
return event.isEnabled();
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SELECTION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -861,32 +786,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -1035,22 +934,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SCRIPT EVENTS (Player-specific: start event only, others via abstract)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// NBT SERIALIZATION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -1096,7 +979,7 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
}
|
||||
playingAbilityAnimation = compound.getBoolean("AbilityAnimating");
|
||||
|
||||
// Active toggles - restore state directly (no onToggleOn callback during load)
|
||||
// Active toggles - restore state directly (no onToggle callback during load)
|
||||
activeToggles.clear();
|
||||
if (compound.hasKey("ActiveToggles")) {
|
||||
NBTTagList toggleNbt = compound.getTagList("ActiveToggles", 10); // 10 = TAG_COMPOUND
|
||||
@@ -1117,9 +1000,6 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
*/
|
||||
private void validateUnlockedAbilities() {
|
||||
if (AbilityController.Instance == null) return;
|
||||
// Only validate on the server - the client trusts server-sent data.
|
||||
// Custom ability definitions may not have been synced to the client yet,
|
||||
// which would cause valid abilities to be incorrectly pruned.
|
||||
if (playerData == null || !(playerData.player instanceof EntityPlayerMP)) return;
|
||||
|
||||
Iterator<String> it = unlockedAbilities.iterator();
|
||||
|
||||
@@ -178,19 +178,50 @@ public class Quest implements ICompatibilty, IQuest {
|
||||
public long getTimeUntilRepeat(EntityPlayer player) {
|
||||
if (ConfigMain.ProfilesEnabled && profileOptions.enableOptions && profileOptions.cooldownControl == EnumProfileSync.Shared) {
|
||||
Profile profile = ProfileController.Instance.getProfile(player);
|
||||
IPlayer iPlayer = NoppesUtilServer.getIPlayer(player);
|
||||
long timeRemaining = 0L;
|
||||
for (ISlot slot : profile.getSlots().values()) {
|
||||
IPlayerData playerData = ProfileController.Instance.getSlotPlayerData(iPlayer, slot.getId());
|
||||
IPlayerQuestData iPlayerQuestData = playerData.getQuestData();
|
||||
timeRemaining = Math.max(timeRemaining, getTimeUntilRepeatQuestData(player, iPlayerQuestData));
|
||||
if (profile != null) {
|
||||
Long questTime = profile.sharedQuestTimestamps.get(this.id);
|
||||
if (questTime == null) return 0L;
|
||||
return calculateRemainingCooldown(player, questTime);
|
||||
}
|
||||
return timeRemaining;
|
||||
}
|
||||
IPlayerQuestData questData = PlayerData.get(player).getQuestData();
|
||||
return getTimeUntilRepeatQuestData(player, questData);
|
||||
}
|
||||
|
||||
public long calculateRemainingCooldown(EntityPlayer player, long questTime) {
|
||||
switch (repeat) {
|
||||
case MCDAILY: {
|
||||
long now = player.worldObj.getTotalWorldTime();
|
||||
long remainingTicks = questTime + 24000 - now;
|
||||
return Math.max(0, remainingTicks * 50);
|
||||
}
|
||||
case MCWEEKLY: {
|
||||
long now = player.worldObj.getTotalWorldTime();
|
||||
long remainingTicks = questTime + 168000 - now;
|
||||
return Math.max(0, remainingTicks * 50);
|
||||
}
|
||||
case MCCUSTOM: {
|
||||
long now = player.worldObj.getTotalWorldTime();
|
||||
long remainingTicks = questTime + this.customCooldown - now;
|
||||
return Math.max(0, remainingTicks * 50);
|
||||
}
|
||||
case RLDAILY: {
|
||||
long remainingMillis = questTime + 86400000 - System.currentTimeMillis();
|
||||
return Math.max(0, remainingMillis);
|
||||
}
|
||||
case RLWEEKLY: {
|
||||
long remainingMillis = questTime + 604800000 - System.currentTimeMillis();
|
||||
return Math.max(0, remainingMillis);
|
||||
}
|
||||
case RLCUSTOM: {
|
||||
long remainingMillis = questTime + this.customCooldown - System.currentTimeMillis();
|
||||
return Math.max(0, remainingMillis);
|
||||
}
|
||||
default:
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
public long getTimeUntilRepeatQuestData(EntityPlayer player, IPlayerQuestData questData) {
|
||||
long questTime = questData.getLastCompletedTime(this.id);
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityCounter;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDefend;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDodge;
|
||||
import kamkeel.npcs.addon.client.DBCClient;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumSoundOperation;
|
||||
@@ -709,6 +712,21 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
// Resistances
|
||||
i = stats.resistances.applyResistance(damagesource, i);
|
||||
|
||||
// Defend abilities
|
||||
AbilityDefend defend = this.abilities != null ? this.abilities.getActiveDefend() : null;
|
||||
if (defend != null) {
|
||||
// Dodge & Counter: cancel attack entirely
|
||||
if (defend instanceof AbilityDodge || defend instanceof AbilityCounter) {
|
||||
float result = defend.onDefend(attackingEntity, damagesource, i);
|
||||
if (result != i) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Guard: reduce damage
|
||||
i = defend.onDefend(attackingEntity, damagesource, i);
|
||||
}
|
||||
}
|
||||
|
||||
NpcEvent.DamagedEvent event = new NpcEvent.DamagedEvent(this.wrappedNPC, attackingEntity, i, damagesource);
|
||||
if (EventHooks.onNPCDamaged(this, event) || isKilled())
|
||||
return false;
|
||||
|
||||
@@ -65,6 +65,11 @@ public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
|
||||
|
||||
EntityAbilityOrb orb = (EntityAbilityOrb) entity;
|
||||
|
||||
if (orb.getChargeProgress() < 1.0f) {
|
||||
orb.setDead();
|
||||
return;
|
||||
}
|
||||
|
||||
orb.startMoving(null);
|
||||
|
||||
world.playSoundAtEntity(
|
||||
@@ -86,6 +91,19 @@ public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
|
||||
|
||||
int chargeTime = 20 + material.getHarvestLevel() * 8;
|
||||
|
||||
// Keep a fully-charged orb alive while the player is still holding
|
||||
if (tick > chargeTime && stack.stackTagCompound != null) {
|
||||
Entity existing = ((WorldServer) player.worldObj)
|
||||
.getEntityByID(stack.stackTagCompound.getInteger("MagicProjectile"));
|
||||
if (existing instanceof EntityAbilityOrb) {
|
||||
EntityAbilityOrb orb = (EntityAbilityOrb) existing;
|
||||
if (orb.isCharging()) {
|
||||
orb.resetChargeTick();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (tick == chargeTime) {
|
||||
|
||||
if (!player.capabilities.isCreativeMode && !hasInfinite(stack)) {
|
||||
@@ -127,7 +145,7 @@ public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
|
||||
);
|
||||
|
||||
orb.setupCharging(
|
||||
new EnergyAnchorData(AnchorPoint.FRONT, 0, -1, 0),
|
||||
new EnergyAnchorData(AnchorPoint.EYE, 0, 0, 1),
|
||||
chargeTime
|
||||
);
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ import kamkeel.npcs.controllers.ProfileController;
|
||||
import kamkeel.npcs.controllers.TelegraphController;
|
||||
import kamkeel.npcs.entity.EntityAbilityBeam;
|
||||
import kamkeel.npcs.entity.EntityAbilityDisc;
|
||||
import kamkeel.npcs.entity.EntityAbilityDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import kamkeel.npcs.entity.EntityAbilityLaser;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import kamkeel.npcs.entity.EntityAbilityPanel;
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
||||
import kamkeel.npcs.entity.EntityEnergySweeper;
|
||||
import kamkeel.npcs.entity.EntityEnergyProjectile;
|
||||
import kamkeel.npcs.entity.EntityEnergySlicer;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -456,12 +456,12 @@ public class NpcAPI extends AbstractNpcAPI {
|
||||
data = new ScriptEntityData(new ScriptEnergySlicer<>((EntityEnergySlicer) entity));
|
||||
else if (entity instanceof EntityEnergyProjectile)
|
||||
data = new ScriptEntityData(new ScriptEnergyProjectile((EntityEnergyProjectile) entity));
|
||||
else if (entity instanceof EntityAbilityDome)
|
||||
data = new ScriptEntityData(new ScriptEnergyDome<>((EntityAbilityDome) entity));
|
||||
else if (entity instanceof EntityAbilityPanel)
|
||||
data = new ScriptEntityData(new ScriptEnergyPanel<>((EntityAbilityPanel) entity));
|
||||
else if (entity instanceof EntityAbilitySweeper)
|
||||
data = new ScriptEntityData(new ScriptEnergySweeper<>((EntityAbilitySweeper) entity));
|
||||
else if (entity instanceof EntityEnergyDome)
|
||||
data = new ScriptEntityData(new ScriptEnergyDome<>((EntityEnergyDome) entity));
|
||||
else if (entity instanceof EntityEnergyPanel)
|
||||
data = new ScriptEntityData(new ScriptEnergyPanel<>((EntityEnergyPanel) entity));
|
||||
else if (entity instanceof EntityEnergySweeper)
|
||||
data = new ScriptEntityData(new ScriptEnergySweeper<>((EntityEnergySweeper) entity));
|
||||
else
|
||||
data = new ScriptEntityData(new ScriptEntity<>(entity));
|
||||
entity.registerExtendedProperties("ScriptedObject", data);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilityBarrier;
|
||||
import kamkeel.npcs.entity.EntityAbilityDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import noppes.npcs.api.entity.IEnergyBarrier;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
|
||||
/**
|
||||
* Base script wrapper for energy barrier entities (Dome, Panel).
|
||||
* All shared methods delegate directly to EntityAbilityBarrier base.
|
||||
* All shared methods delegate directly to EntityEnergyBarrier base.
|
||||
*/
|
||||
public class ScriptEnergyBarrier<T extends EntityAbilityBarrier> extends ScriptEnergyAbility<T> implements IEnergyBarrier {
|
||||
public class ScriptEnergyBarrier<T extends EntityEnergyBarrier> extends ScriptEnergyAbility<T> implements IEnergyBarrier {
|
||||
|
||||
public ScriptEnergyBarrier(T entity) {
|
||||
super(entity);
|
||||
@@ -138,6 +138,6 @@ public class ScriptEnergyBarrier<T extends EntityAbilityBarrier> extends ScriptE
|
||||
}
|
||||
|
||||
public int getBarrierType() {
|
||||
return entity instanceof EntityAbilityDome ? 0 : 1;
|
||||
return entity instanceof EntityEnergyDome ? 0 : 1;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilityDome;
|
||||
import kamkeel.npcs.entity.EntityEnergyDome;
|
||||
import noppes.npcs.api.entity.IEnergyDome;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
|
||||
public class ScriptEnergyDome<T extends EntityAbilityDome> extends ScriptEnergyBarrier<T> implements IEnergyDome {
|
||||
public class ScriptEnergyDome<T extends EntityEnergyDome> extends ScriptEnergyBarrier<T> implements IEnergyDome {
|
||||
|
||||
public ScriptEnergyDome(T entity) {
|
||||
super(entity);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilityPanel;
|
||||
import kamkeel.npcs.entity.EntityEnergyPanel;
|
||||
import noppes.npcs.api.entity.IEnergyPanel;
|
||||
import noppes.npcs.scripted.constants.EntityType;
|
||||
|
||||
public class ScriptEnergyPanel<T extends EntityAbilityPanel> extends ScriptEnergyBarrier<T> implements IEnergyPanel {
|
||||
public class ScriptEnergyPanel<T extends EntityEnergyPanel> extends ScriptEnergyBarrier<T> implements IEnergyPanel {
|
||||
|
||||
public ScriptEnergyPanel(T entity) {
|
||||
super(entity);
|
||||
@@ -52,6 +52,6 @@ public class ScriptEnergyPanel<T extends EntityAbilityPanel> extends ScriptEnerg
|
||||
}
|
||||
|
||||
public boolean isLaunched() {
|
||||
return entity.getMode() == EntityAbilityPanel.PanelMode.LAUNCHED;
|
||||
return entity.getMode() == EntityEnergyPanel.PanelMode.LAUNCHED;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import kamkeel.npcs.entity.EntityAbilitySweeper;
|
||||
import kamkeel.npcs.entity.EntityEnergySweeper;
|
||||
|
||||
public class ScriptEnergySweeper<T extends EntityAbilitySweeper> extends ScriptEnergyAbility<T> {
|
||||
public class ScriptEnergySweeper<T extends EntityEnergySweeper> extends ScriptEnergyAbility<T> {
|
||||
public ScriptEnergySweeper(T entity) {
|
||||
super(entity);
|
||||
}
|
||||
|
||||
@@ -8,22 +8,48 @@ import noppes.npcs.api.IDamageSource;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.event.IAbilityEvent;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
/**
|
||||
* Events fired during NPC ability execution lifecycle.
|
||||
* Unified ability events for both NPCs and Players.
|
||||
*/
|
||||
public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
public class AbilityEvent extends CustomNPCsEvent implements IAbilityEvent {
|
||||
protected final IEntityLivingBase entity;
|
||||
public final IPlayer player;
|
||||
public final ICustomNpc<?> npc;
|
||||
protected final Ability ability;
|
||||
protected final IEntityLivingBase target;
|
||||
private transient IAbility abilityCopy;
|
||||
|
||||
public AbilityEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
|
||||
super(npc);
|
||||
public AbilityEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target) {
|
||||
this.entity = entity != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity) : null;
|
||||
this.ability = ability;
|
||||
this.target = target != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(target) : null;
|
||||
this.player = (this.entity instanceof IPlayer) ? (IPlayer) this.entity : null;
|
||||
this.npc = (this.entity instanceof ICustomNpc) ? (ICustomNpc<?>) this.entity : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICustomNpc<?> getNpc() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNPC() {
|
||||
return entity instanceof ICustomNpc;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,13 +70,10 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
return "abilityEvent";
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when an ability starts executing (enters WINDUP phase).
|
||||
*/
|
||||
@Cancelable
|
||||
public static class StartEvent extends AbilityEvent implements IAbilityEvent.StartEvent {
|
||||
public StartEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
|
||||
super(npc, ability, target);
|
||||
public StartEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target) {
|
||||
super(entity, ability, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,13 +82,10 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when an ability enters the ACTIVE phase and performs its effect.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ExecuteEvent extends AbilityEvent implements IAbilityEvent.ExecuteEvent {
|
||||
public ExecuteEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
|
||||
super(npc, ability, target);
|
||||
public ExecuteEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target) {
|
||||
super(entity, ability, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,16 +94,13 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when an ability is interrupted by damage.
|
||||
*/
|
||||
public static class InterruptEvent extends AbilityEvent implements IAbilityEvent.InterruptEvent {
|
||||
private final IDamageSource damageSource;
|
||||
private final float damage;
|
||||
|
||||
public InterruptEvent(ICustomNpc npc, Ability ability, EntityLivingBase target, DamageSource source, float damage) {
|
||||
super(npc, ability, target);
|
||||
this.damageSource = NpcAPI.Instance().getIDamageSource(source);
|
||||
public InterruptEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target, DamageSource source, float damage) {
|
||||
super(entity, ability, target);
|
||||
this.damageSource = source != null ? NpcAPI.Instance().getIDamageSource(source) : null;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@@ -103,12 +120,9 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when an ability completes its full execution cycle.
|
||||
*/
|
||||
public static class CompleteEvent extends AbilityEvent implements IAbilityEvent.CompleteEvent {
|
||||
public CompleteEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
|
||||
super(npc, ability, target);
|
||||
public CompleteEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target) {
|
||||
super(entity, ability, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,10 +131,6 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when an ability hits an entity with damage.
|
||||
* This is a cancelable event - canceling prevents the damage from being applied.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class HitEvent extends AbilityEvent implements IAbilityEvent.HitEvent {
|
||||
private final IEntityLivingBase hitEntity;
|
||||
@@ -128,9 +138,9 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
private float knockback;
|
||||
private float knockbackUp;
|
||||
|
||||
public HitEvent(ICustomNpc npc, Ability ability, EntityLivingBase target,
|
||||
public HitEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target,
|
||||
EntityLivingBase hitEntity, float damage, float knockback, float knockbackUp) {
|
||||
super(npc, ability, target);
|
||||
super(entity, ability, target);
|
||||
this.hitEntity = hitEntity != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(hitEntity) : null;
|
||||
this.damage = damage;
|
||||
this.knockback = knockback;
|
||||
@@ -178,16 +188,12 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired every tick while an ability is executing.
|
||||
* Provides information about the current phase and tick.
|
||||
*/
|
||||
public static class TickEvent extends AbilityEvent implements IAbilityEvent.TickEvent {
|
||||
private final int abilityPhase;
|
||||
private final int tick;
|
||||
|
||||
public TickEvent(ICustomNpc npc, Ability ability, EntityLivingBase target, int phase, int tick) {
|
||||
super(npc, ability, target);
|
||||
public TickEvent(EntityLivingBase entity, Ability ability, EntityLivingBase target, int phase, int tick) {
|
||||
super(entity, ability, target);
|
||||
this.abilityPhase = phase;
|
||||
this.tick = tick;
|
||||
}
|
||||
@@ -208,17 +214,13 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a toggle ability changes state.
|
||||
* Canceling prevents the toggle from changing state.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ToggleEvent extends AbilityEvent implements IAbilityEvent.ToggleEvent {
|
||||
private final int oldState;
|
||||
private final int newState;
|
||||
|
||||
public ToggleEvent(ICustomNpc npc, Ability ability, int oldState, int newState) {
|
||||
super(npc, ability, null);
|
||||
public ToggleEvent(EntityLivingBase entity, Ability ability, int oldState, int newState) {
|
||||
super(entity, ability, null);
|
||||
this.oldState = oldState;
|
||||
this.newState = newState;
|
||||
}
|
||||
@@ -244,17 +246,13 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired every 10 ticks for each active toggle ability.
|
||||
* Scripts can set enabled to false to force-deactivate.
|
||||
*/
|
||||
public static class ToggleUpdateEvent extends AbilityEvent implements IAbilityEvent.ToggleUpdateEvent {
|
||||
private final int tick;
|
||||
private final int state;
|
||||
private boolean enabled = true;
|
||||
|
||||
public ToggleUpdateEvent(ICustomNpc npc, Ability ability, int tick, int state) {
|
||||
super(npc, ability, null);
|
||||
public ToggleUpdateEvent(EntityLivingBase entity, Ability ability, int tick, int state) {
|
||||
super(entity, ability, null);
|
||||
this.tick = tick;
|
||||
this.state = state;
|
||||
}
|
||||
@@ -281,7 +279,7 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_TOGGLE_UPDATE.function;
|
||||
return EnumScriptType.ABILITY_TOGGLE_TICK.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package noppes.npcs.scripted.event;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.api.IDamageSource;
|
||||
import noppes.npcs.api.ability.IChainedAbility;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.event.IChainEvent;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
/**
|
||||
* Unified chain events for both NPCs and Players.
|
||||
*/
|
||||
public class ChainEvent extends CustomNPCsEvent implements IChainEvent {
|
||||
protected final IEntityLivingBase entity;
|
||||
public final IPlayer player;
|
||||
public final ICustomNpc<?> npc;
|
||||
protected final ChainedAbility chain;
|
||||
protected final IEntityLivingBase target;
|
||||
protected final int entryIndex;
|
||||
|
||||
public ChainEvent(EntityLivingBase entity, ChainedAbility chain, int entryIndex, EntityLivingBase target) {
|
||||
this.entity = entity != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity) : null;
|
||||
this.chain = chain;
|
||||
this.entryIndex = entryIndex;
|
||||
this.target = target != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(target) : null;
|
||||
this.player = (this.entity instanceof IPlayer) ? (IPlayer) this.entity : null;
|
||||
this.npc = (this.entity instanceof ICustomNpc) ? (ICustomNpc<?>) this.entity : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICustomNpc<?> getNpc() {
|
||||
return npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNPC() {
|
||||
return entity instanceof ICustomNpc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChainedAbility getChain() {
|
||||
return chain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEntryIndex() {
|
||||
return entryIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "chainEvent";
|
||||
}
|
||||
|
||||
public static class StartEvent extends ChainEvent implements IChainEvent.StartEvent {
|
||||
public StartEvent(EntityLivingBase entity, ChainedAbility chain, int entryIndex, EntityLivingBase target) {
|
||||
super(entity, chain, entryIndex, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.CHAIN_START.function;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NextEvent extends ChainEvent implements IChainEvent.NextEvent {
|
||||
public NextEvent(EntityLivingBase entity, ChainedAbility chain, int entryIndex, EntityLivingBase target) {
|
||||
super(entity, chain, entryIndex, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.CHAIN_NEXT.function;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CompleteEvent extends ChainEvent implements IChainEvent.CompleteEvent {
|
||||
public CompleteEvent(EntityLivingBase entity, ChainedAbility chain, int entryIndex, EntityLivingBase target) {
|
||||
super(entity, chain, entryIndex, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.CHAIN_COMPLETE.function;
|
||||
}
|
||||
}
|
||||
|
||||
public static class InterruptEvent extends ChainEvent implements IChainEvent.InterruptEvent {
|
||||
private final IDamageSource damageSource;
|
||||
private final float damage;
|
||||
|
||||
public InterruptEvent(EntityLivingBase entity, ChainedAbility chain, int entryIndex, EntityLivingBase target,
|
||||
DamageSource source, float damage) {
|
||||
super(entity, chain, entryIndex, 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.CHAIN_INTERRUPT.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,286 +0,0 @@
|
||||
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;
|
||||
import noppes.npcs.api.event.IPlayerAbilityEvent;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
/**
|
||||
* Events fired during player ability execution lifecycle.
|
||||
*/
|
||||
public class PlayerAbilityEvent extends PlayerEvent implements IPlayerAbilityEvent {
|
||||
protected final Ability ability;
|
||||
protected final IEntityLivingBase target;
|
||||
private transient IAbility abilityCopy;
|
||||
|
||||
public PlayerAbilityEvent(IPlayer player, Ability ability, EntityLivingBase target) {
|
||||
super(player);
|
||||
this.ability = ability;
|
||||
this.target = target != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(target) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility getAbility() {
|
||||
if (abilityCopy == null && ability != null) {
|
||||
abilityCopy = ability.deepCopy();
|
||||
}
|
||||
return abilityCopy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
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.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class HitEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.HitEvent {
|
||||
private final IEntityLivingBase hitEntity;
|
||||
private float damage;
|
||||
private float knockback;
|
||||
private float knockbackUp;
|
||||
|
||||
public HitEvent(IPlayer player, Ability ability, EntityLivingBase target,
|
||||
EntityLivingBase hitEntity, float damage, float knockback, float knockbackUp) {
|
||||
super(player, ability, target);
|
||||
this.hitEntity = hitEntity != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(hitEntity) : null;
|
||||
this.damage = damage;
|
||||
this.knockback = knockback;
|
||||
this.knockbackUp = knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getHitEntity() {
|
||||
return hitEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(float damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockback() {
|
||||
return knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockback(float knockback) {
|
||||
this.knockback = knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockbackUp() {
|
||||
return knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockbackUp(float knockbackUp) {
|
||||
this.knockbackUp = knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_HIT.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a toggle ability changes state.
|
||||
* Canceling prevents the toggle from changing state.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ToggleEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.ToggleEvent {
|
||||
private final int oldState;
|
||||
private final int newState;
|
||||
|
||||
public ToggleEvent(IPlayer player, Ability ability, int oldState, int newState) {
|
||||
super(player, ability, null);
|
||||
this.oldState = oldState;
|
||||
this.newState = newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTogglingOn() {
|
||||
return newState > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOldState() {
|
||||
return oldState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNewState() {
|
||||
return newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_TOGGLE.function;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired every 10 ticks for each active toggle ability.
|
||||
* Scripts can set enabled to false to force-deactivate.
|
||||
*/
|
||||
public static class ToggleUpdateEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.ToggleUpdateEvent {
|
||||
private final int tick;
|
||||
private final int state;
|
||||
private boolean enabled = true;
|
||||
|
||||
public ToggleUpdateEvent(IPlayer player, Ability ability, int tick, int state) {
|
||||
super(player, ability, null);
|
||||
this.tick = tick;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTick() {
|
||||
return tick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_TOGGLE_UPDATE.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,11 @@ public class ScriptGuiTexturedRect extends ScriptGuiComponent implements ITextur
|
||||
float scale;
|
||||
String texture;
|
||||
|
||||
// Animation
|
||||
boolean animated = false;
|
||||
int frameCount = 1;
|
||||
int frametime = 2;
|
||||
|
||||
public ScriptGuiTexturedRect() {
|
||||
this.textureY = -1;
|
||||
this.scale = 1.0F;
|
||||
@@ -76,6 +81,25 @@ public class ScriptGuiTexturedRect extends ScriptGuiComponent implements ITextur
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isAnimated() {
|
||||
return this.animated && this.frameCount > 1;
|
||||
}
|
||||
|
||||
public int getFrameCount() {
|
||||
return this.frameCount;
|
||||
}
|
||||
|
||||
public int getFrameTime() {
|
||||
return this.frametime;
|
||||
}
|
||||
|
||||
public ITexturedRect setAnimation(int frameCount, int frametime) {
|
||||
this.animated = frameCount > 1;
|
||||
this.frameCount = Math.max(1, frameCount);
|
||||
this.frametime = Math.max(1, frametime);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return 2;
|
||||
}
|
||||
@@ -89,6 +113,12 @@ public class ScriptGuiTexturedRect extends ScriptGuiComponent implements ITextur
|
||||
nbt.setIntArray("texPos", new int[]{this.textureX, this.textureY});
|
||||
}
|
||||
|
||||
if (this.animated) {
|
||||
nbt.setBoolean("animated", true);
|
||||
nbt.setInteger("frameCount", this.frameCount);
|
||||
nbt.setInteger("frameTime", this.frametime);
|
||||
}
|
||||
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@@ -101,6 +131,13 @@ public class ScriptGuiTexturedRect extends ScriptGuiComponent implements ITextur
|
||||
this.setTextureOffset(nbt.getIntArray("texPos")[0], nbt.getIntArray("texPos")[1]);
|
||||
}
|
||||
|
||||
if (nbt.hasKey("animated") && nbt.getBoolean("animated")) {
|
||||
this.setAnimation(
|
||||
nbt.hasKey("frameCount") ? Math.max(1, nbt.getInteger("frameCount")) : 1,
|
||||
nbt.hasKey("frameTime") ? Math.max(1, nbt.getInteger("frameTime")) : 2
|
||||
);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -147,6 +147,33 @@ public abstract class ScriptCustomizableItem extends ScriptItemStack implements
|
||||
return this.itemDisplay.translateZ != null ? this.itemDisplay.translateZ : 0;
|
||||
}
|
||||
|
||||
public Boolean isTextureAnimated() {
|
||||
return this.itemDisplay.animated != null ? this.itemDisplay.animated : false;
|
||||
}
|
||||
|
||||
public void setTextureAnimated(Boolean animated) {
|
||||
this.itemDisplay.animated = animated;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public Integer getFrameCount() {
|
||||
return this.itemDisplay.frameCount != null ? this.itemDisplay.frameCount : 1;
|
||||
}
|
||||
|
||||
public void setFrameCount(Integer frameCount) {
|
||||
this.itemDisplay.frameCount = frameCount != null ? Math.max(1, frameCount) : 1;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public Integer getFrameTime() {
|
||||
return this.itemDisplay.frametime != null ? this.itemDisplay.frametime : 2;
|
||||
}
|
||||
|
||||
public void setFrameTime(Integer frametime) {
|
||||
this.itemDisplay.frametime = frametime != null ? Math.max(1, frametime) : 2;
|
||||
saveItemData();
|
||||
}
|
||||
|
||||
public NBTTagCompound getMCNbt() {
|
||||
NBTTagCompound compound = super.getMCNbt();
|
||||
compound.setTag("ItemData", this.getItemNBT(new NBTTagCompound()));
|
||||
|
||||
@@ -58,8 +58,8 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
|
||||
@Override
|
||||
public void addAbilityReference(String key) {
|
||||
// Validate ability exists and allows NPCs
|
||||
Ability ability = AbilityController.Instance.resolveAbility(key);
|
||||
// Validate ability exists and allows NPCs (peek avoids deep copy)
|
||||
Ability ability = AbilityController.Instance.peekAbility(key);
|
||||
if (ability == null) {
|
||||
return; // Ability doesn't exist
|
||||
}
|
||||
@@ -145,6 +145,11 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
data.interruptCurrentAbility(null, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeCurrentAbility() {
|
||||
data.completeCurrentAbility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGlobalCooldown() {
|
||||
return (int) data.getRemainingCooldown();
|
||||
@@ -191,8 +196,8 @@ 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);
|
||||
// Validate ability exists and allows NPCs (peek avoids deep copy)
|
||||
Ability ability = AbilityController.Instance.peekAbility(key);
|
||||
if (ability == null) {
|
||||
return false; // Ability doesn't exist
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
|
||||
|
||||
@Override
|
||||
public void unlockAbility(String key) {
|
||||
// Validate ability exists and allows players
|
||||
Ability ability = AbilityController.Instance.resolveAbility(key);
|
||||
// Validate ability exists and allows players (peek avoids deep copy)
|
||||
Ability ability = AbilityController.Instance.peekAbility(key);
|
||||
if (ability == null) {
|
||||
return; // Ability doesn't exist
|
||||
}
|
||||
@@ -94,6 +94,11 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
|
||||
data.interruptCurrentAbility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeCurrentAbility() {
|
||||
data.completeCurrentAbility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnCooldown() {
|
||||
return data.isOnCooldown();
|
||||
@@ -162,7 +167,7 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
|
||||
* Uses the same resolution as unlockAbility: registry key for built-in, UUID for custom.
|
||||
*/
|
||||
private String resolveCanonicalKey(String key) {
|
||||
Ability ability = AbilityController.Instance.resolveAbility(key);
|
||||
Ability ability = AbilityController.Instance.peekAbility(key);
|
||||
if (ability != null && ability.getId() != null) {
|
||||
return ability.getId();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user