Search in sources :

Example 1 with PerkTreePoint

use of hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint in project AstralSorcery by HellFirePvP.

the class ScreenJournalPerkTree method drawPerkTree.

private void drawPerkTree(MatrixStack renderStack, float partialTicks) {
    PlayerEntity player = Minecraft.getInstance().player;
    PlayerProgress progress = ResearchHelper.getClientProgress();
    PlayerPerkData perkData = progress.getPerkData();
    RenderSystem.enableBlend();
    RenderSystem.defaultBlendFunc();
    TexturesAS.TEX_GUI_LINE_CONNECTION.bindTexture();
    RenderingUtils.draw(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX, buf -> {
        for (Tuple<AbstractPerk, AbstractPerk> perkConnection : PerkTree.PERK_TREE.getConnections()) {
            if (!perkConnection.getA().isVisible(progress, player) || !perkConnection.getB().isVisible(progress, player)) {
                continue;
            }
            AllocationStatus status;
            int alloc = 0;
            if (perkData.hasPerkAllocation(perkConnection.getA(), PerkAllocationType.UNLOCKED)) {
                alloc++;
            }
            if (perkData.hasPerkAllocation(perkConnection.getB(), PerkAllocationType.UNLOCKED)) {
                alloc++;
            }
            if (alloc == 2) {
                status = AllocationStatus.ALLOCATED;
            } else if (alloc == 1 && progress.getPerkData().hasFreeAllocationPoint(player, LogicalSide.CLIENT)) {
                status = AllocationStatus.UNLOCKABLE;
            } else {
                status = AllocationStatus.UNALLOCATED;
            }
            Point.Float offsetOne = perkConnection.getA().getPoint().getOffset();
            Point.Float offsetTwo = perkConnection.getB().getPoint().getOffset();
            drawConnection(buf, renderStack, status, offsetOne, offsetTwo, ClientScheduler.getClientTick() + (int) offsetOne.x + (int) offsetOne.y + (int) offsetTwo.x + (int) offsetTwo.y);
        }
    });
    RenderSystem.disableBlend();
    drawBuffer.beginDrawingPerks();
    List<Runnable> renderDynamic = Lists.newArrayList();
    for (PerkTreePoint<?> perkPoint : PerkTree.PERK_TREE.getPerkPoints(LogicalSide.CLIENT)) {
        AbstractPerk perk = perkPoint.getPerk();
        if (!perk.isVisible(progress, player)) {
            continue;
        }
        Point.Float offset = perkPoint.getOffset();
        Rectangle.Float perkRect = drawPerk(drawBuffer, renderStack, perkPoint, partialTicks, ClientScheduler.getClientTick() + (int) offset.x + (int) offset.y, perkData.isPerkSealed(perk), renderDynamic);
        if (perkRect != null) {
            this.thisFramePerks.put(perk, perkRect);
        }
    }
    RenderSystem.enableBlend();
    RenderSystem.defaultBlendFunc();
    drawBuffer.draw();
    RenderSystem.disableBlend();
    renderDynamic.forEach(Runnable::run);
    this.unlockEffects.keySet().removeIf(perk -> !drawPerkUnlock(perk, renderStack, this.unlockEffects.get(perk)));
    this.breakEffects.keySet().removeIf(perk -> !drawPerkSealBreak(perk, renderStack, this.breakEffects.get(perk), partialTicks));
}
Also used : PlayerPerkData(hellfirepvp.astralsorcery.common.data.research.PlayerPerkData) ScalingPoint(hellfirepvp.astralsorcery.client.screen.helper.ScalingPoint) PerkTreePoint(hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint) PlayerProgress(hellfirepvp.astralsorcery.common.data.research.PlayerProgress) ScalingPoint(hellfirepvp.astralsorcery.client.screen.helper.ScalingPoint) PerkTreePoint(hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 2 with PerkTreePoint

use of hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint in project AstralSorcery by HellFirePvP.

the class KeyTreeConnector method mayUnlockPerk.

@Override
public boolean mayUnlockPerk(PlayerProgress progress, PlayerEntity player) {
    if (!progress.getPerkData().hasFreeAllocationPoint(player, getSide(player)) || !canSee(player, progress))
        return false;
    PlayerPerkData perkData = progress.getPerkData();
    LogicalSide side = getSide(player);
    boolean hasAllAdjacent = true;
    for (AbstractPerk otherPerks : PerkTree.PERK_TREE.getConnectedPerks(side, this)) {
        if (!perkData.hasPerkAllocation(otherPerks, PerkAllocationType.UNLOCKED)) {
            hasAllAdjacent = false;
            break;
        }
    }
    if (!hasAllAdjacent) {
        return PerkTree.PERK_TREE.getPerkPoints(getSide(player)).stream().map(PerkTreePoint::getPerk).filter(perk -> perk instanceof KeyTreeConnector).anyMatch(perk -> perkData.hasPerkAllocation(perk, PerkAllocationType.UNLOCKED));
    } else {
        return true;
    }
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) StringNBT(net.minecraft.nbt.StringNBT) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) MajorPerk(hellfirepvp.astralsorcery.common.perk.node.MajorPerk) AbstractPerk(hellfirepvp.astralsorcery.common.perk.AbstractPerk) PerkTreePoint(hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint) PerkTree(hellfirepvp.astralsorcery.common.perk.PerkTree) hellfirepvp.astralsorcery.common.data.research(hellfirepvp.astralsorcery.common.data.research) AstralSorcery(hellfirepvp.astralsorcery.AstralSorcery) ResourceLocation(net.minecraft.util.ResourceLocation) Nullable(javax.annotation.Nullable) LogicalSide(net.minecraftforge.fml.LogicalSide) AbstractPerk(hellfirepvp.astralsorcery.common.perk.AbstractPerk) PerkTreePoint(hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint) LogicalSide(net.minecraftforge.fml.LogicalSide)

