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);
}
}
}
}
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;
}
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;
}
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;
}
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);
}
}
}
}
Aggregations