PneumaticCraft: Repressurized

PneumaticCraft: Repressurized

50M Downloads

API Request: Allow Pressure Chamber mod recipe to specify dynamic pressure

mc-ganduron opened this issue ยท 3 comments

commented

I have a mod with a Pressure Chamber recipe that varies its output items according to the input's NBT, similar in spirit to the enchanting/disenchanting recipes. Ideally (in my case) the required pressure would also be a function of the input. Currently a Pressure Chamber recipe is restricted to one pressure for all possible input items. I'd like to propose a change to the Pressure Chamber recipe API to allow variable pressures according to the input items.

If you're open to the idea, I was thinking the changes would look something like this (nothing tested, just eyeballed):

PressureChamberRecipe Changes

    // Replaces getCraftingPressure()
    /**
     * Returns the minimum pressure required to craft the recipe. Negative pressures are also acceptable; in this
     * case the pressure chamber's pressure must be <strong>lower</strong> than the required pressure.
     *
     * @param chamberHandler  items in the pressure chamber
     * @param ingredientSlots slots in the chamber handler where the ingredients can be found, as returned from {@link #findIngredients(IItemHandler)}
     * @return threshold pressure
     */
    public abstract float getCraftingPressure(IItemHandler chamberHandler, List<Integer> ingredientSlots);


    /**
     * Get the required crafting pressure for the items specified by {@link #getInputsForDisplay()}, for display purposes.
     */
    public abstract float getCraftingPressureForDisplay();

PressureChamberRecipeImpl Changes

    // Replaces getCraftingPressure()
    @Override
    public float getCraftingPressure(IItemHandler chamberHandler, List<Integer> ingredientSlots) {
        // Uniform pressure for all cases. Special cases should override.
        return pressureRequired;
    }

    @Override
    public float getCraftingPressureForDisplay() {
        return pressureRequired;
    }
    // TBD: changes to write(PacketBuffer)

TileEntityPressureChamberValve Changes

    private void processApplicableRecipes() {
        for (ApplicableRecipe applicableRecipe : applicableRecipes) {
            PressureChamberRecipe recipe = applicableRecipe.recipe;
            // Calculate the required pressure once, then test against the chamber's active pressure.
            float requiredPressure = recipe.getCraftingPressure(itemsInChamber, applicableRecipe.slots);
            boolean pressureOK = requiredPressure <= getPressure() && requiredPressure > 0F
                    || requiredPressure >= getPressure() && requiredPressure < 0F;
            if (Math.abs(requiredPressure) < Math.abs(recipePressure)) {
                recipePressure = requiredPressure;
            }
        }
        // etc...
    }

JEIPressureChamberRecipeCategory Changes
Replace calls to getCraftingPressure() with calls to getCraftingPressureForDisplay(). It may be useful to indicate somehow that the pressure varies according to the input. This is less of a concern for me than the recipe functionality, though, so I haven't given it much thought.

commented

Yeah, this is probably a good idea. As it happens, I've been reviewing some other recipes in the mod with an eye to adding more context like this.

It would be nice to avoid an API break, though; I think this would be better:

@Deprecated
public abstract float getCraftingPressure();  // don't use this; override the below 2-arg variant instead

public float getCraftingPressure(IItemHandler chamberHandler, List<Integer> ingredientSlots) {
    return getCraftingPressure();
}

then you're free to override the 2-arg variant in your recipe implementation. The deprecated method can disappear in the 1.17/1.18 release.

commented

Looks good, runs good. Thanks a lot.

commented

Added in 2.13.4 release