3838import mezz .jei .api .gui .builder .ITooltipBuilder ;
3939import mezz .jei .api .gui .drawable .IDrawable ;
4040import mezz .jei .api .gui .drawable .IDrawableStatic ;
41- import mezz .jei .api .gui .ingredient .IRecipeSlotTooltipCallback ;
42- import mezz .jei .api .gui .ingredient .IRecipeSlotView ;
4341import mezz .jei .api .gui .ingredient .IRecipeSlotsView ;
4442import mezz .jei .api .helpers .IJeiHelpers ;
4543import mezz .jei .api .recipe .IFocusGroup ;
4644import mezz .jei .api .recipe .RecipeIngredientRole ;
4745import mezz .jei .api .recipe .RecipeType ;
48- import mezz .jei .api .recipe .category .IRecipeCategory ;
46+ import mezz .jei .api .recipe .category .AbstractRecipeCategory ;
4947import net .minecraft .client .Minecraft ;
5048import net .minecraft .client .gui .GuiGraphics ;
5149import net .minecraft .network .chat .Component ;
5654import net .neoforged .neoforge .fluids .FluidType ;
5755import org .jetbrains .annotations .Nullable ;
5856
59- class ViewerCategoryJei <D > implements IRecipeCategory <D > {
57+ class ViewerCategoryJei <D > extends AbstractRecipeCategory <D > {
6058 private final IJeiHelpers helpers ;
6159 public final ViewerCategory <D > wrapped ;
6260 public final RecipeType <D > recipeType ;
63- private final IDrawable background , icon , itemSlot , fluidSlot ;
61+ private final IDrawable fluidSlot ;
6462
6563 public ViewerCategoryJei (IJeiHelpers helpers , ViewerCategory <D > wrapped ) {
64+ super (
65+ RecipeType .create (wrapped .id .getNamespace (), wrapped .id .getPath (), wrapped .dataClass ),
66+ wrapped .title ,
67+ DrawableIcon .create (helpers .getGuiHelper (), wrapped .icon ),
68+ wrapped .width - 8 ,
69+ wrapped .height - 8 );
70+
6671 this .helpers = helpers ;
6772 this .wrapped = wrapped ;
6873 this .recipeType = RecipeType .create (wrapped .id .getNamespace (), wrapped .id .getPath (), wrapped .dataClass );
6974
70- this .background = helpers .getGuiHelper ().createBlankDrawable (wrapped .width - 8 , wrapped .height - 8 );
71- this .icon = wrapped .icon instanceof ViewerCategory .Icon .Stack stack ? helpers .getGuiHelper ().createDrawableItemStack (stack .stack ())
72- : new IDrawable () {
73- @ Override
74- public int getWidth () {
75- return 18 ;
76- }
77-
78- @ Override
79- public int getHeight () {
80- return 18 ;
81- }
82-
83- @ Override
84- public void draw (GuiGraphics guiGraphics , int xOffset , int yOffset ) {
85- var texture = (ViewerCategory .Icon .Texture ) wrapped .icon ;
86- guiGraphics .blit (texture .loc (), xOffset - 1 , yOffset - 1 , 0 , texture .u (), texture .v (), 18 , 18 , 256 , 256 );
87- }
88- };
89- this .itemSlot = helpers .getGuiHelper ().getSlotDrawable ();
90- this .fluidSlot = helpers .getGuiHelper ().createDrawable (MachineScreen .SLOT_ATLAS , 18 , 0 , 18 , 18 );
91- }
92-
93- @ Override
94- public RecipeType <D > getRecipeType () {
95- return recipeType ;
96- }
97-
98- @ Override
99- public Component getTitle () {
100- return wrapped .title ;
101- }
102-
103- @ Override
104- public IDrawable getBackground () {
105- return background ;
106- }
107-
108- @ Override
109- public IDrawable getIcon () {
110- return icon ;
75+ var guiHelper = helpers .getGuiHelper ();
76+ this .fluidSlot = guiHelper .createDrawable (MachineScreen .SLOT_ATLAS , 18 , 0 , 18 , 18 );
11177 }
11278
11379 @ Override
@@ -130,8 +96,9 @@ public void invisibleOutput(ItemStack stack) {
13096 }
13197
13298 private ViewerCategory .SlotBuilder slot (RecipeIngredientRole role , int x , int y ) {
133- var slotBuilder = builder .addSlot (role , x - 4 , y - 4 );
134- slotBuilder .setBackground (itemSlot , -1 , -1 );
99+ var slotBuilder = builder .addSlot (role , x - 4 , y - 4 )
100+ .setStandardSlotBackground ();
101+
135102 return new ViewerCategory .SlotBuilder () {
136103 @ Override
137104 public ViewerCategory .SlotBuilder variant (TransferVariant <?> variant ) {
@@ -150,23 +117,11 @@ public ViewerCategory.SlotBuilder variant(TransferVariant<?> variant) {
150117 }
151118
152119 private static void addProbability (IRecipeSlotBuilder slot , float probability ) {
153- slot .addTooltipCallback (new IRecipeSlotTooltipCallback () {
154- @ Override
155- public void onTooltip (IRecipeSlotView recipeSlotView , List <Component > tooltip ) {
156- var input = recipeSlotView .getRole () == RecipeIngredientRole .INPUT ;
157- var probabilityLine = ViewerUtil .getProbabilityTooltip (probability , input );
158- if (probabilityLine != null ) {
159- tooltip .add (probabilityLine );
160- }
161- }
162-
163- @ Override
164- public void onRichTooltip (IRecipeSlotView recipeSlotView , ITooltipBuilder tooltip ) {
165- var input = recipeSlotView .getRole () == RecipeIngredientRole .INPUT ;
166- var probabilityLine = ViewerUtil .getProbabilityTooltip (probability , input );
167- if (probabilityLine != null ) {
168- tooltip .add (probabilityLine );
169- }
120+ slot .addRichTooltipCallback ((recipeSlotView , tooltip ) -> {
121+ var input = recipeSlotView .getRole () == RecipeIngredientRole .INPUT ;
122+ var probabilityLine = ViewerUtil .getProbabilityTooltip (probability , input );
123+ if (probabilityLine != null ) {
124+ tooltip .add (probabilityLine );
170125 }
171126 });
172127 }
@@ -218,6 +173,7 @@ public ViewerCategory.SlotBuilder markCatalyst() {
218173
219174 @ Override
220175 public void draw (D recipe , IRecipeSlotsView recipeSlotsView , GuiGraphics guiGraphics , double mouseX , double mouseY ) {
176+ guiGraphics .pose ().pushPose ();
221177 guiGraphics .pose ().translate (-4 , -4 , 0 );
222178
223179 wrapped .buildWidgets (recipe , new ViewerCategory .WidgetList () {
@@ -254,7 +210,7 @@ public void drawable(Consumer<GuiGraphics> widget) {
254210 @ Override
255211 public void item (double x , double y , double w , double h , ItemLike item ) {
256212 guiGraphics .pose ().pushPose ();
257- var drawable = helpers .getGuiHelper ().createDrawableItemStack (item . asItem (). getDefaultInstance () );
213+ var drawable = helpers .getGuiHelper ().createDrawableItemLike (item );
258214 guiGraphics .pose ().translate (x , y , 0 );
259215 guiGraphics .pose ().scale ((float ) w / 16 , (float ) h / 16 , 0 );
260216 drawable .draw (guiGraphics );
@@ -265,6 +221,8 @@ public void item(double x, double y, double w, double h, ItemLike item) {
265221 public void tooltip (int x , int y , int w , int h , List <Component > tooltip ) {
266222 }
267223 });
224+
225+ guiGraphics .pose ().popPose ();
268226 }
269227
270228 @ Override
0 commit comments