ConcretePowderBlock .java

net.minecraft.world.level.block.ConcretePowderBlock (class): members: concrete, onLand, getDustColor, neighbourState, directionToNeighbour, updateShape.

net.minecraft.world.level.blockclass87 linescommonextends FallingBlock3.0 KB

API Surface (4)

void onLand(final Level level, final BlockPos pos, final BlockState state, final BlockState replacedBlock, final FallingBlockEntity entity)
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)
int getDustColor(final BlockState blockState, final BlockGetter level, final BlockPos pos)

Fields & Constants (8)

concrete
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

ConcretePowderBlock.java87 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.tags.FluidTags;
6
import net.minecraft.util.RandomSource;
7
import net.minecraft.world.entity.item.FallingBlockEntity;
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
16
public class ConcretePowderBlock extends FallingBlock {
17
	private final Block concrete;
18
19
	public ConcretePowderBlock(final Block concrete, final BlockBehaviour.Properties properties) {
20
		super(properties);
21
		this.concrete = concrete;
22
	}
23
24
	@Override
25
	public void onLand(final Level level, final BlockPos pos, final BlockState state, final BlockState replacedBlock, final FallingBlockEntity entity) {
26
		if (shouldSolidify(level, pos, replacedBlock)) {
27
			level.setBlockAndUpdate(pos, this.concrete.defaultBlockState());
28
		}
29
	}
30
31
	@Override
32
	public BlockState getStateForPlacement(final BlockPlaceContext context) {
33
		BlockGetter level = context.getLevel();
34
		BlockPos pos = context.getClickedPos();
35
		BlockState replacedBlock = level.getBlockState(pos);
36
		return shouldSolidify(level, pos, replacedBlock) ? this.concrete.defaultBlockState() : super.getStateForPlacement(context);
37
	}
38
39
	private static boolean shouldSolidify(final BlockGetter level, final BlockPos pos, final BlockState replacedBlock) {
40
		return canSolidify(replacedBlock) || touchesLiquid(level, pos);
41
	}
42
43
	private static boolean touchesLiquid(final BlockGetter level, final BlockPos pos) {
44
		boolean touchesLiquid = false;
45
		BlockPos.MutableBlockPos testPos = pos.mutable();
46
47
		for (Direction direction : Direction.values()) {
48
			BlockState blockState = level.getBlockState(testPos);
49
			if (direction != Direction.DOWN || canSolidify(blockState)) {
50
				testPos.setWithOffset(pos, direction);
51
				blockState = level.getBlockState(testPos);
52
				if (canSolidify(blockState) && !blockState.isFaceSturdy(level, pos, direction.getOpposite())) {
53
					touchesLiquid = true;
54
					break;
55
				}
56
			}
57
		}
58
59
		return touchesLiquid;
60
	}
61
62
	private static boolean canSolidify(final BlockState state) {
63
		return state.getFluidState().is(FluidTags.WATER);
64
	}
65
66
	@Override
67
	protected BlockState updateShape(
68
		final BlockState state,
69
		final LevelReader level,
70
		final ScheduledTickAccess ticks,
71
		final BlockPos pos,
72
		final Direction directionToNeighbour,
73
		final BlockPos neighbourPos,
74
		final BlockState neighbourState,
75
		final RandomSource random
76
	) {
77
		return touchesLiquid(level, pos)
78
			? this.concrete.defaultBlockState()
79
			: super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
80
	}
81
82
	@Override
83
	public int getDustColor(final BlockState blockState, final BlockGetter level, final BlockPos pos) {
84
		return blockState.getMapColor(level, pos).col;
85
	}
86
}
87

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