Search in sources :

Example 1 with PktSyncPerkActivity

use of hellfirepvp.astralsorcery.common.network.play.server.PktSyncPerkActivity in project AstralSorcery by HellFirePvP.

the class ResearchManager method removeAllAllocatedPerks.

private static void removeAllAllocatedPerks(PlayerProgress progress, PlayerEntity player) {
    PlayerPerkData perkData = progress.getPerkData();
    List<AbstractPerk> allocatedPerks = new ArrayList<>(perkData.getAllocatedPerks(PerkAllocationType.UNLOCKED));
    List<AbstractPerk> syncRemovable = new ArrayList<>();
    for (AbstractPerk perk : allocatedPerks) {
        if (doRemovePerk(progress, player, LogicalSide.SERVER, perk, PlayerPerkAllocation.unlock(), false)) {
            syncRemovable.add(perk);
        }
    }
    List<ResourceLocation> removals = syncRemovable.stream().map(AbstractPerk::getRegistryName).collect(Collectors.toList());
    PacketChannel.CHANNEL.sendToPlayer(player, new PktSyncPerkActivity(removals));
}
Also used : AbstractPerk(hellfirepvp.astralsorcery.common.perk.AbstractPerk) ResourceLocation(net.minecraft.util.ResourceLocation) PktSyncPerkActivity(hellfirepvp.astralsorcery.common.network.play.server.PktSyncPerkActivity)

Example 2 with PktSyncPerkActivity

use of hellfirepvp.astralsorcery.common.network.play.server.PktSyncPerkActivity in project AstralSorcery by HellFirePvP.

the class PerkEffectHelper method onPlayerConnectEvent.

public static void onPlayerConnectEvent(ServerPlayerEntity player) {
    modifyAllPerks(player, LogicalSide.SERVER, Action.ADD);
    // Restore current overscaled health
    CompoundNBT asData = NBTHelper.getPersistentData(player);
    if (asData.contains("health", Constants.NBT.TAG_FLOAT)) {
        player.setHealth(asData.getFloat("health"));
    }
    PacketChannel.CHANNEL.sendToPlayer(player, new PktSyncPerkActivity(PktSyncPerkActivity.Type.UNLOCKALL));
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) PktSyncPerkActivity(hellfirepvp.astralsorcery.common.network.play.server.PktSyncPerkActivity)

Example 3 with PktSyncPerkActivity

use of hellfirepvp.astralsorcery.common.network.play.server.PktSyncPerkActivity in project AstralSorcery by HellFirePvP.

the class PerkEffectHelper method onPlayerCloneEvent.

public static void onPlayerCloneEvent(ServerPlayerEntity original, ServerPlayerEntity newPlayer) {
    modifyAllPerks(original, LogicalSide.SERVER, Action.REMOVE);
    modifyAllPerks(newPlayer, LogicalSide.SERVER, Action.ADD);
    PerkCooldownHelper.removeAllCooldowns(original, LogicalSide.SERVER);
    PacketChannel.CHANNEL.sendToPlayer(newPlayer, new PktSyncPerkActivity(PktSyncPerkActivity.Type.UNLOCKALL));
}
Also used : PktSyncPerkActivity(hellfirepvp.astralsorcery.common.network.play.server.PktSyncPerkActivity)

Example 4 with PktSyncPerkActivity

use of hellfirepvp.astralsorcery.common.network.play.server.PktSyncPerkActivity in project AstralSorcery by HellFirePvP.

the class ResearchManager method setPerkData.

public static boolean setPerkData(PlayerEntity player, @Nonnull AbstractPerk perk, CompoundNBT prevoiusData, CompoundNBT newData) {
    PlayerProgress progress = ResearchHelper.getProgress(player, LogicalSide.SERVER);
    if (!progress.isValid())
        return false;
    PlayerPerkData perkData = progress.getPerkData();
    if (!perkData.hasPerkAllocation(perk))
        return false;
    PerkEffectHelper.modifySource(player, LogicalSide.SERVER, perk, PerkEffectHelper.Action.REMOVE);
    progress.getPerkData().updatePerkData(perk, newData);
    PerkEffectHelper.modifySource(player, LogicalSide.SERVER, perk, PerkEffectHelper.Action.ADD);
    PacketChannel.CHANNEL.sendToPlayer(player, new PktSyncPerkActivity(perk, prevoiusData, newData));
    ResearchSyncHelper.pushProgressToClientUnsafe(progress, player);
    ResearchHelper.savePlayerKnowledge(player);
    return true;
}
Also used : PktSyncPerkActivity(hellfirepvp.astralsorcery.common.network.play.server.PktSyncPerkActivity)

Aggregations

PktSyncPerkActivity (hellfirepvp.astralsorcery.common.network.play.server.PktSyncPerkActivity)4 AbstractPerk (hellfirepvp.astralsorcery.common.perk.AbstractPerk)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 ResourceLocation (net.minecraft.util.ResourceLocation)1