| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Direction;
|
| 5 | import net.minecraft.core.particles.ParticleTypes;
|
| 6 | import net.minecraft.server.level.ServerLevel;
|
| 7 | import net.minecraft.stats.Stats;
|
| 8 | import net.minecraft.util.RandomSource;
|
| 9 | import net.minecraft.world.Containers;
|
| 10 | import net.minecraft.world.InteractionResult;
|
| 11 | import net.minecraft.world.entity.player.Player;
|
| 12 | import net.minecraft.world.inventory.AbstractContainerMenu;
|
| 13 | import net.minecraft.world.level.BlockGetter;
|
| 14 | import net.minecraft.world.level.Level;
|
| 15 | import net.minecraft.world.level.block.entity.BlockEntity;
|
| 16 | import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
| 17 | import net.minecraft.world.level.block.entity.BlockEntityType;
|
| 18 | import net.minecraft.world.level.block.entity.BlockEntityTypes;
|
| 19 | import net.minecraft.world.level.block.entity.BrewingStandBlockEntity;
|
| 20 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 21 | import net.minecraft.world.level.block.state.BlockState;
|
| 22 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 23 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 24 | import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
| 25 | import net.minecraft.world.level.pathfinder.PathComputationType;
|
| 26 | import net.minecraft.world.phys.BlockHitResult;
|
| 27 | import net.minecraft.world.phys.shapes.CollisionContext;
|
| 28 | import net.minecraft.world.phys.shapes.Shapes;
|
| 29 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 30 | import org.jspecify.annotations.Nullable;
|
| 31 |
|
| 32 | public class BrewingStandBlock extends BaseEntityBlock {
|
| 33 | public static final BooleanProperty[] HAS_BOTTLE = new BooleanProperty[]{
|
| 34 | BlockStateProperties.HAS_BOTTLE_0, BlockStateProperties.HAS_BOTTLE_1, BlockStateProperties.HAS_BOTTLE_2
|
| 35 | };
|
| 36 | private static final VoxelShape SHAPE = Shapes.or(Block.column(2.0, 2.0, 14.0), Block.column(14.0, 0.0, 2.0));
|
| 37 |
|
| 38 | public BrewingStandBlock(final BlockBehaviour.Properties properties) {
|
| 39 | super(properties);
|
| 40 | this.registerDefaultState(this.stateDefinition.any().setValue(HAS_BOTTLE[0], false).setValue(HAS_BOTTLE[1], false).setValue(HAS_BOTTLE[2], false));
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | public BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
|
| 45 | return new BrewingStandBlockEntity(worldPosition, blockState);
|
| 46 | }
|
| 47 |
|
| 48 | @Override
|
| 49 | public <T extends BlockEntity> @Nullable BlockEntityTicker<T> getTicker(final Level level, final BlockState blockState, final BlockEntityType<T> type) {
|
| 50 | return level instanceof ServerLevel serverLevel
|
| 51 | ? createTickerHelper(type, BlockEntityTypes.BREWING_STAND, (var1, pos, state, entity) -> BrewingStandBlockEntity.serverTick(serverLevel, pos, state, entity))
|
| 52 | : null;
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
|
| 57 | return SHAPE;
|
| 58 | }
|
| 59 |
|
| 60 | @Override
|
| 61 | protected InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult) {
|
| 62 | if (!level.isClientSide() && level.getBlockEntity(pos) instanceof BrewingStandBlockEntity brewingStandBlockEntity) {
|
| 63 | player.openMenu(brewingStandBlockEntity);
|
| 64 | player.awardStat(Stats.INTERACT_WITH_BREWINGSTAND);
|
| 65 | }
|
| 66 |
|
| 67 | return InteractionResult.SUCCESS;
|
| 68 | }
|
| 69 |
|
| 70 | @Override
|
| 71 | public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
|
| 72 | double x = pos.getX() + 0.4 + random.nextFloat() * 0.2;
|
| 73 | double y = pos.getY() + 0.7 + random.nextFloat() * 0.3;
|
| 74 | double z = pos.getZ() + 0.4 + random.nextFloat() * 0.2;
|
| 75 | level.addParticle(ParticleTypes.SMOKE, x, y, z, 0.0, 0.0, 0.0);
|
| 76 | }
|
| 77 |
|
| 78 | @Override
|
| 79 | protected void affectNeighborsAfterRemoval(final BlockState state, final ServerLevel level, final BlockPos pos, final boolean movedByPiston) {
|
| 80 | Containers.updateNeighboursAfterDestroy(state, level, pos);
|
| 81 | }
|
| 82 |
|
| 83 | @Override
|
| 84 | protected boolean hasAnalogOutputSignal(final BlockState state) {
|
| 85 | return true;
|
| 86 | }
|
| 87 |
|
| 88 | @Override
|
| 89 | protected int getAnalogOutputSignal(final BlockState state, final Level level, final BlockPos pos, final Direction direction) {
|
| 90 | return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(level.getBlockEntity(pos));
|
| 91 | }
|
| 92 |
|
| 93 | @Override
|
| 94 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 95 | builder.add(HAS_BOTTLE[0], HAS_BOTTLE[1], HAS_BOTTLE[2]);
|
| 96 | }
|
| 97 |
|
| 98 | @Override
|
| 99 | protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
|
| 100 | return false;
|
| 101 | }
|
| 102 | }
|
| 103 |
|