Search in sources :

Example 1 with IItemFilter

use of crazypants.enderio.base.filter.IItemFilter in project EnderIO by SleepyTrousers.

the class ItemConduit method writeToNBT.

@Override
public void writeToNBT(@Nonnull NBTTagCompound nbtRoot) {
    super.writeToNBT(nbtRoot);
    for (Entry<EnumFacing, IItemFilter> entry : inputFilters.entrySet()) {
        if (entry.getValue() != null) {
            IItemFilter f = entry.getValue();
            if (!isDefault(f)) {
                NBTTagCompound itemRoot = new NBTTagCompound();
                FilterRegistry.writeFilterToNbt(f, itemRoot);
                nbtRoot.setTag("inFilts." + entry.getKey().name(), itemRoot);
            }
        }
    }
    for (Entry<EnumFacing, ItemStack> entry : functionUpgrades.entrySet()) {
        if (entry.getValue() != null) {
            ItemStack up = entry.getValue();
            NBTTagCompound itemRoot = new NBTTagCompound();
            up.writeToNBT(itemRoot);
            nbtRoot.setTag("functionUpgrades." + entry.getKey().name(), itemRoot);
        }
    }
    for (Entry<EnumFacing, IItemFilter> entry : outputFilters.entrySet()) {
        if (entry.getValue() != null) {
            IItemFilter f = entry.getValue();
            if (!isDefault(f)) {
                NBTTagCompound itemRoot = new NBTTagCompound();
                FilterRegistry.writeFilterToNbt(f, itemRoot);
                nbtRoot.setTag("outFilts." + entry.getKey().name(), itemRoot);
            }
        }
    }
    for (Entry<EnumFacing, ItemStack> entry : inputFilterUpgrades.entrySet()) {
        if (entry.getValue() != null) {
            ItemStack up = entry.getValue();
            IItemFilter filter = getInputFilter(entry.getKey());
            FilterRegistry.writeFilterToStack(filter, up);
            NBTTagCompound itemRoot = new NBTTagCompound();
            up.writeToNBT(itemRoot);
            nbtRoot.setTag("inputFilterUpgrades." + entry.getKey().name(), itemRoot);
        }
    }
    for (Entry<EnumFacing, ItemStack> entry : outputFilterUpgrades.entrySet()) {
        if (entry.getValue() != null) {
            ItemStack up = entry.getValue();
            IItemFilter filter = getOutputFilter(entry.getKey());
            FilterRegistry.writeFilterToStack(filter, up);
            NBTTagCompound itemRoot = new NBTTagCompound();
            up.writeToNBT(itemRoot);
            nbtRoot.setTag("outputFilterUpgrades." + entry.getKey().name(), itemRoot);
        }
    }
    for (Entry<EnumFacing, RedstoneControlMode> entry : extractionModes.entrySet()) {
        if (entry.getValue() != null) {
            short ord = (short) entry.getValue().ordinal();
            nbtRoot.setShort("extRM." + entry.getKey().name(), ord);
        }
    }
    for (Entry<EnumFacing, DyeColor> entry : extractionColors.entrySet()) {
        if (entry.getValue() != null) {
            short ord = (short) entry.getValue().ordinal();
            nbtRoot.setShort("extSC." + entry.getKey().name(), ord);
        }
    }
    for (Entry<EnumFacing, Boolean> entry : selfFeed.entrySet()) {
        if (entry.getValue() != null) {
            nbtRoot.setBoolean("selfFeed." + entry.getKey().name(), entry.getValue());
        }
    }
    for (Entry<EnumFacing, Boolean> entry : roundRobin.entrySet()) {
        if (entry.getValue() != null) {
            nbtRoot.setBoolean("roundRobin." + entry.getKey().name(), entry.getValue());
        }
    }
    for (Entry<EnumFacing, Integer> entry : priority.entrySet()) {
        if (entry.getValue() != null) {
            nbtRoot.setInteger("priority." + entry.getKey().name(), entry.getValue());
        }
    }
    for (Entry<EnumFacing, DyeColor> entry : inputColors.entrySet()) {
        if (entry.getValue() != null) {
            short ord = (short) entry.getValue().ordinal();
            nbtRoot.setShort("inSC." + entry.getKey().name(), ord);
        }
    }
    for (Entry<EnumFacing, DyeColor> entry : outputColors.entrySet()) {
        if (entry.getValue() != null) {
            short ord = (short) entry.getValue().ordinal();
            nbtRoot.setShort("outSC." + entry.getKey().name(), ord);
        }
    }
}
Also used : IItemFilter(crazypants.enderio.base.filter.IItemFilter) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) RedstoneControlMode(crazypants.enderio.base.machine.modes.RedstoneControlMode) DyeColor(com.enderio.core.common.util.DyeColor) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IItemFilter

