Search in sources :

Example 1 with CompoundPartItem

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

the class CompoundPart method randomizeData.

@Override
public PartData randomizeData(GearType gearType, int tier) {
    for (ItemStack stack : this.getIngredient().getItems()) {
        if (stack.getItem() instanceof CompoundPartItem) {
            int materialCount = getRandomMaterialCount(partType);
            List<MaterialInstance> materials = getRandomMaterials(gearType, materialCount, tier);
            ItemStack craftingItem = ((CompoundPartItem) stack.getItem()).create(materials);
            return PartData.of(this, craftingItem);
        }
    }
    return super.randomizeData(gearType, tier);
}
Also used : CompoundPartItem(net.silentchaos512.gear.item.CompoundPartItem) ItemStack(net.minecraft.world.item.ItemStack) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance)

Example 2 with CompoundPartItem

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

the class SalvagingRecipe method salvage.

/**
 * Salvages parts into their respective material items, or fragments if appropriate. This does
 * not necessarily give back the original item used for the material, but an item that matches
 * it.
 *
 * @param part The part
 * @return The list of items to return
 */
public static List<ItemStack> salvage(PartData part) {
    if (part.get() instanceof CompoundPart && part.getItem().getItem() instanceof CompoundPartItem) {
        int craftedCount = ((CompoundPartItem) part.getItem().getItem()).getCraftedCount(part.getItem());
        if (craftedCount < 1) {
            SilentGear.LOGGER.warn("Compound part's crafted count is less than 1? {}", part.getItem());
            return Collections.singletonList(part.getItem());
        }
        List<IMaterialInstance> materials = part.getMaterials();
        Map<IMaterialInstance, Integer> fragments = new LinkedHashMap<>();
        for (IMaterialInstance material : materials) {
            int fragmentCount = 8 / craftedCount;
            fragments.merge(material.onSalvage(), fragmentCount, Integer::sum);
        }
        List<ItemStack> ret = new ArrayList<>();
        for (Map.Entry<IMaterialInstance, Integer> entry : fragments.entrySet()) {
            IMaterialInstance material = entry.getKey();
            int count = entry.getValue();
            int fulls = count / 8;
            int frags = count % 8;
            if (fulls > 0) {
                ret.add(material.getItem());
            }
            if (frags > 0) {
                ret.add(ModItems.FRAGMENT.get().create(material, frags));
            }
        }
        return ret;
    }
    return Collections.singletonList(part.getItem());
}
Also used : CompoundPartItem(net.silentchaos512.gear.item.CompoundPartItem) CompoundPart(net.silentchaos512.gear.gear.part.CompoundPart) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with CompoundPartItem

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

the class ColorUtils method getBlendedColor.

public static int getBlendedColor(CompoundPartItem item, 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();
        List<MaterialLayer> layers = model.getLayerList(item.getGearType(), item.getPartType(), mat).getLayers();
        if (layers.size() > layer) {
            int color = model.getLayerColor(item.getGearType(), item.getPartType(), mat, layer);
            int r = (color >> 16) & 0xFF;
            int g = (color >> 8) & 0xFF;
            int b = color & 0xFF;
            int colorWeight = item.getColorWeight(i, materials.size());
            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) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer)

Aggregations

IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)3 ItemStack (net.minecraft.world.item.ItemStack)2 CompoundPartItem (net.silentchaos512.gear.item.CompoundPartItem)2 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)1 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)1 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)1 CompoundPart (net.silentchaos512.gear.gear.part.CompoundPart)1