CoralPlantBlock .java

net.minecraft.world.level.block.CoralPlantBlock (class): members: deadBlock, onPlace, SHAPE, neighbourState, directionToNeighbour, updateShape, ticks.

net.minecraft.world.level.blockclass72 linescommonextends BaseCoralPlantTypeBlock2.5 KB

API Surface (4)

void onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston)
void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random)
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)
VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)

Fields & Constants (9)

SHAPE
deadBlock
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

CoralPlantBlock.java72 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.level.BlockGetter;
8
import net.minecraft.world.level.Level;
9
import net.minecraft.world.level.LevelReader;
10
import net.minecraft.world.level.ScheduledTickAccess;
11
import net.minecraft.world.level.block.state.BlockBehaviour;
12
import net.minecraft.world.level.block.state.BlockState;
13
import net.minecraft.world.level.material.Fluids;
14
import net.minecraft.world.phys.shapes.CollisionContext;
15
import net.minecraft.world.phys.shapes.VoxelShape;
16
17
/**
18
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
19
 */
20
public class CoralPlantBlock extends BaseCoralPlantTypeBlock {
21
	private final Block deadBlock;
22
	private static final VoxelShape SHAPE = Block.column(12.0, 0.0, 15.0);
23
24
	/**
25
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
26
	 */
27
	public CoralPlantBlock(final Block deadBlock, final BlockBehaviour.Properties properties) {
28
		super(properties);
29
		this.deadBlock = deadBlock;
30
	}
31
32
	@Override
33
	protected void onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston) {
34
		this.tryScheduleDieTick(state, level, level, level.getRandom(), pos);
35
	}
36
37
	@Override
38
	protected void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
39
		if (!scanForWater(state, level, pos)) {
40
			level.setBlock(pos, this.deadBlock.defaultBlockState().setValue(WATERLOGGED, false), 2);
41
		}
42
	}
43
44
	@Override
45
	protected BlockState updateShape(
46
		final BlockState state,
47
		final LevelReader level,
48
		final ScheduledTickAccess ticks,
49
		final BlockPos pos,
50
		final Direction directionToNeighbour,
51
		final BlockPos neighbourPos,
52
		final BlockState neighbourState,
53
		final RandomSource random
54
	) {
55
		if (directionToNeighbour == Direction.DOWN && !state.canSurvive(level, pos)) {
56
			return Blocks.AIR.defaultBlockState();
57
		}
58
59
		this.tryScheduleDieTick(state, level, ticks, random, pos);
60
		if (state.getValue(WATERLOGGED)) {
61
			ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
62
		}
63
64
		return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
65
	}
66
67
	@Override
68
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
69
		return SHAPE;
70
	}
71
}
72

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