Search in sources :

Example 1 with SyncSkillPacket

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()));
    }
}
Also used : SyncSkillPacket(jackiecrazy.wardance.networking.SyncSkillPacket) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) MobEntity(net.minecraft.entity.MobEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with SyncSkillPacket

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

Aggregations

SyncSkillPacket (jackiecrazy.wardance.networking.SyncSkillPacket)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 SkillData (jackiecrazy.wardance.skill.SkillData)1 LivingEntity (net.minecraft.entity.LivingEntity)1 MobEntity (net.minecraft.entity.MobEntity)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1