Search in sources :

Example 26 with GasStack

use of mekanism.api.chemical.gas.GasStack 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 27 with GasStack

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

the class FissionReactorMultiblockData method burnFuel.

private void burnFuel(World world) {
    double lastPartialWaste = partialWaste;
    double lastBurnRemaining = burnRemaining;
    double storedFuel = fuelTank.getStored() + burnRemaining;
    double toBurn = Math.min(Math.min(rateLimit, storedFuel), fuelAssemblies * MekanismGeneratorsConfig.generators.burnPerAssembly.get());
    storedFuel -= toBurn;
    fuelTank.setStackSize((long) storedFuel, Action.EXECUTE);
    burnRemaining = storedFuel % 1;
    heatCapacitor.handleHeat(toBurn * MekanismGeneratorsConfig.generators.energyPerFissionFuel.get().doubleValue());
    // handle waste
    partialWaste += toBurn;
    long newWaste = (long) Math.floor(partialWaste);
    if (newWaste > 0) {
        partialWaste %= 1;
        long leftoverWaste = Math.max(0, newWaste - wasteTank.getNeeded());
        GasStack wasteToAdd = MekanismGases.NUCLEAR_WASTE.getStack(newWaste);
        wasteTank.insert(wasteToAdd, Action.EXECUTE, AutomationType.INTERNAL);
        if (leftoverWaste > 0) {
            double radioactivity = wasteToAdd.getType().get(GasAttributes.Radiation.class).getRadioactivity();
            MekanismAPI.getRadiationManager().radiate(new Coord4D(getBounds().getCenter(), world), leftoverWaste * radioactivity);
        }
    }
    // update previous burn
    lastBurnRate = toBurn;
    if (lastPartialWaste != partialWaste || lastBurnRemaining != burnRemaining) {
        markDirty();
    }
}
Also used : Coord4D(mekanism.api.Coord4D) GasStack(mekanism.api.chemical.gas.GasStack)

Example 28 with GasStack

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

Example 29 with GasStack

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

the class ModuleJetpackUnit method addHUDElements.

@Override
public void addHUDElements(IModule<ModuleJetpackUnit> module, PlayerEntity player, Consumer<IHUDElement> hudElementAdder) {
    if (module.isEnabled()) {
        ItemStack container = module.getContainer();
        GasStack stored = ((ItemMekaSuitArmor) container.getItem()).getContainedGas(container, MekanismGases.HYDROGEN.get());
        double ratio = StorageUtils.getRatio(stored.getAmount(), MekanismConfig.gear.mekaSuitJetpackMaxStorage.getAsLong());
        hudElementAdder.accept(MekanismAPI.getModuleHelper().hudElementPercent(jetpackMode.get().getHUDIcon(), ratio));
    }
}
Also used : ItemMekaSuitArmor(mekanism.common.item.gear.ItemMekaSuitArmor) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack)

Example 30 with GasStack

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

the class PressurizedReactionRecipeSerializer method fromJson.

