Search in sources :

Example 16 with ConfigInfo

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

the class TileComponentConfig method decrementMode.

@ComputerMethod
private void decrementMode(TransmissionType type, RelativeSide side) throws ComputerException {
    tile.validateSecurityIsPublic();
    validateSupportedTransmissionType(type);
    ConfigInfo configInfo = this.configInfo.get(type);
    if (configInfo.getDataType(side) != configInfo.decrementDataType(side)) {
        sideChanged(type, side);
    }
}
Also used : ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod)

Example 17 with ConfigInfo

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

the class InventoryFrequency method handleEject.

public void handleEject(long gameTime) {
    if (isValid() && !activeQEs.isEmpty() && lastEject != gameTime) {
        lastEject = gameTime;
        Map<TransmissionType, BiConsumer<TileEntity, Direction>> typesToEject = new EnumMap<>(TransmissionType.class);
        // All but heat and item
        List<Runnable> transferHandlers = new ArrayList<>(EnumUtils.TRANSMISSION_TYPES.length - 2);
        int expected = 6 * activeQEs.size();
        addEnergyTransferHandler(typesToEject, transferHandlers, expected);
        addFluidTransferHandler(typesToEject, transferHandlers, expected);
        addChemicalTransferHandler(TransmissionType.GAS, storedGas, typesToEject, transferHandlers, expected);
        addChemicalTransferHandler(TransmissionType.INFUSION, storedInfusion, typesToEject, transferHandlers, expected);
        addChemicalTransferHandler(TransmissionType.PIGMENT, storedPigment, typesToEject, transferHandlers, expected);
        addChemicalTransferHandler(TransmissionType.SLURRY, storedSlurry, typesToEject, transferHandlers, expected);
        if (!typesToEject.isEmpty()) {
            // then go through all the QEs and build up the target locations
            for (TileEntityQuantumEntangloporter qe : activeQEs.values()) {
                Map<Direction, TileEntity> adjacentTiles = null;
                for (Map.Entry<TransmissionType, BiConsumer<TileEntity, Direction>> entry : typesToEject.entrySet()) {
                    ConfigInfo config = qe.getConfig().getConfig(entry.getKey());
                    if (config != null && config.isEjecting()) {
                        Set<Direction> outputSides = config.getAllOutputtingSides();
                        if (!outputSides.isEmpty()) {
                            if (adjacentTiles == null) {
                                // Lazy init the map of adjacent tiles
                                adjacentTiles = new EnumMap<>(Direction.class);
                            }
                            for (Direction side : outputSides) {
                                TileEntity tile;
                                if (adjacentTiles.containsKey(side)) {
                                    // Need to use contains because we allow for null values
                                    tile = adjacentTiles.get(side);
                                } else {
                                    // Get tile and provide if not null and the block is loaded, prevents ghost chunk loading
                                    tile = WorldUtils.getTileEntity(qe.getLevel(), qe.getBlockPos().relative(side));
                                    adjacentTiles.put(side, tile);
                                }
                                if (tile != null) {
                                    entry.getValue().accept(tile, side);
                                }
                            }
                        }
                    }
                }
            }
            // Run all our transfer handlers that we have
            for (Runnable transferHandler : transferHandlers) {
                transferHandler.run();
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) Direction(net.minecraft.util.Direction) TileEntity(net.minecraft.tileentity.TileEntity) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) TileEntityQuantumEntangloporter(mekanism.common.tile.TileEntityQuantumEntangloporter) EnumMap(java.util.EnumMap) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) EnumMap(java.util.EnumMap) BiConsumer(java.util.function.BiConsumer)

Example 18 with ConfigInfo

use of mekanism.common.tile.component.config.ConfigInfo 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 19 with ConfigInfo

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

the class TileComponentConfig method addToUpdateTag.

@Override
public void addToUpdateTag(CompoundNBT updateTag) {
    // Note: This is slightly different from read and write as we don't bother syncing the ejecting status
    CompoundNBT configNBT = new CompoundNBT();
    for (Entry<TransmissionType, ConfigInfo> entry : configInfo.entrySet()) {
        TransmissionType type = entry.getKey();
        ConfigInfo info = entry.getValue();
        CompoundNBT sideConfig = new CompoundNBT();
        for (RelativeSide side : EnumUtils.SIDES) {
            sideConfig.putInt(NBTConstants.SIDE + side.ordinal(), info.getDataType(side).ordinal());
        }
        configNBT.put(NBTConstants.CONFIG + type.ordinal(), sideConfig);
    }
    updateTag.put(NBTConstants.COMPONENT_CONFIG, configNBT);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) TransmissionType(mekanism.common.lib.transmitter.TransmissionType) RelativeSide(mekanism.api.RelativeSide) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo)

Example 20 with ConfigInfo

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

the class TileComponentConfig method setMode.

@ComputerMethod
private void setMode(TransmissionType type, RelativeSide side, DataType mode) throws ComputerException {
    tile.validateSecurityIsPublic();
    validateSupportedTransmissionType(type);
    ConfigInfo config = configInfo.get(type);
    if (!config.getSupportedDataTypes().contains(mode)) {
        throw new ComputerException("This machine does not support mode '%s' for transmission type '%s'.", mode, type);
    }
    DataType currentMode = config.getDataType(side);
    if (mode != currentMode) {
        config.setDataType(mode, side);
        sideChanged(type, side);
    }
}
Also used : DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) ComputerException(mekanism.common.integration.computer.ComputerException) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod)

Aggregations

ConfigInfo (mekanism.common.tile.component.config.ConfigInfo)27 TransmissionType (mekanism.common.lib.transmitter.TransmissionType)10 DataType (mekanism.common.tile.component.config.DataType)9 RelativeSide (mekanism.api.RelativeSide)8 Direction (net.minecraft.util.Direction)6 ArrayList (java.util.ArrayList)5 ComputerMethod (mekanism.common.integration.computer.annotation.ComputerMethod)5 CompoundNBT (net.minecraft.nbt.CompoundNBT)5 IInventorySlot (mekanism.api.inventory.IInventorySlot)4 ISlotInfo (mekanism.common.tile.component.config.slot.ISlotInfo)4 InventorySlotInfo (mekanism.common.tile.component.config.slot.InventorySlotInfo)4 TileEntity (net.minecraft.tileentity.TileEntity)4 EnumMap (java.util.EnumMap)3 Map (java.util.Map)3 Nonnull (javax.annotation.Nonnull)3 Nullable (javax.annotation.Nullable)3 ComputerException (mekanism.common.integration.computer.ComputerException)3 TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)3 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)3 HashMap (java.util.HashMap)2