Search in sources :

Example 1 with PartDataList

use of net.silentchaos512.gear.api.part.PartDataList in project Silent-Gear by SilentChaos512.

the class GearData method addUpgradePart.

/**
 * Add an upgrade part to the gear item. Depending on the upgrade, this may replace an existing
 * part.
 * <p>
 * TODO: Should we return something to indicate if the upgrade cannot be applied or replaces an
 * existing upgrade?
 *
 * @param gear The gear item
 * @param part The upgrade part
 */
public static void addUpgradePart(ItemStack gear, PartData part) {
    if (!GearHelper.isGear(gear))
        return;
    PartDataList parts = getConstructionParts(gear);
    // Make sure the upgrade is valid for the gear type
    if (!part.get().canAddToGear(gear, part))
        return;
    // Only one allowed of this type? Remove existing if needed.
    if (part.get().replacesExistingInPosition(part)) {
        parts.removeIf(p -> p.getType() == part.getType());
    }
    // Allow the part to make additional changes if needed
    part.onAddToGear(gear);
    // Other upgrades allow no exact duplicates, but any number of total upgrades
    for (PartData partInList : parts) {
        if (partInList.get() == part.get()) {
            return;
        }
    }
    parts.add(part);
    writeConstructionParts(gear, parts);
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 2 with PartDataList

use of net.silentchaos512.gear.api.part.PartDataList in project Silent-Gear by SilentChaos512.

the class GearData method addPart.

public static void addPart(ItemStack gear, PartData part) {
    PartDataList parts = getConstructionParts(gear);
    parts.add(part);
    writeConstructionParts(gear, parts);
    part.onAddToGear(gear);
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList)

Example 3 with PartDataList

use of net.silentchaos512.gear.api.part.PartDataList in project Silent-Gear by SilentChaos512.

the class GearData method getStatModifiers.

public static StatModifierMap getStatModifiers(ItemStack stack, ICoreItem item, PartDataList parts) {
    GearType gearType = item.getGearType();
    StatModifierMap stats = new StatModifierMap();
    for (ItemStat stat : ItemStats.allStatsOrderedExcluding(item.getExcludedStats(stack))) {
        StatGearKey itemKey = StatGearKey.of(stat, gearType);
        for (PartData part : parts) {
            for (StatInstance mod : part.getStatModifiers(itemKey, stack)) {
                StatInstance modCopy = StatInstance.of(mod.getValue(), mod.getOp(), itemKey);
                stats.put(modCopy.getKey(), modCopy);
            }
        }
    }
    return stats;
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 4 with PartDataList

use of net.silentchaos512.gear.api.part.PartDataList in project Silent-Gear by SilentChaos512.

the class GearGenerator method randomizeParts.

public static ItemStack randomizeParts(ItemStack stack, int tier) {
    if (!(stack.getItem() instanceof ICoreItem)) {
        throw new RuntimeException("Called GearGenerator.randomizeParts on non-gear");
    }
    ICoreItem item = (ICoreItem) stack.getItem();
    GearType gearType = item.getGearType();
    PartDataList parts = PartDataList.of();
    for (PartType partType : item.getRequiredParts()) {
        getRandomPart(gearType, partType, tier).ifPresent(parts::add);
    }
    if (parts.isEmpty()) {
        return ItemStack.EMPTY;
    }
    ItemStack result = stack.copy();
    parts.forEach(p -> p.onAddToGear(result));
    GearData.writeConstructionParts(result, parts);
    // Apply some random upgrades?
    if (item instanceof ICoreTool && tier > 1 && SilentGear.RANDOM.nextFloat() < 0.2f * tier + 0.1f) {
        getRandomPart(gearType, PartType.TIP, tier).ifPresent(part -> GearData.addUpgradePart(result, part));
    }
    GearData.recalculateStats(result, null);
    return result;
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType) ICoreTool(net.silentchaos512.gear.api.item.ICoreTool) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 5 with PartDataList

use of net.silentchaos512.gear.api.part.PartDataList in project Silent-Gear by SilentChaos512.

the class TraitHelper method getTraits.

/**
 * Gets a Map of Traits and levels from the parts, used to calculate trait levels and should not
 * be used in most cases. Consider using {@link #getTraitLevel(ItemStack, ResourceLocation)} or
 * {@link #hasTrait(ItemStack, ResourceLocation)} when appropriate.
 *
 * @param gear     The item
 * @param gearType The gear type
 * @param parts    The list of all parts used in constructing the gear.
 * @return A Map of Traits to their levels
 */
public static Map<ITrait, Integer> getTraits(ItemStack gear, GearType gearType, PartDataList parts) {
    if (parts.isEmpty() || (!gear.isEmpty() && GearHelper.isBroken(gear)))
        return ImmutableMap.of();
    Map<ITrait, Integer> result = new LinkedHashMap<>();
    for (PartData part : parts) {
        PartGearKey key = PartGearKey.of(gearType, part);
        for (TraitInstance inst : part.getTraits(key, gear)) {
            if (inst.conditionsMatch(key, gear, parts)) {
                ITrait trait = inst.getTrait();
                // Get the highest value in any part
                result.merge(trait, inst.getLevel(), Integer::max);
            }
        }
    }
    ITrait[] keys = result.keySet().toArray(new ITrait[0]);
    cancelTraits(result, keys);
    MinecraftForge.EVENT_BUS.post(new GetTraitsEvent(gear, parts, result));
    return result;
}
Also used : PartGearKey(net.silentchaos512.gear.api.util.PartGearKey) GetTraitsEvent(net.silentchaos512.gear.api.event.GetTraitsEvent) ITrait(net.silentchaos512.gear.api.traits.ITrait) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) PartData(net.silentchaos512.gear.gear.part.PartData)

Aggregations

PartDataList (net.silentchaos512.gear.api.part.PartDataList)15 PartData (net.silentchaos512.gear.gear.part.PartData)14 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)7 IPartData (net.silentchaos512.gear.api.part.IPartData)7 ItemStack (net.minecraft.world.item.ItemStack)5 PartType (net.silentchaos512.gear.api.part.PartType)5 GearType (net.silentchaos512.gear.api.item.GearType)3 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)3 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2 ITrait (net.silentchaos512.gear.api.traits.ITrait)2 ArrayList (java.util.ArrayList)1 Tag (net.minecraft.nbt.Tag)1 Component (net.minecraft.network.chat.Component)1 TextComponent (net.minecraft.network.chat.TextComponent)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 GearNamePrefixesEvent (net.silentchaos512.gear.api.event.GearNamePrefixesEvent)1 GetTraitsEvent (net.silentchaos512.gear.api.event.GetTraitsEvent)1 ICoreTool (net.silentchaos512.gear.api.item.ICoreTool)1