CauldronBlock .java

net.minecraft.world.level.block.CauldronBlock (class, 67 lines): members: shouldHandlePrecipitation, POWDER_SNOW_FILL_CHANCE, RAIN_FILL_CHANCE, isFull.

net.minecraft.world.level.blockclass67 linescommonextends AbstractCauldronBlock2.5 KB

API Surface (5)

boolean isFull(final BlockState state)
boolean shouldHandlePrecipitation(final Level level, final Biome.Precipitation precipitation)
void handlePrecipitation(final BlockState state, final Level level, final BlockPos pos, final Biome.Precipitation precipitation)
boolean canReceiveStalactiteDrip(final Fluid fluid)
void receiveStalactiteDrip(final BlockState state, final Level level, final BlockPos pos, final Fluid fluid)

Fields & Constants (2)

RAIN_FILL_CHANCE
POWDER_SNOW_FILL_CHANCE

Full Source

CauldronBlock.java67 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.cauldron.CauldronInteractions;
5
import net.minecraft.world.level.Level;
6
import net.minecraft.world.level.biome.Biome;
7
import net.minecraft.world.level.block.state.BlockBehaviour;
8
import net.minecraft.world.level.block.state.BlockState;
9
import net.minecraft.world.level.gameevent.GameEvent;
10
import net.minecraft.world.level.material.Fluid;
11
import net.minecraft.world.level.material.Fluids;
12
13
public class CauldronBlock extends AbstractCauldronBlock {
14
	private static final float RAIN_FILL_CHANCE = 0.05F;
15
	private static final float POWDER_SNOW_FILL_CHANCE = 0.1F;
16
17
	public CauldronBlock(final BlockBehaviour.Properties properties) {
18
		super(properties, CauldronInteractions.EMPTY);
19
	}
20
21
	@Override
22
	public boolean isFull(final BlockState state) {
23
		return false;
24
	}
25
26
	protected static boolean shouldHandlePrecipitation(final Level level, final Biome.Precipitation precipitation) {
27
		if (precipitation == Biome.Precipitation.RAIN) {
28
			return level.getRandom().nextFloat() < 0.05F;
29
		} else {
30
			return precipitation == Biome.Precipitation.SNOW ? level.getRandom().nextFloat() < 0.1F : false;
31
		}
32
	}
33
34
	@Override
35
	public void handlePrecipitation(final BlockState state, final Level level, final BlockPos pos, final Biome.Precipitation precipitation) {
36
		if (shouldHandlePrecipitation(level, precipitation)) {
37
			if (precipitation == Biome.Precipitation.RAIN) {
38
				level.setBlockAndUpdate(pos, Blocks.WATER_CAULDRON.defaultBlockState());
39
				level.gameEvent(null, GameEvent.BLOCK_CHANGE, pos);
40
			} else if (precipitation == Biome.Precipitation.SNOW) {
41
				level.setBlockAndUpdate(pos, Blocks.POWDER_SNOW_CAULDRON.defaultBlockState());
42
				level.gameEvent(null, GameEvent.BLOCK_CHANGE, pos);
43
			}
44
		}
45
	}
46
47
	@Override
48
	protected boolean canReceiveStalactiteDrip(final Fluid fluid) {
49
		return true;
50
	}
51
52
	@Override
53
	protected void receiveStalactiteDrip(final BlockState state, final Level level, final BlockPos pos, final Fluid fluid) {
54
		if (fluid == Fluids.WATER) {
55
			BlockState newState = Blocks.WATER_CAULDRON.defaultBlockState();
56
			level.setBlockAndUpdate(pos, newState);
57
			level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(newState));
58
			level.levelEvent(1047, pos, 0);
59
		} else if (fluid == Fluids.LAVA) {
60
			BlockState newState = Blocks.LAVA_CAULDRON.defaultBlockState();
61
			level.setBlockAndUpdate(pos, newState);
62
			level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(newState));
63
			level.levelEvent(1046, pos, 0);
64
		}
65
	}
66
}
67

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