Search in sources :

Example 1 with RootPerk

use of hellfirepvp.astralsorcery.common.perk.node.RootPerk 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)

Aggregations

Lists (com.google.common.collect.Lists)1 JsonParseException (com.google.gson.JsonParseException)1 IConstellation (hellfirepvp.astralsorcery.common.constellation.IConstellation)1 AbstractPerk (hellfirepvp.astralsorcery.common.perk.AbstractPerk)1 RootPerk (hellfirepvp.astralsorcery.common.perk.node.RootPerk)1 PerkTreePoint (hellfirepvp.astralsorcery.common.perk.tree.PerkTreePoint)1 java.util (java.util)1 Predicate (java.util.function.Predicate)1 Nullable (javax.annotation.Nullable)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Tuple (net.minecraft.util.Tuple)1 Dist (net.minecraftforge.api.distmarker.Dist)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1 LogicalSide (net.minecraftforge.fml.LogicalSide)1