HopperMenu .java

net.minecraft.world.inventory.HopperMenu (class): members: hopper, CONTAINER_SIZE, quickMoveStack, stillValid, removed. imports: SimpleContainer, Player.

net.minecraft.world.inventoryclass66 linescommonextends AbstractContainerMenu1.8 KB

API Surface (3)

boolean stillValid(final Player player)
ItemStack quickMoveStack(final Player player, final int slotIndex)
void removed(final Player player)

Fields & Constants (2)

CONTAINER_SIZE
hopper

Code Graph: Dependencies (7)

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

Full Source

HopperMenu.java66 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 HopperMenu extends AbstractContainerMenu {
10
	public static final int CONTAINER_SIZE = 5;
11
	private final Container hopper;
12
13
	public HopperMenu(final int containerId, final Inventory inventory) {
14
		this(containerId, inventory, new SimpleContainer(5));
15
	}
16
17
	public HopperMenu(final int containerId, final Inventory inventory, final Container hopper) {
18
		super(MenuType.HOPPER, containerId);
19
		this.hopper = hopper;
20
		checkContainerSize(hopper, 5);
21
		hopper.startOpen(inventory.player);
22
23
		for (int x = 0; x < 5; x++) {
24
			this.addSlot(new Slot(hopper, x, 44 + x * 18, 20));
25
		}
26
27
		this.addStandardInventorySlots(inventory, 8, 51);
28
	}
29
30
	@Override
31
	public boolean stillValid(final Player player) {
32
		return this.hopper.stillValid(player);
33
	}
34
35
	@Override
36
	public ItemStack quickMoveStack(final Player player, final int slotIndex) {
37
		ItemStack clicked = ItemStack.EMPTY;
38
		Slot slot = this.slots.get(slotIndex);
39
		if (slot != null && slot.hasItem()) {
40
			ItemStack stack = slot.getItem();
41
			clicked = stack.copy();
42
			if (slotIndex < this.hopper.getContainerSize()) {
43
				if (!this.moveItemStackTo(stack, this.hopper.getContainerSize(), this.slots.size(), true)) {
44
					return ItemStack.EMPTY;
45
				}
46
			} else if (!this.moveItemStackTo(stack, 0, this.hopper.getContainerSize(), false)) {
47
				return ItemStack.EMPTY;
48
			}
49
50
			if (stack.isEmpty()) {
51
				slot.setByPlayer(ItemStack.EMPTY);
52
			} else {
53
				slot.setChanged();
54
			}
55
		}
56
57
		return clicked;
58
	}
59
60
	@Override
61
	public void removed(final Player player) {
62
		super.removed(player);
63
		this.hopper.stopOpen(player);
64
	}
65
}
66

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