Search in sources :

Example 11 with PartGearKey

use of net.silentchaos512.gear.api.util.PartGearKey in project Silent-Gear by SilentChaos512.

the class CraftedMaterial method getTraits.

@Override
public Collection<TraitInstance> getTraits(IMaterialInstance material, PartGearKey partKey, ItemStack gear) {
    Collection<TraitInstance> ret = super.getTraits(material, partKey, gear);
    IMaterialInstance base = getBaseMaterial(material);
    ret.addAll(base.getTraits(partKey, gear));
    return ret;
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance)

Example 12 with PartGearKey

use of net.silentchaos512.gear.api.util.PartGearKey in project Silent-Gear by SilentChaos512.

the class MaterialRatioTraitCondition method matches.

@Override
public boolean matches(ITrait trait, PartGearKey key, ItemStack gear, List<? extends IGearComponentInstance<?>> components) {
    int count = 0;
    for (IGearComponentInstance<?> comp : components) {
        Collection<TraitInstance> traits = comp.getTraits(key, gear);
        for (TraitInstance inst : traits) {
            if (inst.getTrait() == trait) {
                ++count;
                break;
            }
        }
    }
    float ratio = (float) count / components.size();
    return ratio >= this.requiredRatio;
}
Also used : TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance)

Example 13 with PartGearKey

use of net.silentchaos512.gear.api.util.PartGearKey in project Silent-Gear by SilentChaos512.

the class MaterialDisplay method deserialize.

public static MaterialDisplay deserialize(ResourceLocation modelId, JsonObject json) {
    MaterialDisplay ret = new MaterialDisplay(modelId);
    json.entrySet().forEach(entry -> {
        PartGearKey key = PartGearKey.read(entry.getKey());
        JsonElement value = entry.getValue();
        ret.map.put(key, MaterialLayerList.deserialize(key, value, MaterialLayerList.DEFAULT));
    });
    return ret;
}
Also used : PartGearKey(net.silentchaos512.gear.api.util.PartGearKey) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) JsonElement(com.google.gson.JsonElement)

Example 14 with PartGearKey

use of net.silentchaos512.gear.api.util.PartGearKey in project Silent-Gear by SilentChaos512.

the class MaterialDisplay method getMostSpecificKey.

private PartGearKey getMostSpecificKey(GearType gearType, PartType partType) {
    PartGearKey key = PartGearKey.of(gearType, partType);
    if (map.containsKey(key)) {
        return key;
    }
    PartGearKey parent = key.getParent();
    while (parent != null) {
        if (map.containsKey(parent)) {
            return parent;
        }
        parent = parent.getParent();
    }
    // No match
    return key;
}
Also used : PartGearKey(net.silentchaos512.gear.api.util.PartGearKey)

Example 15 with PartGearKey

use of net.silentchaos512.gear.api.util.PartGearKey in project Silent-Gear by SilentChaos512.

the class MaterialDisplay method of.

public static MaterialDisplay of(ResourceLocation id, Map<PartGearKey, MaterialLayerList> display) {
    MaterialDisplay model = new MaterialDisplay(id);
    model.map.putAll(display);
    return model;
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay)

Aggregations

PartGearKey (net.silentchaos512.gear.api.util.PartGearKey)8 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)6 JsonElement (com.google.gson.JsonElement)2 MutableComponent (net.minecraft.network.chat.MutableComponent)2 TextComponent (net.minecraft.network.chat.TextComponent)2 GearType (net.silentchaos512.gear.api.item.GearType)2 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)2 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)2 PartType (net.silentchaos512.gear.api.part.PartType)2 ITrait (net.silentchaos512.gear.api.traits.ITrait)2 JsonParseException (com.google.gson.JsonParseException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Component (net.minecraft.network.chat.Component)1 GetTraitsEvent (net.silentchaos512.gear.api.event.GetTraitsEvent)1 IMaterialCategory (net.silentchaos512.gear.api.material.IMaterialCategory)1 IMaterialLayerList (net.silentchaos512.gear.api.material.IMaterialLayerList)1 MaterialLayerList (net.silentchaos512.gear.api.material.MaterialLayerList)1 PartData (net.silentchaos512.gear.gear.part.PartData)1