Search in sources :

Example 6 with PartDataList

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

use of net.silentchaos512.gear.api.part.PartDataList 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 8 with PartDataList

use of net.silentchaos512.gear.api.part.PartDataList 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 9 with PartDataList

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

the class GearClientHelper method addInformation.

public static void addInformation(ItemStack stack, Level world, List<Component> tooltip, GearTooltipFlag flag) {
    if (!(stack.getItem() instanceof ICoreItem))
        return;
    ICoreItem item = (ICoreItem) stack.getItem();
    if (GearHelper.isBroken(stack)) {
        tooltip.add(Math.min(1, tooltip.size()), TextUtil.withColor(misc("broken"), Color.FIREBRICK));
    }
    if (GearData.isExampleGear(stack)) {
        tooltip.add(Math.min(1, tooltip.size()), TextUtil.withColor(misc("exampleOutput1"), Color.YELLOW));
        tooltip.add(Math.min(2, tooltip.size()), TextUtil.withColor(misc("exampleOutput2"), Color.YELLOW));
    }
    PartDataList constructionParts = GearData.getConstructionParts(stack);
    if (constructionParts.getMains().isEmpty()) {
        tooltip.add(TextUtil.withColor(misc("invalidParts"), Color.FIREBRICK));
        tooltip.add(TextUtil.withColor(misc("lockedStats"), Color.FIREBRICK));
    } else if (GearData.hasLockedStats(stack)) {
        tooltip.add(TextUtil.withColor(misc("lockedStats"), Color.YELLOW));
    }
    if (!Config.Client.vanillaStyleTooltips.get()) {
        // Let parts add information if they need to
        Collections.reverse(constructionParts);
        for (PartData data : constructionParts) {
            data.get().addInformation(data, stack, tooltip, flag);
        }
    }
    // Traits
    addTraitsInfo(stack, tooltip, flag);
    if (!Config.Client.vanillaStyleTooltips.get()) {
        // Stats
        addStatsInfo(stack, tooltip, flag, item);
    }
    // Tool construction
    if (KeyTracker.isDisplayConstructionDown() && flag.showConstruction) {
        tooltip.add(TextUtil.withColor(misc("tooltip.construction"), Color.GOLD));
        Collections.reverse(constructionParts);
        tooltipListParts(stack, tooltip, constructionParts, flag);
    } else if (flag.showConstruction) {
        tooltip.add(TextUtil.withColor(TextUtil.misc("tooltip.construction"), Color.GOLD).append(new TextComponent(" ").append(TextUtil.withColor(TextUtil.keyBinding(KeyTracker.DISPLAY_CONSTRUCTION), ChatFormatting.GRAY))));
    }
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) TextComponent(net.minecraft.network.chat.TextComponent) PartData(net.silentchaos512.gear.gear.part.PartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem)

Example 10 with PartDataList

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

the class GearSalvagingRecipe method getPossibleResults.

@Override
public List<ItemStack> getPossibleResults(Container inv) {
    ItemStack input = inv.getItem(0);
    List<ItemStack> ret = new ArrayList<>();
    PartDataList parts = GearData.getConstructionParts(input);
    for (PartData part : parts) {
        ret.addAll(salvage(part));
    }
    return ret;
}
Also used : PartDataList(net.silentchaos512.gear.api.part.PartDataList) ArrayList(java.util.ArrayList) PartData(net.silentchaos512.gear.gear.part.PartData) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

PartDataList (net.silentchaos512.gear.api.part.PartDataList)15 PartData (net.silentchaos512.gear.gear.part.PartData)14 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)7 IPartData (net.silentchaos512.gear.api.part.IPartData)7 ItemStack (net.minecraft.world.item.ItemStack)5 PartType (net.silentchaos512.gear.api.part.PartType)5 GearType (net.silentchaos512.gear.api.item.GearType)3 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)3 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2 ITrait (net.silentchaos512.gear.api.traits.ITrait)2 ArrayList (java.util.ArrayList)1 Tag (net.minecraft.nbt.Tag)1 Component (net.minecraft.network.chat.Component)1 TextComponent (net.minecraft.network.chat.TextComponent)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 GearNamePrefixesEvent (net.silentchaos512.gear.api.event.GearNamePrefixesEvent)1 GetTraitsEvent (net.silentchaos512.gear.api.event.GetTraitsEvent)1 ICoreTool (net.silentchaos512.gear.api.item.ICoreTool)1