Search in sources :

Example 6 with IGasHandler

use of mekanism.api.chemical.gas.IGasHandler 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)

Example 7 with IGasHandler

use of mekanism.api.chemical.gas.IGasHandler in project Mekanism by mekanism.

the class ItemFlamethrower method addHUDStrings.

@Override
public void addHUDStrings(List<ITextComponent> list, PlayerEntity player, ItemStack stack, EquipmentSlotType slotType) {
    boolean hasGas = false;
    Optional<IGasHandler> capability = stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY).resolve();
    if (capability.isPresent()) {
        IGasHandler gasHandlerItem = capability.get();
        if (gasHandlerItem.getTanks() > 0) {
            // Validate something didn't go terribly wrong, and we actually do have the tank we expect to have
            GasStack storedGas = gasHandlerItem.getChemicalInTank(0);
            if (!storedGas.isEmpty()) {
                list.add(MekanismLang.FLAMETHROWER_STORED.translateColored(EnumColor.GRAY, EnumColor.ORANGE, storedGas.getAmount()));
                hasGas = true;
            }
        }
    }
    if (!hasGas) {
        list.add(MekanismLang.FLAMETHROWER_STORED.translateColored(EnumColor.GRAY, EnumColor.ORANGE, MekanismLang.NO_GAS));
    }
    list.add(MekanismLang.MODE.translate(getMode(stack)));
}
Also used : IGasHandler(mekanism.api.chemical.gas.IGasHandler) GasStack(mekanism.api.chemical.gas.GasStack)

Aggregations

IGasHandler (mekanism.api.chemical.gas.IGasHandler)7 GasStack (mekanism.api.chemical.gas.GasStack)5 ItemStack (net.minecraft.item.ItemStack)2 IInfusionHandler (mekanism.api.chemical.infuse.IInfusionHandler)1 IPigmentHandler (mekanism.api.chemical.pigment.IPigmentHandler)1 ISlurryHandler (mekanism.api.chemical.slurry.ISlurryHandler)1 FloatingLong (mekanism.api.math.FloatingLong)1 BoxedChemicalHandler (mekanism.common.capabilities.chemical.BoxedChemicalHandler)1 FluidInDetails (mekanism.common.util.MekanismUtils.FluidInDetails)1 Fluid (net.minecraft.fluid.Fluid)1 Direction (net.minecraft.util.Direction)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1