mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 18:57:32 +00:00
Has Effect and Class Condition
This commit is contained in:
1 parent
75a58f7e74
commit
1b5584c585
4 files changed
+116
-6
No files matched your search
@@ -5,6 +5,7 @@ import kamkeel.npcs.controllers.data.ability.conditions.AbilityCondition;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.ConditionHPThreshold;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.ConditionHitCount;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.ConditionItem;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.ConditionHasEffect;
|
||||
import kamkeel.npcs.controllers.data.ability.conditions.ConditionQuestCompleted;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityCharge;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityCutter;
|
||||
@@ -156,6 +157,7 @@ public class AbilityController implements IAbilityHandler {
|
||||
registerCondition(ConditionHitCount::new);
|
||||
registerCondition(ConditionItem::new);
|
||||
registerCondition(ConditionQuestCompleted::new);
|
||||
registerCondition(ConditionHasEffect::new);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
package kamkeel.npcs.controllers.data.ability.conditions;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.UserType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.advanced.SubGuiCustomEffectSelect;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.controllers.CustomEffectController;
|
||||
import noppes.npcs.controllers.data.CustomEffect;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ConditionHasEffect extends AbilityCondition {
|
||||
private int effectId = -1;
|
||||
private int effectIndex = 0;
|
||||
|
||||
public ConditionHasEffect() {
|
||||
this.typeId = "condition.cnpc.has_effect";
|
||||
this.name = "condition.has_effect";
|
||||
this.userType = UserType.PLAYER_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkEntity(EntityLivingBase entity) {
|
||||
if (!(entity instanceof EntityPlayer)) return false;
|
||||
if (effectId < 0) return false;
|
||||
|
||||
EntityPlayer player = (EntityPlayer) entity;
|
||||
return CustomEffectController.getInstance().hasEffect(player, effectId, effectIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getConditionDefinitions(List<FieldDef> defs) {
|
||||
defs.add(FieldDef.subGuiField("condition.select_effect",
|
||||
() -> new SubGuiCustomEffectSelect(effectId, effectIndex),
|
||||
(SubGuiInterface gui) -> {
|
||||
SubGuiCustomEffectSelect sel = (SubGuiCustomEffectSelect) gui;
|
||||
if (sel.getSelectedEffectId() >= 0) {
|
||||
effectId = sel.getSelectedEffectId();
|
||||
effectIndex = sel.getSelectedIndex();
|
||||
}
|
||||
})
|
||||
.buttonLabel(() -> {
|
||||
if (effectId < 0) return "None";
|
||||
CustomEffect effect = getEffect();
|
||||
return effect != null ? effect.getName() : "ID:" + effectId;
|
||||
})
|
||||
.clearable(() -> {
|
||||
effectId = -1;
|
||||
effectIndex = 0;
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConditionSummary() {
|
||||
String filterLabel = StatCollector.translateToLocal("condition.filter." + getFilter().name().toLowerCase());
|
||||
String effectName = "None";
|
||||
if (effectId >= 0) {
|
||||
CustomEffect effect = getEffect();
|
||||
effectName = effect != null ? effect.getName() : "ID:" + effectId;
|
||||
}
|
||||
return "[" + filterLabel + "] Effect: " + effectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConfigured() {
|
||||
return effectId >= 0;
|
||||
}
|
||||
|
||||
private CustomEffect getEffect() {
|
||||
HashMap<Integer, CustomEffect> map = CustomEffectController.getInstance().getEffectMap(effectIndex);
|
||||
return map != null ? map.get(effectId) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTypeNBT(NBTTagCompound nbt) {
|
||||
nbt.setInteger("effectId", effectId);
|
||||
nbt.setInteger("effectIndex", effectIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readTypeNBT(NBTTagCompound nbt) {
|
||||
effectId = nbt.getInteger("effectId");
|
||||
effectIndex = nbt.getInteger("effectIndex");
|
||||
}
|
||||
|
||||
public int getEffectId() {
|
||||
return effectId;
|
||||
}
|
||||
|
||||
public void setEffectId(int effectId) {
|
||||
this.effectId = effectId;
|
||||
}
|
||||
|
||||
public int getEffectIndex() {
|
||||
return effectIndex;
|
||||
}
|
||||
|
||||
public void setEffectIndex(int effectIndex) {
|
||||
this.effectIndex = effectIndex;
|
||||
}
|
||||
}
|
||||
@@ -164,12 +164,10 @@ public class AbilityCutter extends Ability implements IAbilityCutter {
|
||||
currentRotation = -arcAngle / 2.0f;
|
||||
activeSoundPlayed = false;
|
||||
|
||||
// Use the telegraph's locked yaw if available, so the sweep direction
|
||||
// matches the telegraph the player/NPC was seeing during windup.
|
||||
// The telegraph yaw is locked when entering ACTIVE phase via lockPosition().
|
||||
if (!telegraphInstances.isEmpty()) {
|
||||
sweepBaseYaw = telegraphInstances.get(0).getYaw();
|
||||
} else if (target != null) {
|
||||
// Compute sweep direction from caster/target at execution time.
|
||||
// Server-side telegraph instances are not ticked, so their yaw is stale
|
||||
// from windup start — use the caster's current rotation instead.
|
||||
if (target != null) {
|
||||
double dx = target.posX - caster.posX;
|
||||
double dz = target.posZ - caster.posZ;
|
||||
if (dx * dx + dz * dz > 0.0001) {
|
||||
|
||||
Reference in new issue
Block a user