Search in sources :

Example 16 with GearType

use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.

the class PartGearKey method fromNetwork.

public static PartGearKey fromNetwork(FriendlyByteBuf buf) {
    GearType gearType = GearType.get(buf.readUtf());
    PartType partType = Objects.requireNonNull(PartType.get(buf.readResourceLocation()));
    return of(gearType, partType);
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType)

Example 17 with GearType

use of net.silentchaos512.gear.api.item.GearType 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 GearType

use of net.silentchaos512.gear.api.item.GearType 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 19 with GearType

use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.

the class GearHelper method getExamplePartsFromRecipe.

public static Collection<IPartData> getExamplePartsFromRecipe(GearType gearType, Iterable<Ingredient> ingredients) {
    Map<PartType, IPartData> map = new LinkedHashMap<>();
    PartType.MAIN.makeCompoundPart(gearType, Const.Materials.EXAMPLE).ifPresent(p -> map.put(PartType.MAIN, p));
    for (Ingredient ingredient : ingredients) {
        if (ingredient instanceof IGearIngredient) {
            PartType type = ((IGearIngredient) ingredient).getPartType();
            type.makeCompoundPart(gearType, Const.Materials.EXAMPLE).ifPresent(p -> map.put(type, p));
        }
    }
    return map.values();
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) IGearIngredient(net.silentchaos512.gear.crafting.ingredient.IGearIngredient) Ingredient(net.minecraft.world.item.crafting.Ingredient) IGearIngredient(net.silentchaos512.gear.crafting.ingredient.IGearIngredient) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 20 with GearType

use of net.silentchaos512.gear.api.item.GearType 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

GearType (net.silentchaos512.gear.api.item.GearType)25 ItemStack (net.minecraft.world.item.ItemStack)9 PartType (net.silentchaos512.gear.api.part.PartType)9 ArrayList (java.util.ArrayList)8 ResourceLocation (net.minecraft.resources.ResourceLocation)8 JsonObject (com.google.gson.JsonObject)6 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)6 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)6 JsonArray (com.google.gson.JsonArray)5 List (java.util.List)5 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)5 PartGearKey (net.silentchaos512.gear.api.util.PartGearKey)5 JsonParseException (com.google.gson.JsonParseException)4 IMaterial (net.silentchaos512.gear.api.material.IMaterial)4 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)4 IPartData (net.silentchaos512.gear.api.part.IPartData)4 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)4 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)4 ITrait (net.silentchaos512.gear.api.traits.ITrait)4 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)4