Search in sources :

Example 1 with PktUnlockPerk

use of hellfirepvp.astralsorcery.common.network.play.client.PktUnlockPerk in project AstralSorcery by HellFirePvP.

the class ScreenJournalPerkTree method mouseReleased.

@Override
public boolean mouseReleased(double mouseX, double mouseY, int state) {
    if (super.mouseReleased(mouseX, mouseY, state)) {
        return true;
    }
    PlayerEntity player = Minecraft.getInstance().player;
    if (!this.mouseSealStack.isEmpty()) {
        this.mouseSealStack = ItemStack.EMPTY;
        if (Minecraft.getInstance().player == null) {
            return false;
        }
        PlayerPerkData perkData = ResearchHelper.getClientProgress().getPerkData();
        for (Map.Entry<AbstractPerk, Rectangle.Float> rctPerk : this.thisFramePerks.entrySet()) {
            if (rctPerk.getValue().contains(mouseX, mouseY) && this.guiBox.isInBox(mouseX - guiLeft, mouseY - guiTop)) {
                if (perkData.hasPerkEffect(rctPerk.getKey()) && !perkData.isPerkSealed(rctPerk.getKey()) && ItemPerkSeal.useSeal(player, true)) {
                    PktRequestPerkSealAction pkt = new PktRequestPerkSealAction(rctPerk.getKey(), true);
                    PacketChannel.CHANNEL.sendToServer(pkt);
                    return true;
                }
            }
        }
    }
    if (this.unlockPrimed == null) {
        return false;
    }
    for (Map.Entry<AbstractPerk, Rectangle.Float> rctPerk : this.thisFramePerks.entrySet()) {
        if (this.unlockPrimed.equals(rctPerk.getKey()) && rctPerk.getValue().contains(mouseX, mouseY) && this.guiBox.isInBox(mouseX - guiLeft, mouseY - guiTop)) {
            AbstractPerk perk = rctPerk.getKey();
            PlayerProgress prog = ResearchHelper.getClientProgress();
            PlayerPerkData perkData = prog.getPerkData();
            if (!perkData.hasPerkAllocation(perk) && perk.mayUnlockPerk(prog, player)) {
                PktUnlockPerk pkt = new PktUnlockPerk(false, rctPerk.getKey());
                PacketChannel.CHANNEL.sendToServer(pkt);
                break;
            }
        }
    }
    this.unlockPrimed = null;
    return true;
}
Also used : PktUnlockPerk(hellfirepvp.astralsorcery.common.network.play.client.PktUnlockPerk) PlayerPerkData(hellfirepvp.astralsorcery.common.data.research.PlayerPerkData) PktRequestPerkSealAction(hellfirepvp.astralsorcery.common.network.play.client.PktRequestPerkSealAction) PlayerProgress(hellfirepvp.astralsorcery.common.data.research.PlayerProgress) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

PlayerPerkData (hellfirepvp.astralsorcery.common.data.research.PlayerPerkData)1 PlayerProgress (hellfirepvp.astralsorcery.common.data.research.PlayerProgress)1 PktRequestPerkSealAction (hellfirepvp.astralsorcery.common.network.play.client.PktRequestPerkSealAction)1 PktUnlockPerk (hellfirepvp.astralsorcery.common.network.play.client.PktUnlockPerk)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1