Search in sources :

Example 1 with BoxedChemicalHandler

use of mekanism.common.capabilities.chemical.BoxedChemicalHandler in project Mekanism by mekanism.

the class BoxedChemicalNetwork method tickEmit.

private <CHEMICAL extends Chemical<CHEMICAL>, STACK extends ChemicalStack<CHEMICAL>> long tickEmit(@Nonnull STACK stack) {
    ChemicalType chemicalType = ChemicalType.getTypeFor(stack);
    Collection<Map<Direction, LazyOptional<BoxedChemicalHandler>>> acceptorValues = acceptorCache.getAcceptorValues();
    ChemicalHandlerTarget<CHEMICAL, STACK, IChemicalHandler<CHEMICAL, STACK>> target = new ChemicalHandlerTarget<>(stack, acceptorValues.size() * 2);
    for (Map<Direction, LazyOptional<BoxedChemicalHandler>> acceptors : acceptorValues) {
        for (LazyOptional<BoxedChemicalHandler> lazyAcceptor : acceptors.values()) {
            lazyAcceptor.ifPresent(acceptor -> {
                IChemicalHandler<CHEMICAL, STACK> handler = acceptor.getHandlerFor(chemicalType);
                if (handler != null && ChemicalUtil.canInsert(handler, stack)) {
                    target.addHandler(handler);
                }
            });
        }
    }
    return EmitUtils.sendToAcceptors(target, stack.getAmount(), stack);
}
Also used : ChemicalType(mekanism.api.chemical.ChemicalType) ChemicalHandlerTarget(mekanism.common.content.network.distribution.ChemicalHandlerTarget) Direction(net.minecraft.util.Direction) BoxedChemicalHandler(mekanism.common.capabilities.chemical.BoxedChemicalHandler) LazyOptional(net.minecraftforge.common.util.LazyOptional) IChemicalHandler(mekanism.api.chemical.IChemicalHandler) Map(java.util.Map)

Example 2 with BoxedChemicalHandler

use of mekanism.common.capabilities.chemical.BoxedChemicalHandler in project Mekanism by mekanism.

the class BoxedChemicalAcceptorCache method isChemicalAcceptorAndListen.

public boolean isChemicalAcceptorAndListen(@Nullable TileEntity tile, Direction side) {
    // TODO: Improve this to make it easier to add more chemical types
    Direction opposite = side.getOpposite();
    LazyOptional<IGasHandler> gasAcceptor = CapabilityUtils.getCapability(tile, Capabilities.GAS_HANDLER_CAPABILITY, opposite);
    LazyOptional<IInfusionHandler> infusionAcceptor = CapabilityUtils.getCapability(tile, Capabilities.INFUSION_HANDLER_CAPABILITY, opposite);
    LazyOptional<IPigmentHandler> pigmentAcceptor = CapabilityUtils.getCapability(tile, Capabilities.PIGMENT_HANDLER_CAPABILITY, opposite);
    LazyOptional<ISlurryHandler> slurryAcceptor = CapabilityUtils.getCapability(tile, Capabilities.SLURRY_HANDLER_CAPABILITY, opposite);
    if (gasAcceptor.isPresent() || infusionAcceptor.isPresent() || pigmentAcceptor.isPresent() || slurryAcceptor.isPresent()) {
        BoxedChemicalHandler chemicalHandler = new BoxedChemicalHandler();
        if (gasAcceptor.isPresent()) {
            chemicalHandler.addGasHandler(gasAcceptor);
        }
        if (infusionAcceptor.isPresent()) {
            chemicalHandler.addInfusionHandler(infusionAcceptor);
        }
        if (pigmentAcceptor.isPresent()) {
            chemicalHandler.addPigmentHandler(pigmentAcceptor);
        }
        if (slurryAcceptor.isPresent()) {
            chemicalHandler.addSlurryHandler(slurryAcceptor);
        }
        // Update the cached acceptor and if it changed, add a listener to it to listen for invalidation
        updateCachedAcceptorAndListen(side, tile, chemicalHandler);
        return true;
    }
    return false;
}
Also used : IInfusionHandler(mekanism.api.chemical.infuse.IInfusionHandler) IPigmentHandler(mekanism.api.chemical.pigment.IPigmentHandler) IGasHandler(mekanism.api.chemical.gas.IGasHandler) ISlurryHandler(mekanism.api.chemical.slurry.ISlurryHandler) BoxedChemicalHandler(mekanism.common.capabilities.chemical.BoxedChemicalHandler) Direction(net.minecraft.util.Direction)

Aggregations

BoxedChemicalHandler (mekanism.common.capabilities.chemical.BoxedChemicalHandler)2 Direction (net.minecraft.util.Direction)2 Map (java.util.Map)1 ChemicalType (mekanism.api.chemical.ChemicalType)1 IChemicalHandler (mekanism.api.chemical.IChemicalHandler)1 IGasHandler (mekanism.api.chemical.gas.IGasHandler)1 IInfusionHandler (mekanism.api.chemical.infuse.IInfusionHandler)1 IPigmentHandler (mekanism.api.chemical.pigment.IPigmentHandler)1 ISlurryHandler (mekanism.api.chemical.slurry.ISlurryHandler)1 ChemicalHandlerTarget (mekanism.common.content.network.distribution.ChemicalHandlerTarget)1 LazyOptional (net.minecraftforge.common.util.LazyOptional)1