-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show a placeholder error recipe when a recipe layout crashes
- Loading branch information
Showing
10 changed files
with
291 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
92 changes: 92 additions & 0 deletions
92
Gui/src/main/java/mezz/jei/gui/input/handlers/OffsetJeiInputHandler.java
This file contains 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,92 @@ | ||
package mezz.jei.gui.input.handlers; | ||
|
||
import com.mojang.blaze3d.platform.InputConstants; | ||
import mezz.jei.api.gui.inputs.IJeiInputHandler; | ||
import mezz.jei.api.gui.inputs.IJeiUserInput; | ||
import mezz.jei.common.util.MathUtil; | ||
import net.minecraft.client.gui.navigation.ScreenPosition; | ||
import net.minecraft.client.gui.navigation.ScreenRectangle; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class OffsetJeiInputHandler implements IJeiInputHandler { | ||
private final IJeiInputHandler inputHandler; | ||
private final Supplier<ScreenPosition> offset; | ||
|
||
public OffsetJeiInputHandler(IJeiInputHandler inputHandler, Supplier<ScreenPosition> offset) { | ||
this.inputHandler = inputHandler; | ||
this.offset = offset; | ||
} | ||
|
||
@Override | ||
public boolean handleInput(double mouseX, double mouseY, IJeiUserInput input) { | ||
ScreenPosition screenPosition = offset.get(); | ||
final double offsetMouseX = mouseX - screenPosition.x(); | ||
final double offsetMouseY = mouseY - screenPosition.y(); | ||
|
||
ScreenRectangle originalArea = inputHandler.getArea(); | ||
if (MathUtil.contains(originalArea, offsetMouseX, offsetMouseY)) { | ||
ScreenPosition position = originalArea.position(); | ||
double relativeMouseX = offsetMouseX - position.x(); | ||
double relativeMouseY = offsetMouseY - position.y(); | ||
return inputHandler.handleInput(relativeMouseX, relativeMouseY, input); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public boolean handleMouseScrolled(double mouseX, double mouseY, double scrollDeltaX, double scrollDeltaY) { | ||
ScreenPosition screenPosition = offset.get(); | ||
final double offsetMouseX = mouseX - screenPosition.x(); | ||
final double offsetMouseY = mouseY - screenPosition.y(); | ||
|
||
ScreenRectangle originalArea = inputHandler.getArea(); | ||
if (MathUtil.contains(originalArea, offsetMouseX, offsetMouseY)) { | ||
ScreenPosition position = originalArea.position(); | ||
double relativeMouseX = offsetMouseX - position.x(); | ||
double relativeMouseY = offsetMouseY - position.y(); | ||
return inputHandler.handleMouseScrolled(relativeMouseX, relativeMouseY, scrollDeltaX, scrollDeltaY); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public boolean handleMouseDragged(double mouseX, double mouseY, InputConstants.Key mouseKey, double dragX, double dragY) { | ||
ScreenPosition screenPosition = offset.get(); | ||
final double offsetMouseX = mouseX - screenPosition.x(); | ||
final double offsetMouseY = mouseY - screenPosition.y(); | ||
|
||
ScreenRectangle originalArea = inputHandler.getArea(); | ||
if (MathUtil.contains(originalArea, offsetMouseX, offsetMouseY)) { | ||
ScreenPosition position = originalArea.position(); | ||
double relativeMouseX = offsetMouseX - position.x(); | ||
double relativeMouseY = offsetMouseY - position.y(); | ||
return inputHandler.handleMouseDragged(relativeMouseX, relativeMouseY, mouseKey, dragX, dragY); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public void handleMouseMoved(double mouseX, double mouseY) { | ||
ScreenPosition screenPosition = offset.get(); | ||
final double offsetMouseX = mouseX - screenPosition.x(); | ||
final double offsetMouseY = mouseY - screenPosition.y(); | ||
|
||
ScreenRectangle originalArea = inputHandler.getArea(); | ||
if (MathUtil.contains(originalArea, offsetMouseX, offsetMouseY)) { | ||
ScreenPosition position = originalArea.position(); | ||
double relativeMouseX = offsetMouseX - position.x(); | ||
double relativeMouseY = offsetMouseY - position.y(); | ||
inputHandler.handleMouseMoved(relativeMouseX, relativeMouseY); | ||
} | ||
} | ||
|
||
@Override | ||
public ScreenRectangle getArea() { | ||
ScreenRectangle area = inputHandler.getArea(); | ||
return new ScreenRectangle(offset.get(), area.width(), area.height()); | ||
} | ||
} |
This file contains 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
157 changes: 157 additions & 0 deletions
157
Gui/src/main/java/mezz/jei/gui/recipes/layouts/RecipeLayoutDrawableErrored.java
This file contains 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,157 @@ | ||
package mezz.jei.gui.recipes.layouts; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import mezz.jei.api.gui.IRecipeLayoutDrawable; | ||
import mezz.jei.api.gui.drawable.IScalableDrawable; | ||
import mezz.jei.api.gui.ingredient.IRecipeSlotDrawable; | ||
import mezz.jei.api.gui.ingredient.IRecipeSlotsView; | ||
import mezz.jei.api.gui.inputs.IJeiInputHandler; | ||
import mezz.jei.api.gui.inputs.RecipeSlotUnderMouse; | ||
import mezz.jei.api.gui.widgets.IScrollBoxWidget; | ||
import mezz.jei.api.helpers.IGuiHelper; | ||
import mezz.jei.api.helpers.IJeiHelpers; | ||
import mezz.jei.api.ingredients.IIngredientType; | ||
import mezz.jei.api.recipe.category.IRecipeCategory; | ||
import mezz.jei.api.runtime.IJeiRuntime; | ||
import mezz.jei.common.Internal; | ||
import mezz.jei.common.util.ImmutableRect2i; | ||
import mezz.jei.gui.input.handlers.OffsetJeiInputHandler; | ||
import net.minecraft.ChatFormatting; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.navigation.ScreenPosition; | ||
import net.minecraft.client.renderer.Rect2i; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.FormattedText; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public class RecipeLayoutDrawableErrored<R> implements IRecipeLayoutDrawable<R> { | ||
private final IRecipeCategory<R> recipeCategory; | ||
private final R recipe; | ||
private final IScrollBoxWidget scrollBoxWidget; | ||
private final IJeiInputHandler inputHandler; | ||
private final IScalableDrawable background; | ||
private final int borderPadding; | ||
private ImmutableRect2i area; | ||
|
||
public RecipeLayoutDrawableErrored(IRecipeCategory<R> recipeCategory, R recipe, IScalableDrawable background, int borderPadding) { | ||
this.recipeCategory = recipeCategory; | ||
this.recipe = recipe; | ||
this.area = new ImmutableRect2i(0, 0, Math.max(100, recipeCategory.getWidth()), recipeCategory.getHeight()); | ||
this.background = background; | ||
this.borderPadding = borderPadding; | ||
|
||
List<FormattedText> lines = new ArrayList<>(); | ||
lines.add(Component.translatable("gui.jei.category.recipe.crashed").withStyle(ChatFormatting.RED)); | ||
lines.add(Component.empty()); | ||
lines.add(Component.literal(recipeCategory.getRecipeType().getUid().toString()).withStyle(ChatFormatting.GRAY)); | ||
ResourceLocation registryName = recipeCategory.getRegistryName(recipe); | ||
if (registryName != null) { | ||
lines.add(Component.empty()); | ||
lines.add(Component.literal(registryName.toString()).withStyle(ChatFormatting.GRAY)); | ||
} | ||
|
||
IJeiRuntime jeiRuntime = Internal.getJeiRuntime(); | ||
IJeiHelpers jeiHelpers = jeiRuntime.getJeiHelpers(); | ||
IGuiHelper guiHelper = jeiHelpers.getGuiHelper(); | ||
this.scrollBoxWidget = guiHelper.createScrollBoxWidget(area.width(), area.getHeight(), 0, 0) | ||
.setContents(lines); | ||
|
||
this.inputHandler = new OffsetJeiInputHandler(this.scrollBoxWidget, this::getScreenPosition); | ||
} | ||
|
||
private ScreenPosition getScreenPosition() { | ||
return this.area.getScreenPosition(); | ||
} | ||
|
||
@Override | ||
public void setPosition(int posX, int posY) { | ||
this.area = this.area.setPosition(posX, posY); | ||
} | ||
|
||
@Override | ||
public void drawRecipe(GuiGraphics guiGraphics, int mouseX, int mouseY) { | ||
background.draw(guiGraphics, getRectWithBorder()); | ||
|
||
PoseStack poseStack = guiGraphics.pose(); | ||
poseStack.pushPose(); | ||
{ | ||
poseStack.translate(area.x(), area.y(), 0); | ||
scrollBoxWidget.draw(guiGraphics, mouseX, mouseY); | ||
} | ||
poseStack.popPose(); | ||
} | ||
|
||
@Override | ||
public void drawOverlays(GuiGraphics guiGraphics, int mouseX, int mouseY) { | ||
|
||
} | ||
|
||
@Override | ||
public boolean isMouseOver(double mouseX, double mouseY) { | ||
return area.contains(mouseX, mouseY); | ||
} | ||
|
||
@Override | ||
public <T> Optional<T> getIngredientUnderMouse(int mouseX, int mouseY, IIngredientType<T> ingredientType) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<IRecipeSlotDrawable> getRecipeSlotUnderMouse(double mouseX, double mouseY) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Optional<RecipeSlotUnderMouse> getSlotUnderMouse(double mouseX, double mouseY) { | ||
return Optional.empty(); | ||
} | ||
|
||
@Override | ||
public Rect2i getRect() { | ||
return area.toMutable(); | ||
} | ||
|
||
@Override | ||
public Rect2i getRectWithBorder() { | ||
return area.expandBy(borderPadding).toMutable(); | ||
} | ||
|
||
@Override | ||
public Rect2i getRecipeTransferButtonArea() { | ||
return new Rect2i(0, 0, 0, 0); | ||
} | ||
|
||
@Override | ||
public Rect2i getRecipeBookmarkButtonArea() { | ||
return new Rect2i(0, 0, 0, 0); | ||
} | ||
|
||
@Override | ||
public IRecipeSlotsView getRecipeSlotsView() { | ||
return List::of; | ||
} | ||
|
||
@Override | ||
public IRecipeCategory<R> getRecipeCategory() { | ||
return recipeCategory; | ||
} | ||
|
||
@Override | ||
public R getRecipe() { | ||
return recipe; | ||
} | ||
|
||
@Override | ||
public IJeiInputHandler getInputHandler() { | ||
return inputHandler; | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
|
||
} | ||
} |
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -74,4 +74,4 @@ modrinthId=u6dRKJwZ | |
jUnitVersion=5.8.2 | ||
|
||
# Version | ||
specificationVersion=19.18.9 | ||
specificationVersion=19.18.10 |