package net.minecraft.world.level.block; import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.util.RandomSource; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; public class WetSpongeBlock extends Block { public static final MapCodec CODEC = simpleCodec(WetSpongeBlock::new); @Override public MapCodec codec() { return CODEC; } protected WetSpongeBlock(BlockBehaviour.Properties properties) { super(properties); } @Override protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) { if (level.dimensionType().ultraWarm()) { level.setBlock(pos, Blocks.SPONGE.defaultBlockState(), 3); level.levelEvent(2009, pos, 0); level.playSound(null, pos, SoundEvents.WET_SPONGE_DRIES, SoundSource.BLOCKS, 1.0F, (1.0F + level.getRandom().nextFloat() * 0.2F) * 0.7F); } } @Override public void animateTick(BlockState state, Level level, BlockPos pos, RandomSource random) { Direction direction = Direction.getRandom(random); if (direction != Direction.UP) { BlockPos blockPos = pos.relative(direction); BlockState blockState = level.getBlockState(blockPos); if (!state.canOcclude() || !blockState.isFaceSturdy(level, blockPos, direction.getOpposite())) { double d = pos.getX(); double e = pos.getY(); double f = pos.getZ(); if (direction == Direction.DOWN) { e -= 0.05; d += random.nextDouble(); f += random.nextDouble(); } else { e += random.nextDouble() * 0.8; if (direction.getAxis() == Direction.Axis.X) { f += random.nextDouble(); if (direction == Direction.EAST) { d++; } else { d += 0.05; } } else { d += random.nextDouble(); if (direction == Direction.SOUTH) { f++; } else { f += 0.05; } } } level.addParticle(ParticleTypes.DRIPPING_WATER, d, e, f, 0.0, 0.0, 0.0); } } } }