Search in sources :

Example 21 with PartData

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

the class ConversionRecipe method getParts.

private Collection<? extends IPartData> getParts() {
    PartDataList ret = PartDataList.of();
    // noinspection OverlyLongLambda
    this.resultMaterials.forEach((partType, list) -> {
        partType.getCompoundPartItem(item.getGearType()).ifPresent(partItem -> {
            PartData part = PartData.from(partItem.create(list));
            if (part != null) {
                ret.add(part);
            }
        });
    });
    return ret;
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartData(net.silentchaos512.gear.gear.part.PartData) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 22 with PartData

use of net.silentchaos512.gear.gear.part.PartData 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 23 with PartData

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

the class GearPartSwapRecipe method getRemainingItems.

@Override
public NonNullList<ItemStack> getRemainingItems(CraftingContainer inv) {
    NonNullList<ItemStack> list = NonNullList.withSize(inv.getContainerSize(), ItemStack.EMPTY);
    ItemStack gear = StackList.from(inv).uniqueMatch(s -> s.getItem() instanceof ICoreItem);
    PartDataList oldParts = GearData.getConstructionParts(gear);
    Map<PartType, Integer> removedCount = new HashMap<>();
    for (int i = 0; i < list.size(); ++i) {
        ItemStack stack = inv.getItem(i);
        if (stack.getItem() instanceof ICoreItem) {
            list.set(i, ItemStack.EMPTY);
        } else {
            PartData newPart = PartData.from(stack);
            if (newPart != null && !Config.Common.destroySwappedParts.get()) {
                PartType type = newPart.getType();
                List<PartData> partsOfType = oldParts.getPartsOfType(type);
                if (partsOfType.size() >= type.getMaxPerItem(GearHelper.getType(gear))) {
                    int index = removedCount.getOrDefault(type, 0);
                    if (index < partsOfType.size()) {
                        PartData oldPart = partsOfType.get(index);
                        oldPart.onRemoveFromGear(gear);
                        list.set(i, oldPart.getItem());
                        removedCount.merge(type, 1, Integer::sum);
                    }
                } else {
                    list.set(i, ItemStack.EMPTY);
                }
            }
        }
    }
    return list;
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) PartType(net.silentchaos512.gear.api.part.PartType) PartData(net.silentchaos512.gear.gear.part.PartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 24 with PartData

use of net.silentchaos512.gear.gear.part.PartData 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 25 with PartData

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

the class IGearRecipe method getParts.

default Collection<PartData> getParts(Container inv) {
    List<MaterialInstance> materials = new ArrayList<>();
    IMaterial first = null;
    List<PartData> parts = new ArrayList<>();
    for (int i = 0; i < inv.getContainerSize(); ++i) {
        ItemStack stack = inv.getItem(i);
        if (!stack.isEmpty()) {
            MaterialInstance mat = MaterialInstance.from(stack);
            if (mat != null) {
                // If classic mixing is disabled, all materials must be the same
                if (first == null) {
                    first = mat.get();
                } else if (!Config.Common.allowLegacyMaterialMixing.get() && first != mat.get()) {
                    return Collections.emptyList();
                }
                materials.add(mat);
            } else {
                PartData part = PartData.from(stack);
                if (part != null) {
                    parts.add(part);
                }
            }
        }
    }
    if (!materials.isEmpty()) {
        // Construct a tool head
        createToolHead(this.getOutputItem().getGearType(), materials).ifPresent(part -> parts.add(0, part));
    }
    return parts;
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) PartData(net.silentchaos512.gear.gear.part.PartData) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

PartData (net.silentchaos512.gear.gear.part.PartData)36 ItemStack (net.minecraft.world.item.ItemStack)16 IPartData (net.silentchaos512.gear.api.part.IPartData)14 PartDataList (net.silentchaos512.gear.api.part.PartDataList)13 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)12 PartType (net.silentchaos512.gear.api.part.PartType)9 GearType (net.silentchaos512.gear.api.item.GearType)8 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)8 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)6 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)6 ArrayList (java.util.ArrayList)5 Component (net.minecraft.network.chat.Component)5 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)5 TextComponent (net.minecraft.network.chat.TextComponent)4 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)4 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)4 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)4 Nullable (javax.annotation.Nullable)3 CompoundTag (net.minecraft.nbt.CompoundTag)3 MutableComponent (net.minecraft.network.chat.MutableComponent)3