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);
}
}
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();
}
}
}
}
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;
}
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);
}
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);
}
}
Aggregations