Search in sources :

Example 6 with StackList

use of net.silentchaos512.lib.collection.StackList in project Silent-Gear by SilentChaos512.

the class QuickRepairRecipe method assemble.

@Override
public ItemStack assemble(CraftingContainer inv) {
    StackList list = StackList.from(inv);
    ItemStack gear = list.uniqueOfType(ICoreItem.class).copy();
    ItemStack repairKit = list.uniqueOfType(RepairKitItem.class);
    Collection<ItemStack> mats = list.allMatches(mat -> ModRecipes.isRepairMaterial(gear, mat));
    // Repair with materials first
    repairWithLooseMaterials(gear, repairKit, mats);
    // Then use repair kit, if necessary
    if (gear.getDamageValue() > 0 && repairKit.getItem() instanceof RepairKitItem) {
        RepairKitItem item = (RepairKitItem) repairKit.getItem();
        int value = item.getDamageToRepair(gear, repairKit, RepairContext.Type.QUICK);
        if (value > 0) {
            gear.setDamageValue(gear.getDamageValue() - Math.round(value));
        }
    }
    GearData.incrementRepairCount(gear, 1);
    GearData.recalculateStats(gear, ForgeHooks.getCraftingPlayer());
    return gear;
}
Also used : RepairKitItem(net.silentchaos512.gear.item.RepairKitItem) StackList(net.silentchaos512.lib.collection.StackList) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 7 with StackList

use of net.silentchaos512.lib.collection.StackList in project Silent-Gear by SilentChaos512.

the class CombineFragmentsRecipe method assemble.

@Override
public ItemStack assemble(CraftingContainer craftingInventory) {
    StackList list = StackList.from(craftingInventory);
    ItemStack stack = list.firstOfType(FragmentItem.class);
    if (stack.isEmpty())
        return ItemStack.EMPTY;
    IMaterialInstance material = FragmentItem.getMaterial(stack);
    if (material == null)
        return ItemStack.EMPTY;
    // Get the actual item the fragment came from (if present)
    if (!material.getItem().isEmpty()) {
        return material.getItem();
    }
    // Try to get an equivalent item from the material's ingredient
    ItemStack[] matchingStacks = material.getIngredient().getItems();
    if (matchingStacks.length < 1) {
        if (material.getIngredient() instanceof ExclusionIngredient) {
            // Get excluded ingredients if no others are available
            ItemStack[] allMatches = ((ExclusionIngredient) material.getIngredient()).getMatchingStacksWithExclusions();
            if (allMatches.length > 0) {
                return allMatches[0];
            }
        }
        return ItemStack.EMPTY;
    }
    return matchingStacks[0].copy();
}
Also used : ExclusionIngredient(net.silentchaos512.lib.crafting.ingredient.ExclusionIngredient) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) StackList(net.silentchaos512.lib.collection.StackList) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

ItemStack (net.minecraft.world.item.ItemStack)7 StackList (net.silentchaos512.lib.collection.StackList)7 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)4 PartType (net.silentchaos512.gear.api.part.PartType)3 RepairKitItem (net.silentchaos512.gear.item.RepairKitItem)3 PartData (net.silentchaos512.gear.gear.part.PartData)2 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 NonNullList (net.minecraft.core.NonNullList)1 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 CraftingContainer (net.minecraft.world.inventory.CraftingContainer)1 CustomRecipe (net.minecraft.world.item.crafting.CustomRecipe)1 RecipeSerializer (net.minecraft.world.item.crafting.RecipeSerializer)1 Level (net.minecraft.world.level.Level)1 ForgeHooks (net.minecraftforge.common.ForgeHooks)1 ForgeRegistryEntry (net.minecraftforge.registries.ForgeRegistryEntry)1 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)1