Example 3 with PerkTreePoint

use of hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint in project AstralSorcery by HellFirePvP.

the class PreparedPerkTreeData method create.

static PreparedPerkTreeData create(Collection<LoadedPerkData> perks) {
    PreparedPerkTreeData treeData = new PreparedPerkTreeData();
    perks.stream().map(LoadedPerkData::getPerk).forEach(perk -> {
        if (perk instanceof RootPerk) {
            treeData.rootPerks.put(((RootPerk) perk).getConstellation(), (RootPerk) perk);
        }
        PerkTreePoint<? extends AbstractPerk> offsetPoint = perk.getPoint();
        if (treeData.treePoints.contains(offsetPoint)) {
            throw new IllegalArgumentException("Tried to register perk-point at already placed position: " + offsetPoint.getOffset().toString());
        }
        treeData.treePoints.add((PerkTreePoint<AbstractPerk>) offsetPoint);
    });
    perks.forEach(perkData -> {
        for (ResourceLocation connection : perkData.getConnections()) {
            AbstractPerk perkTo = treeData.getPerk(perk -> connection.equals(perk.getRegistryName())).orElseThrow(() -> new JsonParseException("Cannot connect to unknown perk: " + connection));
            treeData.getConnector(perkTo).ifPresent(connector -> {
                connector.connect(perkData.getPerk());
            });
        }
    });
    treeData.version = treeData.computeTreeHash();
    return treeData;
}
Also used : JsonParseException(com.google.gson.JsonParseException) java.util(java.util) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) Predicate(java.util.function.Predicate) Tuple(net.minecraft.util.Tuple) AbstractPerk(hellfirepvp.astralsorcery.common.perk.AbstractPerk) PerkTreePoint(hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint) Dist(net.minecraftforge.api.distmarker.Dist) Lists(com.google.common.collect.Lists) RootPerk(hellfirepvp.astralsorcery.common.perk.node.RootPerk) ResourceLocation(net.minecraft.util.ResourceLocation) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation) Nullable(javax.annotation.Nullable) LogicalSide(net.minecraftforge.fml.LogicalSide) AbstractPerk(hellfirepvp.astralsorcery.common.perk.AbstractPerk) RootPerk(hellfirepvp.astralsorcery.common.perk.node.RootPerk) ResourceLocation(net.minecraft.util.ResourceLocation) JsonParseException(com.google.gson.JsonParseException)

