Search in sources :

Example 31 with IMaterialInstance

use of net.silentchaos512.gear.api.material.IMaterialInstance 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)

Example 32 with IMaterialInstance

use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.

the class GearClientHelper method tooltipListParts.

public static void tooltipListParts(ItemStack gear, List<Component> tooltip, Collection<PartData> parts, GearTooltipFlag flag) {
    TextListBuilder builder = new TextListBuilder();
    for (PartData part : parts) {
        if (part.get().isVisible()) {
            int partNameColor = Color.blend(part.getColor(gear), Color.VALUE_WHITE, 0.25f) & 0xFFFFFF;
            MutableComponent partNameText = TextUtil.withColor(part.getDisplayName(gear).copy(), partNameColor);
            builder.add(flag.isAdvanced() ? partNameText.append(TextUtil.misc("spaceBrackets", part.getType().getName()).withStyle(ChatFormatting.DARK_GRAY)) : partNameText);
            // List materials for compound parts
            if (part.get() instanceof CompoundPart) {
                builder.indent();
                for (IMaterialInstance material : CompoundPartItem.getMaterials(part.getItem())) {
                    int nameColor = material.getNameColor(part.getType(), GearType.ALL);
                    builder.add(TextUtil.withColor(material.getDisplayNameWithModifiers(part.getType(), ItemStack.EMPTY), nameColor));
                }
                builder.unindent();
            }
        }
    }
    tooltip.addAll(builder.build());
}
Also used : MutableComponent(net.minecraft.network.chat.MutableComponent) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) PartData(net.silentchaos512.gear.gear.part.PartData) CompoundPart(net.silentchaos512.gear.gear.part.CompoundPart)

Example 33 with IMaterialInstance

use of net.silentchaos512.gear.api.material.IMaterialInstance in project Silent-Gear by SilentChaos512.

the class FragmentModelOverrideList method getOverrideModel.

private BakedModel getOverrideModel(ItemStack stack, @Nullable ClientLevel worldIn, @Nullable LivingEntity entityIn) {
    List<MaterialLayer> layers = new ArrayList<>();
    IMaterialInstance material = FragmentItem.getMaterial(stack);
    if (material != null) {
        IMaterialDisplay model = material.getDisplayProperties();
        int layerLevel = 0;
        for (MaterialLayer layer : model.getLayerList(GearType.FRAGMENT, PartType.MAIN, material)) {
            int blendedColor = model.getLayerColor(GearType.FRAGMENT, PartType.MAIN, material, layerLevel);
            layers.add(new MaterialLayer(layer.getTextureId(), blendedColor));
            ++layerLevel;
        }
    }
    return model.bake(layers, owner, bakery, spriteGetter, modelTransform, this, modelLocation);
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) ArrayList(java.util.ArrayList)

Aggregations

IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)24 ItemStack (net.minecraft.world.item.ItemStack)10 PartType (net.silentchaos512.gear.api.part.PartType)6 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)6 ResourceLocation (net.minecraft.resources.ResourceLocation)5 IMaterial (net.silentchaos512.gear.api.material.IMaterial)5 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)5 Nullable (javax.annotation.Nullable)4 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)4 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 Component (net.minecraft.network.chat.Component)3 SilentGear (net.silentchaos512.gear.SilentGear)3 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)3 JsonObject (com.google.gson.JsonObject)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2