Skip to content
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

Added mouse input handler and key input handle for JemiRecipe #319

Merged
merged 6 commits into from
Sep 30, 2023

Conversation

Sleepwalkerx
Copy link
Contributor

I don't know for what reason it wasn't implemented, but due to the absence of this code, JEI recipes don't handle clicks and keystrokes.

@emilyploszaj
Copy link
Owner

It is a bit silly that it was never implemented. However, I don't really want to add and expose an API like this on DrawableWidget. It'd be fine to just create a new widget for JEMI input events that doesn't render anything.

@Sleepwalkerx
Copy link
Contributor Author

Well, I made this code based on how you made DrawableWidget. I saw that you were creating a Consumer and decided to do it in the same style.
OK, then you propose to completely abandon DrawableWidget and make a separate widget for Jemi, or you want to create two widgets, but one for rendering and the other for intercepting inputs?

@Sleepwalkerx
Copy link
Contributor Author

Just if I understand you correctly, you want to create two widgets on top of each other, only one will be with a render, and the other without.
I don't see the point in this when you can just move all the logic (including render and tooltips) to a new JemiWidget.

@emilyploszaj
Copy link
Owner

I was suggesting leaving the drawable widget as it is, and adding a new widget, even just an anonymous or internal class, that just handles the input events.

Thinking about it though, a new custom widget class (inside JemiRecipe) that handles rendering, tooltips, and input events for the JEMI display would probably be reasonable.

@Sleepwalkerx
Copy link
Contributor Author

I did as you said. Check it out.

@SiverDX
Copy link

SiverDX commented Sep 29, 2023

EmiDrawContext context = EmiDrawContext.wrap(draw);
context.push();
context.matrices().translate(x, y, 0);
EmiDrawContext emiDrawContext = EmiDrawContext.wrap(context.raw());
category.getBackground().draw(context.raw());
category.draw(recipe, recipeLayoutDrawable.getRecipeSlotsView(), context.raw(), mouseX, mouseY);
emiDrawContext.resetColor();
context.pop();

why are you creating a second EmiDrawContext

@Sleepwalkerx
Copy link
Contributor Author

EmiDrawContext context = EmiDrawContext.wrap(draw);
context.push();
context.matrices().translate(x, y, 0);
EmiDrawContext emiDrawContext = EmiDrawContext.wrap(context.raw());
category.getBackground().draw(context.raw());
category.draw(recipe, recipeLayoutDrawable.getRecipeSlotsView(), context.raw(), mouseX, mouseY);
emiDrawContext.resetColor();
context.pop();

why are you creating a second EmiDrawContext

because it is done in the original logic. I don't want to break anything...

@Sleepwalkerx
Copy link
Contributor Author

I removed it.

Copy link
Owner

@emilyploszaj emilyploszaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the comment I have it looks good to me. Have you tested this with mods that use JEI's input features to make sure it works?

public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
MinecraftClient client = MinecraftClient.getInstance();
double mouseX = client.mouse.getX() * (double)client.getWindow().getScaledWidth() / (double)client.getWindow().getWidth();
double mouseY = client.mouse.getY() * (double)client.getWindow().getScaledHeight() / (double)client.getWindow().getHeight();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to use EmiScreenManager.lastMouseX and EmiScreenManager.lastMouseY just to reduce the use of calculations.

@Sleepwalkerx
Copy link
Contributor Author

Other than the comment I have it looks good to me. Have you tested this with mods that use JEI's input features to make sure it works?

Initially, I discovered this problem when using the CustomMachinery mod and after these changes, the click in JEI began to work normally for CM. In general, I think it will work fine.

@emilyploszaj emilyploszaj merged commit b773b7b into emilyploszaj:1.20 Sep 30, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants