Search in sources :

Example 1 with StorageFilterCache

use of mcjty.rftools.items.storage.StorageFilterCache in project RFTools by McJty.

the class ScannerTileEntity method mapState.

private IBlockState mapState(List<ModifierEntry> modifiers, Map<IBlockState, IBlockState> modifierMapping, BlockPos pos, IBlockState inState) {
    if (modifiers.isEmpty()) {
        return inState;
    }
    if (!modifierMapping.containsKey(inState)) {
        IBlockState outState = inState;
        boolean stop = false;
        for (ModifierEntry modifier : modifiers) {
            if (stop) {
                break;
            }
            switch(modifier.getType()) {
                case FILTER_SLOT:
                    {
                        ItemStack inputItem = inState.getBlock().getItem(getWorld(), pos, inState);
                        if (!modifier.getIn().isEmpty() && modifier.getIn().getItem() == ModularStorageSetup.storageFilterItem) {
                            StorageFilterCache filter = StorageFilterItem.getCache(modifier.getIn());
                            if (filter.match(inputItem)) {
                                outState = getOutput(inState, modifier);
                                stop = true;
                            }
                        } else {
                            // Empty input stack in modifier also matches
                            if (modifier.getIn().isEmpty() || ItemStack.areItemsEqual(inputItem, modifier.getIn())) {
                                outState = getOutput(inState, modifier);
                                stop = true;
                            }
                        }
                        break;
                    }
                case FILTER_ORE:
                    {
                        ItemStack inputItem = inState.getBlock().getItem(getWorld(), pos, inState);
                        if (!inputItem.isEmpty()) {
                            int[] oreIDs = OreDictionary.getOreIDs(inputItem);
                            for (int id : oreIDs) {
                                if (OreDictionary.getOreName(id).startsWith("ore")) {
                                    outState = getOutput(inState, modifier);
                                    stop = true;
                                    break;
                                }
                            }
                        }
                        break;
                    }
                case FILTER_LIQUID:
                    if (inState.getBlock() instanceof BlockLiquid) {
                        outState = getOutput(inState, modifier);
                        stop = true;
                    }
                    break;
                case FILTER_TILEENTITY:
                    if (getWorld().getTileEntity(pos) != null) {
                        outState = getOutput(inState, modifier);
                        stop = true;
                    }
                    break;
            }
        }
        modifierMapping.put(inState, outState);
    }
    return modifierMapping.get(inState);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) StorageFilterCache(mcjty.rftools.items.storage.StorageFilterCache) ModifierEntry(mcjty.rftools.items.modifier.ModifierEntry) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ModifierEntry (mcjty.rftools.items.modifier.ModifierEntry)1 StorageFilterCache (mcjty.rftools.items.storage.StorageFilterCache)1 BlockLiquid (net.minecraft.block.BlockLiquid)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemStack (net.minecraft.item.ItemStack)1