Skip to content

feat: add a proper SPS recipe type - #8404

Open
Satherov wants to merge 1 commit into
mekanism:1.21.xfrom
Satherov:1.21.x
Open

feat: add a proper SPS recipe type#8404
Satherov wants to merge 1 commit into
mekanism:1.21.xfrom
Satherov:1.21.x

Conversation

@Satherov

Copy link
Copy Markdown

Adds a proper recipe type to the sps allowing for custom recipes and data generation

MekanismConfigTranslations.GENERAL_SPS.applyToBuilder(builder).push("sps");
spsInputPerAntimatter = CachedIntValue.wrap(this, MekanismConfigTranslations.GENERAL_SPS_ANTIMATTER_COST.applyToBuilder(builder)
.defineInRange("inputPerAntimatter", FluidType.BUCKET_VOLUME, 1, Integer.MAX_VALUE));
spsInputTankCapacity = CachedLongValue.wrap(this, MekanismConfigTranslations.GENERAL_SPS_CAPACITY_OUTPUT.applyToBuilder(builder)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgotten translation? output != input

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, added an input translation, my bad 😅

import net.minecraft.world.item.crafting.RecipeHolder;

public class SPSRecipeCategory extends BaseRecipeCategory<SPSRecipeViewerRecipe> {
public class PhaseShiftingRecipeCategory extends HolderRecipeCategory<PhaseShiftingRecipe> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if this (and similar) wasn't renamed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed all occurrences of PhaseShifting to SPS

list.add(MekanismLang.STATUS.translate(MekanismLang.ACTIVE));
list.add(MekanismLang.SPS_ENERGY_INPUT.translate(EnergyDisplay.of(
MathUtils.multiplyClamped(MekanismConfig.general.spsEnergyPerInput.get(), MekanismConfig.general.spsInputPerAntimatter.get()))));
list.add(MekanismLang.SPS_ENERGY_USAGE.translate(EnergyDisplay.of(recipe.getEnergyUsage() * 1000)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why's there * 1000 here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this is there is because otherwise the JEI gui is off by a magnitude of 1000. I'm not sure what's the reason for that, the sps gui lines up with the actual consumption, but JEI doesnt

Energy Consumption

image

SPS GUI

image

JEI GUI with the * 1000

image

JEI GUI without the * 1000

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then there's a bug elsewhere which needs to be solved. Why does the display differ?

Also you should have it display Joules so that you get it matching exactly what the code says

list.add(MekanismLang.STATUS.translate(MekanismLang.ACTIVE));
list.add(MekanismLang.SPS_ENERGY_INPUT.translate(EnergyDisplay.of(
MathUtils.multiplyClamped(MekanismConfig.general.spsEnergyPerInput.get(), MekanismConfig.general.spsInputPerAntimatter.get()))));
list.add(MekanismLang.SPS_ENERGY_USAGE.translate(EnergyDisplay.of(energy_usage * 1000)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* 1000 (see other comment)

final int inputPerAntimatter = MekanismConfig.general.spsInputPerAntimatter.get();
long inputNeeded = (inputPerAntimatter - inputProcessed) + inputPerAntimatter * (outputTank.getNeeded() - 1);
double processable = (double) receivedEnergy / MekanismConfig.general.spsEnergyPerInput.get();
lastReceivedRecipeAmount = cachedRecipe.getInput().amount();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this variable name doesn't seem to match what it's used for - I only see it being set with the recipe's required amount (which should be updated in the cached recipe check)

Comment thread src/main/resources/assets/mekanism/gui/sps_icon.png
));
}

public static MekanismRecipeSerializer<BasicPhaseShiftingRecipe> phaseShifting(Function3<ChemicalStackIngredient, ChemicalStack, Long, BasicPhaseShiftingRecipe> factory) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This factory and return generic is wrong - it should follow the others and have a RECIPE extends generic

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this? I was following the other "Basic" recipes above which didn't have a generic return either. The non basic version of the sps recipe won't work there because it doesnt have access to the proper output. My example to compare was the NucleosynthesizingRecipe and BasicNucleosynthesizingRecipe which doesn't have a generic return in the MekanismRecipeSerializer

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's why they have, for example, RECIPE extends ChemicalChemicalToChemicalRecipe & IBasicChemicalOutput

ChemicalStack toAdd = MekanismChemicals.ANTIMATTER.asStack(inputProcessed / inputPerAntimatter);
outputTank.insert(toAdd, Action.EXECUTE, AutomationType.INTERNAL);
inputProcessed %= inputPerAntimatter;
if (inputProcessed >= lastReceivedRecipeAmount) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be inputProcessed >= recipe.amount

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inputProcessed >= recipe.getInput().amount() ? recipe.amount doesn't exist
image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah unclear that it was pseudocode sorry


public static final RVRecipeTypeWrapper<?, ItemStackChemicalToItemStackRecipe, ?> PAINTING = new RVRecipeTypeWrapper<>(MekanismRecipeType.PAINTING, ItemStackChemicalToItemStackRecipe.class, -25, -13, 146, 60, MekanismBlocks.PAINTING_MACHINE);

//TODO This needs a better icon [sps_icon.png]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove todo from code, put in PR description if still needed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the todo

public @NotNull CachedRecipe<PhaseShiftingRecipe> createNewCachedRecipe(@NotNull PhaseShiftingRecipe recipe, int cacheIndex) {
// This is unused since the SPS uses a special way of handling recipes, but we still have to add the function due to the
// implementation of the LookupHandler. You could probably make a custom variation of the CachedRecipe and the
// RecipeCacheLookupMonitor, but that seems incredibly annoying for a single use case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have a couple of custom ones ;)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I could tell not for this use case tho and looking into it doesnt seem like a super simple task to make one either. I can make one if that's required for this to be merged, but what I have works and is fairly performant so I was hoping to get around that 😓

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the existing functionality already operated on an operations basis, it should be fairly easy to copy paste it into the process part of the RCLM?

At the very least, I'd like to see the recipe cache part use the RCLM like other machines (which means that any tank change and probably energy change causes a recipe check). Currently what you've written doesn't properly handle input change - e.g. output has antimatter, but next input is another recipe with different output


protected final ChemicalStackIngredient input;
protected final ChemicalStack output;
private final long energy_usage;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable naming wrong - use camelCase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants