Skip to content

Commit

Permalink
Add more helpers for drawing common recipe elements
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Sep 19, 2024
1 parent be35470 commit 55b258f
Show file tree
Hide file tree
Showing 34 changed files with 387 additions and 147 deletions.
5 changes: 0 additions & 5 deletions Common/src/main/java/mezz/jei/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
import net.minecraft.resources.ResourceLocation;

public final class Constants {
public static final String TEXTURE_GUI_PATH = "textures/jei/gui/";
public static final String TEXTURE_GUI_VANILLA = Constants.TEXTURE_GUI_PATH + "gui_vanilla.png";

public static final ResourceLocation RECIPE_GUI_VANILLA = ResourceLocation.fromNamespaceAndPath(ModIds.JEI_ID, TEXTURE_GUI_VANILLA);

public static final RecipeType<?> UNIVERSAL_RECIPE_TRANSFER_TYPE = RecipeType.create(ModIds.JEI_ID, "universal_recipe_transfer_handler", Object.class);
public static final ResourceLocation LOCATION_JEI_GUI_TEXTURE_ATLAS = ResourceLocation.fromNamespaceAndPath(ModIds.JEI_ID, "textures/atlas/gui.png");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package mezz.jei.common.gui.elements;

import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.api.helpers.IGuiHelper;
import net.minecraft.client.gui.GuiGraphics;

public class DrawableAnimatedRecipeArrow extends DrawableAnimated {
private final IDrawableStatic blankArrow;

public DrawableAnimatedRecipeArrow(IGuiHelper guiHelper, int ticksPerCycle) {
super(guiHelper.getRecipeArrowFilled(), ticksPerCycle, StartDirection.LEFT, false);
this.blankArrow = guiHelper.getRecipeArrow();
}

@Override
public void draw(GuiGraphics guiGraphics, int xOffset, int yOffset) {
this.blankArrow.draw(guiGraphics, xOffset, yOffset);
super.draw(guiGraphics, xOffset, yOffset);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package mezz.jei.common.gui.elements;

import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.api.helpers.IGuiHelper;
import net.minecraft.client.gui.GuiGraphics;

public class DrawableAnimatedRecipeFlame extends DrawableAnimated {
private final IDrawableStatic emptyFlame;

public DrawableAnimatedRecipeFlame(IGuiHelper guiHelper, int ticksPerCycle) {
super(guiHelper.getRecipeFlameFilled(), ticksPerCycle, StartDirection.TOP, true);
this.emptyFlame = guiHelper.getRecipeFlameEmpty();
}

@Override
public void draw(GuiGraphics guiGraphics, int xOffset, int yOffset) {
this.emptyFlame.draw(guiGraphics, xOffset, yOffset);
super.draw(guiGraphics, xOffset, yOffset);
}
}
54 changes: 52 additions & 2 deletions Common/src/main/java/mezz/jei/common/gui/textures/Textures.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class Textures {
private final JeiSpriteUploader spriteUploader;

private final IDrawableStatic slot;
private final IDrawableStatic outputSlot;
private final DrawableNineSliceTexture recipeCatalystSlotBackground;
private final DrawableNineSliceTexture ingredientListSlotBackground;
private final DrawableNineSliceTexture bookmarkListSlotBackground;
Expand Down Expand Up @@ -44,14 +45,23 @@ public class Textures {
private final DrawableNineSliceTexture catalystTab;
private final DrawableNineSliceTexture recipeOptionsTab;
private final IDrawableStatic flameIcon;
private final IDrawableStatic flameEmptyIcon;
private final IDrawableStatic recipeArrow;
private final IDrawableStatic recipeArrowFilled;
private final IDrawableStatic recipePlusSign;
private final IDrawableStatic bookmarksFirst;
private final IDrawableStatic craftableFirst;

private final IDrawableStatic brewingStandBackground;
private final IDrawableStatic brewingStandBlazeHeat;
private final IDrawableStatic brewingStandBubbles;
private final IDrawableStatic brewingStandArrow;

public Textures(JeiSpriteUploader spriteUploader) {
this.spriteUploader = spriteUploader;

this.slot = createGuiSprite("slot", 18, 18);
this.outputSlot = createGuiSprite("output_slot", 26, 26);
this.recipeCatalystSlotBackground = createNineSliceGuiSprite("recipe_catalyst_slot_background", 18, 18, 4, 4, 4, 4);
this.ingredientListSlotBackground = createNineSliceGuiSprite("ingredient_list_slot_background", 18, 18, 4, 4, 4, 4);
this.bookmarkListSlotBackground = createNineSliceGuiSprite("bookmark_list_slot_background", 18, 18, 4, 4, 4, 4);
Expand All @@ -72,7 +82,14 @@ public Textures(JeiSpriteUploader spriteUploader) {
this.scrollbarMarker = createNineSliceGuiSprite("scrollbar_marker", 12, 15, 2, 2, 2, 1);
this.catalystTab = createNineSliceGuiSprite("catalyst_tab", 28, 28, 8, 9, 8, 8);
this.recipeOptionsTab = createNineSliceGuiSprite("recipe_options_tab", 28, 28, 8, 9, 8, 8);
this.recipeArrow = createGuiSprite("recipe_arrow", 22, 15);
this.recipeArrow = createGuiSprite("recipe_arrow", 22, 16);
this.recipeArrowFilled = createGuiSprite("recipe_arrow_filled", 22, 16);
this.recipePlusSign = createGuiSprite("recipe_plus_sign", 13, 13);

this.brewingStandBackground = createGuiSprite("brewing_stand_background", 64, 60);
this.brewingStandBlazeHeat = createGuiSprite("brewing_stand_blaze_heat", 18, 4);
this.brewingStandBubbles = createGuiSprite("brewing_stand_bubbles", 11, 28);
this.brewingStandArrow = createGuiSprite("brewing_stand_arrow", 7, 27);

DrawableSprite rawShapelessIcon = createGuiSprite("icons/shapeless_icon", 36, 36)
.trim(1, 2, 1, 1);
Expand All @@ -90,6 +107,7 @@ public Textures(JeiSpriteUploader spriteUploader) {
this.bookmarkButtonEnabledIcon = createGuiSprite("icons/bookmark_button_enabled", 16, 16);
this.infoIcon = createGuiSprite("icons/info", 16, 16);
this.flameIcon = createGuiSprite("icons/flame", 14, 14);
this.flameEmptyIcon = createGuiSprite("icons/flame_empty", 14, 14);
this.bookmarksFirst = createGuiSprite("icons/bookmarks_first", 16, 16);
this.craftableFirst = createGuiSprite("icons/craftable_first", 16, 16);
}
Expand All @@ -108,10 +126,14 @@ private DrawableNineSliceTexture createNineSliceGuiSprite(String name, int width
return new DrawableNineSliceTexture(spriteUploader, location, width, height, left, right, top, bottom);
}

public IDrawableStatic getSlotDrawable() {
public IDrawableStatic getSlot() {
return slot;
}

public IDrawableStatic getOutputSlot() {
return outputSlot;
}

public IDrawableStatic getTabSelected() {
return tabSelected;
}
Expand Down Expand Up @@ -216,6 +238,14 @@ public IDrawableStatic getRecipeArrow() {
return recipeArrow;
}

public IDrawableStatic getRecipeArrowFilled() {
return recipeArrowFilled;
}

public IDrawableStatic getRecipePlusSign() {
return recipePlusSign;
}

public DrawableNineSliceTexture getRecipeCatalystSlotBackground() {
return recipeCatalystSlotBackground;
}
Expand All @@ -232,6 +262,10 @@ public IDrawableStatic getFlameIcon() {
return flameIcon;
}

public IDrawableStatic getFlameEmptyIcon() {
return flameEmptyIcon;
}

public DrawableNineSliceTexture getScrollbarMarker() {
return scrollbarMarker;
}
Expand All @@ -240,6 +274,22 @@ public DrawableNineSliceTexture getScrollbarBackground() {
return scrollbarBackground;
}

public IDrawableStatic getBrewingStandBackground() {
return brewingStandBackground;
}

public IDrawableStatic getBrewingStandBlazeHeat() {
return brewingStandBlazeHeat;
}

public IDrawableStatic getBrewingStandBubbles() {
return brewingStandBubbles;
}

public IDrawableStatic getBrewingStandArrow() {
return brewingStandArrow;
}

public JeiSpriteUploader getSpriteUploader() {
return spriteUploader;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,24 @@ public interface IRecipeSlotBuilder extends IIngredientAcceptor<IRecipeSlotBuild

/**
* Set a normal slot background to draw behind the slot's ingredients.
* This background is 18x18 pixels and offset by -1, -1 to match vanilla slots.
* This background is 18x18 pixels and offset by (-1, -1) to match vanilla slots.
*
* @see IGuiHelper#getSlotDrawable() for the slot background drawable.
*
* @since 19.18.7
*/
IRecipeSlotBuilder setStandardSlotBackground();

/**
* Set a normal slot background to draw behind the slot's ingredients.
* This background is 26x26 pixels and offset by (-5, -5) to match vanilla output slots.
*
* @see IGuiHelper#getOutputSlot() for the slot background drawable.
*
* @since 19.18.8
*/
IRecipeSlotBuilder setOutputSlotBackground();

/**
* Set a custom background to draw behind the slot's ingredients.
*
Expand Down
77 changes: 76 additions & 1 deletion CommonApi/src/main/java/mezz/jei/api/helpers/IGuiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mezz.jei.api.gui.drawable.IDrawableBuilder;
import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.api.gui.ingredient.ICraftingGridHelper;
import mezz.jei.api.gui.widgets.IRecipeWidget;
import mezz.jei.api.gui.widgets.IScrollBoxWidget;
import mezz.jei.api.gui.widgets.IScrollGridWidgetFactory;
import mezz.jei.api.gui.widgets.ISlottedWidgetFactory;
Expand Down Expand Up @@ -52,10 +53,77 @@ default IDrawableStatic createDrawable(ResourceLocation resourceLocation, int u,
IDrawableAnimated createAnimatedDrawable(IDrawableStatic drawable, int ticksPerCycle, IDrawableAnimated.StartDirection startDirection, boolean inverted);

/**
* Returns a slot drawable for drawing extra slots on guis
* Creates an animated texture for a gui, revealing the texture over time.
*
* @param drawable the underlying texture to draw
* @param tickTimer a timer to help render things that normally depend on ticks
* @param startDirection the direction that the animation starts drawing the texture
*
* @since 19.18.8
*/
IDrawableAnimated createAnimatedDrawable(IDrawableStatic drawable, ITickTimer tickTimer, IDrawableAnimated.StartDirection startDirection);

/**
* Returns a vanilla-style slot for drawing on guis.
*/
IDrawableStatic getSlotDrawable();

/**
* Returns a vanilla-style large output slot for drawing on guis.
*
* @since 19.18.8
*/
IDrawableStatic getOutputSlot();

/**
* Returns a vanilla-style recipe arrow for drawing on guis.
*
* @since 19.18.8
*/
IDrawableStatic getRecipeArrow();

/**
* Returns a vanilla-style filled (white) recipe arrow for drawing on guis.
*
* @since 19.18.8
*/
IDrawableStatic getRecipeArrowFilled();

/**
* Returns a vanilla-style recipe arrow that fills over time, for drawing on guis.
*
* @since 19.18.8
*/
IDrawableAnimated createAnimatedRecipeArrow(int ticksPerCycle);

/**
* Returns a vanilla-style grey plus sign for drawing on guis.
*
* @since 19.18.8
*/
IDrawableStatic getRecipePlusSign();

/**
* Returns a vanilla-style recipe flame (red) for drawing on guis.
*
* @since 19.18.8
*/
IDrawableStatic getRecipeFlameFilled();

/**
* Returns a vanilla-style recipe flame background (grey) for drawing on guis.
*
* @since 19.18.8
*/
IDrawableStatic getRecipeFlameEmpty();

/**
* Returns a vanilla-style recipe flame that empties over time, for drawing on guis.
*
* @since 19.18.8
*/
IDrawableAnimated createAnimatedRecipeFlame(int ticksPerCycle);

/**
* Returns a blank drawable for using as a blank recipe background.
*/
Expand Down Expand Up @@ -128,6 +196,13 @@ default IDrawable createDrawableItemLike(ItemLike itemLike) {
*/
int getScrollBoxScrollbarExtraWidth();

/**
* Create a simple widget from an {@link IDrawable}
*
* @since 19.18.8
*/
IRecipeWidget createWidgetFromDrawable(IDrawable drawable, int xPos, int yPos);

/**
* Create a timer to help with rendering things that normally depend on ticks.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public <T> void setInputs(List<IRecipeSlotBuilder> slotBuilders, IIngredientType

@Override
public <T> IRecipeSlotBuilder createAndSetOutputs(IRecipeLayoutBuilder builder, IIngredientType<T> ingredientType, @Nullable List<@Nullable T> outputs) {
IRecipeSlotBuilder outputSlot = builder.addSlot(RecipeIngredientRole.OUTPUT, 95, 19);
IRecipeSlotBuilder outputSlot = builder.addSlot(RecipeIngredientRole.OUTPUT, 95, 19)
.setOutputSlotBackground();
if (outputs != null) {
outputSlot.addIngredients(ingredientType, outputs);
}
Expand All @@ -105,7 +106,8 @@ private static List<IRecipeSlotBuilder> createInputSlots(IRecipeLayoutBuilder bu
List<IRecipeSlotBuilder> inputSlots = new ArrayList<>();
for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 3; ++x) {
IRecipeSlotBuilder slot = builder.addSlot(RecipeIngredientRole.INPUT, x * 18 + 1, y * 18 + 1);
IRecipeSlotBuilder slot = builder.addSlot(RecipeIngredientRole.INPUT, x * 18 + 1, y * 18 + 1)
.setStandardSlotBackground();
inputSlots.add(slot);
}
}
Expand Down
Loading

0 comments on commit 55b258f

Please sign in to comment.