@Nonnull
@Override
public RECIPE fromJson(@Nonnull ResourceLocation recipeId, @Nonnull JsonObject json) {
    JsonElement itemInput = JSONUtils.isArrayNode(json, JsonConstants.ITEM_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.ITEM_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.ITEM_INPUT);
    ItemStackIngredient solidIngredient = ItemStackIngredient.deserialize(itemInput);
    JsonElement fluidInput = JSONUtils.isArrayNode(json, JsonConstants.FLUID_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.FLUID_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.FLUID_INPUT);
    FluidStackIngredient fluidIngredient = FluidStackIngredient.deserialize(fluidInput);
    JsonElement gasInput = JSONUtils.isArrayNode(json, JsonConstants.GAS_INPUT) ? JSONUtils.getAsJsonArray(json, JsonConstants.GAS_INPUT) : JSONUtils.getAsJsonObject(json, JsonConstants.GAS_INPUT);
    GasStackIngredient gasIngredient = GasStackIngredient.deserialize(gasInput);
    FloatingLong energyRequired = FloatingLong.ZERO;
    if (json.has(JsonConstants.ENERGY_REQUIRED)) {
        energyRequired = SerializerHelper.getFloatingLong(json, JsonConstants.ENERGY_REQUIRED);
    }
    int duration;
    JsonElement ticks = json.get(JsonConstants.DURATION);
    if (!JSONUtils.isNumberValue(ticks)) {
        throw new JsonSyntaxException("Expected duration to be a number greater than zero.");
    }
    duration = ticks.getAsJsonPrimitive().getAsInt();
    if (duration <= 0) {
        throw new JsonSyntaxException("Expected duration to be a number greater than zero.");
    }
    ItemStack itemOutput = ItemStack.EMPTY;
    GasStack gasOutput = GasStack.EMPTY;
    if (json.has(JsonConstants.ITEM_OUTPUT)) {
        itemOutput = SerializerHelper.getItemStack(json, JsonConstants.ITEM_OUTPUT);
        if (itemOutput.isEmpty()) {
            throw new JsonSyntaxException("Reaction chamber item output must not be empty, if it is defined.");
        }
        if (json.has(JsonConstants.GAS_OUTPUT)) {
            // The gas is optional given we have an output item
            gasOutput = SerializerHelper.getGasStack(json, JsonConstants.GAS_OUTPUT);
            if (gasOutput.isEmpty()) {
                throw new JsonSyntaxException("Reaction chamber gas output must not be empty, if it is defined.");
            }
        }
    } else {
        // If we don't have an output item, we are required to have an output gas
        gasOutput = SerializerHelper.getGasStack(json, JsonConstants.GAS_OUTPUT);
        if (gasOutput.isEmpty()) {
            throw new JsonSyntaxException("Reaction chamber gas output must not be empty, if there is no item output.");
        }
    }
    return this.factory.create(recipeId, solidIngredient, fluidIngredient, gasIngredient, energyRequired, duration, itemOutput, gasOutput);
}
Also used : ItemStackIngredient(mekanism.api.recipes.inputs.ItemStackIngredient) FloatingLong(mekanism.api.math.FloatingLong) JsonSyntaxException(com.google.gson.JsonSyntaxException) FluidStackIngredient(mekanism.api.recipes.inputs.FluidStackIngredient) JsonElement(com.google.gson.JsonElement) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack) GasStackIngredient(mekanism.api.recipes.inputs.chemical.GasStackIngredient) Nonnull(javax.annotation.Nonnull)

Aggregations

GasStack (mekanism.api.chemical.gas.GasStack)44 ItemStack (net.minecraft.item.ItemStack)17 JsonSyntaxException (com.google.gson.JsonSyntaxException)8 IngredientHelper (mekanism.common.integration.projecte.IngredientHelper)8 FluidStackIngredient (mekanism.api.recipes.inputs.FluidStackIngredient)7 FluidStack (net.minecraftforge.fluids.FluidStack)7 List (java.util.List)6 IGasHandler (mekanism.api.chemical.gas.IGasHandler)6 PigmentStack (mekanism.api.chemical.pigment.PigmentStack)6 FloatingLong (mekanism.api.math.FloatingLong)6 GasStackIngredient (mekanism.api.recipes.inputs.chemical.GasStackIngredient)6 NonNull (mekanism.api.annotations.NonNull)5 InfusionStack (mekanism.api.chemical.infuse.InfusionStack)5 SlurryStack (mekanism.api.chemical.slurry.SlurryStack)5 Nonnull (javax.annotation.Nonnull)4 JsonElement (com.google.gson.JsonElement)3 Collections (java.util.Collections)3 Nullable (javax.annotation.Nullable)3 ChemicalType (mekanism.api.chemical.ChemicalType)3 BoxedChemicalStack (mekanism.api.chemical.merged.BoxedChemicalStack)3