Search in sources :

Example 6 with ItemAttribute

use of com.simibubi.create.content.logistics.item.filter.ItemAttribute in project Create by Creators-of-Create.

the class BlueprintItem method convertIItemListToFilter.

private static ItemStack convertIItemListToFilter(Value itemList) {
    Collection<ItemStack> stacks = itemList.getItems();
    if (itemList instanceof ItemValue) {
        for (ItemStack itemStack : stacks) return itemStack;
    }
    if (itemList instanceof TagValue) {
        ResourceLocation resourcelocation = new ResourceLocation(GsonHelper.getAsString(itemList.serialize(), "tag"));
        ItemStack filterItem = AllItems.ATTRIBUTE_FILTER.asStack();
        filterItem.getOrCreateTag().putInt("WhitelistMode", WhitelistMode.WHITELIST_DISJ.ordinal());
        ListTag attributes = new ListTag();
        ItemAttribute at = new ItemAttribute.InTag(resourcelocation);
        CompoundTag compoundNBT = new CompoundTag();
        at.serializeNBT(compoundNBT);
        compoundNBT.putBoolean("Inverted", false);
        attributes.add(compoundNBT);
        filterItem.getOrCreateTag().put("MatchedAttributes", attributes);
        return filterItem;
    }
    if (itemList instanceof MultiItemValue) {
        ItemStack result = AllItems.FILTER.asStack();
        ItemStackHandler filterItems = FilterItem.getFilterItems(result);
        int i = 0;
        for (ItemStack itemStack : stacks) {
            if (i >= 18)
                break;
            filterItems.setStackInSlot(i++, itemStack);
        }
        CompoundTag tag = result.getOrCreateTag();
        tag.put("Items", filterItems.serializeNBT());
        tag.putBoolean("RespectNBT", true);
        return result;
    }
    return ItemStack.EMPTY;
}
Also used : MultiItemValue(net.minecraftforge.common.crafting.MultiItemValue) ItemStackHandler(net.minecraftforge.items.ItemStackHandler) ItemValue(net.minecraft.world.item.crafting.Ingredient.ItemValue) MultiItemValue(net.minecraftforge.common.crafting.MultiItemValue) ResourceLocation(net.minecraft.resources.ResourceLocation) ItemStack(net.minecraft.world.item.ItemStack) TagValue(net.minecraft.world.item.crafting.Ingredient.TagValue) ItemAttribute(com.simibubi.create.content.logistics.item.filter.ItemAttribute) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

ItemAttribute (com.simibubi.create.content.logistics.item.filter.ItemAttribute)6 ArrayList (java.util.ArrayList)5 ListTag (net.minecraft.nbt.ListTag)5 CompoundTag (net.minecraft.nbt.CompoundTag)3 ResourceLocation (net.minecraft.resources.ResourceLocation)2 ItemStack (net.minecraft.world.item.ItemStack)2 ItemStackHandler (net.minecraftforge.items.ItemStackHandler)2 WhitelistMode (com.simibubi.create.content.logistics.item.filter.AttributeFilterContainer.WhitelistMode)1 FilterItem (com.simibubi.create.content.logistics.item.filter.FilterItem)1 Item (net.minecraft.world.item.Item)1 ItemValue (net.minecraft.world.item.crafting.Ingredient.ItemValue)1 TagValue (net.minecraft.world.item.crafting.Ingredient.TagValue)1 MultiItemValue (net.minecraftforge.common.crafting.MultiItemValue)1