Search in sources :

Example 36 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class ModKitRemovePartRecipe method assemble.

@Override
public ItemStack assemble(CraftingContainer inv) {
    StackList list = StackList.from(inv);
    ItemStack gear = list.uniqueOfType(ICoreItem.class);
    ItemStack modKit = list.uniqueOfType(ModKitItem.class);
    if (gear.isEmpty() || modKit.isEmpty())
        return ItemStack.EMPTY;
    ItemStack result = gear.copy();
    PartType type = ModKitItem.getSelectedType(modKit);
    if (GearData.removeFirstPartOfType(result, type)) {
        GearData.recalculateStats(result, ForgeHooks.getCraftingPlayer());
    }
    return result;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) StackList(net.silentchaos512.lib.collection.StackList) ItemStack(net.minecraft.world.item.ItemStack)

Example 37 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class PartType method create.

/**
 * Call during mod construction to create a new part type.
 *
 * @param builder Type builder
 * @return The new PartType
 * @throws IllegalArgumentException if a type with the same name already exists
 */
public static PartType create(Builder builder) {
    if (VALUES.containsKey(builder.name))
        throw new IllegalArgumentException(String.format("Already have PartType \"%s\"", builder.name));
    PartType type = new PartType(builder);
    VALUES.put(builder.name, type);
    if (!type.alias.isEmpty()) {
        VALUES.put(new ModResourceLocation(type.alias), type);
    }
    return type;
}
Also used : ModResourceLocation(net.silentchaos512.gear.util.ModResourceLocation)

Example 38 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class PartType method fromJson.

public static PartType fromJson(JsonObject json, String key) {
    String str = GsonHelper.getAsString(json, key);
    PartType type = get(new ModResourceLocation(str));
    if (type == null) {
        throw new JsonSyntaxException("Unknown part type: " + str);
    }
    return type;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) ModResourceLocation(net.silentchaos512.gear.util.ModResourceLocation)

Example 39 with PartType

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

Example 40 with PartType

use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.

the class CompoundMaterial method getPartTypes.

@Override
public Set<PartType> getPartTypes(IMaterialInstance material) {
    List<IMaterialInstance> subMaterials = getMaterials(material);
    if (subMaterials.isEmpty()) {
        return Collections.emptySet();
    } else if (subMaterials.size() == 1) {
        return subMaterials.get(0).getPartTypes();
    }
    Set<PartType> set = new LinkedHashSet<>(subMaterials.get(0).getPartTypes());
    for (int i = 1; i < subMaterials.size(); ++i) {
        Set<PartType> set1 = subMaterials.get(i).getPartTypes();
        Set<PartType> toRemove = new HashSet<>();
        for (PartType type : set) {
            if (!set1.contains(type)) {
                toRemove.add(type);
            }
        }
        set.removeAll(toRemove);
    }
    return set;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType)

Aggregations

PartType (net.silentchaos512.gear.api.part.PartType)37 ItemStack (net.minecraft.world.item.ItemStack)14 PartData (net.silentchaos512.gear.gear.part.PartData)14 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)13 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)10 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)10 TextComponent (net.minecraft.network.chat.TextComponent)9 ResourceLocation (net.minecraft.resources.ResourceLocation)9 GearType (net.silentchaos512.gear.api.item.GearType)9 PartDataList (net.silentchaos512.gear.api.part.PartDataList)9 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)9 Component (net.minecraft.network.chat.Component)8 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)8 IPartData (net.silentchaos512.gear.api.part.IPartData)8 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)8 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)7 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)7 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 MutableComponent (net.minecraft.network.chat.MutableComponent)5