SporeBlossomBlock .java

net.minecraft.world.level.block.SporeBlossomBlock (class): members: ADD_PARTICLE_ATTEMPTS, PARTICLE_XZ_RADIUS, PARTICLE_Y_MAX, animateTick, canSurvive.

net.minecraft.world.level.blockclass81 linescommonextends Block2.9 KB

API Surface (4)

boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos)
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 animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random)
VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)

Fields & Constants (11)

SHAPE
ADD_PARTICLE_ATTEMPTS
PARTICLE_XZ_RADIUS
PARTICLE_Y_MAX
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

SporeBlossomBlock.java81 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.ParticleTypes;
6
import net.minecraft.util.Mth;
7
import net.minecraft.util.RandomSource;
8
import net.minecraft.world.level.BlockGetter;
9
import net.minecraft.world.level.Level;
10
import net.minecraft.world.level.LevelReader;
11
import net.minecraft.world.level.ScheduledTickAccess;
12
import net.minecraft.world.level.block.state.BlockBehaviour;
13
import net.minecraft.world.level.block.state.BlockState;
14
import net.minecraft.world.phys.shapes.CollisionContext;
15
import net.minecraft.world.phys.shapes.VoxelShape;
16
17
public class SporeBlossomBlock extends Block {
18
	private static final VoxelShape SHAPE = Block.column(12.0, 13.0, 16.0);
19
	private static final int ADD_PARTICLE_ATTEMPTS = 14;
20
	private static final int PARTICLE_XZ_RADIUS = 10;
21
	private static final int PARTICLE_Y_MAX = 10;
22
23
	public SporeBlossomBlock(final BlockBehaviour.Properties properties) {
24
		super(properties);
25
	}
26
27
	@Override
28
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
29
		return Block.canSupportCenter(level, pos.above(), Direction.DOWN) && !level.isWaterAt(pos);
30
	}
31
32
	@Override
33
	protected BlockState updateShape(
34
		final BlockState state,
35
		final LevelReader level,
36
		final ScheduledTickAccess ticks,
37
		final BlockPos pos,
38
		final Direction directionToNeighbour,
39
		final BlockPos neighbourPos,
40
		final BlockState neighbourState,
41
		final RandomSource random
42
	) {
43
		return directionToNeighbour == Direction.UP && !this.canSurvive(state, level, pos)
44
			? Blocks.AIR.defaultBlockState()
45
			: super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
46
	}
47
48
	@Override
49
	public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
50
		int plantX = pos.getX();
51
		int plantY = pos.getY();
52
		int plantZ = pos.getZ();
53
		double xFalling = plantX + random.nextDouble();
54
		double yFalling = plantY + 0.7;
55
		double zFalling = plantZ + random.nextDouble();
56
		level.addParticle(ParticleTypes.FALLING_SPORE_BLOSSOM, xFalling, yFalling, zFalling, 0.0, 0.0, 0.0);
57
		BlockPos.MutableBlockPos ambientPos = new BlockPos.MutableBlockPos();
58
59
		for (int i = 0; i < 14; i++) {
60
			ambientPos.set(plantX + Mth.nextInt(random, -10, 10), plantY - random.nextInt(10), plantZ + Mth.nextInt(random, -10, 10));
61
			BlockState particlePosState = level.getBlockState(ambientPos);
62
			if (!particlePosState.isCollisionShapeFullBlock(level, ambientPos)) {
63
				level.addParticle(
64
					ParticleTypes.SPORE_BLOSSOM_AIR,
65
					ambientPos.getX() + random.nextDouble(),
66
					ambientPos.getY() + random.nextDouble(),
67
					ambientPos.getZ() + random.nextDouble(),
68
					0.0,
69
					0.0,
70
					0.0
71
				);
72
			}
73
		}
74
	}
75
76
	@Override
77
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
78
		return SHAPE;
79
	}
80
}
81

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