Skip to content

Commit

Permalink
fix: fix Bio-Forge GUI crashing the game when clicking next page button
Browse files Browse the repository at this point in the history
  • Loading branch information
Elenterius committed Apr 25, 2023
1 parent 6a752a7 commit 4046464
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ private void drawTabs(PoseStack poseStack) {
private void drawRecipes(PoseStack poseStack) {
if (!recipeBook.hasRecipesOnPage()) return;

//TODO: refactor - move into the loop below
if (recipeBook.hasSelectedRecipe() && recipeBook.isSelectedRecipeVisible()) {
int gridIndex = recipeBook.getGridIndexOfSelectedRecipe();
BioForgeRecipe recipe = recipeBook.getRecipeByGrid(gridIndex);
Expand All @@ -228,10 +229,10 @@ private void drawRecipes(PoseStack poseStack) {
}

int maxRecipes = recipeBook.getMaxRecipesOnGrid();
for (int i = 0; i < maxRecipes; i++) {
BioForgeRecipe recipe = recipeBook.getRecipeByGrid(i);
boolean isCraftable = recipeBook.getRecipeCollectionByGrid(i).isCraftable(recipe);
drawRecipeTile(poseStack, i, isCraftable, recipe.getResultItem());
for (int gridIndex = 0; gridIndex < maxRecipes; gridIndex++) {
BioForgeRecipe recipe = recipeBook.getRecipeByGrid(gridIndex);
boolean isCraftable = recipeBook.getRecipeCollectionByGrid(gridIndex).isCraftable(recipe);
drawRecipeTile(poseStack, gridIndex, isCraftable, recipe.getResultItem());
}

drawPagination(poseStack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,18 @@ public int getMaxRecipesOnGrid() {
return Math.min(GRID_SIZE, shownRecipes.size() - startIndex);
}

//TODO: refactor
public boolean isSelectedRecipeVisible() {
int maxIndex = startIndex + GRID_SIZE;
if (recipeSelection.tab == activeTab) {
return recipeSelection.index >= startIndex && recipeSelection.index < maxIndex && getGridIndexOfSelectedRecipe() < getMaxRecipesOnGrid();
}

if (recipeSelection.recipe != null && (activeTab == 0 || getCurrentCategory() == recipeSelection.recipe.getTab())) {
//find gridIndex recipeSelection in foreign tab
int maxRecipes = getMaxRecipesOnGrid();
for (int i = 0; i < maxRecipes; i++) {
if (getRecipe(startIndex + i).isRecipeEqual(recipeSelection.recipe)) {
crossoverGridIndex = startIndex + i;
for (int gridIndex = 0; gridIndex < maxRecipes; gridIndex++) {
if (getRecipe(startIndex + gridIndex).isRecipeEqual(recipeSelection.recipe)) {
crossoverGridIndex = startIndex + gridIndex;
return true;
}
}
Expand All @@ -178,7 +178,7 @@ public int getGridIndexOfSelectedRecipe() {
}

if (recipeSelection.recipe != null && (activeTab == 0 || getCurrentCategory() == recipeSelection.recipe.getTab())) {
return crossoverGridIndex;
return crossoverGridIndex - startIndex;
}

return 0;
Expand Down

0 comments on commit 4046464

Please sign in to comment.