Search in sources :

Example 6 with SkillData

use of jackiecrazy.wardance.skill.SkillData in project WarDance by Jackiecrazy.

the class Mark method read.

@Override
public void read(CompoundNBT from) {
    statuus.clear();
    if (from.contains("ActiveAfflictions", 9)) {
        ListNBT listnbt = from.getList("ActiveAfflictions", 10);
        for (int i = 0; i < listnbt.size(); ++i) {
            CompoundNBT compoundnbt = listnbt.getCompound(i);
            SkillData effectinstance = SkillData.read(compoundnbt);
            if (effectinstance != null) {
                this.statuus.put(effectinstance.getSkill(), effectinstance);
            }
        }
    }
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) SkillData(jackiecrazy.wardance.skill.SkillData) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 7 with SkillData

use of jackiecrazy.wardance.skill.SkillData in project WarDance by Jackiecrazy.

the class SkillCapability method update.

@Override
public void update() {
    final LivingEntity caster = dude.get();
    if (caster == null)
        return;
    final boolean gate = caster.level.getGameRules().getBoolean(WarDance.GATED_SKILLS);
    sync |= gatedSkills != gate;
    gatedSkills = gate;
    for (SkillData d : data.values()) {
        if (d == null || d.getSkill() == null) {
            continue;
        }
        if (d.getSkill().equippedTick(caster, d)) {
            d.markDirty();
            fastSync = true;
        }
    }
    for (SkillData s : getAllSkillData().values()) {
        // active ends. Add to cast history and forward to skill for individual handling.
        if (s.getDuration() < 0 && s.getState() == Skill.STATE.ACTIVE) {
            lastCast.add(s.getSkill());
            while (lastCast.size() > 5) lastCast.remove();
            changeSkillState(s.getSkill(), Skill.STATE.COOLING);
        // cooldown ends. Forward to skill for individual handling.
        } else if (s.getDuration() <= 0 && s.getState() == Skill.STATE.COOLING) {
            changeSkillState(s.getSkill(), Skill.STATE.INACTIVE);
        }
    }
    if (sync && caster instanceof ServerPlayerEntity)
        CombatChannel.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) caster), new SyncSkillPacket(this.write()));
    else if (caster instanceof ServerPlayerEntity) {
        CompoundNBT written = fastWrite();
        if (!written.isEmpty())
            CombatChannel.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) caster), new SyncSkillPacket(written));
    }
    sync = false;
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) SkillData(jackiecrazy.wardance.skill.SkillData) SyncSkillPacket(jackiecrazy.wardance.networking.SyncSkillPacket) CompoundNBT(net.minecraft.nbt.CompoundNBT) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 8 with SkillData

use of jackiecrazy.wardance.skill.SkillData in project WarDance by Jackiecrazy.

the class SkillCapability method fastWrite.

private CompoundNBT fastWrite() {
    CompoundNBT to = new CompoundNBT();
    if (!this.data.isEmpty()) {
        ListNBT listnbt = new ListNBT();
        for (SkillData effectinstance : this.data.values()) {
            if (effectinstance._isDirty()) {
                listnbt.add(effectinstance.write(new CompoundNBT()));
            }
        }
        if (!listnbt.isEmpty()) {
            to.put("skillData", listnbt);
            to.putBoolean("fast", true);
        }
    }
    return to;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) SkillData(jackiecrazy.wardance.skill.SkillData) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 9 with SkillData

use of jackiecrazy.wardance.skill.SkillData in project WarDance by Jackiecrazy.

the class SkillCapability method write.

@Override
public CompoundNBT write() {
    CompoundNBT to = new CompoundNBT();
    to.putInt("holster", index);
    to.putBoolean("gamerule", gatedSkills);
    if (!this.data.isEmpty()) {
        ListNBT listnbt = new ListNBT();
        for (SkillData effectinstance : this.data.values()) {
            listnbt.add(effectinstance.write(new CompoundNBT()));
        }
        to.put("skillData", listnbt);
    }
    for (int a = 0; a < equippedSkill.size(); a++) if (equippedSkill.get(a) != null)
        to.putString("equippedSkill" + a, equippedSkill.get(a).getRegistryName().toString());
    ListNBT str = new ListNBT();
    for (Skill add : skillList) {
        str.add(StringNBT.valueOf(add.getRegistryName().toString()));
    }
    to.put("randomList", str);
    return to;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) SkillData(jackiecrazy.wardance.skill.SkillData) Skill(jackiecrazy.wardance.skill.Skill) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 10 with SkillData

use of jackiecrazy.wardance.skill.SkillData in project WarDance by Jackiecrazy.

the class SkillCapability method read.

@Override
public void read(CompoundNBT from) {
    if (!from.getBoolean("fast")) {
        data.clear();
        index = from.getInt("holster");
        // it's the easy way out...
        gatedSkills = from.getBoolean("gamerule");
        Skill[] als = new Skill[10];
        for (int a = 0; a < als.length; a++) if (from.contains("equippedSkill" + a))
            als[a] = (Skill.getSkill(from.getString("equippedSkill" + a)));
        // if (from.getBoolean("skillListDirty")) {
        skillList.clear();
        if (from.contains("randomList", Constants.NBT.TAG_LIST)) {
            ListNBT list = from.getList("randomList", Constants.NBT.TAG_STRING);
            for (Object s : list.toArray()) {
                if (s instanceof StringNBT && Skill.getSkill(((StringNBT) s).getAsString()) != null)
                    skillList.add(Skill.getSkill(((StringNBT) s).getAsString()));
            }
        }
        // }
        equippedSkill.clear();
        equippedSkill.addAll(Arrays.asList(als));
    }
    if (from.contains("skillData", 9)) {
        ListNBT listnbt = from.getList("skillData", 10);
        for (int i = 0; i < listnbt.size(); ++i) {
            CompoundNBT compoundnbt = listnbt.getCompound(i);
            SkillData data = SkillData.read(compoundnbt);
            if (data != null) {
                this.data.put(data.getSkill(), data);
            }
        }
    }
}
Also used : Skill(jackiecrazy.wardance.skill.Skill) ListNBT(net.minecraft.nbt.ListNBT) SkillData(jackiecrazy.wardance.skill.SkillData) CompoundNBT(net.minecraft.nbt.CompoundNBT) StringNBT(net.minecraft.nbt.StringNBT)

Aggregations

SkillData (jackiecrazy.wardance.skill.SkillData)12 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 ListNBT (net.minecraft.nbt.ListNBT)5 LivingEntity (net.minecraft.entity.LivingEntity)4 Skill (jackiecrazy.wardance.skill.Skill)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 CombatDamageSource (jackiecrazy.wardance.api.CombatDamageSource)1 SyncSkillPacket (jackiecrazy.wardance.networking.SyncSkillPacket)1 UpdateAfflictionPacket (jackiecrazy.wardance.networking.UpdateAfflictionPacket)1 StringNBT (net.minecraft.nbt.StringNBT)1