HangingRootsBlock .java

net.minecraft.world.level.block.HangingRootsBlock (class, 91 lines): members: WATERLOGGED, getFluidState, canSurvive, SHAPE, neighbourState, updateShape.

net.minecraft.world.level.blockclass91 linescommonextends Block3.3 KB

Implements

API Surface (5)

void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
FluidState getFluidState(final BlockState state)
boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos)
VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
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)

Fields & Constants (9)

WATERLOGGED
SHAPE
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

HangingRootsBlock.java91 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.item.context.BlockPlaceContext;
7
import net.minecraft.world.level.BlockGetter;
8
import net.minecraft.world.level.LevelReader;
9
import net.minecraft.world.level.ScheduledTickAccess;
10
import net.minecraft.world.level.block.state.BlockBehaviour;
11
import net.minecraft.world.level.block.state.BlockState;
12
import net.minecraft.world.level.block.state.StateDefinition;
13
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
14
import net.minecraft.world.level.block.state.properties.BooleanProperty;
15
import net.minecraft.world.level.material.FluidState;
16
import net.minecraft.world.level.material.Fluids;
17
import net.minecraft.world.phys.shapes.CollisionContext;
18
import net.minecraft.world.phys.shapes.VoxelShape;
19
import org.jspecify.annotations.Nullable;
20
21
/**
22
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
23
 */
24
public class HangingRootsBlock extends Block implements SimpleWaterloggedBlock {
25
	private static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
26
	private static final VoxelShape SHAPE = Block.column(12.0, 10.0, 16.0);
27
28
	/**
29
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
30
	 */
31
	public HangingRootsBlock(final BlockBehaviour.Properties properties) {
32
		super(properties);
33
		this.registerDefaultState(this.stateDefinition.any().setValue(WATERLOGGED, false));
34
	}
35
36
	@Override
37
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
38
		builder.add(WATERLOGGED);
39
	}
40
41
	@Override
42
	protected FluidState getFluidState(final BlockState state) {
43
		return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
44
	}
45
46
	@Override
47
	public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
48
		BlockState state = super.getStateForPlacement(context);
49
		if (state != null) {
50
			FluidState fluidState = context.getLevel().getFluidState(context.getClickedPos());
51
			return state.setValue(WATERLOGGED, fluidState.is(Fluids.WATER));
52
		} else {
53
			return null;
54
		}
55
	}
56
57
	@Override
58
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
59
		BlockPos attachedToPos = pos.above();
60
		BlockState attachedToState = level.getBlockState(attachedToPos);
61
		return attachedToState.isFaceSturdy(level, attachedToPos, Direction.DOWN);
62
	}
63
64
	@Override
65
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
66
		return SHAPE;
67
	}
68
69
	@Override
70
	protected BlockState updateShape(
71
		final BlockState state,
72
		final LevelReader level,
73
		final ScheduledTickAccess ticks,
74
		final BlockPos pos,
75
		final Direction directionToNeighbour,
76
		final BlockPos neighbourPos,
77
		final BlockState neighbourState,
78
		final RandomSource random
79
	) {
80
		if (directionToNeighbour == Direction.UP && !this.canSurvive(state, level, pos)) {
81
			return Blocks.AIR.defaultBlockState();
82
		}
83
84
		if (state.getValue(WATERLOGGED)) {
85
			ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
86
		}
87
88
		return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
89
	}
90
}
91

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