Search in sources :

Example 16 with IMaterialInstance

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

the class ConversionRecipe method deserializeMaterials.

private static void deserializeMaterials(JsonObject json, ConversionRecipe recipe) {
    JsonObject resultJson = json.getAsJsonObject("result");
    for (Map.Entry<String, JsonElement> entry : resultJson.getAsJsonObject("materials").entrySet()) {
        PartType partType = PartType.get(Objects.requireNonNull(SilentGear.getIdWithDefaultNamespace(entry.getKey())));
        JsonElement element = entry.getValue();
        if (element.isJsonArray()) {
            List<IMaterialInstance> list = new ArrayList<>();
            for (JsonElement e : element.getAsJsonArray()) {
                list.add(LazyMaterialInstance.deserialize(e.getAsJsonObject()));
            }
            recipe.resultMaterials.put(partType, list);
        } else {
            recipe.resultMaterials.put(partType, Collections.singletonList(LazyMaterialInstance.deserialize(element.getAsJsonObject())));
        }
    }
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 17 with IMaterialInstance

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

the class FillRepairKitRecipe method isRepairMaterial.

private static boolean isRepairMaterial(IMaterialInstance material) {
    float durability = material.getStat(PartType.MAIN, ItemStats.DURABILITY);
    float armorDurability = material.getStat(PartType.MAIN, ItemStats.ARMOR_DURABILITY);
    IMaterial mat = material.get();
    return mat != null && mat.allowedInPart(material, PartType.MAIN) && (durability > 0 || armorDurability > 0);
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial)

Example 18 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(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 19 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(CompoundMaterialItem 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(GearType.ALL, PartType.MAIN, mat).getLayers();
        if (layers.size() > layer) {
            int color = layers.get(layer).getColor();
            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 20 with IMaterialInstance

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

the class AbstractMaterial method isCraftingAllowed.

@Override
public boolean isCraftingAllowed(IMaterialInstance material, PartType partType, GearType gearType, @Nullable Container inventory) {
    if (isGearTypeBlacklisted(gearType) || !allowedInPart(material, partType)) {
        return false;
    }
    if (stats.containsKey(partType) || (getParent() != null && getParent().isCraftingAllowed(material, partType, gearType, inventory))) {
        if (partType == PartType.MAIN) {
            ItemStat stat = gearType.getDurabilityStat();
            StatGearKey key = StatGearKey.of(stat, gearType);
            return !getStatModifiers(material, partType, key).isEmpty() && getStatUnclamped(material, partType, key, ItemStack.EMPTY) > 0;
        }
        return true;
    }
    return false;
}
Also used : StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

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