Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix slot grid when the amount of slots is a prime number #195

Merged
merged 2 commits into from
Oct 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ protected void addInventorySlotGroup(ModularUI.Builder builder, IItemHandlerModi
for (int i = 0; i < itemSlotsToDown; i++) {
for (int j = 0; j < itemSlotsToLeft; j++) {
int slotIndex = i * itemSlotsToLeft + j;
if (slotIndex >= itemInputsCount) break;
int x = startInputsX + 18 * j;
int y = startInputsY + 18 * i;
addSlot(builder, x, y, slotIndex, itemHandler, fluidHandler, invertFluids, isOutputs);
Expand Down Expand Up @@ -446,20 +447,27 @@ protected TextureArea[] getOverlaysForSlot(boolean isOutput, boolean isFluid, bo
}

protected static int[] determineSlotsGrid(int itemInputsCount) {
int itemSlotsToLeft = 0;
int itemSlotsToDown = 0;
int itemSlotsToLeft;
int itemSlotsToDown;
double sqrt = Math.sqrt(itemInputsCount);
if (sqrt % 1 == 0) { //check if square root is integer
//case for 1, 4, 9 slots - it's square inputs (the most common case)
//if the number of input has an integer root
//return it.
if (sqrt % 1 == 0) {
itemSlotsToLeft = itemSlotsToDown = (int) sqrt;
} else if (itemInputsCount % 3 == 0) {
//case for 3 and 6 slots - 3 by horizontal and i / 3 by vertical (common case too)
itemSlotsToDown = itemInputsCount / 3;
} else if (itemInputsCount == 3) {
itemSlotsToLeft = 3;
} else if (itemInputsCount % 2 == 0) {
//case for 2 inputs - 2 by horizontal and i / 3 by vertical (for 2 slots)
itemSlotsToDown = itemInputsCount / 2;
itemSlotsToLeft = 2;
itemSlotsToDown = 1;
}
else {
//if we couldn't fit all into a perfect square,
//increase the amount of slots to the left
itemSlotsToLeft = (int) Math.ceil(sqrt);
itemSlotsToDown = itemSlotsToLeft - 1;
//if we still can't fit all the slots in a grid,
//increase the amount of slots on the bottom
if (itemInputsCount > itemSlotsToLeft * itemSlotsToDown) {
itemSlotsToDown = itemSlotsToLeft;
}
}
return new int[]{itemSlotsToLeft, itemSlotsToDown};
}
Expand Down