containerInventories[0] = inventories[0];
containerInventories[1] = inventories[1];
containerInventories[2] = craftingGrid;
containerInventories[3] = recipes;
ContainerWorkbenchBackpack container;
if(inventories[1] instanceof AbstractInventoryBackpack) {
container = new ContainerWorkbenchBackpack(containerInventories, backpack);
} else {
container = new ContainerWorkbenchBackpack(craftingGrid);
}
// set container width (needed for gui)
container.setWidth(9 * SLOT + 2 * X_SPACING);
int xSpacing;
int x;
if(backpack.isIntelligent()) {
xSpacing = X_SPACING;
x = xSpacing + 72;
} else {
xSpacing = BIG_X_SPACING;
x = xSpacing + 95;
}
int y = 17;
container.addBoundary(Boundaries.EXTRA);
// result slot
container.addSlot(new SlotCraftingAdvanced(entityPlayer, container, 0, x, y + 18, containerInventories));
x = xSpacing;
container.addBoundary(Boundaries.EXTRA_END);
container.addBoundary(Boundaries.CRAFTING);
// crafting grid
for(int row = 0; row < 3; row++) {
for(int col = 0; col < 3; col++) {
container.addSlot(new SlotPhantom(craftingGrid, col + row * 3, x, y));
x += SLOT;
}
y += SLOT;
x = xSpacing;
}
container.addBoundary(Boundaries.CRAFTING_END);
if(backpack.isIntelligent()) {
// recipes
y = 17;
x += 108;
for(int row = 0; row < 3; row++) {
for(int col = 0; col < 3; col++) {
container.addSlot(new SlotPhantom(recipes, col + row * 3, x, y));
x += SLOT;
}
y += SLOT;
x = xSpacing + 108;
}
}
x = X_SPACING;
y += 5;
container.addBoundary(Boundaries.BACKPACK);
int remainingSlots = inventories[1].getSizeInventory();
// backpack inventory
for(int row = 0; row < inventories[1].getSizeInventory() / backpack.getSlotsPerRow(); row++) {
int cols = remainingSlots - 9 >= 9 ? 9 : remainingSlots;
remainingSlots -= cols;
if(cols * SLOT < 9 * SLOT/* && !hasScrollbar */) {
x += (int) Math.round(9 * SLOT / 2. - cols * SLOT / 2.) + 1;
}
for(int col = 0; col < cols; ++col) {
container.addSlot(new SlotBackpack(inventories[1], col + row * 9, x, y));
x += SLOT;
}
y += SLOT;
x = X_SPACING;
}
container.addBoundary(Boundaries.BACKPACK_END);
container.addBoundary(Boundaries.INVENTORY);
y += 14; // space for label
// player inventory
for(int row = 0; row < 3; row++) {
for(int col = 0; col < 9; col++) {
container.addSlot(new Slot(inventories[0], col + row * 9 + 9, x, y));
x += SLOT;
}
y += SLOT;
x = X_SPACING;
}
container.addBoundary(Boundaries.INVENTORY_END);
container.addBoundary(Boundaries.HOTBAR);
y += 6;
// hotbar
for(int col = 0; col < 9; col++) {
container.addSlot(new Slot(inventories[0], col, x, y));
x += SLOT;
}
container.addBoundary(Boundaries.HOTBAR_END);
y += SLOT;
y += 7;
// set container height (needed for gui)
container.setHeight(y);
return container;
}