Search in sources :

Example 1 with PlayerContainer

use of net.minecraft.inventory.container.PlayerContainer in project SophisticatedBackpacks by P3pp3rF1y.

the class BackpackOpenMessage method handleMessage.

private static void handleMessage(@Nullable ServerPlayerEntity player, BackpackOpenMessage msg) {
    if (player == null) {
        return;
    }
    if (player.containerMenu instanceof BackpackContainer) {
        BackpackContext backpackContext = ((BackpackContainer) player.containerMenu).getBackpackContext();
        if (msg.slotIndex == -1) {
            openBackpack(player, backpackContext.getParentBackpackContext());
        } else if (((BackpackContainer) player.containerMenu).isBackpackInventorySlot(msg.slotIndex)) {
            openBackpack(player, backpackContext.getSubBackpackContext(msg.slotIndex));
        }
    } else if (player.containerMenu instanceof IContextAwareContainer) {
        BackpackContext backpackContext = ((IContextAwareContainer) player.containerMenu).getBackpackContext();
        openBackpack(player, backpackContext);
    } else if (msg.slotIndex > -1 && player.containerMenu instanceof PlayerContainer) {
        int slotIndex = msg.slotIndex;
        String inventoryProvider = PlayerInventoryProvider.MAIN_INVENTORY;
        if (msg.slotIndex == CHEST_SLOT) {
            inventoryProvider = PlayerInventoryProvider.ARMOR_INVENTORY;
        } else if (msg.slotIndex == OFFHAND_SLOT) {
            inventoryProvider = PlayerInventoryProvider.OFFHAND_INVENTORY;
            slotIndex = 0;
        }
        BackpackContext.Item backpackContext = new BackpackContext.Item(inventoryProvider, slotIndex, true);
        openBackpack(player, backpackContext);
    } else {
        findAndOpenFirstBackpack(player);
    }
}
Also used : PlayerContainer(net.minecraft.inventory.container.PlayerContainer) BackpackContext(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContext) BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) IContextAwareContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.IContextAwareContainer)

Aggregations

PlayerContainer (net.minecraft.inventory.container.PlayerContainer)1 BackpackContainer (net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer)1 BackpackContext (net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContext)1 IContextAwareContainer (net.p3pp3rf1y.sophisticatedbackpacks.common.gui.IContextAwareContainer)1