-
Notifications
You must be signed in to change notification settings - Fork 11
Implementations of Jei and Rei recipe viewer slots #78
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
base: 1.20.1
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,52 @@ | ||
| package brachy.modularui.integration.jei; | ||
|
|
||
| import brachy.modularui.api.drawable.IDrawable; | ||
| import brachy.modularui.api.widget.IWidget; | ||
| 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.widget.Widget; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
| import lombok.experimental.Accessors; | ||
| import mezz.jei.api.gui.builder.IRecipeSlotBuilder; | ||
| import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable; | ||
|
|
||
| import net.minecraftforge.fluids.FluidStack; | ||
|
|
||
| import org.apache.commons.lang3.NotImplementedException; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| @ApiStatus.Experimental | ||
| public class JeiRecipeViewerSlot extends RecipeViewerSlotWidget<JeiRecipeViewerSlot> { | ||
| @Accessors(fluent = true) | ||
| @Getter | ||
| @Setter | ||
| private RecipeSlotRole recipeSlotRole; | ||
| @Getter | ||
| private EntryList<?> value; | ||
| @Accessors(fluent = true) | ||
| @Getter | ||
| @Setter | ||
| private float chance = 1f; | ||
|
|
||
| public JeiRecipeViewerSlot() { | ||
| throw new NotImplementedException(); | ||
| } | ||
| recipeSlotRole = RecipeSlotRole.RENDER_ONLY; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this assigned somewhere else, or?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the field has
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh righto |
||
|
|
||
| @Override | ||
| public JeiRecipeViewerSlot recipeSlotRole(RecipeSlotRole recipeSlotRole) { | ||
| return getThis(); | ||
| size(18, 18); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> JeiRecipeViewerSlot value(EntryList<T> entryList) { | ||
| return getThis(); | ||
| } | ||
|
|
||
| @Override | ||
| public JeiRecipeViewerSlot chance(float chance) { | ||
| this.value = entryList; | ||
| if (this.value.getType() == FluidStack.class) { | ||
| background(GuiTextures.SLOT_FLUID); | ||
| } else { | ||
| background(GuiTextures.SLOT_ITEM); // TODO other types | ||
| } | ||
| return getThis(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,31 +1,104 @@ | ||||||||||||||||
| package brachy.modularui.integration.rei; | ||||||||||||||||
|
|
||||||||||||||||
| 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.screen.viewport.ModularGuiContext; | ||||||||||||||||
| import brachy.modularui.theme.WidgetThemeEntry; | ||||||||||||||||
|
|
||||||||||||||||
| import org.apache.commons.lang3.NotImplementedException; | ||||||||||||||||
| import me.shedaniel.math.Point; | ||||||||||||||||
| import me.shedaniel.rei.api.client.gui.widgets.Slot; | ||||||||||||||||
|
|
||||||||||||||||
| import me.shedaniel.rei.api.client.gui.widgets.Widgets; | ||||||||||||||||
|
|
||||||||||||||||
| import net.minecraft.world.item.ItemStack; | ||||||||||||||||
| import net.minecraftforge.fluids.FluidStack; | ||||||||||||||||
|
|
||||||||||||||||
| import lombok.Getter; | ||||||||||||||||
| import lombok.Setter; | ||||||||||||||||
| import lombok.experimental.Accessors; | ||||||||||||||||
| import org.jetbrains.annotations.ApiStatus; | ||||||||||||||||
|
|
||||||||||||||||
| import java.util.function.UnaryOperator; | ||||||||||||||||
|
|
||||||||||||||||
| @ApiStatus.Experimental | ||||||||||||||||
| public class ReiRecipeViewerSlot extends RecipeViewerSlotWidget<ReiRecipeViewerSlot> { | ||||||||||||||||
|
|
||||||||||||||||
| @ApiStatus.Internal | ||||||||||||||||
| @Getter | ||||||||||||||||
| private Slot slotWidget; | ||||||||||||||||
| private int x, y; | ||||||||||||||||
|
|
||||||||||||||||
| @Accessors(fluent = true) | ||||||||||||||||
| @Getter | ||||||||||||||||
| private RecipeSlotRole recipeSlotRole; | ||||||||||||||||
| @Getter | ||||||||||||||||
| private EntryList<?> value; | ||||||||||||||||
| @Accessors(fluent = true) | ||||||||||||||||
| @Getter | ||||||||||||||||
| @Setter | ||||||||||||||||
| private float chance = 1f; | ||||||||||||||||
|
|
||||||||||||||||
| public ReiRecipeViewerSlot() { | ||||||||||||||||
| throw new NotImplementedException(); | ||||||||||||||||
| super(); | ||||||||||||||||
| slotWidget = Widgets.createSlot(new Point()).disableBackground(); | ||||||||||||||||
| recipeSlotRole = RecipeSlotRole.RENDER_ONLY; | ||||||||||||||||
|
|
||||||||||||||||
| size(18, 18); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| @Override | ||||||||||||||||
| public ReiRecipeViewerSlot recipeSlotRole(RecipeSlotRole recipeSlotRole) { | ||||||||||||||||
| this.recipeSlotRole = recipeSlotRole; | ||||||||||||||||
| rebuildReiSlot(); | ||||||||||||||||
| return getThis(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| @Override | ||||||||||||||||
| public <T> ReiRecipeViewerSlot value(EntryList<T> entryList) { | ||||||||||||||||
| this.value = entryList; | ||||||||||||||||
| rebuildReiSlot(); | ||||||||||||||||
| if (this.value.getType() == FluidStack.class) { | ||||||||||||||||
| background(GuiTextures.SLOT_FLUID); | ||||||||||||||||
| } else { | ||||||||||||||||
| background(GuiTextures.SLOT_ITEM); // TODO other types | ||||||||||||||||
| } | ||||||||||||||||
| return getThis(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| @SuppressWarnings("unchecked") | ||||||||||||||||
| private void rebuildReiSlot() { | ||||||||||||||||
| slotWidget = Widgets.createSlot(new Point()).disableBackground(); | ||||||||||||||||
| if (this.value.getType() == ItemStack.class) { | ||||||||||||||||
| slotWidget.entries(REIStackConverter.ITEM.convertTo((EntryList<ItemStack>) this.value, chance, UnaryOperator.identity())); | ||||||||||||||||
| } else if (this.value.getType() == FluidStack.class) { | ||||||||||||||||
| slotWidget.entries(REIStackConverter.FLUID.convertTo((EntryList<FluidStack>) this.value, chance, UnaryOperator.identity())); | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+73
to
+77
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add this method to avoid unchecked generic issues (you could also put it in private static <T> EntryIngredient convertToReiEntry(EntryList<T> entries, float chance) {
return REIStackConverter.getForNullable(entries.getType()).convertTo(entries, chance, UnaryOperator.identity()));
}And then do this:
Suggested change
|
||||||||||||||||
| if (recipeSlotRole == RecipeSlotRole.INPUT) { | ||||||||||||||||
| slotWidget.markInput(); | ||||||||||||||||
| } else if (recipeSlotRole == RecipeSlotRole.OUTPUT) { | ||||||||||||||||
| slotWidget.markOutput(); | ||||||||||||||||
| } else { | ||||||||||||||||
| slotWidget.unmarkInputOrOutput(); | ||||||||||||||||
|
Comment on lines
+82
to
+83
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does REI not have a way to mark an ingredient as a 'catalyst'? |
||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| @Override | ||||||||||||||||
| public ReiRecipeViewerSlot chance(float chance) { | ||||||||||||||||
| return getThis(); | ||||||||||||||||
| 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); | ||||||||||||||||
|
Comment on lines
+89
to
+91
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| @Override | ||||||||||||||||
| public Result onMousePressed(int button) { | ||||||||||||||||
| this.slotWidget.mouseClicked(getContext().getMouseX(), getContext().getAbsMouseY(), button); | ||||||||||||||||
| return Result.SUCCESS; | ||||||||||||||||
|
Comment on lines
+96
to
+97
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, did you intend to use window-relative or absolute cursor positioning here? rn you have a mix of both in this method.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mostly just copied the emi slot for rei and just modified what was nessecary. I would guess the same issue exists in the emi slot |
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| @Override | ||||||||||||||||
| public Result onKeyPressed(int keyCode, int scanCode, int modifiers) { | ||||||||||||||||
| return this.slotWidget.keyPressed(keyCode, scanCode, modifiers) ? Result.SUCCESS : Result.ACCEPT; | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| import brachy.modularui.integration.recipeviewer.handlers.fluid.EmptyFluidTank; | ||
| import brachy.modularui.integration.recipeviewer.util.RecipeScreenRenderingUtil; | ||
| import brachy.modularui.integration.rei.REIStackConverter; | ||
| import brachy.modularui.integration.rei.ReiRecipeViewerSlot; | ||
| import brachy.modularui.screen.ModularPanel; | ||
| import brachy.modularui.screen.ModularScreen; | ||
| import brachy.modularui.utils.memoization.MemoizedSupplier; | ||
|
|
@@ -18,6 +19,8 @@ | |
| import brachy.modularui.widgets.slot.FluidSlot; | ||
| import brachy.modularui.widgets.slot.ItemSlot; | ||
|
|
||
| import me.shedaniel.rei.api.client.gui.widgets.Slot; | ||
|
|
||
| import net.minecraft.client.gui.GuiGraphics; | ||
| import net.minecraft.client.gui.components.events.GuiEventListener; | ||
| import net.minecraft.network.chat.Component; | ||
|
|
@@ -72,16 +75,16 @@ public ModularUIREIDisplay(ResourceLocation recipeId, Supplier<IWidget> widgetSu | |
| }, Duration.ofSeconds(10)); | ||
|
|
||
| WidgetTree.foreachChildBFS(widgetSupplier.get(), widget -> { | ||
| if (!(widget instanceof IngredientProvider<?> provider)) return true; | ||
| if (!(widget instanceof ReiRecipeViewerSlot provider)) return true; | ||
|
|
||
| RecipeSlotRole role = provider.getRecipeRole(); | ||
| RecipeSlotRole role = provider.recipeSlotRole(); | ||
| if (role == RecipeSlotRole.RENDER_ONLY) return true; | ||
|
|
||
| REIStackConverter.Converter<?> converter = REIStackConverter.getForNullable(provider.ingredientClass()); | ||
| REIStackConverter.Converter<?> converter = REIStackConverter.getForNullable(provider.getValue().getType()); | ||
| if (converter == null) return true; | ||
|
|
||
| @SuppressWarnings({"rawtypes", "unchecked"}) | ||
| EntryIngredient ingredient = ((REIStackConverter.Converter) converter).convertTo(provider); | ||
| EntryIngredient ingredient = EntryIngredient.of(provider.getSlotWidget().getEntries()); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does REI's |
||
|
|
||
| switch (role) { | ||
| case INPUT -> inputEntries.add(ingredient); | ||
|
|
@@ -102,44 +105,30 @@ public List<Widget> createWidgets(Rectangle bounds) { | |
| widgets.add(new UIWrapperWidget()); | ||
|
|
||
| WidgetTree.foreachChildBFS(this.screen.get().getMainPanel(), widget -> { | ||
| if (!(widget instanceof IngredientProvider<?> provider)) return true; | ||
| if (!(widget instanceof ReiRecipeViewerSlot provider)) return true; | ||
|
|
||
| RecipeSlotRole role = provider.getRecipeRole(); | ||
| RecipeSlotRole role = provider.recipeSlotRole(); | ||
| if (role == RecipeSlotRole.RENDER_ONLY) return true; | ||
|
|
||
| REIStackConverter.Converter<?> converter = REIStackConverter.getForNullable(provider.ingredientClass()); | ||
| REIStackConverter.Converter<?> converter = REIStackConverter.getForNullable(provider.getValue().getType()); | ||
| if (converter == null) return true; | ||
|
|
||
| @SuppressWarnings({"rawtypes", "unchecked"}) | ||
| EntryIngredient ingredient = ((REIStackConverter.Converter) converter).convertTo(provider); | ||
| EntryIngredient ingredient = EntryIngredient.of(provider.getSlotWidget().getEntries()); | ||
| Area area = widget.getArea(); | ||
|
|
||
| EntryWidget entryWidget = new EntryWidget(new Rectangle(area.x(), area.y(), area.w(), area.h())); | ||
| // Clear the MUI slots and add EMI slots based on them. | ||
| if (provider instanceof ItemSlot itemSlot) { | ||
| itemSlot.slot(RecipeScreenRenderingUtil.EMPTY_ITEM_HANDLER, 0).invisible(); | ||
| } else if (provider instanceof FluidSlot fluidSlot) { | ||
| fluidSlot.syncHandler(EmptyFluidTank.INSTANCE).invisible(); | ||
| } | ||
|
|
||
| entryWidget.background(false) | ||
| .entries(ingredient.castAsList()); | ||
| if (role == RecipeSlotRole.INPUT) { | ||
| entryWidget.markIsInput(); | ||
| } else if (role == RecipeSlotRole.OUTPUT) { | ||
| entryWidget.markIsOutput(); | ||
| } else { | ||
| entryWidget.unmarkInputOrOutput(); | ||
| } | ||
| if (widget instanceof ITooltip<?> tooltip && tooltip.hasTooltip()) { | ||
| if (tooltip.tooltip().getRichText() instanceof RichText richText) { | ||
| Slot entryWidget = provider.getSlotWidget(); | ||
| /* | ||
| if (provider.hasTooltip()) { | ||
| if (provider.tooltip().getRichText() instanceof RichText richText) { | ||
| var textList = richText.getAsText(); | ||
| entryWidget.tooltipProcessor(text -> { | ||
| textList.forEach(line -> line.map(t -> text.add((Component) t), text::add)); | ||
| return text; | ||
| }); | ||
| } | ||
| } | ||
| */ | ||
| widgets.add(entryWidget); | ||
| return true; | ||
| }, true); | ||
|
|
||
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.
remove unused imports & apply other formatting cleanups please