FallingBlock .java

net.minecraft.world.level.block.FallingBlock (class, 75 lines): members: getDelayAfterPlace, falling, isFree, getDustColor, onPlace, animateTick, ticks.

net.minecraft.world.level.blockclass75 linescommonextends Block2.6 KB

Implements

API Surface (7)

void onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston)
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 falling(final FallingBlockEntity entity)
int getDelayAfterPlace()
boolean isFree(final BlockState state)
void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random)

Fields & Constants (7)

state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

FallingBlock.java75 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.core.particles.BlockParticleOption;
6
import net.minecraft.core.particles.ParticleTypes;
7
import net.minecraft.server.level.ServerLevel;
8
import net.minecraft.tags.BlockTags;
9
import net.minecraft.util.ParticleUtils;
10
import net.minecraft.util.RandomSource;
11
import net.minecraft.world.entity.item.FallingBlockEntity;
12
import net.minecraft.world.level.BlockGetter;
13
import net.minecraft.world.level.Level;
14
import net.minecraft.world.level.LevelReader;
15
import net.minecraft.world.level.ScheduledTickAccess;
16
import net.minecraft.world.level.block.state.BlockBehaviour;
17
import net.minecraft.world.level.block.state.BlockState;
18
19
public abstract class FallingBlock extends Block implements Fallable {
20
	public FallingBlock(final BlockBehaviour.Properties properties) {
21
		super(properties);
22
	}
23
24
	@Override
25
	protected void onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston) {
26
		level.scheduleTick(pos, this, this.getDelayAfterPlace());
27
	}
28
29
	@Override
30
	protected BlockState updateShape(
31
		final BlockState state,
32
		final LevelReader level,
33
		final ScheduledTickAccess ticks,
34
		final BlockPos pos,
35
		final Direction directionToNeighbour,
36
		final BlockPos neighbourPos,
37
		final BlockState neighbourState,
38
		final RandomSource random
39
	) {
40
		ticks.scheduleTick(pos, this, this.getDelayAfterPlace());
41
		return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
42
	}
43
44
	@Override
45
	protected void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
46
		if (isFree(level.getBlockState(pos.below())) && pos.getY() >= level.getMinY()) {
47
			FallingBlockEntity entity = FallingBlockEntity.fall(level, pos, state);
48
			this.falling(entity);
49
		}
50
	}
51
52
	protected void falling(final FallingBlockEntity entity) {
53
	}
54
55
	protected int getDelayAfterPlace() {
56
		return 2;
57
	}
58
59
	public static boolean isFree(final BlockState state) {
60
		return state.isAir() || state.is(BlockTags.FIRE) || state.liquid() || state.canBeReplaced();
61
	}
62
63
	@Override
64
	public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
65
		if (random.nextInt(16) == 0) {
66
			BlockPos below = pos.below();
67
			if (isFree(level.getBlockState(below))) {
68
				ParticleUtils.spawnParticleBelow(level, pos, random, new BlockParticleOption(ParticleTypes.FALLING_DUST, state));
69
			}
70
		}
71
	}
72
73
	public abstract int getDustColor(BlockState blockState, BlockGetter level, BlockPos pos);
74
}
75

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