-
Notifications
You must be signed in to change notification settings - Fork 6
Make recipe viewer slots more generic and fix some emi stuff #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
23918a8
start working on generic recipe viewer slot
gustovafing e0b9ab8
get rendering working
gustovafing bd3a527
update background rendering
gustovafing 06b1bb0
fix size
gustovafing 5a23f75
make text widget use a supplier
gustovafing c8bc64e
fix recursion error
gustovafing 40890cb
fix value init
gustovafing c60390d
make text non final
gustovafing b4c8114
revert test machine change
gustovafing cd26aa6
fix stuff
gustovafing c85c9d3
use emi/rei stack converter classes
gustovafing 6754978
fix
gustovafing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
108 changes: 108 additions & 0 deletions
108
src/main/java/brachy/modularui/integration/emi/EmiRecipeViewerSlot.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package brachy.modularui.integration.emi; | ||
|
|
||
| import brachy.modularui.drawable.ClientTooltipComponentIcon; | ||
| import brachy.modularui.drawable.GuiTextures; | ||
| import brachy.modularui.integration.recipeviewer.RecipeSlotRole; | ||
| import brachy.modularui.integration.recipeviewer.RecipeViewerSlotWidget; | ||
| import brachy.modularui.integration.recipeviewer.entry.EntryList; | ||
| import brachy.modularui.integration.recipeviewer.entry.fluid.FluidEntryList; | ||
| import brachy.modularui.integration.recipeviewer.entry.item.ItemEntryList; | ||
|
|
||
| import brachy.modularui.screen.viewport.ModularGuiContext; | ||
| import brachy.modularui.theme.WidgetThemeEntry; | ||
|
|
||
| import dev.emi.emi.api.stack.EmiIngredient; | ||
| import dev.emi.emi.api.widget.SlotWidget; | ||
|
|
||
| import dev.emi.emi.api.widget.TankWidget; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import lombok.experimental.Accessors; | ||
|
|
||
| import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; | ||
| import net.minecraft.world.item.crafting.Ingredient; | ||
|
|
||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| public class EmiRecipeViewerSlot extends RecipeViewerSlotWidget<EmiRecipeViewerSlot> { | ||
|
|
||
| @ApiStatus.Internal | ||
| @Getter | ||
| private SlotWidget slotWidget; | ||
| private int x, y; | ||
|
|
||
| @Accessors(fluent = true) | ||
| @Getter | ||
| private RecipeSlotRole recipeSlotRole; | ||
| private EntryList<?> value; | ||
| @Accessors(fluent = true) | ||
| @Getter | ||
| @Setter | ||
| private float chance = 1f; | ||
|
|
||
| public EmiRecipeViewerSlot() { | ||
| super(); | ||
| slotWidget = new SlotWidget(EmiIngredient.of(Ingredient.EMPTY), 0, 0); | ||
| recipeSlotRole = RecipeSlotRole.RENDER_ONLY; | ||
|
|
||
| size(18, 18); | ||
|
|
||
| tooltipAutoUpdate(true); | ||
| tooltipDynamic(tooltip -> { | ||
| for (ClientTooltipComponent ctc : this.slotWidget.getTooltip(getContext().getAbsMouseX(), getContext().getAbsMouseY())) { | ||
| tooltip.addDrawableLine(new ClientTooltipComponentIcon(ctc)); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public EmiRecipeViewerSlot recipeSlotRole(RecipeSlotRole recipeSlotRole) { | ||
| this.recipeSlotRole = recipeSlotRole; | ||
| slotWidget.catalyst(recipeSlotRole == RecipeSlotRole.CATALYST); | ||
| return getThis(); | ||
| } | ||
|
|
||
| @Override | ||
| public EmiRecipeViewerSlot value(FluidEntryList fluidEntryList) { | ||
| value = fluidEntryList; | ||
| rebuildEmiSlot(); | ||
| background(GuiTextures.SLOT_FLUID); | ||
| return getThis(); | ||
| } | ||
|
|
||
| @Override | ||
| public EmiRecipeViewerSlot value(ItemEntryList itemEntryList) { | ||
| value = itemEntryList; | ||
| rebuildEmiSlot(); | ||
| background(GuiTextures.SLOT_ITEM); | ||
| return getThis(); | ||
| } | ||
|
|
||
| private void rebuildEmiSlot() { | ||
| if (value instanceof ItemEntryList itemEntryList) { | ||
| slotWidget = new SlotWidget(EmiStackConverter.ITEM.convertTo(itemEntryList, chance), 0, 0); | ||
| } else if (value instanceof FluidEntryList fluidEntryList) { | ||
| slotWidget = new TankWidget(EmiStackConverter.FLUID.convertTo(fluidEntryList, chance), 0, 0, 18, 18, 1); | ||
| } | ||
| slotWidget.drawBack(false); | ||
| } | ||
|
|
||
| @Override | ||
| public void draw(ModularGuiContext context, WidgetThemeEntry<?> widgetTheme) { | ||
| context.getGraphics().pose().translate(-this.x, -this.y, 0); | ||
| this.slotWidget.render(context.getGraphics(), context.getMouseX(), context.getMouseY(), context.getRenderPartialTicks()); | ||
| context.getGraphics().pose().translate(this.x, this.y, 0); | ||
| } | ||
|
|
||
| @Override | ||
| public Result onMousePressed(int button) { | ||
| this.slotWidget.mouseClicked(getContext().getMouseX(), getContext().getAbsMouseY(), button); | ||
| return Result.SUCCESS; | ||
| } | ||
|
|
||
| @Override | ||
| public Result onKeyPressed(int keyCode, int scanCode, int modifiers) { | ||
| return this.slotWidget.keyPressed(keyCode, scanCode, modifiers) ? Result.SUCCESS : Result.ACCEPT; | ||
| } | ||
| } | ||
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
52 changes: 0 additions & 52 deletions
52
src/main/java/brachy/modularui/integration/emi/recipe/EMISlotWidgetWrapper.java
This file was deleted.
Oops, something went wrong.
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
56 changes: 56 additions & 0 deletions
56
src/main/java/brachy/modularui/integration/jei/JeiIngredientHandler.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package brachy.modularui.integration.jei; | ||
|
|
||
| import brachy.modularui.integration.recipeviewer.entry.fluid.FluidEntryList; | ||
| import brachy.modularui.integration.recipeviewer.entry.item.ItemEntryList; | ||
|
|
||
| import mezz.jei.common.input.ClickableIngredient; | ||
| import mezz.jei.common.util.ImmutableRect2i; | ||
|
|
||
| import net.minecraft.world.item.ItemStack; | ||
| import net.minecraftforge.fluids.FluidStack; | ||
|
|
||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static brachy.modularui.integration.jei.ModularUIJeiPlugin.jeiHelpers; | ||
|
|
||
| public class JeiIngredientHandler { | ||
|
|
||
| public static List<ItemStack> toJeiIngredient(ItemEntryList list) { | ||
| return list.getStacks() | ||
| .stream() | ||
| .filter(stack -> !stack.isEmpty()) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public static List<FluidStack> toJeiIngredient(FluidEntryList list) { | ||
| return list.getStacks() | ||
| .stream() | ||
| .filter(stack -> !stack.isEmpty()) | ||
| .toList(); | ||
| } | ||
|
|
||
| public static <T> @Nullable ClickableIngredient<T> getJEIStackClickable(T stack, int x, int y, int w, int h) { | ||
| return jeiHelpers.getIngredientManager().createTypedIngredient(stack) | ||
| .map(typedIngredient -> new ClickableIngredient<>(typedIngredient, new ImmutableRect2i(x, y, w, h))) | ||
| .orElse(null); | ||
| } | ||
|
|
||
| public static List<ClickableIngredient<ItemStack>> toJeiIngredientClickable(ItemEntryList list, int x, int y, int w, int h) { | ||
| return list.getStacks() | ||
| .stream() | ||
| .filter(stack -> !stack.isEmpty()) | ||
| .map(stack -> getJEIStackClickable(stack, x, y, w, h)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public static List<ClickableIngredient<FluidStack>> toJeiIngredientClickable(FluidEntryList list, int x, int y, int w, int h) { | ||
| return list.getStacks() | ||
| .stream() | ||
| .filter(stack -> !stack.isEmpty()) | ||
| .map(stack -> getJEIStackClickable(stack, x, y, w, h)) | ||
| .toList(); | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this hardcoded to items and fluids?