PathBlock .java

net.minecraft.world.level.block.PathBlock (class): members: turnToBaseBlock, baseBlock, useShapeForLightOcclusion, isPathfindable, canSurvive, SHAPE.

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

API Surface (8)

boolean useShapeForLightOcclusion(final BlockState state)
BlockState getStateForPlacement(final BlockPlaceContext 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)
void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random)
void turnToBaseBlock(final @Nullable Entity sourceEntity, final BlockState state, final Level level, final BlockPos pos)
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)
boolean isPathfindable(final BlockState state, final PathComputationType type)

Fields & Constants (9)

SHAPE
baseBlock
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

PathBlock.java93 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.server.level.ServerLevel;
6
import net.minecraft.util.RandomSource;
7
import net.minecraft.world.entity.Entity;
8
import net.minecraft.world.item.context.BlockPlaceContext;
9
import net.minecraft.world.level.BlockGetter;
10
import net.minecraft.world.level.Level;
11
import net.minecraft.world.level.LevelReader;
12
import net.minecraft.world.level.ScheduledTickAccess;
13
import net.minecraft.world.level.block.state.BlockBehaviour;
14
import net.minecraft.world.level.block.state.BlockState;
15
import net.minecraft.world.level.gameevent.GameEvent;
16
import net.minecraft.world.level.pathfinder.PathComputationType;
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 PathBlock extends Block {
25
	private static final VoxelShape SHAPE = Block.column(16.0, 0.0, 15.0);
26
	private final Block baseBlock;
27
28
	/**
29
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
30
	 */
31
	public PathBlock(final Block baseBlock, final BlockBehaviour.Properties properties) {
32
		super(properties);
33
		this.baseBlock = baseBlock;
34
	}
35
36
	@Override
37
	protected boolean useShapeForLightOcclusion(final BlockState state) {
38
		return true;
39
	}
40
41
	@Override
42
	public BlockState getStateForPlacement(final BlockPlaceContext context) {
43
		return !this.defaultBlockState().canSurvive(context.getLevel(), context.getClickedPos())
44
			? Block.pushEntitiesUp(this.defaultBlockState(), Blocks.DIRT.defaultBlockState(), context.getLevel(), context.getClickedPos())
45
			: super.getStateForPlacement(context);
46
	}
47
48
	@Override
49
	protected BlockState updateShape(
50
		final BlockState state,
51
		final LevelReader level,
52
		final ScheduledTickAccess ticks,
53
		final BlockPos pos,
54
		final Direction directionToNeighbour,
55
		final BlockPos neighbourPos,
56
		final BlockState neighbourState,
57
		final RandomSource random
58
	) {
59
		if (directionToNeighbour == Direction.UP && !state.canSurvive(level, pos)) {
60
			ticks.scheduleTick(pos, this, 1);
61
		}
62
63
		return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
64
	}
65
66
	@Override
67
	protected void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
68
		this.turnToBaseBlock(null, state, level, pos);
69
	}
70
71
	public void turnToBaseBlock(final @Nullable Entity sourceEntity, final BlockState state, final Level level, final BlockPos pos) {
72
		BlockState newState = pushEntitiesUp(state, this.baseBlock.defaultBlockState(), level, pos);
73
		level.setBlockAndUpdate(pos, newState);
74
		level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(sourceEntity, newState));
75
	}
76
77
	@Override
78
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
79
		BlockState aboveState = level.getBlockState(pos.above());
80
		return !aboveState.isSolid() || aboveState.getBlock() instanceof FenceGateBlock;
81
	}
82
83
	@Override
84
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
85
		return SHAPE;
86
	}
87
88
	@Override
89
	protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
90
		return false;
91
	}
92
}
93

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