Search in sources :

Example 1 with InventorySlotInfo

use of mekanism.common.tile.component.config.slot.InventorySlotInfo in project Mekanism by mekanism.

the class TileComponentConfig method setupItemIOConfig.

public ConfigInfo setupItemIOConfig(List<IInventorySlot> inputSlots, List<IInventorySlot> outputSlots, IInventorySlot energySlot, boolean alwaysAllow) {
    ConfigInfo itemConfig = getConfig(TransmissionType.ITEM);
    if (itemConfig != null) {
        itemConfig.addSlotInfo(DataType.INPUT, new InventorySlotInfo(true, alwaysAllow, inputSlots));
        itemConfig.addSlotInfo(DataType.OUTPUT, new InventorySlotInfo(alwaysAllow, true, outputSlots));
        List<IInventorySlot> ioSlots = new ArrayList<>(inputSlots);
        ioSlots.addAll(outputSlots);
        itemConfig.addSlotInfo(DataType.INPUT_OUTPUT, new InventorySlotInfo(true, true, ioSlots));
        itemConfig.addSlotInfo(DataType.ENERGY, new InventorySlotInfo(true, true, energySlot));
        // Set default config directions
        itemConfig.setDefaults();
    }
    return itemConfig;
}
Also used : IInventorySlot(mekanism.api.inventory.IInventorySlot) ArrayList(java.util.ArrayList) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) InventorySlotInfo(mekanism.common.tile.component.config.slot.InventorySlotInfo)

Example 2 with InventorySlotInfo

use of mekanism.common.tile.component.config.slot.InventorySlotInfo in project Mekanism by mekanism.

the class TileComponentEjector method outputItems.

/**
 * @apiNote Ensure that it can eject before calling this method.
 */
private void outputItems(ConfigInfo info) {
    for (DataType dataType : info.getSupportedDataTypes()) {
        if (!dataType.canOutput()) {
            continue;
        }
        ISlotInfo slotInfo = info.getSlotInfo(dataType);
        if (slotInfo instanceof InventorySlotInfo) {
            // Validate the slot info is of the correct type
            Set<Direction> outputs = info.getSidesForData(dataType);
            if (!outputs.isEmpty()) {
                EjectTransitRequest ejectMap = InventoryUtils.getEjectItemMap(new EjectTransitRequest(tile, outputs.iterator().next()), ((InventorySlotInfo) slotInfo).getSlots());
                if (!ejectMap.isEmpty()) {
                    for (Direction side : outputs) {
                        TileEntity target = WorldUtils.getTileEntity(tile.getLevel(), tile.getBlockPos().relative(side));
                        if (target != null) {
                            // Update the side so that if/when the response uses it, it makes sure it is grabbing from the correct side
                            ejectMap.side = side;
                            // If the spot is not loaded just skip trying to eject to it
                            TransitResponse response;
                            if (target instanceof TileEntityLogisticalTransporterBase) {
                                response = ((TileEntityLogisticalTransporterBase) target).getTransmitter().insert(tile, ejectMap, outputColor, true, 0);
                            } else {
                                response = ejectMap.addToInventory(target, side, 0, false);
                            }
                            if (!response.isEmpty()) {
                                // use the items returned by the TransitResponse; will be visible next loop
                                response.useAll();
                                if (ejectMap.isEmpty()) {
                                    // If we are out of items to eject, break
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    tickDelay = 10;
}
Also used : ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) TileEntity(net.minecraft.tileentity.TileEntity) TransitResponse(mekanism.common.lib.inventory.TransitRequest.TransitResponse) DataType(mekanism.common.tile.component.config.DataType) InventorySlotInfo(mekanism.common.tile.component.config.slot.InventorySlotInfo) Direction(net.minecraft.util.Direction) TileEntityLogisticalTransporterBase(mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase)

Example 3 with InventorySlotInfo

use of mekanism.common.tile.component.config.slot.InventorySlotInfo in project Mekanism by mekanism.

the class TileComponentConfig method setupItemIOExtraConfig.

public ConfigInfo setupItemIOExtraConfig(IInventorySlot inputSlot, IInventorySlot outputSlot, IInventorySlot extraSlot, IInventorySlot energySlot) {
    ConfigInfo itemConfig = getConfig(TransmissionType.ITEM);
    if (itemConfig != null) {
        itemConfig.addSlotInfo(DataType.INPUT, new InventorySlotInfo(true, false, inputSlot));
        itemConfig.addSlotInfo(DataType.OUTPUT, new InventorySlotInfo(false, true, outputSlot));
        itemConfig.addSlotInfo(DataType.INPUT_OUTPUT, new InventorySlotInfo(true, true, inputSlot, outputSlot));
        itemConfig.addSlotInfo(DataType.EXTRA, new InventorySlotInfo(true, true, extraSlot));
        itemConfig.addSlotInfo(DataType.ENERGY, new InventorySlotInfo(true, true, energySlot));
        // Set default config directions
        itemConfig.setDefaults();
    }
    return itemConfig;
}
Also used : ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) InventorySlotInfo(mekanism.common.tile.component.config.slot.InventorySlotInfo)

Example 4 with InventorySlotInfo

use of mekanism.common.tile.component.config.slot.InventorySlotInfo in project Mekanism by mekanism.

the class GuiMekanismTile method getFromSlot.

private DataType getFromSlot(Slot slot) {
    if (slot.index < tile.getSlots() && slot instanceof InventoryContainerSlot) {
        ISideConfiguration config = (ISideConfiguration) tile;
        ConfigInfo info = config.getConfig().getConfig(TransmissionType.ITEM);
        if (info != null) {
            Set<DataType> supportedDataTypes = info.getSupportedDataTypes();
            IInventorySlot inventorySlot = ((InventoryContainerSlot) slot).getInventorySlot();
            for (DataType type : supportedDataTypes) {
                ISlotInfo slotInfo = info.getSlotInfo(type);
                if (slotInfo instanceof InventorySlotInfo && ((InventorySlotInfo) slotInfo).hasSlot(inventorySlot)) {
                    return type;
                }
            }
        }
    }
    return null;
}
Also used : IInventorySlot(mekanism.api.inventory.IInventorySlot) ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) DataType(mekanism.common.tile.component.config.DataType) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) InventorySlotInfo(mekanism.common.tile.component.config.slot.InventorySlotInfo) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Aggregations

InventorySlotInfo (mekanism.common.tile.component.config.slot.InventorySlotInfo)4 ConfigInfo (mekanism.common.tile.component.config.ConfigInfo)3 IInventorySlot (mekanism.api.inventory.IInventorySlot)2 DataType (mekanism.common.tile.component.config.DataType)2 ISlotInfo (mekanism.common.tile.component.config.slot.ISlotInfo)2 ArrayList (java.util.ArrayList)1 InventoryContainerSlot (mekanism.common.inventory.container.slot.InventoryContainerSlot)1 TransitResponse (mekanism.common.lib.inventory.TransitRequest.TransitResponse)1 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)1 TileEntityLogisticalTransporterBase (mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Direction (net.minecraft.util.Direction)1