CarpetBlock .java

net.minecraft.world.level.block.CarpetBlock (class): members: canSurvive, SHAPE, neighbourState, directionToNeighbour, updateShape, neighbourPos, ticks.

net.minecraft.world.level.blockclass47 linescommonextends Block1.5 KB

API Surface (3)

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)
boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos)

Fields & Constants (8)

SHAPE
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

CarpetBlock.java47 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.level.BlockGetter;
7
import net.minecraft.world.level.LevelReader;
8
import net.minecraft.world.level.ScheduledTickAccess;
9
import net.minecraft.world.level.block.state.BlockBehaviour;
10
import net.minecraft.world.level.block.state.BlockState;
11
import net.minecraft.world.phys.shapes.CollisionContext;
12
import net.minecraft.world.phys.shapes.VoxelShape;
13
14
public class CarpetBlock extends Block {
15
	private static final VoxelShape SHAPE = Block.column(16.0, 0.0, 1.0);
16
17
	public CarpetBlock(final BlockBehaviour.Properties properties) {
18
		super(properties);
19
	}
20
21
	@Override
22
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
23
		return SHAPE;
24
	}
25
26
	@Override
27
	protected BlockState updateShape(
28
		final BlockState state,
29
		final LevelReader level,
30
		final ScheduledTickAccess ticks,
31
		final BlockPos pos,
32
		final Direction directionToNeighbour,
33
		final BlockPos neighbourPos,
34
		final BlockState neighbourState,
35
		final RandomSource random
36
	) {
37
		return !state.canSurvive(level, pos)
38
			? Blocks.AIR.defaultBlockState()
39
			: super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
40
	}
41
42
	@Override
43
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
44
		return !level.isEmptyBlock(pos.below());
45
	}
46
}
47

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