| 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.sounds.SoundEvents;
|
| 7 | import net.minecraft.sounds.SoundSource;
|
| 8 | import net.minecraft.util.RandomSource;
|
| 9 | import net.minecraft.world.attribute.EnvironmentAttributes;
|
| 10 | import net.minecraft.world.level.Level;
|
| 11 | import net.minecraft.world.level.block.state.BlockBehaviour;
|
| 12 | import net.minecraft.world.level.block.state.BlockState;
|
| 13 |
|
| 14 | /**
|
| 15 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 16 | */
|
| 17 | public class WetSpongeBlock extends Block {
|
| 18 | /**
|
| 19 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 20 | */
|
| 21 | public WetSpongeBlock(final BlockBehaviour.Properties properties) {
|
| 22 | super(properties);
|
| 23 | }
|
| 24 |
|
| 25 | @Override
|
| 26 | protected void onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston) {
|
| 27 | if (level.environmentAttributes().getValue(EnvironmentAttributes.WATER_EVAPORATES, pos)) {
|
| 28 | level.setBlockAndUpdate(pos, Blocks.SPONGE.defaultBlockState());
|
| 29 | level.levelEvent(2009, pos, 0);
|
| 30 | level.playSound(null, pos, SoundEvents.WET_SPONGE_DRIES, SoundSource.BLOCKS, 1.0F, (1.0F + level.getRandom().nextFloat() * 0.2F) * 0.7F);
|
| 31 | }
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
|
| 36 | Direction direction = Direction.getRandom(random);
|
| 37 | if (direction != Direction.UP) {
|
| 38 | BlockPos relativePos = pos.relative(direction);
|
| 39 | BlockState blockState = level.getBlockState(relativePos);
|
| 40 | if (!state.canOcclude() || !blockState.isFaceSturdy(level, relativePos, direction.getOpposite())) {
|
| 41 | double xx = pos.getX();
|
| 42 | double yy = pos.getY();
|
| 43 | double zz = pos.getZ();
|
| 44 | if (direction == Direction.DOWN) {
|
| 45 | yy -= 0.05;
|
| 46 | xx += random.nextDouble();
|
| 47 | zz += random.nextDouble();
|
| 48 | } else {
|
| 49 | yy += random.nextDouble() * 0.8;
|
| 50 | if (direction.getAxis() == Direction.Axis.X) {
|
| 51 | zz += random.nextDouble();
|
| 52 | if (direction == Direction.EAST) {
|
| 53 | xx += 1.1;
|
| 54 | } else {
|
| 55 | xx += 0.05;
|
| 56 | }
|
| 57 | } else {
|
| 58 | xx += random.nextDouble();
|
| 59 | if (direction == Direction.SOUTH) {
|
| 60 | zz += 1.1;
|
| 61 | } else {
|
| 62 | zz += 0.05;
|
| 63 | }
|
| 64 | }
|
| 65 | }
|
| 66 |
|
| 67 | level.addParticle(ParticleTypes.DRIPPING_WATER, xx, yy, zz, 0.0, 0.0, 0.0);
|
| 68 | }
|
| 69 | }
|
| 70 | }
|
| 71 | }
|
| 72 |
|