Search in sources :

Example 1 with IGasHandler

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

the class ItemScubaTank method addHUDStrings.

@Override
public void addHUDStrings(List<ITextComponent> list, PlayerEntity player, ItemStack stack, EquipmentSlotType slotType) {
    if (slotType == getSlot()) {
        ItemScubaTank scubaTank = (ItemScubaTank) stack.getItem();
        list.add(MekanismLang.SCUBA_TANK_MODE.translateColored(EnumColor.DARK_GRAY, OnOff.of(scubaTank.getFlowing(stack), true)));
        GasStack stored = GasStack.EMPTY;
        Optional<IGasHandler> capability = stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY).resolve();
        if (capability.isPresent()) {
            IGasHandler gasHandlerItem = capability.get();
            if (gasHandlerItem.getTanks() > 0) {
                stored = gasHandlerItem.getChemicalInTank(0);
            }
        }
        list.add(MekanismLang.GENERIC_STORED.translateColored(EnumColor.DARK_GRAY, MekanismGases.OXYGEN, EnumColor.ORANGE, stored.getAmount()));
    }
}
Also used : IGasHandler(mekanism.api.chemical.gas.IGasHandler) GasStack(mekanism.api.chemical.gas.GasStack)

Example 2 with IGasHandler

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

the class ItemJetpack method addHUDStrings.

@Override
public void addHUDStrings(List<ITextComponent> list, PlayerEntity player, ItemStack stack, EquipmentSlotType slotType) {
    if (slotType == getSlot()) {
        ItemJetpack jetpack = (ItemJetpack) stack.getItem();
        list.add(MekanismLang.JETPACK_MODE.translateColored(EnumColor.DARK_GRAY, jetpack.getMode(stack)));
        GasStack stored = GasStack.EMPTY;
        Optional<IGasHandler> capability = stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY).resolve();
        if (capability.isPresent()) {
            IGasHandler gasHandlerItem = capability.get();
            if (gasHandlerItem.getTanks() > 0) {
                stored = gasHandlerItem.getChemicalInTank(0);
            }
        }
        list.add(MekanismLang.JETPACK_STORED.translateColored(EnumColor.DARK_GRAY, EnumColor.ORANGE, stored.getAmount()));
    }
}
Also used : IGasHandler(mekanism.api.chemical.gas.IGasHandler) GasStack(mekanism.api.chemical.gas.GasStack)

Example 3 with IGasHandler

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

the class ItemHohlraum method appendHoverText.

@Override
@OnlyIn(Dist.CLIENT)
public void appendHoverText(@Nonnull ItemStack stack, @Nullable World world, @Nonnull List<ITextComponent> tooltip, @Nonnull ITooltipFlag flag) {
    if (Capabilities.GAS_HANDLER_CAPABILITY != null) {
        // Ensure the capability is not null, as the first call to addInformation happens before capability injection
        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()) {
                    tooltip.add(MekanismLang.STORED.translate(storedGas, storedGas.getAmount()));
                    if (storedGas.getAmount() == gasHandlerItem.getTankCapacity(0)) {
                        tooltip.add(GeneratorsLang.READY_FOR_REACTION.translateColored(EnumColor.DARK_GREEN));
                    } else {
                        tooltip.add(GeneratorsLang.INSUFFICIENT_FUEL.translateColored(EnumColor.DARK_RED));
                    }
                    return;
                }
            }
        }
    }
    tooltip.add(MekanismLang.NO_GAS.translate());
    tooltip.add(GeneratorsLang.INSUFFICIENT_FUEL.translateColored(EnumColor.DARK_RED));
}
Also used : IGasHandler(mekanism.api.chemical.gas.IGasHandler) GasStack(mekanism.api.chemical.gas.GasStack) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 4 with IGasHandler

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

the class FusionReactorMultiblockData method vaporiseHohlraum.

