48 lines
1.9 KiB
Java
48 lines
1.9 KiB
Java
|
package net.minecraft.world.level.block;
|
||
|
|
||
|
import com.mojang.serialization.MapCodec;
|
||
|
import net.minecraft.core.BlockPos;
|
||
|
import net.minecraft.network.chat.Component;
|
||
|
import net.minecraft.stats.Stats;
|
||
|
import net.minecraft.world.InteractionResult;
|
||
|
import net.minecraft.world.MenuProvider;
|
||
|
import net.minecraft.world.SimpleMenuProvider;
|
||
|
import net.minecraft.world.entity.player.Inventory;
|
||
|
import net.minecraft.world.entity.player.Player;
|
||
|
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||
|
import net.minecraft.world.inventory.CraftingMenu;
|
||
|
import net.minecraft.world.level.Level;
|
||
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||
|
import net.minecraft.world.level.block.state.BlockState;
|
||
|
import net.minecraft.world.phys.BlockHitResult;
|
||
|
|
||
|
public class CraftingTableBlock extends Block {
|
||
|
public static final MapCodec<CraftingTableBlock> CODEC = simpleCodec(CraftingTableBlock::new);
|
||
|
private static final Component CONTAINER_TITLE = Component.translatable("container.crafting");
|
||
|
|
||
|
@Override
|
||
|
public MapCodec<? extends CraftingTableBlock> codec() {
|
||
|
return CODEC;
|
||
|
}
|
||
|
|
||
|
protected CraftingTableBlock(BlockBehaviour.Properties p_52225_) {
|
||
|
super(p_52225_);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected InteractionResult useWithoutItem(BlockState p_52233_, Level p_52234_, BlockPos p_52235_, Player p_52236_, BlockHitResult p_52238_) {
|
||
|
if (!p_52234_.isClientSide) {
|
||
|
p_52236_.openMenu(p_52233_.getMenuProvider(p_52234_, p_52235_));
|
||
|
p_52236_.awardStat(Stats.INTERACT_WITH_CRAFTING_TABLE);
|
||
|
}
|
||
|
|
||
|
return InteractionResult.SUCCESS;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected MenuProvider getMenuProvider(BlockState p_52240_, Level p_52241_, BlockPos p_52242_) {
|
||
|
return new SimpleMenuProvider(
|
||
|
(p_52229_, p_52230_, p_52231_) -> new CraftingMenu(p_52229_, p_52230_, ContainerLevelAccess.create(p_52241_, p_52242_)), CONTAINER_TITLE
|
||
|
);
|
||
|
}
|
||
|
}
|