| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Direction;
|
| 5 | import net.minecraft.server.level.ServerLevel;
|
| 6 | import net.minecraft.world.Containers;
|
| 7 | import net.minecraft.world.InteractionResult;
|
| 8 | import net.minecraft.world.entity.player.Player;
|
| 9 | import net.minecraft.world.inventory.AbstractContainerMenu;
|
| 10 | import net.minecraft.world.item.context.BlockPlaceContext;
|
| 11 | import net.minecraft.world.level.Level;
|
| 12 | import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
|
| 13 | import net.minecraft.world.level.block.entity.BlockEntity;
|
| 14 | import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
| 15 | import net.minecraft.world.level.block.entity.BlockEntityType;
|
| 16 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 17 | import net.minecraft.world.level.block.state.BlockState;
|
| 18 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 19 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 20 | import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
| 21 | import net.minecraft.world.level.block.state.properties.EnumProperty;
|
| 22 | import net.minecraft.world.phys.BlockHitResult;
|
| 23 | import org.jspecify.annotations.Nullable;
|
| 24 |
|
| 25 | public abstract class AbstractFurnaceBlock extends BaseEntityBlock {
|
| 26 | public static final EnumProperty<Direction> FACING = HorizontalDirectionalBlock.FACING;
|
| 27 | public static final BooleanProperty LIT = BlockStateProperties.LIT;
|
| 28 |
|
| 29 | protected AbstractFurnaceBlock(final BlockBehaviour.Properties properties) {
|
| 30 | super(properties);
|
| 31 | this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(LIT, false));
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | protected InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult) {
|
| 36 | if (!level.isClientSide()) {
|
| 37 | this.openContainer(level, pos, player);
|
| 38 | }
|
| 39 |
|
| 40 | return InteractionResult.SUCCESS;
|
| 41 | }
|
| 42 |
|
| 43 | protected abstract void openContainer(final Level level, final BlockPos pos, final Player player);
|
| 44 |
|
| 45 | @Override
|
| 46 | public BlockState getStateForPlacement(final BlockPlaceContext context) {
|
| 47 | return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
|
| 48 | }
|
| 49 |
|
| 50 | @Override
|
| 51 | protected void affectNeighborsAfterRemoval(final BlockState state, final ServerLevel level, final BlockPos pos, final boolean movedByPiston) {
|
| 52 | Containers.updateNeighboursAfterDestroy(state, level, pos);
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | protected boolean hasAnalogOutputSignal(final BlockState state) {
|
| 57 | return true;
|
| 58 | }
|
| 59 |
|
| 60 | @Override
|
| 61 | protected int getAnalogOutputSignal(final BlockState state, final Level level, final BlockPos pos, final Direction direction) {
|
| 62 | return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(level.getBlockEntity(pos));
|
| 63 | }
|
| 64 |
|
| 65 | @Override
|
| 66 | protected BlockState rotate(final BlockState state, final Rotation rotation) {
|
| 67 | return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
|
| 68 | }
|
| 69 |
|
| 70 | @Override
|
| 71 | protected BlockState mirror(final BlockState state, final Mirror mirror) {
|
| 72 | return state.rotate(mirror.getRotation(state.getValue(FACING)));
|
| 73 | }
|
| 74 |
|
| 75 | @Override
|
| 76 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 77 | builder.add(FACING, LIT);
|
| 78 | }
|
| 79 |
|
| 80 | protected static <T extends BlockEntity> @Nullable BlockEntityTicker<T> createFurnaceTicker(
|
| 81 | final Level level, final BlockEntityType<T> actualType, final BlockEntityType<? extends AbstractFurnaceBlockEntity> expectedType
|
| 82 | ) {
|
| 83 | return level instanceof ServerLevel serverLevel
|
| 84 | ? createTickerHelper(actualType, expectedType, (innerLevel, pos, state, entity) -> AbstractFurnaceBlockEntity.serverTick(serverLevel, pos, state, entity))
|
| 85 | : null;
|
| 86 | }
|
| 87 | }
|
| 88 |
|