Skip to content

Commit

Permalink
Merge tag 'v1.5.0' into 1.8.8
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle.properties
  • Loading branch information
mezz committed Dec 9, 2015
2 parents 0b0e13d + b0474ec commit 0769caf
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 129 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -2,5 +2,5 @@ mcversion=1.8.8
forgeversion=11.15.0.1611-1.8.8

version_major=2
version_minor=4
version_minor=5
version_patch=0
84 changes: 51 additions & 33 deletions src/main/java/mezz/jei/gui/Focus.java
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.ImmutableList;

import javax.annotation.Nonnull;
import java.util.List;

import net.minecraft.item.ItemStack;

Expand All @@ -12,8 +13,14 @@
import mezz.jei.api.recipe.IRecipeCategory;

public class Focus {
public enum Mode {
INPUT, OUTPUT, NONE
}

private final ItemStack stack;
private final Fluid fluid;
@Nonnull
private Mode mode = Mode.NONE;

public Focus() {
this.stack = null;
Expand Down Expand Up @@ -55,52 +62,63 @@ public boolean isBlank() {
return stack == null && fluid == null;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Focus)) {
return false;
}
Focus other = (Focus) obj;
return ItemStack.areItemStacksEqual(this.stack, other.getStack()) && fluid == other.fluid;
public void setMode(@Nonnull Mode mode) {
this.mode = mode;
}

@Nonnull
public ImmutableList<IRecipeCategory> getCategoriesWithInput() {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipeCategoriesWithInput(stack);
} else {
return JEIManager.recipeRegistry.getRecipeCategoriesWithInput(fluid);
}
public Mode getMode() {
return mode;
}

@Nonnull
public ImmutableList<IRecipeCategory> getCategoriesWithOutput() {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipeCategoriesWithOutput(stack);
} else {
return JEIManager.recipeRegistry.getRecipeCategoriesWithOutput(fluid);
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Focus)) {
return false;
}
Focus other = (Focus) obj;
return ItemStack.areItemStacksEqual(this.stack, other.getStack()) && fluid == other.fluid && mode == other.mode;
}

@Nonnull
public ImmutableList<Object> getRecipesWithInput(IRecipeCategory recipeCategory) {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipesWithInput(recipeCategory, stack);
} else {
return JEIManager.recipeRegistry.getRecipesWithInput(recipeCategory, fluid);
public ImmutableList<IRecipeCategory> getCategories() {
switch (mode) {
case INPUT: {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipeCategoriesWithInput(stack);
} else {
return JEIManager.recipeRegistry.getRecipeCategoriesWithInput(fluid);
}
}
case OUTPUT: {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipeCategoriesWithOutput(stack);
} else {
return JEIManager.recipeRegistry.getRecipeCategoriesWithOutput(fluid);
}
}
}
return JEIManager.recipeRegistry.getRecipeCategories();
}

@Nonnull
public ImmutableList<Object> getRecipesWithOutput(IRecipeCategory recipeCategory) {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipesWithOutput(recipeCategory, stack);
} else {
return JEIManager.recipeRegistry.getRecipesWithOutput(recipeCategory, fluid);
public List<Object> getRecipes(IRecipeCategory recipeCategory) {
switch (mode) {
case INPUT: {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipesWithInput(recipeCategory, stack);
} else {
return JEIManager.recipeRegistry.getRecipesWithInput(recipeCategory, fluid);
}
}
case OUTPUT: {
if (stack != null) {
return JEIManager.recipeRegistry.getRecipesWithOutput(recipeCategory, stack);
} else {
return JEIManager.recipeRegistry.getRecipesWithOutput(recipeCategory, fluid);
}
}
}
}

