feat: add a proper SPS recipe type - #8404
Conversation
| 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) |
There was a problem hiding this comment.
forgotten translation? output != input
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
I'd prefer if this (and similar) wasn't renamed
There was a problem hiding this comment.
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))); |
There was a problem hiding this comment.
There was a problem hiding this comment.
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))); |
| 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(); |
There was a problem hiding this comment.
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)
| )); | ||
| } | ||
|
|
||
| public static MekanismRecipeSerializer<BasicPhaseShiftingRecipe> phaseShifting(Function3<ChemicalStackIngredient, ChemicalStack, Long, BasicPhaseShiftingRecipe> factory) { |
There was a problem hiding this comment.
This factory and return generic is wrong - it should follow the others and have a RECIPE extends generic
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
should be inputProcessed >= recipe.amount
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
remove todo from code, put in PR description if still needed
| 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. |
There was a problem hiding this comment.
we already have a couple of custom ones ;)
There was a problem hiding this comment.
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 😓
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
variable naming wrong - use camelCase





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