56 lines
2 KiB
Java
56 lines
2 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import java.util.Optional;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.sounds.SoundEvent;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.LevelAccessor;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
|
import net.minecraft.world.level.material.Fluid;
|
|
import net.minecraft.world.level.material.FluidState;
|
|
import net.minecraft.world.level.material.Fluids;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
public interface SimpleWaterloggedBlock extends BucketPickup, LiquidBlockContainer {
|
|
@Override
|
|
default boolean canPlaceLiquid(@Nullable LivingEntity owner, BlockGetter level, BlockPos pos, BlockState state, Fluid fluid) {
|
|
return fluid == Fluids.WATER;
|
|
}
|
|
|
|
@Override
|
|
default boolean placeLiquid(LevelAccessor level, BlockPos pos, BlockState state, FluidState fluidState) {
|
|
if (!(Boolean)state.getValue(BlockStateProperties.WATERLOGGED) && fluidState.getType() == Fluids.WATER) {
|
|
if (!level.isClientSide()) {
|
|
level.setBlock(pos, state.setValue(BlockStateProperties.WATERLOGGED, true), 3);
|
|
level.scheduleTick(pos, fluidState.getType(), fluidState.getType().getTickDelay(level));
|
|
}
|
|
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
default ItemStack pickupBlock(@Nullable LivingEntity owner, LevelAccessor level, BlockPos pos, BlockState state) {
|
|
if ((Boolean)state.getValue(BlockStateProperties.WATERLOGGED)) {
|
|
level.setBlock(pos, state.setValue(BlockStateProperties.WATERLOGGED, false), 3);
|
|
if (!state.canSurvive(level, pos)) {
|
|
level.destroyBlock(pos, true);
|
|
}
|
|
|
|
return new ItemStack(Items.WATER_BUCKET);
|
|
} else {
|
|
return ItemStack.EMPTY;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
default Optional<SoundEvent> getPickupSound() {
|
|
return Fluids.WATER.getPickupSound();
|
|
}
|
|
}
|