Search in sources :

Example 1 with ISlotInfo

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

the class ModelEnergyCube method renderSidesBatched.

public void renderSidesBatched(@Nonnull TileEntityEnergyCube tile, @Nonnull MatrixStack matrix, @Nonnull IRenderTypeBuffer renderer, int light, int overlayLight) {
    Set<RelativeSide> enabledSides = EnumSet.noneOf(RelativeSide.class);
    Set<RelativeSide> outputSides = EnumSet.noneOf(RelativeSide.class);
    ConfigInfo config = tile.getConfig().getConfig(TransmissionType.ENERGY);
    if (config != null) {
        for (RelativeSide side : EnumUtils.SIDES) {
            ISlotInfo slotInfo = config.getSlotInfo(side);
            if (slotInfo != null) {
                if (slotInfo.canInput()) {
                    enabledSides.add(side);
                } else if (slotInfo.canOutput()) {
                    enabledSides.add(side);
                    outputSides.add(side);
                }
            }
        }
    }
    renderSidesBatched(matrix, renderer, light, overlayLight, enabledSides, outputSides, false);
}
Also used : ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) RelativeSide(mekanism.api.RelativeSide) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo)

Example 2 with ISlotInfo

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

the class TileComponentEjector method eject.

/**
 * @apiNote Ensure that it can eject before calling this method.
 */
private void eject(TransmissionType type, ConfigInfo info) {
    // Used to keep track of tanks to what sides they output to
    Map<Object, Set<Direction>> outputData = null;
    for (DataType dataType : info.getSupportedDataTypes()) {
        if (dataType.canOutput()) {
            ISlotInfo slotInfo = info.getSlotInfo(dataType);
            if (slotInfo != null) {
                Set<Direction> outputSides = info.getSidesForData(dataType);
                if (!outputSides.isEmpty()) {
                    if (outputData == null) {
                        // Lazy init outputData
                        outputData = new HashMap<>();
                    }
                    if (type.isChemical() && slotInfo instanceof ChemicalSlotInfo) {
                        for (IChemicalTank<?, ?> tank : ((ChemicalSlotInfo<?, ?, ?>) slotInfo).getTanks()) {
                            if (!tank.isEmpty() && (canTankEject == null || canTankEject.test(tank))) {
                                outputData.computeIfAbsent(tank, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
                            }
                        }
                    } else if (type == TransmissionType.FLUID && slotInfo instanceof FluidSlotInfo) {
                        for (IExtendedFluidTank tank : ((FluidSlotInfo) slotInfo).getTanks()) {
                            if (!tank.isEmpty()) {
                                outputData.computeIfAbsent(tank, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
                            }
                        }
                    } else if (type == TransmissionType.ENERGY && slotInfo instanceof EnergySlotInfo) {
                        for (IEnergyContainer container : ((EnergySlotInfo) slotInfo).getContainers()) {
                            if (!container.isEmpty()) {
                                outputData.computeIfAbsent(container, t -> EnumSet.noneOf(Direction.class)).addAll(outputSides);
                            }
                        }
                    }
                }
            }
        }
    }
    if (outputData != null && !outputData.isEmpty()) {
        for (Map.Entry<Object, Set<Direction>> entry : outputData.entrySet()) {
            if (type.isChemical()) {
                ChemicalUtil.emit(entry.getValue(), (IChemicalTank<?, ?>) entry.getKey(), tile, chemicalEjectRate.getAsLong());
            } else if (type == TransmissionType.FLUID) {
                FluidUtils.emit(entry.getValue(), (IExtendedFluidTank) entry.getKey(), tile, fluidEjectRate.getAsInt());
            } else if (type == TransmissionType.ENERGY) {
                IEnergyContainer container = (IEnergyContainer) entry.getKey();
                CableUtils.emit(entry.getValue(), container, tile, energyEjectRate == null ? container.getMaxEnergy() : energyEjectRate.get());
            }
        }
    }
}
Also used : ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) LongSupplier(java.util.function.LongSupplier) SyncableInt(mekanism.common.inventory.container.sync.SyncableInt) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) CompoundNBT(net.minecraft.nbt.CompoundNBT) Direction(net.minecraft.util.Direction) FluidSlotInfo(mekanism.common.tile.component.config.slot.FluidSlotInfo) TileTransitRequest(mekanism.common.lib.inventory.TileTransitRequest) Map(java.util.Map) EnumSet(java.util.EnumSet) TileEntityLogisticalTransporterBase(mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase) EnumMap(java.util.EnumMap) NBTUtils(mekanism.common.util.NBTUtils) Predicate(java.util.function.Predicate) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) Set(java.util.Set) List(java.util.List) ComputerException(mekanism.common.integration.computer.ComputerException) InventoryUtils(mekanism.common.util.InventoryUtils) RelativeSide(mekanism.api.RelativeSide) ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) NBTConstants(mekanism.api.NBTConstants) ChemicalUtil(mekanism.common.util.ChemicalUtil) EnumColor(mekanism.api.text.EnumColor) CableUtils(mekanism.common.util.CableUtils) SyncableBoolean(mekanism.common.inventory.container.sync.SyncableBoolean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ISpecificContainerTracker(mekanism.common.inventory.container.MekanismContainer.ISpecificContainerTracker) ChemicalSlotInfo(mekanism.common.tile.component.config.slot.ChemicalSlotInfo) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) TransitResponse(mekanism.common.lib.inventory.TransitRequest.TransitResponse) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod) IEnergyContainer(mekanism.api.energy.IEnergyContainer) Nonnull(javax.annotation.Nonnull) IntSupplier(java.util.function.IntSupplier) Nullable(javax.annotation.Nullable) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) EnumUtils(mekanism.common.util.EnumUtils) DataType(mekanism.common.tile.component.config.DataType) InventorySlotInfo(mekanism.common.tile.component.config.slot.InventorySlotInfo) TransporterUtils(mekanism.common.util.TransporterUtils) FluidUtils(mekanism.common.util.FluidUtils) NBT(net.minecraftforge.common.util.Constants.NBT) EnergySlotInfo(mekanism.common.tile.component.config.slot.EnergySlotInfo) WorldUtils(mekanism.common.util.WorldUtils) TileEntity(net.minecraft.tileentity.TileEntity) IChemicalTank(mekanism.api.chemical.IChemicalTank) MekanismConfig(mekanism.common.config.MekanismConfig) FloatingLongSupplier(mekanism.api.math.FloatingLongSupplier) ISyncableData(mekanism.common.inventory.container.sync.ISyncableData) FluidSlotInfo(mekanism.common.tile.component.config.slot.FluidSlotInfo) EnumSet(java.util.EnumSet) Set(java.util.Set) EnergySlotInfo(mekanism.common.tile.component.config.slot.EnergySlotInfo) Direction(net.minecraft.util.Direction) ChemicalSlotInfo(mekanism.common.tile.component.config.slot.ChemicalSlotInfo) IEnergyContainer(mekanism.api.energy.IEnergyContainer) DataType(mekanism.common.tile.component.config.DataType) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap)

