Skip to content

Commit

Permalink
Fix rendering of non 3x3 recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
boq committed Aug 4, 2018
1 parent 264411c commit e450062
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ public class GuiComponentCraftingGrid extends GuiComponentSprite {

private static final Random rnd = new Random();

private final int width;

private final ItemStack[][] items;

private final ItemStack[] selectedItems;

private int changeCountdown = UPDATE_DELAY;

public GuiComponentCraftingGrid(int x, int y, ItemStack[] items, Icon background) {
this(x, y, CollectionUtils.transform(ItemStack[].class, items, input -> new ItemStack[] { input.copy() }), background);
public GuiComponentCraftingGrid(int x, int y, ItemStack[] items, int width, Icon background) {
this(x, y, CollectionUtils.transform(ItemStack[].class, items, input -> new ItemStack[] { input.copy() }), width, background);
}

public GuiComponentCraftingGrid(int x, int y, ItemStack[][] items, Icon background) {
public GuiComponentCraftingGrid(int x, int y, ItemStack[][] items, int width, Icon background) {
super(x, y, background);
Preconditions.checkNotNull(items, "No items in grid");
this.items = items;
this.width = width;
this.selectedItems = new ItemStack[items.length];

selectItems();
Expand Down Expand Up @@ -55,8 +58,8 @@ public void render(int offsetX, int offsetY, int mouseX, int mouseY) {
for (int i = 0; i < items.length; i++) {
ItemStack input = selectedItems[i];
if (!input.isEmpty()) {
int row = (i % 3);
int column = i / 3;
int row = i % width;
int column = i / width;
int itemX = offsetX + gridOffsetX + (row * itemBoxSize);
int itemY = offsetY + gridOffsetY + (column * itemBoxSize);
drawItemStack(input, x + itemX, y + itemY, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javax.annotation.Nonnull;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.common.crafting.IShapedRecipe;
import openmods.gui.Icon;
import openmods.gui.component.GuiComponentCraftingGrid;
import openmods.gui.component.GuiComponentHCenter;
Expand All @@ -25,8 +26,11 @@ public StandardRecipePage(String title, String description, @Nonnull ItemStack r
{
final IRecipe recipe = RecipeUtils.getFirstRecipeForItemStack(resultingItem);
if (recipe != null) {
ItemStack[][] input = RecipeUtils.getFullRecipeInput(recipe);
if (input != null) addComponent(new GuiComponentCraftingGrid(10, 20, input, iconCraftingGrid));
final ItemStack[][] input = RecipeUtils.getFullRecipeInput(recipe);
if (input != null) {
final int width = (recipe instanceof IShapedRecipe)? ((IShapedRecipe)recipe).getRecipeWidth() : 3;
addComponent(new GuiComponentCraftingGrid(10, 20, input, width, iconCraftingGrid));
}
}
}

Expand Down

0 comments on commit e450062

Please sign in to comment.