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);
}
}
Aggregations