Fix validation for item and fluid tags#4699
Merged
gustovafing merged 5 commits intoGregTechCEu:1.20.1from Mar 5, 2026
Merged
Conversation
gustovafing
approved these changes
Mar 5, 2026
screret
reviewed
Mar 5, 2026
src/main/java/com/gregtechceu/gtceu/integration/kjs/recipe/KJSHelpers.java
Show resolved
Hide resolved
gustovafing
pushed a commit
that referenced
this pull request
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When you use an incorrect item tag in a KubeJS recipe input for GT machines, the error you get is very non-descriptive:
Error in 'ServerEvents.recipes': Index 0 out of bounds for length 0For incorrect fluid tags it's even worse, the recipe just gets registered without errors but the fluid input will require 20mB of nothing.
A broken item tag here can also mean a valid item tag that has no items registered in it.
This PR fixes checks for tags as inputs.
Implementation Details
The problem with the item tags is that the validation checks
if (stack == null || stack.isEmpty()), however a tag Ingredient always has one TagValue in values, so isEmpty() is always false.It's solved by checking the number of items in the item tag and throwing a descriptive error when it's zero.
The problem with fluid tags is similar, but there's an additional issue. Tags aren't actually bound to their items/fluids yet in minecraft's registries during this phase of the recipe loading. KubeJS gets around this by mixing in on getItems (
IngredientTagValueMixin.kjs$getItems) and resolving the binding itself inTagContext.patchIngredientTags.Since GTCEu owns Fluid Ingredients, we can just patch it in without a mixin. Needs a little indirection to handle the case where KubeJS is not present though.
With that, fluid tags are checked the same way as items.
Outcome
Incorrect item and fluid tags are caught and reported clearly.

Additional Info
Example broken recipes:
Potential compatibility issues
I haven't tested this without KubeJS, but this indirection guard is used in other places in the repo without issue.
Tested against 7.5.2 on 1.20.1 but presumably this applies to 8.0.0 too.