Search in sources :

Example 16 with GasStack

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

the class PressurizedReactionRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof PressurizedReactionRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    boolean handled = false;
    PressurizedReactionRecipe recipe = (PressurizedReactionRecipe) iRecipe;
    List<@NonNull ItemStack> itemRepresentations = recipe.getInputSolid().getRepresentations();
    List<@NonNull FluidStack> fluidRepresentations = recipe.getInputFluid().getRepresentations();
    List<@NonNull GasStack> gasRepresentations = recipe.getInputGas().getRepresentations();
    for (ItemStack itemRepresentation : itemRepresentations) {
        NormalizedSimpleStack nssItem = NSSItem.createItem(itemRepresentation);
        for (FluidStack fluidRepresentation : fluidRepresentations) {
            NormalizedSimpleStack nssFluid = NSSFluid.createFluid(fluidRepresentation);
            for (GasStack gasRepresentation : gasRepresentations) {
                NormalizedSimpleStack nssGas = NSSGas.createGas(gasRepresentation);
                Pair<@NonNull ItemStack, @NonNull GasStack> output = recipe.getOutput(itemRepresentation, fluidRepresentation, gasRepresentation);
                ItemStack itemOutput = output.getLeft();
                GasStack gasOutput = output.getRight();
                IngredientHelper ingredientHelper = new IngredientHelper(mapper);
                ingredientHelper.put(nssItem, itemRepresentation.getCount());
                ingredientHelper.put(nssFluid, fluidRepresentation.getAmount());
                ingredientHelper.put(nssGas, gasRepresentation.getAmount());
                if (itemOutput.isEmpty()) {
                    // We only have a gas output
                    if (!gasOutput.isEmpty() && ingredientHelper.addAsConversion(gasOutput)) {
                        handled = true;
                    }
                } else if (gasOutput.isEmpty()) {
                    // We only have an item output
                    if (ingredientHelper.addAsConversion(itemOutput)) {
                        handled = true;
                    }
                } else {
                    NormalizedSimpleStack nssItemOutput = NSSItem.createItem(itemOutput);
                    NormalizedSimpleStack nssGasOutput = NSSGas.createGas(gasOutput);
                    // We have both so do our best guess
                    // Add trying to calculate the item output (using it as if we needed negative of gas output)
                    ingredientHelper.put(nssGasOutput, -gasOutput.getAmount());
                    if (ingredientHelper.addAsConversion(nssItemOutput, itemOutput.getCount())) {
                        handled = true;
                    }
                    // Add trying to calculate gas output (using it as if we needed negative of item output)
                    ingredientHelper.resetHelper();
                    ingredientHelper.put(nssItem, itemRepresentation.getCount());
                    ingredientHelper.put(nssFluid, fluidRepresentation.getAmount());
                    ingredientHelper.put(nssGas, gasRepresentation.getAmount());
                    ingredientHelper.put(nssItemOutput, -itemOutput.getCount());
                    if (ingredientHelper.addAsConversion(nssGasOutput, gasOutput.getAmount())) {
                        handled = true;
                    }
                }
            }
        }
    }
    return handled;
}
Also used : PressurizedReactionRecipe(mekanism.api.recipes.PressurizedReactionRecipe) NormalizedSimpleStack(moze_intel.projecte.api.nss.NormalizedSimpleStack) FluidStack(net.minecraftforge.fluids.FluidStack) GasStack(mekanism.api.chemical.gas.GasStack) ItemStack(net.minecraft.item.ItemStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper)

Example 17 with GasStack

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

the class RotaryRecipeMapper method handleRecipe.

@Override
public boolean handleRecipe(IMappingCollector<NormalizedSimpleStack, Long> mapper, IRecipe<?> iRecipe, INSSFakeGroupManager groupManager) {
    if (!(iRecipe instanceof RotaryRecipe)) {
        // Double check that we have a type of recipe we know how to handle
        return false;
    }
    RotaryRecipe recipe = (RotaryRecipe) iRecipe;
    boolean handled = false;
    if (recipe.hasFluidToGas()) {
        for (FluidStack representation : recipe.getFluidInput().getRepresentations()) {
            GasStack output = recipe.getGasOutput(representation);
            if (!output.isEmpty()) {
                IngredientHelper ingredientHelper = new IngredientHelper(mapper);
                ingredientHelper.put(representation);
                if (ingredientHelper.addAsConversion(output)) {
                    handled = true;
                }
            }
        }
    }
    if (recipe.hasGasToFluid()) {
        for (GasStack representation : recipe.getGasInput().getRepresentations()) {
            FluidStack output = recipe.getFluidOutput(representation);
            if (!output.isEmpty()) {
                IngredientHelper ingredientHelper = new IngredientHelper(mapper);
                ingredientHelper.put(representation);
                if (ingredientHelper.addAsConversion(output)) {
                    handled = true;
                }
            }
        }
    }
    return handled;
}
Also used : RotaryRecipe(mekanism.api.recipes.RotaryRecipe) FluidStack(net.minecraftforge.fluids.FluidStack) GasStack(mekanism.api.chemical.gas.GasStack) IngredientHelper(mekanism.common.integration.projecte.IngredientHelper)

Example 18 with GasStack

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

the class PressurizedReactionCachedRecipe method isInputValid.

@Override
public boolean isInputValid() {
    GasStack gas = gasInputHandler.getInput();
    if (gas.isEmpty()) {
        return false;
    }
    FluidStack fluid = fluidInputHandler.getInput();
    if (fluid.isEmpty()) {
        return false;
    }
    return recipe.test(itemInputHandler.getInput(), fluid, gas);
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) GasStack(mekanism.api.chemical.gas.GasStack)

Example 19 with GasStack

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

the class TileEntityGasGenerator method onUpdateServer.

@Override
protected void onUpdateServer() {
    super.onUpdateServer();
    energySlot.drainContainer();
    fuelSlot.fillTank();
    boolean operate = (!fuelTank.isEmpty() || burnTicks > 0) && MekanismUtils.canFunction(this);
    if (operate && getEnergyContainer().insert(generationRate, Action.SIMULATE, AutomationType.INTERNAL).isZero()) {
        setActive(true);
        if (!fuelTank.isEmpty() && fuelTank.getType().has(Fuel.class)) {
            Fuel fuel = fuelTank.getType().get(Fuel.class);
            maxBurnTicks = fuel.getBurnTicks();
            generationRate = fuel.getEnergyPerTick();
        }
        long toUse = getToUse();
        FloatingLong toUseGeneration = generationRate.multiply(toUse);
        output = MekanismConfig.general.FROM_H2.get().max(toUseGeneration).multiply(2);
        long total = burnTicks + fuelTank.getStored() * maxBurnTicks;
        total -= toUse;
        getEnergyContainer().insert(toUseGeneration, Action.EXECUTE, AutomationType.INTERNAL);
        if (!fuelTank.isEmpty()) {
            // TODO: Improve this as it is sort of hacky
            fuelTank.setStack(new GasStack(fuelTank.getStack(), total / maxBurnTicks));
        }
        burnTicks = total % maxBurnTicks;
        gasUsedLastTick = toUse / (double) maxBurnTicks;
    } else {
        if (!operate) {
            reset();
        }
        gasUsedLastTick = 0;
        setActive(false);
    }
}
Also used : SyncableFloatingLong(mekanism.common.inventory.container.sync.SyncableFloatingLong) FloatingLong(mekanism.api.math.FloatingLong) Fuel(mekanism.api.chemical.gas.attribute.GasAttributes.Fuel) GasStack(mekanism.api.chemical.gas.GasStack)

Example 20 with GasStack

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

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