| 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.sounds.SoundEvents;
|
| 7 | import net.minecraft.sounds.SoundSource;
|
| 8 | import net.minecraft.stats.Stats;
|
| 9 | import net.minecraft.util.RandomSource;
|
| 10 | import net.minecraft.world.InteractionHand;
|
| 11 | import net.minecraft.world.InteractionResult;
|
| 12 | import net.minecraft.world.entity.item.ItemEntity;
|
| 13 | import net.minecraft.world.entity.player.Player;
|
| 14 | import net.minecraft.world.item.ItemStack;
|
| 15 | import net.minecraft.world.item.Items;
|
| 16 | import net.minecraft.world.level.Level;
|
| 17 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 18 | import net.minecraft.world.level.block.state.BlockState;
|
| 19 | import net.minecraft.world.level.gameevent.GameEvent;
|
| 20 | import net.minecraft.world.level.storage.loot.BuiltInLootTables;
|
| 21 | import net.minecraft.world.phys.BlockHitResult;
|
| 22 |
|
| 23 | /**
|
| 24 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 25 | */
|
| 26 | public class PumpkinBlock extends Block {
|
| 27 | /**
|
| 28 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 29 | */
|
| 30 | public PumpkinBlock(final BlockBehaviour.Properties properties) {
|
| 31 | super(properties);
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | protected InteractionResult useItemOn(
|
| 36 | final ItemStack itemStack,
|
| 37 | final BlockState state,
|
| 38 | final Level level,
|
| 39 | final BlockPos pos,
|
| 40 | final Player player,
|
| 41 | final InteractionHand hand,
|
| 42 | final BlockHitResult hitResult
|
| 43 | ) {
|
| 44 | if (!itemStack.is(Items.SHEARS)) {
|
| 45 | return super.useItemOn(itemStack, state, level, pos, player, hand, hitResult);
|
| 46 | } else if (level instanceof ServerLevel serverLevel) {
|
| 47 | Direction clickedDirection = hitResult.getDirection();
|
| 48 | Direction direction = clickedDirection.getAxis() == Direction.Axis.Y ? player.getDirection().getOpposite() : clickedDirection;
|
| 49 | dropFromBlockInteractLootTable(
|
| 50 | serverLevel,
|
| 51 | BuiltInLootTables.CARVE_PUMPKIN,
|
| 52 | pos,
|
| 53 | state,
|
| 54 | level.getBlockEntity(pos),
|
| 55 | itemStack,
|
| 56 | player,
|
| 57 | (ignored, pumpkinSeeds) -> {
|
| 58 | ItemEntity entity = new ItemEntity(
|
| 59 | level, pos.getX() + 0.5 + direction.getStepX() * 0.65, pos.getY() + 0.1, pos.getZ() + 0.5 + direction.getStepZ() * 0.65, pumpkinSeeds
|
| 60 | );
|
| 61 | RandomSource random = level.getRandom();
|
| 62 | entity.setDeltaMovement(0.05 * direction.getStepX() + random.nextDouble() * 0.02, 0.05, 0.05 * direction.getStepZ() + random.nextDouble() * 0.02);
|
| 63 | level.addFreshEntity(entity);
|
| 64 | }
|
| 65 | );
|
| 66 | level.playSound(null, pos, SoundEvents.PUMPKIN_CARVE, SoundSource.BLOCKS, 1.0F, 1.0F);
|
| 67 | level.setBlock(pos, Blocks.CARVED_PUMPKIN.defaultBlockState().setValue(CarvedPumpkinBlock.FACING, direction), 11);
|
| 68 | itemStack.hurtAndBreak(1, player, hand.asEquipmentSlot());
|
| 69 | level.gameEvent(player, GameEvent.SHEAR, pos);
|
| 70 | player.awardStat(Stats.ITEM_USED.get(Items.SHEARS));
|
| 71 | return InteractionResult.SUCCESS;
|
| 72 | } else {
|
| 73 | return InteractionResult.SUCCESS;
|
| 74 | }
|
| 75 | }
|
| 76 | }
|
| 77 |
|