Soncresity Industries Wiki

Locked Cancel Slot

A locked slot that closes the current GUI and plays the click sound from the SI: Essentials Common Cnfg by default

The locked cancel slot is very straight forward, it doesn't allow any interactions with it and when clicked it will close the current GUI and play the click sound from the SI: Essentials Common Cnfg (SOUND_FEEDBACK_CLICK_ID) by default.

Example Usage

SlotUtils Usage

This example uses the SlotUtils class to position the Slot correctly in the GUI. Currently, the SlotUtils class only supports 6 rows (54 slots) but more will be added in the future.

MyScreen.java
public class MyScreenHandler extends AbstractContainerMenu {
    private final Container container;

    public MyScreenHandler(MenuType<?> menuType, int syncId, Inventory inv) {
        super(menuType, syncId);
        this.container = new SimpleContainer(54); // A simple container with 54 slots (6 rows of 9)

        // Create the item that will be displayed in the locked cancel slot
        ItemStack cancel = new ItemStack(SrpxItems.CANCEL_ITEM);
        cancel.set(DataComponents.CUSTOM_NAME, MessageUtils.getDeserializedText("<dark_red><b><u>Cancel"));
        cancel.set(DataComponents.LORE, new ItemLore(List.of(
                MessageUtils.getDeserializedText("<red>Click to <b>close</b> this menu")
        )));

        // Add the locked cancel slot to the container
        for (int i = 0; i < 54; i++) {
            // Used to calculate the x and y position of the slot in the GUI
            int x = SlotUtils.getXPos(i);
            int y = SlotUtils.getYPos(i);

            if (i == 53) { // The last slot in the GUI (bottom right corner)
                container.setItem(i, cancel);
                /* With the Slots multiple constructors, you can easily configure the sound that is played when the slot is interacted with.
                 * Example:
                 * LockedCancelSlot(container, i, x, y) - Plays the default click sound from the SI: Essentials Common Cnfg when clicked
                 * LockedCancelSlot(container, i, x, y, false) - Disables the sound when clicked
                 * LockedCancelSlot(container, i, x, y, true, SoundType.PRIVATE, SoundSource.MASTER, SoundEvents.LEVER_CLICK, 0.8f, 1.0f) - Plays the lever click sound at volume 0.8 and pitch 1.0 for the player that clicked the slot
                 */
                this.addSlot(new LockedCancelSlot(container, i, x, y));
                continue; // Skip the rest of this loop iteration
            }

            // Fill up other slots (will break the GUI if not not all slots are filled up)
            // You could set this to ItemStack.EMPTY
            container.setItem(i, new ItemStack(Items.BLACK_STAINED_GLASS_PANE));
            // The locked slot doesn't allow any interactions with it (Read more about it on its page)
            this.addSlot(new LockedSlot(container, i, x, y));
        }
    }

    // Disallow quick moving items
    @Override
    public ItemStack quickMoveStack(Player player, int i) {
        return ItemStack.EMPTY;
    }

    @Override
    public boolean stillValid(Player player) {
        return true;
    }
}

With this setup, you will have a locked cancel slot in the bottom right corner of your GUI that closes the GUI and plays the click sound from the SI: Essentials Common Cnfg (SOUND_FEEDBACK_CLICK_ID) when clicked.

On this page