azalea_inventory/
operations.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
use std::ops::RangeInclusive;

use azalea_buf::McBuf;

use crate::{
    item::MaxStackSizeExt, AnvilMenuLocation, BeaconMenuLocation, BlastFurnaceMenuLocation,
    BrewingStandMenuLocation, CartographyTableMenuLocation, Crafter3x3MenuLocation,
    CraftingMenuLocation, EnchantmentMenuLocation, FurnaceMenuLocation, Generic3x3MenuLocation,
    Generic9x1MenuLocation, Generic9x2MenuLocation, Generic9x3MenuLocation, Generic9x4MenuLocation,
    Generic9x5MenuLocation, Generic9x6MenuLocation, GrindstoneMenuLocation, HopperMenuLocation,
    ItemSlot, ItemSlotData, LecternMenuLocation, LoomMenuLocation, Menu, MenuLocation,
    MerchantMenuLocation, Player, PlayerMenuLocation, ShulkerBoxMenuLocation, SmithingMenuLocation,
    SmokerMenuLocation, StonecutterMenuLocation,
};

#[derive(Debug, Clone)]
pub enum ClickOperation {
    Pickup(PickupClick),
    QuickMove(QuickMoveClick),
    Swap(SwapClick),
    Clone(CloneClick),
    Throw(ThrowClick),
    QuickCraft(QuickCraftClick),
    PickupAll(PickupAllClick),
}

#[derive(Debug, Clone)]
pub enum PickupClick {
    /// Left mouse click. Note that in the protocol, None is represented as
    /// -999.
    Left { slot: Option<u16> },
    /// Right mouse click. Note that in the protocol, None is represented as
    /// -999.
    Right { slot: Option<u16> },
    /// Drop cursor stack.
    LeftOutside,
    /// Drop cursor single item.
    RightOutside,
}
impl From<PickupClick> for ClickOperation {
    fn from(click: PickupClick) -> Self {
        ClickOperation::Pickup(click)
    }
}

/// Shift click
#[derive(Debug, Clone)]
pub enum QuickMoveClick {
    /// Shift + left mouse click
    Left { slot: u16 },
    /// Shift + right mouse click (identical behavior)
    Right { slot: u16 },
}
impl From<QuickMoveClick> for ClickOperation {
    fn from(click: QuickMoveClick) -> Self {
        ClickOperation::QuickMove(click)
    }
}

/// Used when you press number keys or F in an inventory.
#[derive(Debug, Clone)]
pub struct SwapClick {
    pub source_slot: u16,
    pub target_slot: u8,
}

