PowderSnowBlock .java

net.minecraft.world.level.block.PowderSnowBlock (class): members: IN_BLOCK_HORIZONTAL_SPEED_MULTIPLIER, HORIZONTAL_PARTICLE_MOMENTUM_FACTOR, pickupBlock.

net.minecraft.world.level.blockclass167 linescommonextends Block6.5 KB

Implements

API Surface (10)

boolean skipRendering(final BlockState state, final BlockState neighborState, final Direction direction)
void entityInside(final BlockState state, final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise)
void fallOn(final Level level, final BlockState state, final BlockPos pos, final Entity entity, final double fallDistance)
VoxelShape getEntityInsideCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final Entity entity)
VoxelShape getCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
VoxelShape getVisualShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
boolean canEntityWalkOnPowderSnow(final Entity entity)
ItemStack pickupBlock(final @Nullable LivingEntity user, final LevelAccessor level, final BlockPos pos, final BlockState state)
Optional<SoundEvent> getPickupSound()
boolean isPathfindable(final BlockState state, final PathComputationType type)

Fields & Constants (8)

HORIZONTAL_PARTICLE_MOMENTUM_FACTOR
IN_BLOCK_HORIZONTAL_SPEED_MULTIPLIER
IN_BLOCK_VERTICAL_SPEED_MULTIPLIER
NUM_BLOCKS_TO_FALL_INTO_BLOCK
FALLING_COLLISION_SHAPE
MINIMUM_FALL_DISTANCE_FOR_SOUND
MINIMUM_FALL_DISTANCE_FOR_BIG_SOUND
effectApplier

Full Source

PowderSnowBlock.java167 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import java.util.Optional;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.core.particles.ParticleTypes;
7
import net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket;
8
import net.minecraft.server.level.ServerLevel;
9
import net.minecraft.sounds.SoundEvent;
10
import net.minecraft.sounds.SoundEvents;
11
import net.minecraft.tags.EntityTypeTags;
12
import net.minecraft.util.Mth;
13
import net.minecraft.util.RandomSource;
14
import net.minecraft.world.entity.Entity;
15
import net.minecraft.world.entity.EquipmentSlot;
16
import net.minecraft.world.entity.InsideBlockEffectApplier;
17
import net.minecraft.world.entity.InsideBlockEffectType;
18
import net.minecraft.world.entity.LivingEntity;
19
import net.minecraft.world.entity.item.FallingBlockEntity;
20
import net.minecraft.world.entity.player.Player;
21
import net.minecraft.world.item.ItemStack;
22
import net.minecraft.world.item.Items;
23
import net.minecraft.world.level.BlockGetter;
24
import net.minecraft.world.level.Level;
25
import net.minecraft.world.level.LevelAccessor;
26
import net.minecraft.world.level.block.state.BlockBehaviour;
27
import net.minecraft.world.level.block.state.BlockState;
28
import net.minecraft.world.level.gamerules.GameRules;
29
import net.minecraft.world.level.pathfinder.PathComputationType;
30
import net.minecraft.world.phys.Vec3;
31
import net.minecraft.world.phys.shapes.CollisionContext;
32
import net.minecraft.world.phys.shapes.EntityCollisionContext;
33
import net.minecraft.world.phys.shapes.Shapes;
34
import net.minecraft.world.phys.shapes.VoxelShape;
35
import org.jspecify.annotations.Nullable;
36
37
public class PowderSnowBlock extends Block implements BucketPickup {
38
	private static final float HORIZONTAL_PARTICLE_MOMENTUM_FACTOR = 0.083333336F;
39
	private static final float IN_BLOCK_HORIZONTAL_SPEED_MULTIPLIER = 0.9F;
40
	private static final float IN_BLOCK_VERTICAL_SPEED_MULTIPLIER = 1.5F;
41
	private static final float NUM_BLOCKS_TO_FALL_INTO_BLOCK = 2.5F;
42
	private static final VoxelShape FALLING_COLLISION_SHAPE = Shapes.box(0.0, 0.0, 0.0, 1.0, 0.9F, 1.0);
43
	private static final double MINIMUM_FALL_DISTANCE_FOR_SOUND = 4.0;
44
	private static final double MINIMUM_FALL_DISTANCE_FOR_BIG_SOUND = 7.0;
45
46
	public PowderSnowBlock(final BlockBehaviour.Properties properties) {
47
		super(properties);
48
	}
49
50
	@Override
51
	protected boolean skipRendering(final BlockState state, final BlockState neighborState, final Direction direction) {
52
		return neighborState.is(this) ? true : super.skipRendering(state, neighborState, direction);
53
	}
54
55
	@Override
56
	protected void entityInside(
57
		final BlockState state, final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise
58
	) {
59
		if (!(entity instanceof LivingEntity) || entity.getInBlockState().is(this)) {
60
			entity.makeStuckInBlock(state, new Vec3(0.9F, 1.5, 0.9F));
61
			if (level instanceof ServerLevel serverLevel) {
62
				RandomSource random = level.getRandom();
63
				Vec3 knownMovement = entity.getKnownMovement();
64
				boolean isMoving = knownMovement.x() != 0.0 || knownMovement.z() != 0.0;
65
				if (isMoving && random.nextBoolean()) {
66
					serverLevel.sendParticles(
67
						ParticleTypes.SNOWFLAKE,
68
						entity.getX(),
69
						pos.getY() + 1,
70
						entity.getZ(),
71
						1,
72
						0.0,
73
						0.0,
74
						0.0,
75
						Mth.randomBetween(random, -1.0F, 1.0F) * 0.083333336F,
76
						0.05F,
77
						Mth.randomBetween(random, -1.0F, 1.0F) * 0.083333336F,
78
						ClientboundLevelParticlesPacket.RandomizationType.ALTERNATIVE
79
					);
80
				}
81
			}
82
		}
83
84
		BlockPos position = pos.immutable();
85
		effectApplier.runBefore(
86
			InsideBlockEffectType.EXTINGUISH,
87
			e -> {
88
				if (level instanceof ServerLevel serverLevel
89
					&& e.isOnFire()
90
					&& (serverLevel.getGameRules().get(GameRules.MOB_GRIEFING) || e instanceof Player)
91
					&& e.mayInteract(serverLevel, position)) {
92
					level.destroyBlock(position, false);
93
				}
94
			}
95
		);
96
		effectApplier.apply(InsideBlockEffectType.FREEZE);
97
		effectApplier.apply(InsideBlockEffectType.EXTINGUISH);
98
	}
99
100
	@Override
101
	public void fallOn(final Level level, final BlockState state, final BlockPos pos, final Entity entity, final double fallDistance) {
102
		if (!(fallDistance < 4.0) && entity instanceof LivingEntity livingEntity) {
103
			LivingEntity.Fallsounds entityFallsounds = livingEntity.getFallSounds();
104
			SoundEvent fallSound = fallDistance < 7.0 ? entityFallsounds.small() : entityFallsounds.big();
105
			entity.playSound(fallSound, 1.0F, 1.0F);
106
		}
107
	}
108
109
	@Override
110
	protected VoxelShape getEntityInsideCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final Entity entity) {
111
		VoxelShape collisionShape = this.getCollisionShape(state, level, pos, CollisionContext.of(entity));
112
		return collisionShape.isEmpty() ? Shapes.block() : collisionShape;
113
	}
