Search in sources :

Example 11 with PartData

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

the class CompoundPartModelOverrideList method getOverrideModel.

private BakedModel getOverrideModel(ItemStack stack, @Nullable ClientLevel worldIn, @Nullable LivingEntity entityIn) {
    List<MaterialLayer> layers = new ArrayList<>();
    PartData part = PartData.from(stack);
    MaterialInstance primaryMaterial = CompoundPartItem.getPrimaryMaterial(stack);
    if (part != null && primaryMaterial != null) {
        addWithBlendedColor(layers, part, primaryMaterial, stack);
    }
    return model.bake(layers, "test", owner, bakery, spriteGetter, modelTransform, this, modelLocation);
}
Also used : MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) ArrayList(java.util.ArrayList) PartData(net.silentchaos512.gear.gear.part.PartData) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

Example 12 with PartData

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

the class SalvagerTileEntity method getSalvagedPartsWithChance.

private Collection<ItemStack> getSalvagedPartsWithChance(SalvagingRecipe recipe, ItemStack stack) {
    double lossRate = getLossRate(stack);
    SilentGear.LOGGER.debug("Loss rate for '{}': {}", stack, lossRate);
    ImmutableList.Builder<ItemStack> builder = ImmutableList.builder();
    for (ItemStack part : recipe.getPossibleResults(this)) {
        ItemStack copy = part.copy();
        int count = copy.getCount();
        PartData partData = PartData.from(part);
        double partLossRate = partData != null ? partData.get().getSalvageLossRate(partData, stack, lossRate) : lossRate;
        for (int i = 0; i < count; ++i) {
            if (MathUtils.tryPercentage(SilentGear.RANDOM, partLossRate)) {
                copy.shrink(1);
            }
        }
        if (!copy.isEmpty()) {
            builder.add(copy);
        }
    }
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PartData(net.silentchaos512.gear.gear.part.PartData) ItemStack(net.minecraft.world.item.ItemStack)

Example 13 with PartData

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

the class GearData method getBlendedColor.

@Deprecated
private static int getBlendedColor(ItemStack gear, List<PartData> parts) {
    int[] componentSums = new int[3];
    int maxColorSum = 0;
    int colorCount = 0;
    int partCount = parts.size();
    for (int i = 0; i < partCount; ++i) {
        PartData part = parts.get(i);
        int color = part.get().getColor(part, gear, 0, 0);
        int r = (color >> 16) & 0xFF;
        int g = (color >> 8) & 0xFF;
        int b = color & 0xFF;
        // Add earlier colors multiple times, to give them greater weight
        int colorWeight = (partCount - i) * (partCount - 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;
        }
    }
    if (colorCount > 0) {
        int r = componentSums[0] / colorCount;
        int g = componentSums[1] / colorCount;
        int b = componentSums[2] / colorCount;
        float maxAverage = (float) maxColorSum / (float) colorCount;
        float max = (float) Math.max(r, Math.max(g, b));
        r = (int) ((float) r * maxAverage / max);
        g = (int) ((float) g * maxAverage / max);
        b = (int) ((float) b * maxAverage / max);
        int finalColor = (r << 8) + g;
        finalColor = (finalColor << 8) + b;
        return finalColor;
    }
    return Color.VALUE_WHITE;
}
Also used : PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 14 with PartData

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

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

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