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;
}
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;
}
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);
}
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);
}
}
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()));
}
}
Aggregations