| 1 | package net.minecraft.world.level.block;
|
| 2 |
|
| 3 | import java.util.function.ToIntFunction;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.server.level.ServerLevel;
|
| 6 | import net.minecraft.sounds.SoundEvents;
|
| 7 | import net.minecraft.sounds.SoundSource;
|
| 8 | import net.minecraft.util.Mth;
|
| 9 | import net.minecraft.world.InteractionResult;
|
| 10 | import net.minecraft.world.entity.Entity;
|
| 11 | import net.minecraft.world.level.Level;
|
| 12 | import net.minecraft.world.level.block.state.BlockState;
|
| 13 | import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
| 14 | import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
| 15 | import net.minecraft.world.level.gameevent.GameEvent;
|
| 16 | import net.minecraft.world.level.storage.loot.BuiltInLootTables;
|
| 17 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 18 |
|
| 19 | public interface CaveVines {
|
| 20 | VoxelShape SHAPE = Block.column(14.0, 0.0, 16.0);
|
| 21 | BooleanProperty BERRIES = BlockStateProperties.BERRIES;
|
| 22 |
|
| 23 | static InteractionResult use(final Entity sourceEntity, final BlockState state, final Level level, final BlockPos pos) {
|
| 24 | if (state.getValue(BERRIES)) {
|
| 25 | if (level instanceof ServerLevel serverLevel) {
|
| 26 | Block.dropFromBlockInteractLootTable(
|
| 27 | serverLevel,
|
| 28 | BuiltInLootTables.HARVEST_CAVE_VINE,
|
| 29 | pos,
|
| 30 | state,
|
| 31 | level.getBlockEntity(pos),
|
| 32 | null,
|
| 33 | sourceEntity,
|
| 34 | (serverlvl, itemStack) -> Block.popResource(serverlvl, pos, itemStack)
|
| 35 | );
|
| 36 | float pitch = Mth.randomBetween(serverLevel.getRandom(), 0.8F, 1.2F);
|
| 37 | serverLevel.playSound(null, pos, SoundEvents.CAVE_VINES_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, pitch);
|
| 38 | BlockState newState = state.setValue(BERRIES, false);
|
| 39 | serverLevel.setBlock(pos, newState, 2);
|
| 40 | serverLevel.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(sourceEntity, newState));
|
| 41 | }
|
| 42 |
|
| 43 | return InteractionResult.SUCCESS;
|
| 44 | } else {
|
| 45 | return InteractionResult.PASS;
|
| 46 | }
|
| 47 | }
|
| 48 |
|
| 49 | static boolean hasGlowBerries(final BlockState state) {
|
| 50 | return state.hasProperty(BERRIES) && state.getValue(BERRIES);
|
| 51 | }
|
| 52 |
|
| 53 | static ToIntFunction<BlockState> emission(final int lightEmission) {
|
| 54 | return state -> state.getValue(BlockStateProperties.BERRIES) ? lightEmission : 0;
|
| 55 | }
|
| 56 | }
|
| 57 |
|