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

Fix recipe book crashes #1121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,4 @@

public interface RecipeTab extends RecipeAreaDisplay {
ItemStack icon();

/**
* If this tab does not use the search bar then no-op this.
*/
void initializeSearchResults(String query);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookResults;
import net.minecraft.client.gui.widget.ToggleButtonWidget;
import net.minecraft.component.DataComponentTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,40 @@ public void initialize(MinecraftClient client, int parentLeft, int parentTop) {
@Override
public void draw(DrawContext context, int x, int y, int mouseX, int mouseY, float delta) {
assert recipeBook.searchField != null;
recipeBook.searchField.render(context, mouseX, mouseY, delta);
recipeBook.filterOption.render(context, mouseX, mouseY, delta);
results.draw(context, x, y, mouseX, mouseY, delta);

if (ItemRepository.filesImported()) {
recipeBook.searchField.render(context, mouseX, mouseY, delta);
recipeBook.filterOption.render(context, mouseX, mouseY, delta);
results.draw(context, x, y, mouseX, mouseY, delta);
} else {
//68 is from 137 / 2 and 137 is the height from which the page flip buttons are rendered
context.drawCenteredTextWithShadow(MinecraftClient.getInstance().textRenderer, "Loading...", x + (SkyblockRecipeBookWidget.IMAGE_WIDTH / 2), y + 68, 0xFFFFFFFF);
}
}

@Override
public void drawTooltip(DrawContext context, int x, int y) {
results.drawTooltip(context, x, y);
if (ItemRepository.filesImported()) results.drawTooltip(context, x, y);
}

@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (results.mouseClicked(mouseX, mouseY, button)) {
return true;
} else {
if (recipeBook.searchField != null) {
boolean magnifyingGlassClicked = recipeBook.searchFieldRect != null && recipeBook.searchFieldRect.contains(MathHelper.floor(mouseX), MathHelper.floor(mouseY));
if (ItemRepository.filesImported()) {
if (results.mouseClicked(mouseX, mouseY, button)) {
return true;
} else {
if (recipeBook.searchField != null) {
boolean magnifyingGlassClicked = recipeBook.searchFieldRect != null && recipeBook.searchFieldRect.contains(MathHelper.floor(mouseX), MathHelper.floor(mouseY));

if (magnifyingGlassClicked || recipeBook.searchField.mouseClicked(mouseX, mouseY, button)) {
results.closeRecipeView();
recipeBook.searchField.setFocused(true);
if (magnifyingGlassClicked || recipeBook.searchField.mouseClicked(mouseX, mouseY, button)) {
results.closeRecipeView();
recipeBook.searchField.setFocused(true);

return true;
return true;
}
recipeBook.searchField.setFocused(false);
return recipeBook.filterOption.mouseClicked(mouseX, mouseY, button);
}
recipeBook.searchField.setFocused(false);
return recipeBook.filterOption.mouseClicked(mouseX, mouseY, button);
}
}

Expand All @@ -55,18 +63,11 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {

@Override
public boolean keyPressed(double mouseX, double mouseY, int keyCode, int scanCode, int modifiers) {
return this.results.keyPressed(mouseX, mouseY, keyCode, scanCode, modifiers);
return ItemRepository.filesImported() ? this.results.keyPressed(mouseX, mouseY, keyCode, scanCode, modifiers) : false;
}

@Override
public void updateSearchResults(String query, FilterOption filterOption, boolean refresh) {
results.updateSearchResults(query, filterOption, refresh);
}

@Override
public void initializeSearchResults(String query) {
if (ItemRepository.filesImported()) {
updateSearchResults(query, FilterOption.ALL);
}
if (ItemRepository.filesImported()) results.updateSearchResults(query, filterOption, refresh);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* Based on {@link net.minecraft.client.gui.screen.recipebook.RecipeBookWidget}.
*/
public class SkyblockRecipeBookWidget extends RecipeBookWidget<NoopRecipeScreenHandler> {
private static final int IMAGE_WIDTH = RecipeBookWidget.field_32408;
protected static final int IMAGE_WIDTH = RecipeBookWidget.field_32408;
private static final int IMAGE_HEIGHT = RecipeBookWidget.field_32409;
//Corresponds to field_32410 in RecipeBookWidget
private static final int OFFSET_X_POSITION = 86;
Expand Down Expand Up @@ -106,7 +106,7 @@ protected void reset() {

//Tab Init
this.currentTab.left().initialize(this.client, left, top);
this.currentTab.left().initializeSearchResults(defaultSearchText);
this.currentTab.left().updateSearchResults(defaultSearchText, FilterOption.ALL);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ public ItemStack icon() {
@Override
public void updateSearchResults(String query, FilterOption filterOption, boolean refresh) {}

@Override
public void initializeSearchResults(String query) {}

private static class EventRenderer {
private static final int HEIGHT = 20;

Expand Down
Loading