private void vaporiseHohlraum() {
    ItemStack hohlraum = reactorSlot.getStack();
    Optional<IGasHandler> capability = hohlraum.getCapability(Capabilities.GAS_HANDLER_CAPABILITY).resolve();
    if (capability.isPresent()) {
        IGasHandler gasHandlerItem = capability.get();
        if (gasHandlerItem.getTanks() > 0) {
            fuelTank.insert(gasHandlerItem.getChemicalInTank(0), Action.EXECUTE, AutomationType.INTERNAL);
            lastPlasmaTemperature = getPlasmaTemp();
            reactorSlot.setEmpty();
            setBurning(true);
        }
    }
}
Also used : IGasHandler(mekanism.api.chemical.gas.IGasHandler) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IGasHandler

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

the class ModuleElectrolyticBreathingUnit method tickServer.

@Override
public void tickServer(IModule<ModuleElectrolyticBreathingUnit> module, PlayerEntity player) {
    int productionRate = 0;
    // Check if the mask is underwater
    // Note: Being in water is checked first to ensure that if it is raining and the player is in water
    // they get the full strength production
    float eyeHeight = player.getEyeHeight();
    Map<Fluid, FluidInDetails> fluidsIn = MekanismUtils.getFluidsIn(player, bb -> {
        // Grab the center of the BB as that is where the player is for purposes of what it renders it intersects with
        double centerX = (bb.minX + bb.maxX) / 2;
        double centerZ = (bb.minZ + bb.maxZ) / 2;
        // For the y range check a range of where the mask's breathing unit is based on where the eyes are
        return new AxisAlignedBB(centerX, Math.min(bb.minY + eyeHeight - 0.27, bb.maxY), centerZ, centerX, Math.min(bb.minY + eyeHeight - 0.14, bb.maxY), centerZ);
    });
    if (fluidsIn.entrySet().stream().anyMatch(entry -> entry.getKey().is(FluidTags.WATER) && entry.getValue().getMaxHeight() >= 0.11)) {
        // If the position the bottom of the mask is almost entirely in water set the production rate to our max rate
        // if the mask is only partially in water treat it as not being in it enough to actually function
        productionRate = getMaxRate(module);
    } else if (player.isInRain()) {
        // If the player is not in water but is in rain set the production to half power
        productionRate = getMaxRate(module) / 2;
    }
    if (productionRate > 0) {
        FloatingLong usage = MekanismConfig.general.FROM_H2.get().multiply(2);
        int maxRate = Math.min(productionRate, module.getContainerEnergy().divideToInt(usage));
        long hydrogenUsed = 0;
        GasStack hydrogenStack = MekanismGases.HYDROGEN.getStack(maxRate * 2L);
        ItemStack chestStack = player.getItemBySlot(EquipmentSlotType.CHEST);
        if (checkChestPlate(chestStack)) {
            Optional<IGasHandler> chestCapability = chestStack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY).resolve();
            if (chestCapability.isPresent()) {
                hydrogenUsed = maxRate * 2L - chestCapability.get().insertChemical(hydrogenStack, Action.EXECUTE).getAmount();
                hydrogenStack.shrink(hydrogenUsed);
            }
        }
        if (fillHeld.get()) {
            ItemStack handStack = player.getItemBySlot(EquipmentSlotType.MAINHAND);
            Optional<IGasHandler> handCapability = handStack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY).resolve();
            if (handCapability.isPresent()) {
                hydrogenUsed = maxRate * 2L - handCapability.get().insertChemical(hydrogenStack, Action.EXECUTE).getAmount();
            }
        }
        int oxygenUsed = Math.min(maxRate, player.getMaxAirSupply() - player.getAirSupply());
        long used = Math.max((int) Math.ceil(hydrogenUsed / 2D), oxygenUsed);
        module.useEnergy(player, usage.multiply(used));
        player.setAirSupply(player.getAirSupply() + oxygenUsed);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) FluidInDetails(mekanism.common.util.MekanismUtils.FluidInDetails) Fluid(net.minecraft.fluid.Fluid) FloatingLong(mekanism.api.math.FloatingLong) IGasHandler(mekanism.api.chemical.gas.IGasHandler) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack)

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