SimpleWaterloggedBlock .java

net.minecraft.world.level.block.SimpleWaterloggedBlock (interface): members: pickupBlock, canPlaceLiquid, placeLiquid, getPickupSound. imports: Fluid.

net.minecraft.world.level.blockinterface57 linescommonextends BucketPickup2.0 KB

API Surface (0)

No public/protected methods detected (fields or constants only).

Full Source

SimpleWaterloggedBlock.java57 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import java.util.Optional;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.sounds.SoundEvent;
6
import net.minecraft.world.entity.LivingEntity;
7
import net.minecraft.world.item.ItemStack;
8
import net.minecraft.world.item.Items;
9
import net.minecraft.world.level.BlockGetter;
10
import net.minecraft.world.level.LevelAccessor;
11
import net.minecraft.world.level.block.state.BlockState;
12
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
13
import net.minecraft.world.level.material.Fluid;
14
import net.minecraft.world.level.material.FluidState;
15
import net.minecraft.world.level.material.Fluids;
16
import org.jspecify.annotations.Nullable;
17
18
public interface SimpleWaterloggedBlock extends BucketPickup, LiquidBlockContainer {
19
	@Override
20
	default boolean canPlaceLiquid(final @Nullable LivingEntity user, final BlockGetter level, final BlockPos pos, final BlockState state, final Fluid type) {
21
		return type == Fluids.WATER;
22
	}
23
24
	@Override
25
	default boolean placeLiquid(final LevelAccessor level, final BlockPos pos, final BlockState state, final FluidState fluidState) {
26
		if (!state.getValue(BlockStateProperties.WATERLOGGED) && fluidState.is(Fluids.WATER)) {
27
			if (!level.isClientSide()) {
28
				level.setBlockAndUpdate(pos, state.setValue(BlockStateProperties.WATERLOGGED, true));
29
				level.scheduleTick(pos, fluidState.getType(), fluidState.getType().getTickDelay(level));
30
			}
31
32
			return true;
33
		} else {
34
			return false;
35
		}
36
	}
37
38
	@Override
39
	default ItemStack pickupBlock(final @Nullable LivingEntity user, final LevelAccessor level, final BlockPos pos, final BlockState state) {
40
		if (state.getValue(BlockStateProperties.WATERLOGGED)) {
41
			level.setBlockAndUpdate(pos, state.setValue(BlockStateProperties.WATERLOGGED, false));
42
			if (!state.canSurvive(level, pos)) {
43
				level.destroyBlock(pos, true);
44
			}
45
46
			return new ItemStack(Items.WATER_BUCKET);
47
		} else {
48
			return ItemStack.EMPTY;
49
		}
50
	}
51
52
	@Override
53
	default Optional<SoundEvent> getPickupSound() {
54
		return Fluids.WATER.getPickupSound();
55
	}
56
}
57

Decompiled Minecraft 26.3 source of SimpleWaterloggedBlock (net/minecraft/world/level/block/SimpleWaterloggedBlock.java) with Mojang official mappings, stored verbatim on the site.