114
115
	@Override
116
	protected VoxelShape getCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
117
		if (!context.isPlacement() && context instanceof EntityCollisionContext entityCollisionContext) {
118
			Entity entity = entityCollisionContext.getEntity();
119
			if (entity != null) {
120
				if (entity.fallDistance > 2.5) {
121
					return FALLING_COLLISION_SHAPE;
122
				}
123
124
				boolean isFallingBlock = entity instanceof FallingBlockEntity;
125
				if (isFallingBlock || canEntityWalkOnPowderSnow(entity) && context.isAbove(Shapes.block(), pos, false) && !context.isDescending()) {
126
					return super.getCollisionShape(state, level, pos, context);
127
				}
128
			}
129
		}
130
131
		return Shapes.empty();
132
	}
133
134
	@Override
135
	protected VoxelShape getVisualShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
136
		return Shapes.empty();
137
	}
138
139
	public static boolean canEntityWalkOnPowderSnow(final Entity entity) {
140
		if (entity.is(EntityTypeTags.POWDER_SNOW_WALKABLE_MOBS)) {
141
			return true;
142
		} else {
143
			return entity instanceof LivingEntity livingEntity ? livingEntity.getItemBySlot(EquipmentSlot.FEET).is(Items.LEATHER_BOOTS) : false;
144
		}
145
	}
146
147
	@Override
148
	public ItemStack pickupBlock(final @Nullable LivingEntity user, final LevelAccessor level, final BlockPos pos, final BlockState state) {
149
		level.setBlock(pos, Blocks.AIR.defaultBlockState(), 11);
150
		if (!level.isClientSide()) {
151
			level.levelEvent(2001, pos, Block.getId(state));
152
		}
153
154
		return new ItemStack(Items.POWDER_SNOW_BUCKET);
155
	}
156
157
	@Override
158
	public Optional<SoundEvent> getPickupSound() {
159
		return Optional.of(SoundEvents.BUCKET_FILL_POWDER_SNOW);
160
	}
161
162
	@Override
163
	protected boolean isPathfindable(final BlockState state, final PathComputationType type) {
164
		return true;
165
	}
166
}
167

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