Example 3 with ISlotInfo

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

the class ConfigHolder method getSlotInfo.

@Nullable
private ISlotInfo getSlotInfo(Direction side) {
    Direction direction = facingSupplier.get();
    if (direction != lastDirection) {
        // Invalid entire cache and update what direction we had as last if our last direction doesn't match the one we currently are facing
        cachedSlotInfo.clear();
        lastDirection = direction;
    } else if (cachedSlotInfo.containsKey(side)) {
        return cachedSlotInfo.get(side);
    }
    ISlotInfo slotInfo;
    TileComponentConfig config = configSupplier.get();
    if (config == null) {
        slotInfo = NO_CONFIG;
    } else {
        TransmissionType transmissionType = getTransmissionType();
        ConfigInfo configInfo = config.getConfig(transmissionType);
        if (configInfo == null) {
            slotInfo = NO_CONFIG;
        } else {
            if (!listenerAdded) {
                // If we haven't added a listener to our config yet add one to remove the cached info we have for that side
                listenerAdded = true;
                config.addConfigChangeListener(transmissionType, cachedSlotInfo::remove);
            }
            slotInfo = configInfo.getSlotInfo(RelativeSide.fromDirections(direction, side));
            if (slotInfo != null && !slotInfo.isEnabled()) {
                // If we have a slot info, but it is not actually enabled, just store it as null to avoid having to recheck if it is enabled later
                slotInfo = null;
            }
        }
    }
    cachedSlotInfo.put(side, slotInfo);
    return slotInfo;
}
Also used : ISlotInfo(mekanism.common.tile.component.config.slot.ISlotInfo) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) TileComponentConfig(mekanism.common.tile.component.TileComponentConfig) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) Direction(net.minecraft.util.Direction) Nullable(javax.annotation.Nullable)

Example 4 with ISlotInfo

use of mekanism.common.tile.component.config.slot.ISlotInfo 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 5 with ISlotInfo

use of mekanism.common.tile.component.config.slot.ISlotInfo 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

ISlotInfo (mekanism.common.tile.component.config.slot.ISlotInfo)5 ConfigInfo (mekanism.common.tile.component.config.ConfigInfo)4 DataType (mekanism.common.tile.component.config.DataType)3 InventorySlotInfo (mekanism.common.tile.component.config.slot.InventorySlotInfo)3 Nullable (javax.annotation.Nullable)2 RelativeSide (mekanism.api.RelativeSide)2 TransitResponse (mekanism.common.lib.inventory.TransitRequest.TransitResponse)2 TransmissionType (mekanism.common.lib.transmitter.TransmissionType)2 TileEntityLogisticalTransporterBase (mekanism.common.tile.transmitter.TileEntityLogisticalTransporterBase)2 Direction (net.minecraft.util.Direction)2 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 IntSupplier (java.util.function.IntSupplier)1 LongSupplier (java.util.function.LongSupplier)1 Predicate (java.util.function.Predicate)1