Search in sources :

Example 16 with PartData

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

the class GearData method getTier.

/**
 * Gets the tier of the gear item. The tier is the same as the main part with the highest tier.
 *
 * @param gear The gear item
 * @return The gear tier
 */
public static int getTier(ItemStack gear) {
    if (!GearHelper.isGear(gear))
        return -1;
    CompoundTag data = getData(gear, NBT_ROOT_CONSTRUCTION);
    if (!data.contains(NBT_TIER)) {
        List<PartData> parts = getConstructionParts(gear).getMains();
        int max = 0;
        for (PartData part : parts) {
            if (part.getTier() > max) {
                max = part.getTier();
            }
        }
        data.putInt(NBT_TIER, max);
    }
    return data.getInt(NBT_TIER);
}
Also used : PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 17 with PartData

use of net.silentchaos512.gear.gear.part.PartData 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 18 with PartData

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

the class GearHelper method isEquivalent.

/**
 * Check if both gear items are made of the same parts.
 *
 * @param gear1 First item
 * @param gear2 Second item
 * @return True only if all parts are identical
 */
public static boolean isEquivalent(ItemStack gear1, ItemStack gear2) {
    if (!GearHelper.isGear(gear1) || !GearHelper.isGear(gear2) || gear1.getItem() != gear2.getItem()) {
        return false;
    }
    List<PartData> parts1 = GearData.getConstructionParts(gear1);
    List<PartData> parts2 = GearData.getConstructionParts(gear2);
    if (parts1.size() != parts2.size()) {
        return false;
    }
    if (parts1.isEmpty()) {
        return true;
    }
    for (PartData part1 : parts1) {
        for (PartData part2 : parts2) {
            if (part1.equals(part2)) {
                parts2.remove(part2);
                break;
            }
        }
    }
    return parts2.isEmpty();
}
Also used : PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 19 with PartData

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

the class GearHelper method getDisplayName.

public static Component getDisplayName(ItemStack gear) {
    PartData part = GearData.getPrimaryPart(gear);
    if (part == null)
        return new TranslatableComponent(gear.getDescriptionId());
    Component partName = part.getMaterialName(gear);
    if (TimedEvents.isAprilFools()) {
        partName = partName.copy().append(new TextComponent(" & Knuckles"));
    }
    Component gearName = new TranslatableComponent(gear.getDescriptionId() + ".nameProper", partName);
    Component result = gearName;
    if (gear.getItem() instanceof ICoreTool) {
        ICoreItem item = (ICoreItem) gear.getItem();
        if (item.requiresPartOfType(PartType.ROD) && GearData.getPartOfType(gear, PartType.ROD) == null) {
            result = new TranslatableComponent(gear.getDescriptionId() + ".noRod", gearName);
        } else if (item.requiresPartOfType(PartType.CORD) && GearData.getPartOfType(gear, PartType.CORD) == null) {
            result = new TranslatableComponent(gear.getDescriptionId() + ".unstrung", gearName);
        }
    }
    // Prefixes
    for (Component t : getNamePrefixes(gear, GearData.getConstructionParts(gear))) {
        result = t.copy().append(new TextComponent(" ")).append(result);
    }
    return result;
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ICoreTool(net.silentchaos512.gear.api.item.ICoreTool) PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) TextComponent(net.minecraft.network.chat.TextComponent) Component(net.minecraft.network.chat.Component)

Example 20 with PartData

use of net.silentchaos512.gear.gear.part.PartData 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

PartData (net.silentchaos512.gear.gear.part.PartData)36 ItemStack (net.minecraft.world.item.ItemStack)16 IPartData (net.silentchaos512.gear.api.part.IPartData)14 PartDataList (net.silentchaos512.gear.api.part.PartDataList)13 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)12 PartType (net.silentchaos512.gear.api.part.PartType)9 GearType (net.silentchaos512.gear.api.item.GearType)8 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)8 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)6 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)6 ArrayList (java.util.ArrayList)5 Component (net.minecraft.network.chat.Component)5 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)5 TextComponent (net.minecraft.network.chat.TextComponent)4 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)4 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)4 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)4 Nullable (javax.annotation.Nullable)3 CompoundTag (net.minecraft.nbt.CompoundTag)3 MutableComponent (net.minecraft.network.chat.MutableComponent)3