Skip to content

Commit

Permalink
Allow Recipe Inputs Without Index
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Jan 9, 2025
1 parent 3d7e58e commit ffabbdd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/main/groovy-tests/jeiTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,26 @@ crafting.shapedBuilder()
*
* They appear AFTER any item tooltips.
*
* You MUST provide a Resource Location of the Recipe Name, and the index of the input.
* You MUST provide a Resource Location of the Recipe Name. You MAY provide an index of the input.
* If you do not provide an index, it will be applied to ALL INPUTS!
*/

// Outside of builder
// Specify an index between 0 and 8! This represents the slot number. It goes from left to right, top to bottom.
// E.g. slot 4 = 2nd row, 2nd column
addRecipeInputTooltip('gregtech:block_decompress_aluminium', 4,
translatableLiteral("This is consumed!!!").addFormat(TooltipHelper.BLINKING_CYAN))

// Outside of builder, no index (applied to all inputs)
addRecipeInputTooltip('gregtech:block_compress_aluminium',
translatableLiteral("This is consumed???").addFormat(TooltipHelper.BLINKING_CYAN))

// In a crafting shaped/shapeless builder
crafting.shapelessBuilder()
.output(item('minecraft:apple'))
.input(item('minecraft:diamond'), item('minecraft:apple'))
// You must specify an index between 0 and 8! This represents the slot number. It goes from left to right, top to bottom.
// E.g. slot 1 = 1st row, 2nd column
.setInputTooltip(1, translatableLiteral('Is a Gold Ingot.').addFormat(TextFormatting.GOLD),
// No index, applied to all inputs
.setInputTooltip(translatableLiteral('Is a Gold Ingot. 100% Pure Quality.').addFormat(TextFormatting.GOLD),
translatable('tooltip.nomilabs.growth_chamber.description'))
.register()

Expand All @@ -98,9 +104,13 @@ crafting.shapedBuilder()
.matrix('AAA', 'ABA', 'ABA')
.key('A', item('minecraft:diamond'))
.key('B', item('minecraft:apple'))
// You must specify an index between 0 and 8! This represents the slot number. It goes from left to right, top to bottom.
// Specify an index between 0 and 8! This represents the slot number. It goes from left to right, top to bottom.
// E.g. slot 1 = 1st row, 2nd column
.setInputTooltip(1, translatableLiteral('Is a Gold Ingot?? No.').addFormat(TextFormatting.GOLD),
translatable('tooltip.nomilabs.growth_chamber.description'))
// Specify an index between 0 and 8! This represents the slot number. It goes from left to right, top to bottom.
// E.g. slot 4 = 2nd row, 2nd column
.setInputTooltip(4, translatableLiteral('Is a Gold Ingot?').addFormat(TextFormatting.GOLD),
.setInputTooltip(4, translatableLiteral('Is a Gold Ingot? Perhaps.').addFormat(TextFormatting.GOLD),
translatable('tooltip.nomilabs.growth_chamber.description'))
.register()

14 changes: 14 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/groovy/GroovyHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,20 @@ public static void addRecipeInputTooltip(String recipeName, int slotIndex,
slotIndex, tooltip);
}

public static void addRecipeInputTooltip(ResourceLocation recipeName,
LabsTranslate.Translatable... tooltip) {
for (int i = 0; i < 9; i++)
LabsJEIPlugin.addGroovyRecipeInputTooltip(recipeName, i, tooltip);
}

public static void addRecipeInputTooltip(String recipeName,
LabsTranslate.Translatable... tooltip) {
if (recipeName.contains(":"))
addRecipeInputTooltip(new ResourceLocation(recipeName), tooltip);
else
addRecipeInputTooltip(new ResourceLocation(GroovyHelper.getPackId(), recipeName), tooltip);
}

/* Hiding Ignore NBT */
public static void hideItemIgnoreNBT(ItemStack stack) {
LabsJEIPlugin.hideItemNBTMatch(stack, (tag) -> true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public CraftingRecipeBuilder.Shapeless setInputTooltip(int slotIndex, LabsTransl
return (CraftingRecipeBuilder.Shapeless) (Object) this;
}

@Unique
public CraftingRecipeBuilder.Shapeless setInputTooltip(LabsTranslate.Translatable... tooltip) {
for (int i = 0; i < 9; i++)
setInputTooltip(i, tooltip);
return (CraftingRecipeBuilder.Shapeless) (Object) this;
}

@Inject(method = "register()Lnet/minecraft/item/crafting/IRecipe;", at = @At("RETURN"))
private void setStrict(CallbackInfoReturnable<IRecipe> cir) {
var val = cir.getReturnValue();
Expand Down

0 comments on commit ffabbdd

Please sign in to comment.