aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/MouseInventoryClickHandler.h
blob: ab45168775a142615f1e4f53c127beeed07d13df (plain)
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
#pragma once

// 4J The body of this class was commented out in Java. Copying here for completeness

class MouseInventoryClickHandler
{
/*	public static void handle(int buttonNum, boolean clickedOutside, int slotId, Player player) {
		Inventory inventory = player.inventory;
		Slot slot = player.getInventorySlot(slotId);
		if (slot != null) {
			ItemInstance clicked = slot.getItem();
			if (clicked == null && inventory.carried == null) {
			} else if (clicked != null && inventory.carried == null) {
				int c = buttonNum == 0 ? clicked.count : (clicked.count + 1) / 2;
				inventory.carried = slot.container.removeItem(slot.slot, c);
				if (clicked.count == 0) slot.set(null);
				slot.onTake();
			} else if (clicked == null && inventory.carried != null && slot.mayPlace(inventory.carried)) {
				int c = buttonNum == 0 ? inventory.carried.count : 1;
				if (c > slot.getMaxStackSize()) c = slot.getMaxStackSize();
				slot.set(inventory.carried.remove(c));
				if (inventory.carried.count == 0) inventory.carried = null;
			} else if (clicked != null && inventory.carried != null) {

				if (slot.mayPlace(inventory.carried)) {
					if (clicked.id != inventory.carried.id) {
						if (inventory.carried.count <= slot.getMaxStackSize()) {
							ItemInstance tmp = clicked;
							slot.set(inventory.carried);
							inventory.carried = tmp;
						}
					} else if (clicked.id == inventory.carried.id) {
						if (buttonNum == 0) {
							int c = inventory.carried.count;
							if (c > slot.getMaxStackSize() - clicked.count) c = slot.getMaxStackSize() - clicked.count;
							if (c > inventory.carried.getMaxStackSize() - clicked.count) c = inventory.carried.getMaxStackSize() - clicked.count;
							inventory.carried.remove(c);
							if (inventory.carried.count == 0) inventory.carried = null;
							clicked.count += c;
						} else if (buttonNum == 1) {
							int c = 1;
							if (c > slot.getMaxStackSize() - clicked.count) c = slot.getMaxStackSize() - clicked.count;
							if (c > inventory.carried.getMaxStackSize() - clicked.count) c = inventory.carried.getMaxStackSize() - clicked.count;
							inventory.carried.remove(c);
							if (inventory.carried.count == 0) inventory.carried = null;
							clicked.count += c;
						}
					}
				} else {
					if (clicked.id == inventory.carried.id && inventory.carried.getMaxStackSize() > 1) {
						int c = clicked.count;
						if (c > 0 && c + inventory.carried.count <= inventory.carried.getMaxStackSize()) {
							inventory.carried.count += c;
							clicked.remove(c);
							if (clicked.count == 0) slot.set(null);
							slot.onTake();
						}
					}
				}
			}
			slot.setChanged();
		} else if (inventory.carried != null) {
			if (clickedOutside) {
				if (buttonNum == 0) {
					player.drop(inventory.carried);
					inventory.carried = null;
				}
				if (buttonNum == 1) {
					player.drop(inventory.carried.remove(1));
					if (inventory.carried.count == 0) inventory.carried = null;
				}
			}
		}
	}

	public static void handleClose(Player player) {
		Inventory inventory = player.inventory;
		if (inventory.carried != null) {
			player.drop(inventory.carried);
			inventory.carried = null;
		}
	}*/

};