use of crazypants.enderio.base.filter.IItemFilter in project EnderIO by SleepyTrousers.

the class ItemConduit method readFromNBT.

@Override
public void readFromNBT(@Nonnull NBTTagCompound nbtRoot) {
    super.readFromNBT(nbtRoot);
    if (nbtRoot.hasKey("metaData")) {
        metaData = nbtRoot.getShort("metaData");
    } else {
        metaData = 0;
    }
    for (EnumFacing dir : EnumFacing.VALUES) {
        String key = "inFilts." + dir.name();
        if (nbtRoot.hasKey(key)) {
            NBTTagCompound filterTag = (NBTTagCompound) nbtRoot.getTag(key);
            IItemFilter filter = FilterRegistry.loadFilterFromNbt(filterTag);
            inputFilters.put(dir, filter);
        }
        key = "functionUpgrades." + dir.name();
        if (nbtRoot.hasKey(key)) {
            NBTTagCompound upTag = (NBTTagCompound) nbtRoot.getTag(key);
            ItemStack ups = new ItemStack(upTag);
            functionUpgrades.put(dir, ups);
        }
        key = "inputFilterUpgrades." + dir.name();
        if (nbtRoot.hasKey(key)) {
            NBTTagCompound upTag = (NBTTagCompound) nbtRoot.getTag(key);
            ItemStack ups = new ItemStack(upTag);
            inputFilterUpgrades.put(dir, ups);
        }
        key = "outputFilterUpgrades." + dir.name();
        if (nbtRoot.hasKey(key)) {
            NBTTagCompound upTag = (NBTTagCompound) nbtRoot.getTag(key);
            ItemStack ups = new ItemStack(upTag);
            outputFilterUpgrades.put(dir, ups);
        }
        key = "outFilts." + dir.name();
        if (nbtRoot.hasKey(key)) {
            NBTTagCompound filterTag = (NBTTagCompound) nbtRoot.getTag(key);
            IItemFilter filter = FilterRegistry.loadFilterFromNbt(filterTag);
            outputFilters.put(dir, filter);
        }
        key = "extRM." + dir.name();
        if (nbtRoot.hasKey(key)) {
            short ord = nbtRoot.getShort(key);
            if (ord >= 0 && ord < RedstoneControlMode.values().length) {
                extractionModes.put(dir, RedstoneControlMode.values()[ord]);
            }
        }
        key = "extSC." + dir.name();
        if (nbtRoot.hasKey(key)) {
            short ord = nbtRoot.getShort(key);
            if (ord >= 0 && ord < DyeColor.values().length) {
                extractionColors.put(dir, DyeColor.values()[ord]);
            }
        }
        key = "selfFeed." + dir.name();
        if (nbtRoot.hasKey(key)) {
            boolean val = nbtRoot.getBoolean(key);
            selfFeed.put(dir, val);
        }
        key = "roundRobin." + dir.name();
        if (nbtRoot.hasKey(key)) {
            boolean val = nbtRoot.getBoolean(key);
            roundRobin.put(dir, val);
        }
        key = "priority." + dir.name();
        if (nbtRoot.hasKey(key)) {
            int val = nbtRoot.getInteger(key);
            priority.put(dir, val);
        }
        key = "inSC." + dir.name();
        if (nbtRoot.hasKey(key)) {
            short ord = nbtRoot.getShort(key);
            if (ord >= 0 && ord < DyeColor.values().length) {
                inputColors.put(dir, DyeColor.values()[ord]);
            }
        }
        key = "outSC." + dir.name();
        if (nbtRoot.hasKey(key)) {
            short ord = nbtRoot.getShort(key);
            if (ord >= 0 && ord < DyeColor.values().length) {
                outputColors.put(dir, DyeColor.values()[ord]);
            }
        }
    }
    connectionsDirty = true;
}
Also used : IItemFilter(crazypants.enderio.base.filter.IItemFilter) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IItemFilter

