PlayerEnderChestContainer .java

net.minecraft.world.inventory.PlayerEnderChestContainer (class): members: setActiveChest, isActiveChest, storeAsSlots, activeChest, fromSlots, startOpen.

net.minecraft.world.inventoryclass73 linescommonextends SimpleContainer2.0 KB

API Surface (7)

void setActiveChest(final EnderChestBlockEntity activeChest)
boolean isActiveChest(final EnderChestBlockEntity chest)
void fromSlots(final ValueInput.TypedInputList<ItemStackWithSlot> list)
void storeAsSlots(final ValueOutput.TypedOutputList<ItemStackWithSlot> output)
boolean stillValid(final Player player)
void startOpen(final ContainerUser containerUser)
void stopOpen(final ContainerUser containerUser)

Fields & Constants (1)

activeChest

Full Source

PlayerEnderChestContainer.java73 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.inventory;
2
3
import net.minecraft.world.ItemStackWithSlot;
4
import net.minecraft.world.SimpleContainer;
5
import net.minecraft.world.entity.ContainerUser;
6
import net.minecraft.world.entity.player.Player;
7
import net.minecraft.world.item.ItemStack;
8
import net.minecraft.world.level.block.entity.EnderChestBlockEntity;
9
import net.minecraft.world.level.storage.ValueInput;
10
import net.minecraft.world.level.storage.ValueOutput;
11
import org.jspecify.annotations.Nullable;
12
13
public class PlayerEnderChestContainer extends SimpleContainer {
14
	private @Nullable EnderChestBlockEntity activeChest;
15
16
	public PlayerEnderChestContainer() {
17
		super(27);
18
	}
19
20
	public void setActiveChest(final EnderChestBlockEntity activeChest) {
21
		this.activeChest = activeChest;
22
	}
23
24
	public boolean isActiveChest(final EnderChestBlockEntity chest) {
25
		return this.activeChest == chest;
26
	}
27
28
	public void fromSlots(final ValueInput.TypedInputList<ItemStackWithSlot> list) {
29
		for (int i = 0; i < this.getContainerSize(); i++) {
30
			this.setItem(i, ItemStack.EMPTY);
31
		}
32
33
		for (ItemStackWithSlot item : list) {
34
			if (item.isValidInContainer(this.getContainerSize())) {
35
				this.setItem(item.slot(), item.stack());
36
			}
37
		}
38
	}
39
40
	public void storeAsSlots(final ValueOutput.TypedOutputList<ItemStackWithSlot> output) {
41
		for (int i = 0; i < this.getContainerSize(); i++) {
42
			ItemStack itemStack = this.getItem(i);
43
			if (!itemStack.isEmpty()) {
44
				output.add(new ItemStackWithSlot(i, itemStack));
45
			}
46
		}
47
	}
48
49
	@Override
50
	public boolean stillValid(final Player player) {
51
		return this.activeChest != null && !this.activeChest.stillValid(player) ? false : super.stillValid(player);
52
	}
53
54
	@Override
55
	public void startOpen(final ContainerUser containerUser) {
56
		if (this.activeChest != null) {
57
			this.activeChest.startOpen(containerUser);
58
		}
59
60
		super.startOpen(containerUser);
61
	}
62
63
	@Override
64
	public void stopOpen(final ContainerUser containerUser) {
65
		if (this.activeChest != null) {
66
			this.activeChest.stopOpen(containerUser);
67
		}
68
69
		super.stopOpen(containerUser);
70
		this.activeChest = null;
71
	}
72
}
73

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