DispenserMenu .java

net.minecraft.world.inventory.DispenserMenu (class): members: add3x3GridSlots, dispenser, SLOT_COUNT, USE_ROW_SLOT_START, USE_ROW_SLOT_END, INV_SLOT_START.

net.minecraft.world.inventoryclass81 linescommonextends AbstractContainerMenu2.3 KB

API Surface (4)

void add3x3GridSlots(final Container container, final int left, final int top)
boolean stillValid(final Player player)
ItemStack quickMoveStack(final Player player, final int slotIndex)
void removed(final Player player)

Fields & Constants (6)

SLOT_COUNT
INV_SLOT_START
INV_SLOT_END
USE_ROW_SLOT_START
USE_ROW_SLOT_END
dispenser

Code Graph: Dependencies (7)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

DispenserMenu.java81 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.inventory;
2
3
import net.minecraft.world.Container;
4
import net.minecraft.world.SimpleContainer;
5
import net.minecraft.world.entity.player.Inventory;
6
import net.minecraft.world.entity.player.Player;
7
import net.minecraft.world.item.ItemStack;
8
9
public class DispenserMenu extends AbstractContainerMenu {
10
	private static final int SLOT_COUNT = 9;
11
	private static final int INV_SLOT_START = 9;
12
	private static final int INV_SLOT_END = 36;
13
	private static final int USE_ROW_SLOT_START = 36;
14
	private static final int USE_ROW_SLOT_END = 45;
15
	private final Container dispenser;
16
17
	public DispenserMenu(final int containerId, final Inventory inventory) {
18
		this(containerId, inventory, new SimpleContainer(9));
19
	}
20
21
	public DispenserMenu(final int containerId, final Inventory inventory, final Container dispenser) {
22
		super(MenuType.GENERIC_3x3, containerId);
23
		checkContainerSize(dispenser, 9);
24
		this.dispenser = dispenser;
25
		dispenser.startOpen(inventory.player);
26
		this.add3x3GridSlots(dispenser, 62, 17);
27
		this.addStandardInventorySlots(inventory, 8, 84);
28
	}
29
30
	protected void add3x3GridSlots(final Container container, final int left, final int top) {
31
		for (int y = 0; y < 3; y++) {
32
			for (int x = 0; x < 3; x++) {
33
				int slot = x + y * 3;
34
				this.addSlot(new Slot(container, slot, left + x * 18, top + y * 18));
35
			}
36
		}
37
	}
38
39
	@Override
40
	public boolean stillValid(final Player player) {
41
		return this.dispenser.stillValid(player);
42
	}
43
44
	@Override
45
	public ItemStack quickMoveStack(final Player player, final int slotIndex) {
46
		ItemStack clicked = ItemStack.EMPTY;
47
		Slot slot = this.slots.get(slotIndex);
48
		if (slot != null && slot.hasItem()) {
49
			ItemStack stack = slot.getItem();
50
			clicked = stack.copy();
51
			if (slotIndex < 9) {
52
				if (!this.moveItemStackTo(stack, 9, 45, true)) {
53
					return ItemStack.EMPTY;
54
				}
55
			} else if (!this.moveItemStackTo(stack, 0, 9, false)) {
56
				return ItemStack.EMPTY;
57
			}
58
59
			if (stack.isEmpty()) {
60
				slot.setByPlayer(ItemStack.EMPTY);
61
			} else {
62
				slot.setChanged();
63
			}
64
65
			if (stack.getCount() == clicked.getCount()) {
66
				return ItemStack.EMPTY;
67
			}
68
69
			slot.onTake(player, stack);
70
		}
71
72
		return clicked;
73
	}
74
75
	@Override
76
	public void removed(final Player player) {
77
		super.removed(player);
78
		this.dispenser.stopOpen(player);
79
	}
80
}
81

Decompiled Minecraft 26.3 source of DispenserMenu (net/minecraft/world/inventory/DispenserMenu.java) with Mojang official mappings, stored verbatim on the site.