public enum Mode {
INPUT, OUTPUT, NONE
return JEIManager.recipeRegistry.getRecipes(recipeCategory);
}
}
4 changes: 3 additions & 1 deletion src/main/java/mezz/jei/gui/IRecipeGuiLogic.java
Expand Up @@ -25,7 +25,9 @@ public interface IRecipeGuiLogic {

void nextPage();

boolean setFocus(@Nonnull Focus focus, @Nonnull Focus.Mode focusMode);
boolean setFocus(@Nonnull Focus focus);

boolean back();

boolean setCategoryFocus();

Expand Down
49 changes: 28 additions & 21 deletions src/main/java/mezz/jei/gui/ItemListOverlay.java
Expand Up @@ -56,9 +56,9 @@ public class ItemListOverlay implements IShowsRecipeFocuses, IMouseHandler, IKey

// properties of the gui we're beside
private int guiLeft;
private int xSize;
private int width;
private int height;
private int guiXSize;
private int screenWidth;
private int screenHeight;

private boolean open = false;
private boolean enabled = true;
Expand All @@ -69,9 +69,9 @@ public ItemListOverlay(ItemFilter itemFilter) {

public void initGui(@Nonnull GuiContainer guiContainer) {
this.guiLeft = guiContainer.guiLeft;
this.xSize = guiContainer.xSize;
this.width = guiContainer.width;
this.height = guiContainer.height;
this.guiXSize = guiContainer.xSize;
this.screenWidth = guiContainer.width;
this.screenHeight = guiContainer.height;

String next = StatCollector.translateToLocal("jei.button.next");
String back = StatCollector.translateToLocal("jei.button.back");
Expand All @@ -81,14 +81,18 @@ public void initGui(@Nonnull GuiContainer guiContainer) {
final int backButtonWidth = 10 + fontRenderer.getStringWidth(back);
buttonHeight = 5 + fontRenderer.FONT_HEIGHT;

int rightEdge = createItemButtons();
int columns = getColumns();
int xSize = columns * itemStackWidth + (2 * itemStackPadding);
int xEmptySpace = screenWidth - guiLeft - guiXSize - xSize;

int leftEdge = this.guiLeft + this.xSize + borderPadding;
int leftEdge = guiLeft + guiXSize + (xEmptySpace / 2);

int rightEdge = createItemButtons(leftEdge);

nextButton = new GuiButtonExt(0, rightEdge - nextButtonWidth, 0, nextButtonWidth, buttonHeight, next);
backButton = new GuiButtonExt(1, leftEdge, 0, backButtonWidth, buttonHeight, back);

searchField = new GuiTextField(0, fontRenderer, leftEdge, this.height - searchHeight - (2 * borderPadding), rightEdge - leftEdge, searchHeight);
searchField = new GuiTextField(0, fontRenderer, leftEdge, screenHeight - searchHeight - (2 * borderPadding), rightEdge - leftEdge, searchHeight);
searchField.setMaxStringLength(maxSearchLength);
setKeyboardFocus(false);
searchField.setText(itemFilter.getFilterText());
Expand All @@ -97,25 +101,24 @@ public void initGui(@Nonnull GuiContainer guiContainer) {
}

// creates buttons and returns the x value of the right edge of the rightmost button
private int createItemButtons() {
private int createItemButtons(int xStart) {
guiItemStacks.clear();

final int xStart = guiLeft + xSize + borderPadding;
final int yStart = buttonHeight + (2 * borderPadding);

int x = xStart;
int y = yStart;
int maxX = 0;

while (y + itemStackHeight + borderPadding <= height - searchHeight) {
while (y + itemStackHeight + borderPadding <= screenHeight - searchHeight) {
if (x > maxX) {
maxX = x;
}

guiItemStacks.add(GuiItemStackGroup.createGuiItemStack(false, x, y, itemStackPadding));

x += itemStackWidth;
if (x + itemStackWidth + borderPadding > width) {
if (x + itemStackWidth + borderPadding > screenWidth) {
x = xStart;
y += itemStackHeight;
}
Expand All @@ -137,7 +140,7 @@ private void updateLayout() {
itemButton.clear();
} else {
ItemStack stack = itemList.get(i).getItemStack();
itemButton.set(stack, new Focus(), Focus.Mode.NONE);
itemButton.set(stack, new Focus());
}
i++;
}
Expand Down Expand Up @@ -209,7 +212,7 @@ public void handleTick() {

@Override
public boolean isMouseOver(int mouseX, int mouseY) {
return isOpen() && (mouseX >= guiLeft + xSize);
return isOpen() && (mouseX >= guiLeft + guiXSize);
}

@Override
Expand Down Expand Up @@ -308,14 +311,18 @@ public boolean onKeyPressed(int keyCode) {
return false;
}

private int getCountPerPage() {
int xArea = width - (guiLeft + xSize + (2 * borderPadding));
int yArea = height - (buttonHeight + (2 * borderPadding));
private int getColumns() {
int xArea = screenWidth - (guiLeft + guiXSize + (2 * borderPadding));
return xArea / itemStackWidth;
}

int xCount = xArea / itemStackWidth;
int yCount = yArea / itemStackHeight;
private int getRows() {
int yArea = screenHeight - (buttonHeight + searchHeight + (4 * borderPadding));
return yArea / itemStackHeight;
}

return xCount * yCount;
private int getCountPerPage() {
return getColumns() * getRows();
}

private void updatePageCount() {
Expand Down

0 comments on commit 0769caf

Please sign in to comment.