Skip to content

Commit

Permalink
Fix recipe book crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
AzureAaron committed Jan 1, 2025
1 parent a09c6ee commit 796d0b5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
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 @@ -20,31 +20,38 @@ 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) {
recipeBook.searchField.render(context, mouseX, mouseY, delta);
results.draw(context, x, y, mouseX, mouseY, delta);
if (ItemRepository.filesImported()) {
recipeBook.searchField.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);
recipeBook.searchField.setFocused(false);
}
}
}

Expand All @@ -53,13 +60,8 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {

@Override
public void updateSearchResults(String query) {
results.updateSearchResults(query);
}

@Override
public void initializeSearchResults(String query) {
if (ItemRepository.filesImported()) {
updateSearchResults(query);
results.updateSearchResults(query);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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 @@ -98,7 +98,7 @@ protected void reset() {

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

@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) {}

@Override
public void initializeSearchResults(String query) {}

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

Expand Down

0 comments on commit 796d0b5

Please sign in to comment.