Search in sources :

Example 1 with ChemicalHandlerTarget

use of mekanism.common.content.network.distribution.ChemicalHandlerTarget 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)

Aggregations

Map (java.util.Map)1 ChemicalType (mekanism.api.chemical.ChemicalType)1 IChemicalHandler (mekanism.api.chemical.IChemicalHandler)1 BoxedChemicalHandler (mekanism.common.capabilities.chemical.BoxedChemicalHandler)1 ChemicalHandlerTarget (mekanism.common.content.network.distribution.ChemicalHandlerTarget)1 Direction (net.minecraft.util.Direction)1 LazyOptional (net.minecraftforge.common.util.LazyOptional)1