use of jackiecrazy.wardance.networking.SyncSkillPacket in project WarDance by Jackiecrazy.
the class EntityHandler method takeThis.
@SubscribeEvent
public static void takeThis(EntityJoinWorldEvent e) {
if (e.getEntity() instanceof MobEntity) {
MobEntity mob = (MobEntity) e.getEntity();
mob.goalSelector.addGoal(-1, new NoGoal(mob));
mob.targetSelector.addGoal(-1, new NoGoal(mob));
} else if (e.getEntity() instanceof ServerPlayerEntity) {
CombatChannel.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) e.getEntity()), new SyncSkillPacket(CasterData.getCap((LivingEntity) e.getEntity()).write()));
}
}
use of jackiecrazy.wardance.networking.SyncSkillPacket 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;
}
Aggregations