Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi!
I was creating a GUI with a scroll pane, but when i scroll up or down with the mouse (the button is not implemented yet) the GUI will not update until i click on a slot with an item.
How can i resolve this problem?

 

This is the Screen Code:

public class ColossalChestScreen extends BaseChestScreen {

    private ColossalChestContainer colossalContainer;

    public ColossalChestScreen(BaseChestContainer container, PlayerInventory inventory, ITextComponent title) {
        super(container, inventory, title);
        if (container instanceof ColossalChestContainer)
            this.colossalContainer = (ColossalChestContainer) container;
        else
            throw new IllegalArgumentException("Invalid Container for Colossal Chest");
        this.imageHeight = 204;
        this.imageWidth = 197;
        this.inventoryLabelY = 110;
        this.bgLocation = new ResourceLocation(TenChest.MODID, "textures/gui/colossal_chest_gui.png");
    }

    @Override
    public boolean mouseScrolled(double x, double y, double movement) {
        System.out.println("Trying to scroll off " + (-movement));
        this.colossalContainer.scrollOff((int) -movement);
        return super.mouseScrolled(x, y, movement);
    }
}

This is the Container Screen:

public class ColossalChestContainer extends BaseChestContainer {

    public static ColossalChestContainer defaultContainer(int id, IInventory inventory, PlayerInventory playerInventory) {
        return new ColossalChestContainer(id, inventory, playerInventory);
    }

    public static ColossalChestContainer defaultContainer(int id, PlayerInventory inventory) {
        return new ColossalChestContainer(id, new Inventory(9 * MAX_ROWS), inventory);
    }

    public static final int MAX_ROWS = 12;
    private static final int VISIBLE_ROWS = 5;

    private int startingRow = 0;

    public ColossalChestContainer(int id, IInventory inventory, PlayerInventory playerInventory) {
        super(BaseChestContainerType.COLOSSAL_CHEST.get(), id, inventory, playerInventory);
    }

    @Override
    protected void generateSlot(PlayerInventory playerInventory) {
        int index = 0;
        for (int i = 0; i < VISIBLE_ROWS; i++) {
            for (int j = 0; j < 9; j++) {
                this.addSlot(new Slot(this.inventory, index++, 12 + (j * 18), 18 + (i * 18)));
            }
        }

        index = 0;
        for (int i = 0; i < 9; i++) {
            this.addSlot(new Slot(playerInventory, index++, 12 + (i * 18), 181));
        }

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 9; j++) {
                this.addSlot(new Slot(playerInventory, index++, 12 + (j * 18), 123 + (18 * i)));
            }
        }
    }

    public void scrollOff(int val) {
        this.scrollTo(this.startingRow + val);
    }

    public void scrollTo(int row) {
        if (canScrollTo(row)) {
            this.startingRow = row;
            System.out.println("Changed First Row Index to: " + this.startingRow);
            int index = 0;
            for (int i = 0; i < VISIBLE_ROWS; i++) {
                for (int j = 0; j < 9; j++) {
                    int inventoryIndex = (this.startingRow * 9) + index;
                    System.out.println("Inventory Slot Visible at: " + index + " -> " + inventoryIndex);
                    this.setItem(index, this.inventory.getItem(inventoryIndex));
                    index++;
                }
            }
        } else {
            System.out.println("Can't Scroll To " + row);
        }
    }

    public boolean canScrollTo(int rows) {
        return rows >= 0 && rows + VISIBLE_ROWS <= MAX_ROWS;
    }
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.