Search in sources :

Example 1 with ConstellationRegistry

use of hellfirepvp.astralsorcery.common.constellation.ConstellationRegistry in project AstralSorcery by HellFirePvP.

the class EngravedStarMap method applyEffects.

@Nonnull
public ItemStack applyEffects(@Nonnull ItemStack stack) {
    List<Tuple<EngravingEffect.ApplicableEffect, Float>> engravings = new LinkedList<>();
    List<IConstellation> constellations = new LinkedList<>();
    this.getConstellationKeys().stream().map(ConstellationRegistry::getConstellation).filter(Objects::nonNull).forEach(constellations::add);
    for (IConstellation cst : constellations) {
        EngravingEffect effect = cst.getEngravingEffect();
        if (effect != null) {
            List<EngravingEffect.ApplicableEffect> applicable = effect.getApplicableEffects(stack);
            if (!applicable.isEmpty()) {
                float distribution = this.getDistribution(cst);
                for (EngravingEffect.ApplicableEffect applicableEffect : applicable) {
                    engravings.add(new Tuple<>(applicableEffect, distribution));
                }
            }
        }
    }
    engravings.sort(Comparator.comparing(tpl -> {
        EngravingEffect.ApplicableEffect effect = tpl.getA();
        if (effect instanceof EngravingEffect.EnchantmentEffect) {
            if (!((EngravingEffect.EnchantmentEffect) effect).isIgnoreCompatibility()) {
                // Sort incompatible enchantments first since the others won't care.
                return 0;
            }
            return 1;
        }
        return 2;
    }));
    for (Tuple<EngravingEffect.ApplicableEffect, Float> tpl : engravings) {
        EngravingEffect.ApplicableEffect effect = tpl.getA();
        float distribution = tpl.getB();
        stack = effect.apply(stack, distribution, rand);
    }
    return stack;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) java.util(java.util) NBTHelper(hellfirepvp.astralsorcery.common.util.nbt.NBTHelper) World(net.minecraft.world.World) Constants(net.minecraftforge.common.util.Constants) CompoundNBT(net.minecraft.nbt.CompoundNBT) Tuple(net.minecraft.util.Tuple) java.awt(java.awt) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) DayTimeHelper(hellfirepvp.astralsorcery.common.constellation.world.DayTimeHelper) StarLocation(hellfirepvp.astralsorcery.common.constellation.star.StarLocation) MathHelper(net.minecraft.util.math.MathHelper) ResourceLocation(net.minecraft.util.ResourceLocation) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation) ConstellationRegistry(hellfirepvp.astralsorcery.common.constellation.ConstellationRegistry) Nonnull(javax.annotation.Nonnull) DrawnConstellation(hellfirepvp.astralsorcery.common.constellation.DrawnConstellation) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation) ConstellationRegistry(hellfirepvp.astralsorcery.common.constellation.ConstellationRegistry) Tuple(net.minecraft.util.Tuple) Nonnull(javax.annotation.Nonnull)

Example 2 with ConstellationRegistry

use of hellfirepvp.astralsorcery.common.constellation.ConstellationRegistry in project AstralSorcery by HellFirePvP.

the class ItemTome method getStoredConstellations.

public static List<IConstellation> getStoredConstellations(ItemStack stack, PlayerEntity player) {
    LinkedList<IConstellation> out = new LinkedList<>();
    PlayerProgress prog = ResearchHelper.getProgress(player, player.getEntityWorld().isRemote() ? LogicalSide.CLIENT : LogicalSide.SERVER);
    if (prog.isValid()) {
        prog.getStoredConstellationPapers().stream().map(ConstellationRegistry::getConstellation).filter(Objects::nonNull).forEach(out::add);
    }
    return out;
}
Also used : ConstellationRegistry(hellfirepvp.astralsorcery.common.constellation.ConstellationRegistry) LinkedList(java.util.LinkedList) PlayerProgress(hellfirepvp.astralsorcery.common.data.research.PlayerProgress) IConstellation(hellfirepvp.astralsorcery.common.constellation.IConstellation)

Aggregations

ConstellationRegistry (hellfirepvp.astralsorcery.common.constellation.ConstellationRegistry)2 IConstellation (hellfirepvp.astralsorcery.common.constellation.IConstellation)2 DrawnConstellation (hellfirepvp.astralsorcery.common.constellation.DrawnConstellation)1 StarLocation (hellfirepvp.astralsorcery.common.constellation.star.StarLocation)1 DayTimeHelper (hellfirepvp.astralsorcery.common.constellation.world.DayTimeHelper)1 PlayerProgress (hellfirepvp.astralsorcery.common.data.research.PlayerProgress)1 NBTHelper (hellfirepvp.astralsorcery.common.util.nbt.NBTHelper)1 java.awt (java.awt)1 java.util (java.util)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 ItemStack (net.minecraft.item.ItemStack)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 ListNBT (net.minecraft.nbt.ListNBT)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 Tuple (net.minecraft.util.Tuple)1 MathHelper (net.minecraft.util.math.MathHelper)1 World (net.minecraft.world.World)1 Constants (net.minecraftforge.common.util.Constants)1