CraftingTableBlock .java

net.minecraft.world.level.block.CraftingTableBlock (class, 47 lines): members: CONTAINER_TITLE, getMenuProvider, useWithoutItem. imports: CraftingMenu.

net.minecraft.world.level.blockclass47 linescommonextends Block1.7 KB

API Surface (2)

InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult)
MenuProvider getMenuProvider(final BlockState state, final Level level, final BlockPos pos)

Fields & Constants (1)

CONTAINER_TITLE

String literals (1)

"container.crafting"

Full Source

CraftingTableBlock.java47 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.network.chat.Component;
5
import net.minecraft.stats.Stats;
6
import net.minecraft.world.InteractionResult;
7
import net.minecraft.world.MenuProvider;
8
import net.minecraft.world.SimpleMenuProvider;
9
import net.minecraft.world.entity.player.Player;
10
import net.minecraft.world.inventory.ContainerLevelAccess;
11
import net.minecraft.world.inventory.CraftingMenu;
12
import net.minecraft.world.level.Level;
13
import net.minecraft.world.level.block.state.BlockBehaviour;
14
import net.minecraft.world.level.block.state.BlockState;
15
import net.minecraft.world.phys.BlockHitResult;
16
17
/**
18
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
19
 */
20
public class CraftingTableBlock extends Block {
21
	private static final Component CONTAINER_TITLE = Component.translatable("container.crafting");
22
23
	/**
24
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
25
	 */
26
	public CraftingTableBlock(final BlockBehaviour.Properties properties) {
27
		super(properties);
28
	}
29
30
	@Override
31
	protected InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult) {
32
		if (!level.isClientSide()) {
33
			player.openMenu(state.getMenuProvider(level, pos));
34
			player.awardStat(Stats.INTERACT_WITH_CRAFTING_TABLE);
35
		}
36
37
		return InteractionResult.SUCCESS;
38
	}
39
40
	@Override
41
	protected MenuProvider getMenuProvider(final BlockState state, final Level level, final BlockPos pos) {
42
		return new SimpleMenuProvider(
43
			(containerId, inventory, player) -> new CraftingMenu(containerId, inventory, ContainerLevelAccess.create(level, pos)), CONTAINER_TITLE
44
		);
45
	}
46
}
47

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