Skip to content

Commit

Permalink
Make all ingredients in a recipe cycle with the same offset
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Feb 25, 2017
1 parent f180dfc commit abb3c79
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
Expand Up @@ -9,8 +9,8 @@
import net.minecraftforge.fluids.FluidStack;

public class GuiFluidStackGroup extends GuiIngredientGroup<FluidStack> implements IGuiFluidStackGroup {
public GuiFluidStackGroup(IFocus<FluidStack> focus) {
super(FluidStack.class, focus);
public GuiFluidStackGroup(IFocus<FluidStack> focus, int cycleOffset) {
super(FluidStack.class, focus, cycleOffset);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mezz/jei/gui/ingredients/GuiIngredient.java
Expand Up @@ -57,7 +57,7 @@ public GuiIngredient(
int xPosition, int yPosition,
int width, int height,
int xPadding, int yPadding,
int itemCycleOffset
int cycleOffset
) {
this.ingredientRenderer = ingredientRenderer;
this.ingredientHelper = ingredientHelper;
Expand All @@ -72,7 +72,7 @@ public GuiIngredient(
this.xPadding = xPadding;
this.yPadding = yPadding;

this.cycleTimer = new CycleTimer(itemCycleOffset);
this.cycleTimer = new CycleTimer(cycleOffset);
}

public boolean isMouseOver(int xOffset, int yOffset, int mouseX, int mouseY) {
Expand Down
Expand Up @@ -22,11 +22,11 @@
import net.minecraft.client.Minecraft;

public class GuiIngredientGroup<T> implements IGuiIngredientGroup<T> {
private final int itemCycleOffset = (int) (Math.random() * 1000);
private final Map<Integer, GuiIngredient<T>> guiIngredients = new HashMap<Integer, GuiIngredient<T>>();
private final Set<Integer> inputSlots = new HashSet<Integer>();
private final IIngredientHelper<T> ingredientHelper;
private final Class<T> ingredientClass;
private final int cycleOffset;
/**
* If focus is set and any of the guiIngredients contains focus
* they will only display focus instead of rotating through all their values.
Expand All @@ -36,7 +36,7 @@ public class GuiIngredientGroup<T> implements IGuiIngredientGroup<T> {
@Nullable
private ITooltipCallback<T> tooltipCallback;

public GuiIngredientGroup(Class<T> ingredientClass, IFocus<T> focus) {
public GuiIngredientGroup(Class<T> ingredientClass, IFocus<T> focus, int cycleOffset) {
this.ingredientClass = ingredientClass;
if (focus.getMode() == IFocus.Mode.INPUT) {
this.inputFocus = focus;
Expand All @@ -49,11 +49,12 @@ public GuiIngredientGroup(Class<T> ingredientClass, IFocus<T> focus) {
this.outputFocus = new Focus<T>(null);
}
this.ingredientHelper = Internal.getIngredientRegistry().getIngredientHelper(ingredientClass);
this.cycleOffset = cycleOffset;
}

@Override
public void init(int slotIndex, boolean input, IIngredientRenderer<T> ingredientRenderer, int xPosition, int yPosition, int width, int height, int xPadding, int yPadding) {
GuiIngredient<T> guiIngredient = new GuiIngredient<T>(slotIndex, input, ingredientRenderer, ingredientHelper, xPosition, yPosition, width, height, xPadding, yPadding, itemCycleOffset);
GuiIngredient<T> guiIngredient = new GuiIngredient<T>(slotIndex, input, ingredientRenderer, ingredientHelper, xPosition, yPosition, width, height, xPadding, yPadding, cycleOffset);
guiIngredients.put(slotIndex, guiIngredient);
if (input) {
inputSlots.add(slotIndex);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mezz/jei/gui/ingredients/GuiItemStackGroup.java
Expand Up @@ -13,8 +13,8 @@ public class GuiItemStackGroup extends GuiIngredientGroup<ItemStack> implements
private static final int baseHeight = 16;
private static final ItemStackRenderer renderer = new ItemStackRenderer();

public GuiItemStackGroup(IFocus<ItemStack> focus) {
super(ItemStack.class, focus);
public GuiItemStackGroup(IFocus<ItemStack> focus, int cycleOffset) {
super(ItemStack.class, focus, cycleOffset);
}

public static int getWidth(int padding) {
Expand Down
Expand Up @@ -38,7 +38,7 @@ public class RecipeCategoryCraftingItems implements IShowsRecipeFocuses {
public RecipeCategoryCraftingItems(IRecipeRegistry recipeRegistry) {
this.recipeRegistry = recipeRegistry;
IFocus<ItemStack> focus = recipeRegistry.createFocus(IFocus.Mode.NONE, null);
craftingItems = new GuiItemStackGroup(focus);
craftingItems = new GuiItemStackGroup(focus, 0);

ResourceLocation recipeBackgroundResource = new ResourceLocation(Constants.RESOURCE_DOMAIN, Constants.TEXTURE_RECIPE_BACKGROUND_PATH);

Expand All @@ -50,7 +50,7 @@ public RecipeCategoryCraftingItems(IRecipeRegistry recipeRegistry) {

public void updateLayout(List<ItemStack> itemStacks, GuiProperties guiProperties) {
IFocus<ItemStack> focus = recipeRegistry.createFocus(IFocus.Mode.NONE, null);
craftingItems = new GuiItemStackGroup(focus);
craftingItems = new GuiItemStackGroup(focus, 0);

if (!itemStacks.isEmpty()) {
int totalHeight = topDrawable.getHeight() + middleDrawable.getHeight() + bottomDrawable.getHeight();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/mezz/jei/gui/recipes/RecipeLayout.java
Expand Up @@ -31,6 +31,7 @@ public class RecipeLayout implements IRecipeLayoutDrawable {
private static final int RECIPE_BUTTON_SIZE = 12;
public static final int recipeTransferButtonIndex = 100;

private final int ingredientCycleOffset = (int) (Math.random() * 10000);
private final IRecipeCategory recipeCategory;
private final GuiItemStackGroup guiItemStackGroup;
private final GuiFluidStackGroup guiFluidStackGroup;
Expand All @@ -55,8 +56,8 @@ public <T extends IRecipeWrapper> RecipeLayout(int index, IRecipeCategory<T> rec
} else if (focusValue instanceof FluidStack) {
fluidStackFocus = (FluidStack) focusValue;
}
this.guiItemStackGroup = new GuiItemStackGroup(new Focus<ItemStack>(focus.getMode(), itemStackFocus));
this.guiFluidStackGroup = new GuiFluidStackGroup(new Focus<FluidStack>(focus.getMode(), fluidStackFocus));
this.guiItemStackGroup = new GuiItemStackGroup(new Focus<ItemStack>(focus.getMode(), itemStackFocus), ingredientCycleOffset);
this.guiFluidStackGroup = new GuiFluidStackGroup(new Focus<FluidStack>(focus.getMode(), fluidStackFocus), ingredientCycleOffset);

this.guiIngredientGroups = new HashMap<Class, GuiIngredientGroup>();
this.guiIngredientGroups.put(ItemStack.class, this.guiItemStackGroup);
Expand Down Expand Up @@ -204,7 +205,7 @@ public <T> IGuiIngredientGroup<T> getIngredientsGroup(Class<T> ingredientClass)
value = (T) focusValue;
}
IFocus<T> focus = new Focus<T>(this.focus.getMode(), value);
guiIngredientGroup = new GuiIngredientGroup<T>(ingredientClass, focus);
guiIngredientGroup = new GuiIngredientGroup<T>(ingredientClass, focus, ingredientCycleOffset);
guiIngredientGroups.put(ingredientClass, guiIngredientGroup);
}
return guiIngredientGroup;
Expand Down
Expand Up @@ -98,7 +98,7 @@ public IRecipeTransferError transferRecipe(ContainerPlayer container, IRecipeLay
guiIngredients.add(guiIngredient);
}
}
IGuiItemStackGroup playerInvItemStackGroup = new GuiItemStackGroup(new Focus<ItemStack>(null));
IGuiItemStackGroup playerInvItemStackGroup = new GuiItemStackGroup(new Focus<ItemStack>(null), 0);
int[] playerGridIndexes = {0, 1, 3, 4};
for (int i = 0; i < 4; i++) {
int index = playerGridIndexes[i];
Expand Down

0 comments on commit abb3c79

Please sign in to comment.