| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.server.level.ServerLevel;
|
| 5 | import net.minecraft.util.RandomSource;
|
| 6 | import net.minecraft.util.valueproviders.ConstantInt;
|
| 7 | import net.minecraft.util.valueproviders.IntProvider;
|
| 8 | import net.minecraft.world.item.ItemStack;
|
| 9 | import net.minecraft.world.level.Level;
|
| 10 | import net.minecraft.world.level.block.entity.BlockEntity;
|
| 11 | import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
| 12 | import net.minecraft.world.level.block.entity.BlockEntityType;
|
| 13 | import net.minecraft.world.level.block.entity.BlockEntityTypes;
|
| 14 | import net.minecraft.world.level.block.entity.SculkCatalystBlockEntity;
|
| 15 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 16 | import net.minecraft.world.level.block.state.BlockState;
|
| 17 | import net.minecraft.world.level.block.state.StateDefinition;
|
| 18 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 19 | import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
| 20 | import org.jspecify.annotations.Nullable;
|
| 21 |
|
| 22 | public class SculkCatalystBlock extends BaseEntityBlock {
|
| 23 | public static final BooleanProperty PULSE = BlockStateProperties.BLOOM;
|
| 24 | private final IntProvider xpRange = ConstantInt.of(5);
|
| 25 |
|
| 26 | public SculkCatalystBlock(final BlockBehaviour.Properties properties) {
|
| 27 | super(properties);
|
| 28 | this.registerDefaultState(this.stateDefinition.any().setValue(PULSE, false));
|
| 29 | }
|
| 30 |
|
| 31 | @Override
|
| 32 | protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
|
| 33 | builder.add(PULSE);
|
| 34 | }
|
| 35 |
|
| 36 | @Override
|
| 37 | protected void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
|
| 38 | if (state.getValue(PULSE)) {
|
| 39 | level.setBlockAndUpdate(pos, state.setValue(PULSE, false));
|
| 40 | }
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | public @Nullable BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
|
| 45 | return new SculkCatalystBlockEntity(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.isClientSide() ? null : createTickerHelper(type, BlockEntityTypes.SCULK_CATALYST, SculkCatalystBlockEntity::serverTick);
|
| 51 | }
|
| 52 |
|
| 53 | @Override
|
| 54 | protected void spawnAfterBreak(final BlockState state, final ServerLevel level, final BlockPos pos, final ItemStack tool, final boolean dropExperience) {
|
| 55 | super.spawnAfterBreak(state, level, pos, tool, dropExperience);
|
| 56 | if (dropExperience) {
|
| 57 | this.tryDropExperience(level, pos, tool, this.xpRange);
|
| 58 | }
|
| 59 | }
|
| 60 | }
|
| 61 |
|