use of crazypants.enderio.base.filter.IItemFilter in project EnderIO by SleepyTrousers.

the class ItemConduitNetwork method getTargetsForExtraction.

public List<String> getTargetsForExtraction(@Nonnull BlockPos extractFrom, @Nonnull IItemConduit con, @Nonnull ItemStack input) {
    List<String> result = new ArrayList<String>();
    List<NetworkedInventory> invs = getOrCreate(extractFrom);
    for (NetworkedInventory source : invs) {
        if (source.getCon().getBundle().getLocation().equals(con.getBundle().getLocation())) {
            List<Target> sendPriority = source.getSendPriority();
            if (sendPriority != null) {
                for (Target t : sendPriority) {
                    IItemFilter f = t.inv.getCon().getOutputFilter(t.inv.getConDir());
                    if (input.isEmpty() || f == null || f.doesItemPassFilter(getTargetInventory(t), input)) {
                        String s = t.inv.getLocalizedInventoryName() + " " + t.inv.getLocation().toString() + " Distance [" + t.distance + "] ";
                        result.add(s);
                    }
                }
            }
        }
    }
    return result;
}
Also used : Target(crazypants.enderio.conduits.conduit.item.NetworkedInventory.Target) IItemFilter(crazypants.enderio.base.filter.IItemFilter) ArrayList(java.util.ArrayList)

Example 4 with IItemFilter

use of crazypants.enderio.base.filter.IItemFilter in project EnderIO by SleepyTrousers.

the class ItemBasicItemFilter method createFilterFromStack.

@Override
public IItemFilter createFilterFromStack(@Nonnull ItemStack stack) {
    ItemFilter filter = new ItemFilter(filterType);
    NBTTagCompound tag = NbtValue.FILTER.getTag(stack);
    // ^ Response to above - need to move filters to use @Store in conduits
    if (!tag.hasNoTags() || filterType == BasicFilterTypes.filterUpgradeBasic) {
        filter.readFromNBT(tag);
    }
    return filter;
}
Also used : IItemFilter(crazypants.enderio.base.filter.IItemFilter) ItemFilter(crazypants.enderio.base.filter.filters.ItemFilter) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 5 with IItemFilter

use of crazypants.enderio.base.filter.IItemFilter in project EnderIO by SleepyTrousers.

the class ItemExistingItemFilter method createFilterFromStack.

@Override
public IItemFilter createFilterFromStack(@Nonnull ItemStack stack) {
    IItemFilter filter = new ExistingItemFilter();
    NBTTagCompound tag = NbtValue.FILTER.getTag(stack);
    filter.readFromNBT(tag);
    return filter;
}
Also used : IItemFilter(crazypants.enderio.base.filter.IItemFilter) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ExistingItemFilter(crazypants.enderio.base.filter.filters.ExistingItemFilter)

Aggregations

IItemFilter (crazypants.enderio.base.filter.IItemFilter)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 ItemStack (net.minecraft.item.ItemStack)3 EnumFacing (net.minecraft.util.EnumFacing)2 DyeColor (com.enderio.core.common.util.DyeColor)1 ILimitedItemFilter (crazypants.enderio.base.filter.ILimitedItemFilter)1 ExistingItemFilter (crazypants.enderio.base.filter.filters.ExistingItemFilter)1 ItemFilter (crazypants.enderio.base.filter.filters.ItemFilter)1 RedstoneControlMode (crazypants.enderio.base.machine.modes.RedstoneControlMode)1 Target (crazypants.enderio.conduits.conduit.item.NetworkedInventory.Target)1 ArrayList (java.util.ArrayList)1 IItemHandler (net.minecraftforge.items.IItemHandler)1