BarrierBlock .java

net.minecraft.world.level.block.BarrierBlock (class, 96 lines): members: pickupBlock, getShadeBrightness, canPlaceLiquid, getRenderShape, WATERLOGGED.

net.minecraft.world.level.blockclass96 linescommonextends Block3.6 KB

Implements

API Surface (8)

boolean propagatesSkylightDown(final BlockState state)
RenderShape getRenderShape(final BlockState state)
float getShadeBrightness(final BlockState state, final BlockGetter level, final BlockPos pos)
BlockState updateShape(final BlockState state, final LevelReader level, final ScheduledTickAccess ticks, final BlockPos pos, final Direction directionToNeighbour, final BlockPos neighbourPos, final BlockState neighbourState, final RandomSource random)
FluidState getFluidState(final BlockState state)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
ItemStack pickupBlock(final @Nullable LivingEntity user, final LevelAccessor level, final BlockPos pos, final BlockState state)
boolean canPlaceLiquid(final @Nullable LivingEntity user, final BlockGetter level, final BlockPos pos, final BlockState state, final Fluid type)

Fields & Constants (8)

WATERLOGGED
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

BarrierBlock.java96 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.Direction;
5
import net.minecraft.util.RandomSource;
6
import net.minecraft.world.entity.LivingEntity;
7
import net.minecraft.world.entity.player.Player;
8
import net.minecraft.world.item.ItemStack;
9
import net.minecraft.world.item.context.BlockPlaceContext;
10
import net.minecraft.world.level.BlockGetter;
11
import net.minecraft.world.level.LevelAccessor;
12
import net.minecraft.world.level.LevelReader;
13
import net.minecraft.world.level.ScheduledTickAccess;
14
import net.minecraft.world.level.block.state.BlockBehaviour;
15
import net.minecraft.world.level.block.state.BlockState;
16
import net.minecraft.world.level.block.state.StateDefinition;
17
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
18
import net.minecraft.world.level.block.state.properties.BooleanProperty;
19
import net.minecraft.world.level.material.Fluid;
20
import net.minecraft.world.level.material.FluidState;
21
import net.minecraft.world.level.material.Fluids;
22
import org.jspecify.annotations.Nullable;
23
24
/**
25
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
26
 */
27
public class BarrierBlock extends Block implements SimpleWaterloggedBlock {
28
	public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
29
30
	/**
31
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
32
	 */
33
	public BarrierBlock(final BlockBehaviour.Properties properties) {
34
		super(properties);
35
		this.registerDefaultState(this.defaultBlockState().setValue(WATERLOGGED, false));
36
	}
37
38
	@Override
39
	protected boolean propagatesSkylightDown(final BlockState state) {
40
		return state.getFluidState().isEmpty();
41
	}
42
43
	@Override
44
	protected RenderShape getRenderShape(final BlockState state) {
45
		return RenderShape.INVISIBLE;
46
	}
47
48
	@Override
49
	protected float getShadeBrightness(final BlockState state, final BlockGetter level, final BlockPos pos) {
50
		return 1.0F;
51
	}
52
53
	@Override
54
	protected BlockState updateShape(
55
		final BlockState state,
56
		final LevelReader level,
57
		final ScheduledTickAccess ticks,
58
		final BlockPos pos,
59
		final Direction directionToNeighbour,
60
		final BlockPos neighbourPos,
61
		final BlockState neighbourState,
62
		final RandomSource random
63
	) {
64
		if (state.getValue(WATERLOGGED)) {
65
			ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
66
		}
67
68
		return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
69
	}
70
71
	@Override
72
	protected FluidState getFluidState(final BlockState state) {
73
		return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
74
	}
75
76
	@Override
77
	public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
78
		return this.defaultBlockState().setValue(WATERLOGGED, context.getLevel().getFluidState(context.getClickedPos()).is(Fluids.WATER));
79
	}
80
81
	@Override
82
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
83
		builder.add(WATERLOGGED);
84
	}
85
86
	@Override
87
	public ItemStack pickupBlock(final @Nullable LivingEntity user, final LevelAccessor level, final BlockPos pos, final BlockState state) {
88
		return user instanceof Player player && player.isCreative() ? SimpleWaterloggedBlock.super.pickupBlock(user, level, pos, state) : ItemStack.EMPTY;
89
	}
90
91
	@Override
92
	public boolean canPlaceLiquid(final @Nullable LivingEntity user, final BlockGetter level, final BlockPos pos, final BlockState state, final Fluid type) {
93
		return user instanceof Player player && player.isCreative() ? SimpleWaterloggedBlock.super.canPlaceLiquid(user, level, pos, state, type) : false;
94
	}
95
}
96

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