Search in sources :

Example 6 with IPartData

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

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

the class GearHelper method createSampleItem.

private static ItemStack createSampleItem(ICoreItem item, int tier) {
    ItemStack result = GearGenerator.create(item, tier);
    if (result.isEmpty()) {
        Collection<IPartData> parts = new ArrayList<>();
        for (PartType partType : item.getRequiredParts()) {
            partType.makeCompoundPart(item.getGearType(), Const.Materials.EXAMPLE).ifPresent(parts::add);
        }
        result = item.construct(parts);
    }
    GearData.setExampleTag(result, true);
    return result;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 8 with IPartData

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

the class ConversionRecipe method getParts.

private Collection<? extends IPartData> getParts() {
    PartDataList ret = PartDataList.of();
    // noinspection OverlyLongLambda
    this.resultMaterials.forEach((partType, list) -> {
        partType.getCompoundPartItem(item.getGearType()).ifPresent(partItem -> {
            PartData part = PartData.from(partItem.create(list));
            if (part != null) {
                ret.add(part);
            }
        });
    });
    return ret;
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 9 with IPartData

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

the class ColorUtils method getBlendedColor.

public static int getBlendedColor(ICoreItem item, IPartData part, Collection<? extends IMaterialInstance> materials, int layer) {
    int[] componentSums = new int[3];
    int maxColorSum = 0;
    int colorCount = 0;
    int i = 0;
    for (IMaterialInstance mat : materials) {
        IMaterialDisplay model = mat.getDisplayProperties();
        int color = model.getLayerColor(item.getGearType(), part, mat, layer);
        int r = (color >> 16) & 0xFF;
        int g = (color >> 8) & 0xFF;
        int b = color & 0xFF;
        int colorWeight = (materials.size() - i) * (materials.size() - i);
        for (int j = 0; j < colorWeight; ++j) {
            maxColorSum += Math.max(r, Math.max(g, b));
            componentSums[0] += r;
            componentSums[1] += g;
            componentSums[2] += b;
            ++colorCount;
        }
        ++i;
    }
    return blendColors(componentSums, maxColorSum, colorCount);
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay)

Example 10 with IPartData

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

the class ICoreItem method construct.

// region Item properties and construction
default ItemStack construct(Collection<? extends IPartData> parts) {
    ItemStack result = new ItemStack(this);
    GearData.writeConstructionParts(result, parts);
    parts.forEach(p -> p.onAddToGear(result));
    GearData.recalculateStats(result, null);
    // Allow traits to make any needed changes (must be done after a recalculate)
    TraitHelper.activateTraits(result, 0, (trait, level, nothing) -> {
        trait.onGearCrafted(new TraitActionContext(null, level, result));
        return 0;
    });
    return result;
}
Also used : TraitActionContext(net.silentchaos512.gear.api.traits.TraitActionContext) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

IPartData (net.silentchaos512.gear.api.part.IPartData)5 ItemStack (net.minecraft.world.item.ItemStack)4 PartType (net.silentchaos512.gear.api.part.PartType)4 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)3 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 SilentGear (net.silentchaos512.gear.SilentGear)2 GetStatModifierEvent (net.silentchaos512.gear.api.event.GetStatModifierEvent)2 GearType (net.silentchaos512.gear.api.item.GearType)2 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)2 PartDataList (net.silentchaos512.gear.api.part.PartDataList)2 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)2 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)2 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)2 PartData (net.silentchaos512.gear.gear.part.PartData)2 CompoundPartItem (net.silentchaos512.gear.item.CompoundPartItem)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 java.util (java.util)1