use of mekanism.api.chemical.infuse.IInfusionTank in project Mekanism by mekanism.
the class ISideConfiguration method getActiveDataType.
@Nullable
default DataType getActiveDataType(Object container) {
ConfigInfo info = null;
TileComponentConfig config = getConfig();
if (container instanceof IGasTank && config.supports(TransmissionType.GAS)) {
info = config.getConfig(TransmissionType.GAS);
} else if (container instanceof IInfusionTank && config.supports(TransmissionType.INFUSION)) {
info = config.getConfig(TransmissionType.INFUSION);
} else if (container instanceof IPigmentTank && config.supports(TransmissionType.PIGMENT)) {
info = config.getConfig(TransmissionType.PIGMENT);
} else if (container instanceof ISlurryTank && config.supports(TransmissionType.SLURRY)) {
info = config.getConfig(TransmissionType.SLURRY);
} else if (container instanceof IExtendedFluidTank && config.supports(TransmissionType.FLUID)) {
info = config.getConfig(TransmissionType.FLUID);
} else if (container instanceof IInventorySlot && config.supports(TransmissionType.ITEM)) {
info = config.getConfig(TransmissionType.ITEM);
}
if (info != null) {
List<DataType> types = info.getDataTypeForContainer(container);
int count = types.size();
// of <= size - 1 to cut down slightly on the calculations
if (count > 0 && count < info.getSupportedDataTypes().size()) {
return types.get(0);
}
}
return null;
}
use of mekanism.api.chemical.infuse.IInfusionTank in project Mekanism by mekanism.
the class TileEntityMekanism method addContainerTrackers.
@Override
public void addContainerTrackers(MekanismContainer container) {
// setup dynamic container syncing
SyncMapper.INSTANCE.setup(container, getClass(), () -> this);
for (ITileComponent component : components) {
component.trackForMainContainer(container);
}
if (supportsRedstone()) {
container.track(SyncableEnum.create(RedstoneControl::byIndexStatic, RedstoneControl.DISABLED, () -> controlType, value -> controlType = value));
}
boolean isClient = isRemote();
if (canHandleGas() && handles(SubstanceType.GAS)) {
List<IGasTank> gasTanks = getGasTanks(null);
for (IGasTank gasTank : gasTanks) {
container.track(SyncableGasStack.create(gasTank, isClient));
}
}
if (canHandleInfusion() && handles(SubstanceType.INFUSION)) {
List<IInfusionTank> infusionTanks = getInfusionTanks(null);
for (IInfusionTank infusionTank : infusionTanks) {
container.track(SyncableInfusionStack.create(infusionTank, isClient));
}
}
if (canHandlePigment() && handles(SubstanceType.PIGMENT)) {
List<IPigmentTank> pigmentTanks = getPigmentTanks(null);
for (IPigmentTank pigmentTank : pigmentTanks) {
container.track(SyncablePigmentStack.create(pigmentTank, isClient));
}
}
if (canHandleSlurry() && handles(SubstanceType.SLURRY)) {
List<ISlurryTank> slurryTanks = getSlurryTanks(null);
for (ISlurryTank slurryTank : slurryTanks) {
container.track(SyncableSlurryStack.create(slurryTank, isClient));
}
}
if (canHandleFluid() && handles(SubstanceType.FLUID)) {
List<IExtendedFluidTank> fluidTanks = getFluidTanks(null);
for (IExtendedFluidTank fluidTank : fluidTanks) {
container.track(SyncableFluidStack.create(fluidTank, isClient));
}
}
if (canHandleHeat() && handles(SubstanceType.HEAT)) {
List<IHeatCapacitor> heatCapacitors = getHeatCapacitors(null);
for (IHeatCapacitor capacitor : heatCapacitors) {
container.track(SyncableDouble.create(capacitor::getHeat, capacitor::setHeat));
if (capacitor instanceof BasicHeatCapacitor) {
container.track(SyncableDouble.create(capacitor::getHeatCapacity, capacity -> ((BasicHeatCapacitor) capacitor).setHeatCapacity(capacity, false)));
}
}
}
if (canHandleEnergy() && handles(SubstanceType.ENERGY)) {
container.track(SyncableFloatingLong.create(this::getInputRate, this::setInputRate));
List<IEnergyContainer> energyContainers = getEnergyContainers(null);
for (IEnergyContainer energyContainer : energyContainers) {
container.track(SyncableFloatingLong.create(energyContainer::getEnergy, energyContainer::setEnergy));
if (energyContainer instanceof MachineEnergyContainer) {
MachineEnergyContainer<?> machineEnergy = (MachineEnergyContainer<?>) energyContainer;
if (supportsUpgrades() || machineEnergy.adjustableRates()) {
container.track(SyncableFloatingLong.create(machineEnergy::getMaxEnergy, machineEnergy::setMaxEnergy));
container.track(SyncableFloatingLong.create(machineEnergy::getEnergyPerTick, machineEnergy::setEnergyPerTick));
}
}
}
}
}
use of mekanism.api.chemical.infuse.IInfusionTank in project Mekanism by mekanism.
the class InfusionInventorySlot method fillOrConvert.
/**
* Fills the tank from this item OR converts the given item to an infusion type
*/
public static InfusionInventorySlot fillOrConvert(IInfusionTank infusionTank, Supplier<World> worldSupplier, @Nullable IContentsListener listener, int x, int y) {
Objects.requireNonNull(infusionTank, "Infusion tank cannot be null");
Objects.requireNonNull(worldSupplier, "World supplier cannot be null");
Function<ItemStack, InfusionStack> potentialConversionSupplier = stack -> getPotentialConversion(worldSupplier.get(), stack);
return new InfusionInventorySlot(infusionTank, worldSupplier, getFillOrConvertExtractPredicate(infusionTank, InfusionInventorySlot::getCapability, potentialConversionSupplier), getFillOrConvertInsertPredicate(infusionTank, InfusionInventorySlot::getCapability, potentialConversionSupplier), stack -> {
if (stack.getCapability(Capabilities.INFUSION_HANDLER_CAPABILITY).isPresent()) {
// Note: we mark all infusion items as valid and have a more restrictive insert check so that we allow full tanks when they are done being filled
return true;
}
// Allow infusion conversion of items that have an infusion that is valid
InfusionStack conversion = getPotentialConversion(worldSupplier.get(), stack);
return !conversion.isEmpty() && infusionTank.isValid(conversion);
}, listener, x, y);
}
Aggregations