Search in sources :

Example 1 with StackList

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

the class FillRepairKitRecipe method assemble.

@Override
public ItemStack assemble(CraftingContainer inv) {
    StackList list = StackList.from(inv);
    ItemStack repairKit = list.uniqueOfType(RepairKitItem.class).copy();
    repairKit.setCount(1);
    RepairKitItem repairKitItem = (RepairKitItem) repairKit.getItem();
    for (ItemStack mat : list.allMatches(FillRepairKitRecipe::isRepairMaterial)) {
        if (!repairKitItem.addMaterial(repairKit, mat)) {
            // Repair kit is too full to accept more materials
            return ItemStack.EMPTY;
        }
    }
    return repairKit;
}
Also used : RepairKitItem(net.silentchaos512.gear.item.RepairKitItem) StackList(net.silentchaos512.lib.collection.StackList) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with StackList

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

the class GearPartSwapRecipe method assemble.

@Override
public ItemStack assemble(CraftingContainer inv) {
    StackList list = StackList.from(inv);
    ItemStack gear = list.uniqueOfType(ICoreItem.class);
    if (gear.isEmpty())
        return ItemStack.EMPTY;
    Collection<ItemStack> others = list.allMatches(stack -> !(stack.getItem() instanceof ICoreItem));
    if (others.isEmpty())
        return ItemStack.EMPTY;
    ItemStack result = gear.copy();
    PartDataList parts = GearData.getConstructionParts(result);
    for (ItemStack stack : others) {
        PartData part = PartData.from(stack);
        if (part == null)
            return ItemStack.EMPTY;
        PartType type = part.getType();
        List<PartData> partsOfType = new ArrayList<>(parts.getPartsOfType(type));
        int maxPerItem = type.getMaxPerItem(GearHelper.getType(result));
        // Remove old part of type (if over limit), then add replacement
        if (partsOfType.size() >= maxPerItem) {
            PartData oldPart = partsOfType.get(0);
            partsOfType.remove(oldPart);
            parts.remove(oldPart);
            oldPart.onRemoveFromGear(result);
        }
        parts.add(part);
        part.onAddToGear(result);
    }
    GearData.writeConstructionParts(result, parts);
    GearData.removeExcessParts(result);
    GearData.recalculateStats(result, ForgeHooks.getCraftingPlayer());
    return result;
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartType(net.silentchaos512.gear.api.part.PartType) PartData(net.silentchaos512.gear.gear.part.PartData) StackList(net.silentchaos512.lib.collection.StackList) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with StackList

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

the class GearPartSwapRecipe method matches.

@Override
public boolean matches(CraftingContainer inv, Level worldIn) {
    StackList list = StackList.from(inv);
    ItemStack gear = list.uniqueOfType(ICoreItem.class);
    if (gear.isEmpty())
        return false;
    ICoreItem item = (ICoreItem) gear.getItem();
    Collection<ItemStack> others = list.allMatches(stack -> !(stack.getItem() instanceof ICoreItem));
    if (others.isEmpty())
        return false;
    Map<PartType, Integer> typeCounts = new HashMap<>();
    for (ItemStack stack : others) {
        PartData part = PartData.from(stack);
        if (part == null)
            return false;
        // Only required part types, and no duplicates
        PartType type = part.getType();
        if (!item.supportsPart(gear, part) || typeCounts.getOrDefault(type, 0) >= type.getMaxPerItem(item.getGearType())) {
            return false;
        }
        typeCounts.merge(type, 1, Integer::sum);
    }
    return true;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) PartData(net.silentchaos512.gear.gear.part.PartData) StackList(net.silentchaos512.lib.collection.StackList) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 4 with StackList

use of net.silentchaos512.lib.collection.StackList 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 5 with StackList

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

the class QuickRepairRecipe method getRemainingItems.

@Override
public NonNullList<ItemStack> getRemainingItems(CraftingContainer inv) {
    NonNullList<ItemStack> list = NonNullList.withSize(inv.getContainerSize(), ItemStack.EMPTY);
    StackList stackList = StackList.from(inv);
    ItemStack gear = stackList.uniqueMatch(s -> s.getItem() instanceof ICoreItem);
    ItemStack repairKit = stackList.uniqueMatch(s -> s.getItem() instanceof RepairKitItem);
    for (int i = 0; i < list.size(); ++i) {
        ItemStack stack = inv.getItem(i);
        if (stack.getItem() instanceof RepairKitItem) {
            repairWithLooseMaterials(gear, repairKit, stackList.allMatches(mat -> ModRecipes.isRepairMaterial(gear, mat)));
            RepairKitItem item = (RepairKitItem) stack.getItem();
            ItemStack copy = stack.copy();
            item.removeRepairMaterials(copy, item.getRepairMaterials(gear, copy, RepairContext.Type.QUICK));
            list.set(i, copy);
        } else if (stack.hasContainerItem()) {
            list.set(i, stack.getContainerItem());
        }
    }
    return list;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject) GearData(net.silentchaos512.gear.util.GearData) ForgeHooks(net.minecraftforge.common.ForgeHooks) RepairKitItem(net.silentchaos512.gear.item.RepairKitItem) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) MaterialManager(net.silentchaos512.gear.gear.material.MaterialManager) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) CustomRecipe(net.minecraft.world.item.crafting.CustomRecipe) ArrayList(java.util.ArrayList) Const(net.silentchaos512.gear.util.Const) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) Config(net.silentchaos512.gear.config.Config) StackList(net.silentchaos512.lib.collection.StackList) NonNullList(net.minecraft.core.NonNullList) RepairContext(net.silentchaos512.gear.gear.part.RepairContext) ForgeRegistryEntry(net.minecraftforge.registries.ForgeRegistryEntry) ItemStats(net.silentchaos512.gear.api.stats.ItemStats) RecipeSerializer(net.minecraft.world.item.crafting.RecipeSerializer) Collection(java.util.Collection) List(java.util.List) CraftingContainer(net.minecraft.world.inventory.CraftingContainer) ModRecipes(net.silentchaos512.gear.init.ModRecipes) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) 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)

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