Search in sources :

Example 6 with ICoreItem

use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.

the class GearHelper method createSampleItem.

private static ItemStack createSampleItem(ICoreItem item, int tier) {
    ItemStack result = GearGenerator.create(item, tier);
    if (result.isEmpty()) {
        Collection<IPartData> parts = new ArrayList<>();
        for (PartType partType : item.getRequiredParts()) {
            partType.makeCompoundPart(item.getGearType(), Const.Materials.EXAMPLE).ifPresent(parts::add);
        }
        result = item.construct(parts);
    }
    GearData.setExampleTag(result, true);
    return result;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) IPartData(net.silentchaos512.gear.api.part.IPartData)

Example 7 with ICoreItem

use of net.silentchaos512.gear.api.item.ICoreItem in project Silent-Gear by SilentChaos512.

the class GearBlueprintItem method appendSupportedTypesText.

private void appendSupportedTypesText(Collection<Component> list) {
    if (KeyTracker.isDisplayStatsDown()) {
        Optional<ICoreItem> itemOptional = this.gearType.getItem();
        if (itemOptional.isPresent()) {
            TextListBuilder builder = new TextListBuilder();
            ICoreItem item = itemOptional.get();
            ItemStack gear = new ItemStack(item);
            for (PartType type : PartType.getValues()) {
                if (type != PartType.MAIN) {
                    List<IGearPart> partsOfType = PartManager.getPartsOfType(type);
                    if (!partsOfType.isEmpty() && item.supportsPart(gear, PartData.of(partsOfType.get(0)))) {
                        builder.add(type.getDisplayName(0));
                    }
                }
            }
            List<Component> lines = builder.build();
            if (!lines.isEmpty()) {
                list.add(TextUtil.withColor(TextUtil.misc("supportedPartTypes"), Color.GOLD));
                list.addAll(lines);
            }
        }
    } else {
        list.add(TextUtil.withColor(TextUtil.misc("supportedPartTypes"), Color.GOLD).append(" ").append(TextUtil.withColor(TextUtil.keyBinding(KeyTracker.DISPLAY_STATS), ChatFormatting.GRAY)));
    }
}
Also used : TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) PartType(net.silentchaos512.gear.api.part.PartType) IGearPart(net.silentchaos512.gear.api.part.IGearPart) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) ItemStack(net.minecraft.world.item.ItemStack) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent)

Example 8 with ICoreItem

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

use of net.silentchaos512.gear.api.item.ICoreItem 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 10 with ICoreItem

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

Aggregations

ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)25 ItemStack (net.minecraft.world.item.ItemStack)16 PartData (net.silentchaos512.gear.gear.part.PartData)12 PartType (net.silentchaos512.gear.api.part.PartType)10 PartDataList (net.silentchaos512.gear.api.part.PartDataList)7 Component (net.minecraft.network.chat.Component)5 TextComponent (net.minecraft.network.chat.TextComponent)5 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)5 ArrayList (java.util.ArrayList)4 GearType (net.silentchaos512.gear.api.item.GearType)4 ResourceLocation (net.minecraft.resources.ResourceLocation)3 Item (net.minecraft.world.item.Item)3 IPartData (net.silentchaos512.gear.api.part.IPartData)3 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)3 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)3 StackList (net.silentchaos512.lib.collection.StackList)3 CompoundTag (net.minecraft.nbt.CompoundTag)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 Level (net.minecraft.world.level.Level)2 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)2