MinecartChest .java

net.minecraft.world.entity.vehicle.minecart.MinecartChest (class): members: getDefaultDisplayOffset, getDefaultDisplayBlockState, getDropItem, stopOpen.

net.minecraft.world.entity.vehicle.minecartclass75 linescommonextends AbstractMinecartContainer2.4 KB

API Surface (8)

Item getDropItem()
ItemStack getPickResult()
int getContainerSize()
BlockState getDefaultDisplayBlockState()
int getDefaultDisplayOffset()
AbstractContainerMenu createMenu(final int containerId, final Inventory inventory)
void stopOpen(final ContainerUser containerUser)
InteractionResult interact(final Player player, final InteractionHand hand, final Vec3 location)

Full Source

MinecartChest.java75 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.vehicle.minecart;
2
3
import net.minecraft.core.Direction;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.world.InteractionHand;
6
import net.minecraft.world.InteractionResult;
7
import net.minecraft.world.entity.ContainerUser;
8
import net.minecraft.world.entity.EntityType;
9
import net.minecraft.world.entity.monster.piglin.PiglinAi;
10
import net.minecraft.world.entity.player.Inventory;
11
import net.minecraft.world.entity.player.Player;
12
import net.minecraft.world.inventory.AbstractContainerMenu;
13
import net.minecraft.world.inventory.ChestMenu;
14
import net.minecraft.world.item.Item;
15
import net.minecraft.world.item.ItemStack;
16
import net.minecraft.world.item.Items;
17
import net.minecraft.world.level.Level;
18
import net.minecraft.world.level.block.Blocks;
19
import net.minecraft.world.level.block.ChestBlock;
20
import net.minecraft.world.level.block.state.BlockState;
21
import net.minecraft.world.level.gameevent.GameEvent;
22
import net.minecraft.world.phys.Vec3;
23
24
public class MinecartChest extends AbstractMinecartContainer {
25
	public MinecartChest(final EntityType<? extends MinecartChest> type, final Level level) {
26
		super(type, level);
27
	}
28
29
	@Override
30
	protected Item getDropItem() {
31
		return Items.CHEST_MINECART;
32
	}
33
34
	@Override
35
	public ItemStack getPickResult() {
36
		return new ItemStack(Items.CHEST_MINECART);
37
	}
38
39
	@Override
40
	public int getContainerSize() {
41
		return 27;
42
	}
43
44
	@Override
45
	public BlockState getDefaultDisplayBlockState() {
46
		return Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.NORTH);
47
	}
48
49
	@Override
50
	public int getDefaultDisplayOffset() {
51
		return 8;
52
	}
53
54
	@Override
55
	public AbstractContainerMenu createMenu(final int containerId, final Inventory inventory) {
56
		return ChestMenu.threeRows(containerId, inventory, this);
57
	}
58
59
	@Override
60
	public void stopOpen(final ContainerUser containerUser) {
61
		this.level().gameEvent(GameEvent.CONTAINER_CLOSE, this.position(), GameEvent.Context.of(containerUser.getLivingEntity()));
62
	}
63
64
	@Override
65
	public InteractionResult interact(final Player player, final InteractionHand hand, final Vec3 location) {
66
		InteractionResult result = this.interactWithContainerVehicle(player);
67
		if (result.consumesAction() && player.level() instanceof ServerLevel serverLevel) {
68
			this.gameEvent(GameEvent.CONTAINER_OPEN, player);
69
			PiglinAi.angerNearbyPiglins(serverLevel, player, true);
70
		}
71
72
		return result;
73
	}
74
}
75

Decompiled Minecraft 26.3 source of MinecartChest (net/minecraft/world/entity/vehicle/minecart/MinecartChest.java) with Mojang official mappings, stored verbatim on the site.