impl From<SwapClick> for ClickOperation {
    fn from(click: SwapClick) -> Self {
        ClickOperation::Swap(click)
    }
}
/// Middle click, only defined for creative players in non-player
/// inventories.
#[derive(Debug, Clone)]
pub struct CloneClick {
    pub slot: u16,
}
impl From<CloneClick> for ClickOperation {
    fn from(click: CloneClick) -> Self {
        ClickOperation::Clone(click)
    }
}
#[derive(Debug, Clone)]
pub enum ThrowClick {
    /// Drop key (Q)
    Single { slot: u16 },
    /// Ctrl + drop key (Q)
    All { slot: u16 },
}
impl From<ThrowClick> for ClickOperation {
    fn from(click: ThrowClick) -> Self {
        ClickOperation::Throw(click)
    }
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct QuickCraftClick {
    pub kind: QuickCraftKind,
    pub status: QuickCraftStatus,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum QuickCraftKind {
    Left,
    Right,
    Middle,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum QuickCraftStatusKind {
    /// Starting drag
    Start,
    /// Add slot
    Add,
    /// Ending drag
    End,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum QuickCraftStatus {
    /// Starting drag
    Start,
    /// Add a slot.
    Add { slot: u16 },
    /// Ending drag
    End,
}
impl From<QuickCraftStatus> for QuickCraftStatusKind {
    fn from(status: QuickCraftStatus) -> Self {
        match status {
            QuickCraftStatus::Start => QuickCraftStatusKind::Start,
            QuickCraftStatus::Add { .. } => QuickCraftStatusKind::Add,
            QuickCraftStatus::End => QuickCraftStatusKind::End,
        }
    }
}

/// Double click
#[derive(Debug, Clone)]
pub struct PickupAllClick {
    /// The slot that we're double clicking on. It should be empty or at least
    /// not pickup-able (since the carried item is used as the filter).
    pub slot: u16,
    /// Impossible in vanilla clients.
    pub reversed: bool,
}
impl From<PickupAllClick> for ClickOperation {
    fn from(click: PickupAllClick) -> Self {
        ClickOperation::PickupAll(click)
    }
}

impl ClickOperation {
    /// Return the slot number that this operation is acting on, if any.
    ///
    /// Note that in the protocol, "None" is represented as -999.
    pub fn slot_num(&self) -> Option<u16> {
        match self {
            ClickOperation::Pickup(pickup) => match pickup {
                PickupClick::Left { slot } => *slot,
                PickupClick::Right { slot } => *slot,
                PickupClick::LeftOutside => None,
                PickupClick::RightOutside => None,
            },
            ClickOperation::QuickMove(quick_move) => match quick_move {
                QuickMoveClick::Left { slot } => Some(*slot),
                QuickMoveClick::Right { slot } => Some(*slot),
            },
            ClickOperation::Swap(swap) => Some(swap.source_slot),
            ClickOperation::Clone(clone) => Some(clone.slot),
            ClickOperation::Throw(throw) => match throw {
                ThrowClick::Single { slot } => Some(*slot),
                ThrowClick::All { slot } => Some(*slot),
            },
            ClickOperation::QuickCraft(quick_craft) => match quick_craft.status {
                QuickCraftStatus::Start => None,
                QuickCraftStatus::Add { slot } => Some(slot),
                QuickCraftStatus::End => None,
            },
            ClickOperation::PickupAll(pickup_all) => Some(pickup_all.slot),
        }
    }

    pub fn button_num(&self) -> u8 {
        match self {
            ClickOperation::Pickup(pickup) => match pickup {
                PickupClick::Left { .. } => 0,
                PickupClick::Right { .. } => 1,
                PickupClick::LeftOutside => 0,
                PickupClick::RightOutside => 1,
            },
            ClickOperation::QuickMove(quick_move) => match quick_move {
                QuickMoveClick::Left { .. } => 0,
                QuickMoveClick::Right { .. } => 1,
            },
            ClickOperation::Swap(swap) => swap.target_slot,
            ClickOperation::Clone(_) => 2,
            ClickOperation::Throw(throw) => match throw {
                ThrowClick::Single { .. } => 0,
                ThrowClick::All { .. } => 1,
            },
            ClickOperation::QuickCraft(quick_craft) => match quick_craft {
                QuickCraftClick {
                    kind: QuickCraftKind::Left,
                    status: QuickCraftStatus::Start,
                } => 0,
                QuickCraftClick {
                    kind: QuickCraftKind::Right,
                    status: QuickCraftStatus::Start,
                } => 4,
                QuickCraftClick {
                    kind: QuickCraftKind::Middle,
                    status: QuickCraftStatus::Start,
                } => 8,
                QuickCraftClick {
                    kind: QuickCraftKind::Left,
                    status: QuickCraftStatus::Add { .. },
                } => 1,
                QuickCraftClick {
                    kind: QuickCraftKind::Right,
                    status: QuickCraftStatus::Add { .. },
                } => 5,
                QuickCraftClick {
                    kind: QuickCraftKind::Middle,
                    status: QuickCraftStatus::Add { .. },
                } => 9,
                QuickCraftClick {
                    kind: QuickCraftKind::Left,
                    status: QuickCraftStatus::End,
                } => 2,
                QuickCraftClick {
                    kind: QuickCraftKind::Right,
                    status: QuickCraftStatus::End,
                } => 6,
                QuickCraftClick {
                    kind: QuickCraftKind::Middle,
                    status: QuickCraftStatus::End,
                } => 10,
            },
            ClickOperation::PickupAll(_) => 0,
        }
    }

    pub fn click_type(&self) -> ClickType {
        match self {
            ClickOperation::Pickup(_) => ClickType::Pickup,
            ClickOperation::QuickMove(_) => ClickType::QuickMove,
            ClickOperation::Swap(_) => ClickType::Swap,
            ClickOperation::Clone(_) => ClickType::Clone,
            ClickOperation::Throw(_) => ClickType::Throw,
            ClickOperation::QuickCraft(_) => ClickType::QuickCraft,
            ClickOperation::PickupAll(_) => ClickType::PickupAll,
        }
    }
}

#[derive(McBuf, Clone, Copy, Debug)]
pub enum ClickType {
    Pickup = 0,
    QuickMove = 1,
    Swap = 2,
    Clone = 3,
    Throw = 4,
    QuickCraft = 5,
    PickupAll = 6,
}

impl Menu {
    /// Shift-click a slot in this menu.
    ///
    /// Keep in mind that this doesn't send any packets to the server, it just
    /// mutates this specific `Menu`.
    pub fn quick_move_stack(&mut self, slot_index: usize) -> ItemSlot {
        let slot = self.slot(slot_index);
        if slot.is_none() {
            return ItemSlot::Empty;
        };

        let slot_location = self
            .location_for_slot(slot_index)
            .expect("we just checked to make sure the slot is Some above, so this shouldn't be able to error");
        match slot_location {
            MenuLocation::Player(l) => match l {
                PlayerMenuLocation::CraftResult => {
                    self.try_move_item_to_slots(slot_index, Player::INVENTORY_SLOTS);
                }
                PlayerMenuLocation::Craft => {
                    self.try_move_item_to_slots(slot_index, Player::INVENTORY_SLOTS);
                }
                PlayerMenuLocation::Armor => {
                    self.try_move_item_to_slots(slot_index, Player::INVENTORY_SLOTS);
                }
                _ => {
                    // TODO: armor handling (see quickMoveStack in
                    // InventoryMenu.java)

                    // if slot.kind().is_armor() &&

                    // also offhand handling

                    if l == PlayerMenuLocation::Inventory {
                        // shift-clicking in hotbar moves to inventory, and vice versa
                        if Player::is_hotbar_slot(slot_index) {
                            self.try_move_item_to_slots(
                                slot_index,
                                Player::INVENTORY_WITHOUT_HOTBAR_SLOTS,
                            );
                        } else {
                            self.try_move_item_to_slots(slot_index, Player::HOTBAR_SLOTS);
                        }
                    } else {
                        self.try_move_item_to_slots(slot_index, self.player_slots_range());
                    }
                }
            },
            MenuLocation::Generic9x1(l) => match l {
                Generic9x1MenuLocation::Contents => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
                Generic9x1MenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::GENERIC9X1_CONTENTS_SLOTS,
                    );
                }
            },
            MenuLocation::Generic9x2(l) => match l {
                Generic9x2MenuLocation::Contents => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
                Generic9x2MenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::GENERIC9X2_CONTENTS_SLOTS,
                    );
                }
            },
            MenuLocation::Generic9x3(l) => match l {
                Generic9x3MenuLocation::Contents => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
                Generic9x3MenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::GENERIC9X3_CONTENTS_SLOTS,
                    );
                }
            },
            MenuLocation::Generic9x4(l) => match l {
                Generic9x4MenuLocation::Contents => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
                Generic9x4MenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::GENERIC9X4_CONTENTS_SLOTS,
                    );
                }
            },
            MenuLocation::Generic9x5(l) => match l {
                Generic9x5MenuLocation::Contents => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
                Generic9x5MenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::GENERIC9X5_CONTENTS_SLOTS,
                    );
                }
            },
            MenuLocation::Generic9x6(l) => match l {
                Generic9x6MenuLocation::Contents => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
                Generic9x6MenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::GENERIC9X6_CONTENTS_SLOTS,
                    );
                }
            },
            MenuLocation::Generic3x3(l) => match l {
                Generic3x3MenuLocation::Contents => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
                Generic3x3MenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::GENERIC3X3_CONTENTS_SLOTS,
                    );
                }
            },
            MenuLocation::Crafter3x3(l) => match l {
                Crafter3x3MenuLocation::Contents => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
                Crafter3x3MenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::GENERIC3X3_CONTENTS_SLOTS,
                    );
                }
            },
            MenuLocation::Anvil(l) => match l {
                AnvilMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::ANVIL_FIRST_SLOT..=Menu::ANVIL_SECOND_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Beacon(l) => match l {
                BeaconMenuLocation::Payment => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
                BeaconMenuLocation::Player => {
                    self.try_move_item_to_slots(
                        slot_index,
                        Menu::BEACON_PAYMENT_SLOT..=Menu::BEACON_PAYMENT_SLOT,
                    );
                }
            },
            MenuLocation::BlastFurnace(l) => match l {
                BlastFurnaceMenuLocation::Player => {
                    self.try_move_item_to_slots(
                        slot_index,
                        Menu::BLAST_FURNACE_INGREDIENT_SLOT..=Menu::BLAST_FURNACE_FUEL_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::BrewingStand(l) => match l {
                BrewingStandMenuLocation::Player => {
                    self.try_move_item_to_slots(
                        slot_index,
                        *Menu::BREWING_STAND_BOTTLES_SLOTS.start()
                            ..=Menu::BREWING_STAND_INGREDIENT_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Crafting(l) => match l {
                CraftingMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::CRAFTING_GRID_SLOTS,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Enchantment(l) => match l {
                EnchantmentMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::ENCHANTMENT_ITEM_SLOT..=Menu::ENCHANTMENT_LAPIS_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Furnace(l) => match l {
                FurnaceMenuLocation::Player => {
                    self.try_move_item_to_slots(
                        slot_index,
                        Menu::FURNACE_INGREDIENT_SLOT..=Menu::FURNACE_FUEL_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Grindstone(l) => match l {
                GrindstoneMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::GRINDSTONE_INPUT_SLOT..=Menu::GRINDSTONE_ADDITIONAL_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Hopper(l) => match l {
                HopperMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::HOPPER_CONTENTS_SLOTS,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Lectern(l) => match l {
                LecternMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::LECTERN_BOOK_SLOT..=Menu::LECTERN_BOOK_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Loom(l) => match l {
                LoomMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::LOOM_BANNER_SLOT..=Menu::LOOM_PATTERN_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Merchant(l) => match l {
                MerchantMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::MERCHANT_PAYMENTS_SLOTS,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::ShulkerBox(l) => match l {
                ShulkerBoxMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::SHULKER_BOX_CONTENTS_SLOTS,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Smithing(l) => match l {
                SmithingMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::SMITHING_TEMPLATE_SLOT..=Menu::SMITHING_ADDITIONAL_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Smoker(l) => match l {
                SmokerMenuLocation::Player => {
                    self.try_move_item_to_slots(
                        slot_index,
                        Menu::SMOKER_INGREDIENT_SLOT..=Menu::SMOKER_FUEL_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::CartographyTable(l) => match l {
                CartographyTableMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::CARTOGRAPHY_TABLE_MAP_SLOT..=Menu::CARTOGRAPHY_TABLE_ADDITIONAL_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
            MenuLocation::Stonecutter(l) => match l {
                StonecutterMenuLocation::Player => {
                    self.try_move_item_to_slots_or_toggle_hotbar(
                        slot_index,
                        Menu::STONECUTTER_INPUT_SLOT..=Menu::STONECUTTER_INPUT_SLOT,
                    );
                }
                _ => {
                    self.try_move_item_to_slots(slot_index, self.player_slots_range());
                }
            },
        }

        ItemSlot::Empty
    }

    fn try_move_item_to_slots_or_toggle_hotbar(
        &mut self,
        slot_index: usize,
        target_slot_indexes: RangeInclusive<usize>,
    ) {
        if !self.try_move_item_to_slots(slot_index, target_slot_indexes) {
            self.try_move_item_to_slots(
                slot_index,
                if self.is_hotbar_slot(slot_index) {
                    self.player_slots_without_hotbar_range()
                } else {
                    self.hotbar_slots_range()
                },
            );
        }
    }

    /// Whether the given item could be placed in this menu.
    ///
    /// TODO: right now this always returns true
    pub fn may_place(&self, _target_slot_index: usize, _item: &ItemSlotData) -> bool {
        true
    }

    /// Whether the item in the given slot could be clicked and picked up.
    /// TODO: right now this always returns true
    pub fn may_pickup(&self, _source_slot_index: usize) -> bool {
        true
    }

    /// Get the maximum number of items that can be placed in this slot.
    pub fn max_stack_size(&self, _target_slot_index: usize) -> u32 {
        64
    }

    /// Try moving an item to a set of slots in this menu.
    ///
    /// Returns the updated item slot.
    fn try_move_item_to_slots(
        &mut self,
        item_slot_index: usize,
        target_slot_indexes: RangeInclusive<usize>,
    ) -> bool {
        let mut item_slot = self.slot(item_slot_index).unwrap().clone();

        // first see if we can stack it with another item
        if item_slot.kind().stackable() {
            for target_slot_index in target_slot_indexes.clone() {
                self.move_item_to_slot_if_stackable(&mut item_slot, target_slot_index);
                if item_slot.is_empty() {
                    break;
                }
            }
        }

        // and if not then just try putting it in an empty slot
        if item_slot.is_present() {
            for target_slot_index in target_slot_indexes {
                self.move_item_to_slot_if_empty(&mut item_slot, target_slot_index);
                if item_slot.is_empty() {
                    break;
                }
            }
        }

        item_slot.is_empty()
    }

    /// Merge this item slot into the target item slot, only if the target item
    /// slot is present and the same item.
    fn move_item_to_slot_if_stackable(
        &mut self,
        item_slot: &mut ItemSlot,
        target_slot_index: usize,
    ) {
        let ItemSlot::Present(item) = item_slot else {
            return;
        };
        let target_slot = self.slot(target_slot_index).unwrap();
        if let ItemSlot::Present(target_item) = target_slot {
            // the target slot is empty, so we can just move the item there
            if self.may_place(target_slot_index, item)
                && target_item.is_same_item_and_components(item)
            {
                let slot_item_limit = self.max_stack_size(target_slot_index);
                let new_target_slot_data = item.split(u32::min(slot_item_limit, item.count as u32));

                // get the target slot again but mut this time so we can update it
                let target_slot = self.slot_mut(target_slot_index).unwrap();
                *target_slot = ItemSlot::Present(new_target_slot_data);

                item_slot.update_empty();
            }
        }
    }

    fn move_item_to_slot_if_empty(&mut self, item_slot: &mut ItemSlot, target_slot_index: usize) {
        let ItemSlot::Present(item) = item_slot else {
            return;
        };
        let target_slot = self.slot(target_slot_index).unwrap();
        if target_slot.is_empty() && self.may_place(target_slot_index, item) {
            let slot_item_limit = self.max_stack_size(target_slot_index);
            let new_target_slot_data = item.split(u32::min(slot_item_limit, item.count as u32));

            let target_slot = self.slot_mut(target_slot_index).unwrap();
            *target_slot = ItemSlot::Present(new_target_slot_data);
            item_slot.update_empty();
        }
    }
}