Search in sources :

Example 1 with IInfusionTank

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;
}
Also used : IInventorySlot(mekanism.api.inventory.IInventorySlot) IPigmentTank(mekanism.api.chemical.pigment.IPigmentTank) IInfusionTank(mekanism.api.chemical.infuse.IInfusionTank) IGasTank(mekanism.api.chemical.gas.IGasTank) DataType(mekanism.common.tile.component.config.DataType) ConfigInfo(mekanism.common.tile.component.config.ConfigInfo) TileComponentConfig(mekanism.common.tile.component.TileComponentConfig) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) ISlurryTank(mekanism.api.chemical.slurry.ISlurryTank) Nullable(javax.annotation.Nullable)

Example 2 with IInfusionTank

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));
                }
            }
        }
    }
}
Also used : IHeatHandler(mekanism.api.heat.IHeatHandler) IGasTile(mekanism.common.tile.interfaces.chemical.IGasTile) SecurityMode(mekanism.common.lib.security.SecurityMode) IHeatCapacitorHolder(mekanism.common.capabilities.holder.heat.IHeatCapacitorHolder) ComputerMethodMapper(mekanism.common.integration.computer.ComputerMethodMapper) ITileHeatHandler(mekanism.common.capabilities.heat.ITileHeatHandler) IEnergyContainerHolder(mekanism.common.capabilities.holder.energy.IEnergyContainerHolder) GasHandlerManager(mekanism.common.capabilities.resolver.manager.ChemicalHandlerManager.GasHandlerManager) TileComponentConfig(mekanism.common.tile.component.TileComponentConfig) CompoundNBT(net.minecraft.nbt.CompoundNBT) ITierUpgradable(mekanism.common.tile.interfaces.ITierUpgradable) Direction(net.minecraft.util.Direction) SlurryHandlerManager(mekanism.common.capabilities.resolver.manager.ChemicalHandlerManager.SlurryHandlerManager) ITileRadioactive(mekanism.common.tile.interfaces.ITileRadioactive) IComputerTile(mekanism.common.integration.computer.IComputerTile) Block(net.minecraft.block.Block) Capabilities(mekanism.common.capabilities.Capabilities) Map(java.util.Map) InfusionHandlerManager(mekanism.common.capabilities.resolver.manager.ChemicalHandlerManager.InfusionHandlerManager) BoundComputerMethod(mekanism.common.integration.computer.BoundComputerMethod) SyncMapper(mekanism.common.inventory.container.sync.dynamic.SyncMapper) ISound(net.minecraft.client.audio.ISound) ISustainedInventory(mekanism.common.tile.interfaces.ISustainedInventory) ListNBT(net.minecraft.nbt.ListNBT) IChunkLoader(mekanism.common.lib.chunkloading.IChunkLoader) ITileRedstone(mekanism.common.tile.interfaces.ITileRedstone) Attribute(mekanism.common.block.attribute.Attribute) NBTUtils(mekanism.common.util.NBTUtils) EnergyHandlerManager(mekanism.common.capabilities.resolver.manager.EnergyHandlerManager) Set(java.util.Set) IBlockProvider(mekanism.api.providers.IBlockProvider) IMekanismFluidHandler(mekanism.api.fluid.IMekanismFluidHandler) ISecurityTile(mekanism.common.lib.security.ISecurityTile) ITrackableContainer(mekanism.common.inventory.container.ITrackableContainer) MekanismUtils(mekanism.common.util.MekanismUtils) FluidHandlerManager(mekanism.common.capabilities.resolver.manager.FluidHandlerManager) MethodRestriction(mekanism.common.integration.computer.ComputerMethodMapper.MethodRestriction) ComputerException(mekanism.common.integration.computer.ComputerException) ComputerCapabilityHelper(mekanism.common.integration.computer.ComputerCapabilityHelper) IGasTank(mekanism.api.chemical.gas.IGasTank) ITileSound(mekanism.common.tile.interfaces.ITileSound) SyncablePigmentStack(mekanism.common.inventory.container.sync.chemical.SyncablePigmentStack) TileComponentSecurity(mekanism.common.tile.component.TileComponentSecurity) ActionResultType(net.minecraft.util.ActionResultType) SyncableFloatingLong(mekanism.common.inventory.container.sync.SyncableFloatingLong) Util(net.minecraft.util.Util) IInfusionTile(mekanism.common.tile.interfaces.chemical.IInfusionTile) IHeatCapacitor(mekanism.api.heat.IHeatCapacitor) AttributeUpgradeable(mekanism.common.block.attribute.AttributeUpgradeable) IPigmentTank(mekanism.api.chemical.pigment.IPigmentTank) ISlurryTank(mekanism.api.chemical.slurry.ISlurryTank) AttributeComparator(mekanism.common.block.attribute.Attributes.AttributeComparator) ArrayList(java.util.ArrayList) ItemConfigurationCard(mekanism.common.item.ItemConfigurationCard) ItemStack(net.minecraft.item.ItemStack) ItemConfigurator(mekanism.common.item.ItemConfigurator) NetworkHooks(net.minecraftforge.fml.network.NetworkHooks) IMekanismStrictEnergyHandler(mekanism.api.energy.IMekanismStrictEnergyHandler) AttributeStateFacing(mekanism.common.block.attribute.AttributeStateFacing) IEnergyContainer(mekanism.api.energy.IEnergyContainer) ICapabilityHandlerManager(mekanism.common.capabilities.resolver.manager.ICapabilityHandlerManager) Nullable(javax.annotation.Nullable) EnumUtils(mekanism.common.util.EnumUtils) SyncableEnum(mekanism.common.inventory.container.sync.SyncableEnum) PigmentHandlerManager(mekanism.common.capabilities.resolver.manager.ChemicalHandlerManager.PigmentHandlerManager) IComparatorSupport(mekanism.common.tile.interfaces.IComparatorSupport) BlockPos(net.minecraft.util.math.BlockPos) SecurityUtils(mekanism.common.util.SecurityUtils) IUpgradeData(mekanism.common.upgrade.IUpgradeData) AttributeSecurity(mekanism.common.block.attribute.Attributes.AttributeSecurity) BasicHeatCapacitor(mekanism.common.capabilities.heat.BasicHeatCapacitor) IFrequencyHandler(mekanism.common.lib.frequency.IFrequencyHandler) TileEntity(net.minecraft.tileentity.TileEntity) TextComponentUtil(mekanism.api.text.TextComponentUtil) IInventorySlotHolder(mekanism.common.capabilities.holder.slot.IInventorySlotHolder) Action(mekanism.api.Action) SoundEvent(net.minecraft.util.SoundEvent) MekanismAPI(mekanism.api.MekanismAPI) IMekanismInventory(mekanism.api.inventory.IMekanismInventory) SyncableGasStack(mekanism.common.inventory.container.sync.chemical.SyncableGasStack) AutomationType(mekanism.api.inventory.AutomationType) ITileUpgradable(mekanism.common.tile.interfaces.ITileUpgradable) AttributeComputerIntegration(mekanism.common.block.attribute.Attributes.AttributeComputerIntegration) TileComponentUpgrade(mekanism.common.tile.component.TileComponentUpgrade) IInfusionTank(mekanism.api.chemical.infuse.IInfusionTank) AttributeStateActive(mekanism.common.block.attribute.AttributeStateActive) TileEntityType(net.minecraft.tileentity.TileEntityType) BlockState(net.minecraft.block.BlockState) AttributeRedstone(mekanism.common.block.attribute.Attributes.AttributeRedstone) AttributeGui(mekanism.common.block.attribute.AttributeGui) PlayerEntity(net.minecraft.entity.player.PlayerEntity) MachineEnergyContainer(mekanism.common.capabilities.energy.MachineEnergyContainer) SyncableInfusionStack(mekanism.common.inventory.container.sync.chemical.SyncableInfusionStack) SyncableSlurryStack(mekanism.common.inventory.container.sync.chemical.SyncableSlurryStack) DataHandlerUtils(mekanism.api.DataHandlerUtils) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) ITileActive(mekanism.common.tile.interfaces.ITileActive) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Objects(java.util.Objects) IConfigCardAccess(mekanism.api.IConfigCardAccess) List(java.util.List) AttributeSound(mekanism.common.block.attribute.AttributeSound) NBTConstants(mekanism.api.NBTConstants) ItemHandlerManager(mekanism.common.capabilities.resolver.manager.ItemHandlerManager) CachedAmbientTemperature(mekanism.common.capabilities.heat.CachedAmbientTemperature) ITickableTileEntity(net.minecraft.tileentity.ITickableTileEntity) MekanismContainer(mekanism.common.inventory.container.MekanismContainer) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Upgrade(mekanism.api.Upgrade) IPigmentTile(mekanism.common.tile.interfaces.chemical.IPigmentTile) CapabilityUtils(mekanism.common.util.CapabilityUtils) IFluidTankHolder(mekanism.common.capabilities.holder.fluid.IFluidTankHolder) SyncableDouble(mekanism.common.inventory.container.sync.SyncableDouble) Function(java.util.function.Function) ITextComponent(net.minecraft.util.text.ITextComponent) Minecraft(net.minecraft.client.Minecraft) FloatingLong(mekanism.api.math.FloatingLong) ComputerMethod(mekanism.common.integration.computer.annotation.ComputerMethod) ISlurryTile(mekanism.common.tile.interfaces.chemical.ISlurryTile) IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) Hand(net.minecraft.util.Hand) Nonnull(javax.annotation.Nonnull) IntSupplier(java.util.function.IntSupplier) AttributeUpgradeSupport(mekanism.common.block.attribute.AttributeUpgradeSupport) Mekanism(mekanism.common.Mekanism) SoundHandler(mekanism.client.sound.SoundHandler) ITileComponent(mekanism.common.tile.component.ITileComponent) HeatHandlerManager(mekanism.common.capabilities.resolver.manager.HeatHandlerManager) ITileDirectional(mekanism.common.tile.interfaces.ITileDirectional) ObjectOpenHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenHashSet) NBT(net.minecraftforge.common.util.Constants.NBT) TileComponentFrequency(mekanism.common.lib.frequency.TileComponentFrequency) IInventorySlot(mekanism.api.inventory.IInventorySlot) WorldUtils(mekanism.common.util.WorldUtils) Collections(java.util.Collections) MekanismConfig(mekanism.common.config.MekanismConfig) SyncableFluidStack(mekanism.common.inventory.container.sync.SyncableFluidStack) BasicHeatCapacitor(mekanism.common.capabilities.heat.BasicHeatCapacitor) IGasTank(mekanism.api.chemical.gas.IGasTank) ITileComponent(mekanism.common.tile.component.ITileComponent) IPigmentTank(mekanism.api.chemical.pigment.IPigmentTank) IEnergyContainer(mekanism.api.energy.IEnergyContainer) IInfusionTank(mekanism.api.chemical.infuse.IInfusionTank) IHeatCapacitor(mekanism.api.heat.IHeatCapacitor) MachineEnergyContainer(mekanism.common.capabilities.energy.MachineEnergyContainer) IExtendedFluidTank(mekanism.api.fluid.IExtendedFluidTank) ISlurryTank(mekanism.api.chemical.slurry.ISlurryTank)