Example 4 with PerkTreePoint

use of hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint in project AstralSorcery by HellFirePvP.

the class PreparedPerkTreeData method computeTreeHash.

private long computeTreeHash() {
    long[] perkHash = new long[this.treePoints.size()];
    for (int i = 0; i < this.treePoints.size(); i++) {
        PerkTreePoint<? extends AbstractPerk> treePoint = this.treePoints.get(i);
        perkHash[i] = ((long) treePoint.getPerk().hashCode()) << 32 ^ treePoint.getOffset().hashCode();
    }
    long hash = 1L;
    for (long element : perkHash) {
        long elementHash = element ^ (element >>> 32);
        hash = 31 * hash + elementHash;
    }
    return hash;
}
Also used : PerkTreePoint(hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint)

Example 5 with PerkTreePoint

use of hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint in project AstralSorcery by HellFirePvP.

the class ClientProxy method initialize.

@Override
public void initialize() {
    this.clientScheduler = new ClientScheduler();
    if (!AstralSorcery.isDoingDataGeneration()) {
        IReloadableResourceManager resMgr = (IReloadableResourceManager) Minecraft.getInstance().getResourceManager();
        resMgr.addReloadListener(AssetLibrary.INSTANCE);
        resMgr.addReloadListener(AssetPreLoader.INSTANCE);
        resMgr.addReloadListener(ColorizationHelper.onReload());
        resMgr.addReloadListener((stage, resourceManager, preparationsProfiler, reloadProfiler, backgroundExecutor, gameExecutor) -> stage.markCompleteAwaitingOthers(Unit.INSTANCE).thenRunAsync(() -> {
            if (!SelectiveReloadStateHandler.INSTANCE.get().test(VanillaResourceType.LANGUAGES)) {
                return;
            }
            PerkTree.PERK_TREE.getPerkPoints(LogicalSide.CLIENT).stream().map(PerkTreePoint::getPerk).forEach(AbstractPerk::clearClientTextCaches);
        }));
    }
    this.clientConfig = new ClientConfig();
    super.initialize();
    this.addTomeBookmarks();
    RandomWordGenerator.init();
    this.clientConfig.buildConfiguration();
}
Also used : PerkTreePoint(hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint) IReloadableResourceManager(net.minecraft.resources.IReloadableResourceManager) ClientConfig(hellfirepvp.astralsorcery.client.data.config.ClientConfig)

Aggregations

PerkTreePoint (hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint)5 AbstractPerk (hellfirepvp.astralsorcery.common.perk.AbstractPerk)2 Nullable (javax.annotation.Nullable)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 LogicalSide (net.minecraftforge.fml.LogicalSide)2 Lists (com.google.common.collect.Lists)1 JsonParseException (com.google.gson.JsonParseException)1 AstralSorcery (hellfirepvp.astralsorcery.AstralSorcery)1 ClientConfig (hellfirepvp.astralsorcery.client.data.config.ClientConfig)1 ScalingPoint (hellfirepvp.astralsorcery.client.screen.helper.ScalingPoint)1 IConstellation (hellfirepvp.astralsorcery.common.constellation.IConstellation)1 hellfirepvp.astralsorcery.common.data.research (hellfirepvp.astralsorcery.common.data.research)1 PlayerPerkData (hellfirepvp.astralsorcery.common.data.research.PlayerPerkData)1 PlayerProgress (hellfirepvp.astralsorcery.common.data.research.PlayerProgress)1 PerkTree (hellfirepvp.astralsorcery.common.perk.PerkTree)1 MajorPerk (hellfirepvp.astralsorcery.common.perk.node.MajorPerk)1 RootPerk (hellfirepvp.astralsorcery.common.perk.node.RootPerk)1 java.util (java.util)1 Predicate (java.util.function.Predicate)1