Search in sources :

Example 1 with PartGearKey

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

the class CompoundPart method getTraits.

@Override
public Collection<TraitInstance> getTraits(IPartData part, PartGearKey partKey, ItemStack gear) {
    List<TraitInstance> ret = new ArrayList<>(super.getTraits(part, partKey, gear));
    List<IMaterialInstance> materials = getMaterials(part);
    for (TraitInstance inst : TraitHelper.getTraits(materials, partKey, gear)) {
        if (inst.conditionsMatch(partKey, gear, materials)) {
            ret.add(inst);
        }
    }
    return ret;
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) ArrayList(java.util.ArrayList)

Example 2 with PartGearKey

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

the class PartDisplay method deserialize.

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

Example 3 with PartGearKey

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

the class PartDisplay method getMostSpecificKey.

private PartGearKey getMostSpecificKey(GearType gearType) {
    PartGearKey key = PartGearKey.of(gearType, this.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 4 with PartGearKey

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

the class MaterialDisplay method fromNetwork.

public static MaterialDisplay fromNetwork(ResourceLocation materialId, FriendlyByteBuf buf) {
    Map<PartGearKey, MaterialLayerList> map = new LinkedHashMap<>();
    int count = buf.readVarInt();
    for (int i = 0; i < count; ++i) {
        PartGearKey key = PartGearKey.fromNetwork(buf);
        MaterialLayerList layerList = MaterialLayerList.read(buf);
        map.put(key, layerList);
    }
    return of(materialId, map);
}
Also used : PartGearKey(net.silentchaos512.gear.api.util.PartGearKey) MaterialLayerList(net.silentchaos512.gear.api.material.MaterialLayerList) IMaterialLayerList(net.silentchaos512.gear.api.material.IMaterialLayerList) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with PartGearKey

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

the class PartGearKey method fromNetwork.

public static PartGearKey fromNetwork(FriendlyByteBuf buf) {
    GearType gearType = GearType.get(buf.readUtf());
    PartType partType = Objects.requireNonNull(PartType.get(buf.readResourceLocation()));
    return of(gearType, partType);
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType)

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