Example 3 with IInfusionTank

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);
}
Also used : ItemStackToInfuseTypeRecipe(mekanism.api.recipes.ItemStackToInfuseTypeRecipe) MethodsReturnNonnullByDefault(mcp.MethodsReturnNonnullByDefault) MekanismRecipeType(mekanism.common.recipe.MekanismRecipeType) Predicate(java.util.function.Predicate) World(net.minecraft.world.World) IChemicalHandler(mekanism.api.chemical.IChemicalHandler) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) IInfusionHandler(mekanism.api.chemical.infuse.IInfusionHandler) Objects(java.util.Objects) IContentsListener(mekanism.api.IContentsListener) ItemStack(net.minecraft.item.ItemStack) IInfusionTank(mekanism.api.chemical.infuse.IInfusionTank) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) FieldsAreNonnullByDefault(mekanism.api.annotations.FieldsAreNonnullByDefault) Capabilities(mekanism.common.capabilities.Capabilities) InfuseType(mekanism.api.chemical.infuse.InfuseType) NonNull(mekanism.api.annotations.NonNull) Nullable(javax.annotation.Nullable) InfusionStack(mekanism.api.chemical.infuse.InfusionStack) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Nullable (javax.annotation.Nullable)3 IInfusionTank (mekanism.api.chemical.infuse.IInfusionTank)3 Objects (java.util.Objects)2 Function (java.util.function.Function)2 IGasTank (mekanism.api.chemical.gas.IGasTank)2 IPigmentTank (mekanism.api.chemical.pigment.IPigmentTank)2 ISlurryTank (mekanism.api.chemical.slurry.ISlurryTank)2 IExtendedFluidTank (mekanism.api.fluid.IExtendedFluidTank)2 Capabilities (mekanism.common.capabilities.Capabilities)2 ItemStack (net.minecraft.item.ItemStack)2 ObjectOpenHashSet (it.unimi.dsi.fastutil.objects.ObjectOpenHashSet)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 IntSupplier (java.util.function.IntSupplier)1 Predicate (java.util.function.Predicate)1 Supplier (java.util.function.Supplier)1 Nonnull (javax.annotation.Nonnull)1