LayeredCauldronBlock .java

net.minecraft.world.level.block.LayeredCauldronBlock (class): members: BASE_CONTENT_HEIGHT, precipitationType, HEIGHT_PER_LEVEL, MAX_FILL_LEVEL, isFull.

net.minecraft.world.level.blockclass128 linescommonextends AbstractCauldronBlock5.1 KB

API Surface (10)

boolean isFull(final BlockState state)
boolean canReceiveStalactiteDrip(final Fluid fluid)
double getContentHeight(final BlockState state)
VoxelShape getEntityInsideCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final Entity entity)
void entityInside(final BlockState state, final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise)
void lowerFillLevel(final BlockState state, final Level level, final BlockPos pos)
void handlePrecipitation(final BlockState state, final Level level, final BlockPos pos, final Biome.Precipitation precipitation)
int getAnalogOutputSignal(final BlockState state, final Level level, final BlockPos pos, final Direction direction)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
void receiveStalactiteDrip(final BlockState state, final Level level, final BlockPos pos, final Fluid fluid)

Fields & Constants (9)

MIN_FILL_LEVEL
MAX_FILL_LEVEL
LEVEL
BASE_CONTENT_HEIGHT
HEIGHT_PER_LEVEL
FILLED_SHAPES
precipitationType
interactionMap
effectApplier

Full Source

LayeredCauldronBlock.java128 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.cauldron.CauldronInteraction;
6
import net.minecraft.server.level.ServerLevel;
7
import net.minecraft.util.Util;
8
import net.minecraft.world.entity.Entity;
9
import net.minecraft.world.entity.InsideBlockEffectApplier;
10
import net.minecraft.world.entity.InsideBlockEffectType;
11
import net.minecraft.world.level.BlockGetter;
12
import net.minecraft.world.level.Level;
13
import net.minecraft.world.level.biome.Biome;
14
import net.minecraft.world.level.block.state.BlockBehaviour;
15
import net.minecraft.world.level.block.state.BlockState;
16
import net.minecraft.world.level.block.state.StateDefinition;
17
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
18
import net.minecraft.world.level.block.state.properties.IntegerProperty;
19
import net.minecraft.world.level.gameevent.GameEvent;
20
import net.minecraft.world.level.material.Fluid;
21
import net.minecraft.world.level.material.Fluids;
22
import net.minecraft.world.phys.shapes.Shapes;
23
import net.minecraft.world.phys.shapes.VoxelShape;
24
25
public class LayeredCauldronBlock extends AbstractCauldronBlock {
26
	public static final int MIN_FILL_LEVEL = 1;
27
	public static final int MAX_FILL_LEVEL = 3;
28
	public static final IntegerProperty LEVEL = BlockStateProperties.LEVEL_CAULDRON;
29
	private static final int BASE_CONTENT_HEIGHT = 6;
30
	private static final double HEIGHT_PER_LEVEL = 3.0;
31
	private static final VoxelShape[] FILLED_SHAPES = Util.make(
32
		() -> Block.boxes(2, level -> Shapes.or(AbstractCauldronBlock.SHAPE, Block.column(12.0, 4.0, getPixelContentHeight(level + 1))))
33
	);
34
	private final Biome.Precipitation precipitationType;
35
36
	public LayeredCauldronBlock(
37
		final Biome.Precipitation precipitationType, final CauldronInteraction.Dispatcher interactionMap, final BlockBehaviour.Properties properties
38
	) {
39
		super(properties, interactionMap);
40
		this.precipitationType = precipitationType;
41
		this.registerDefaultState(this.stateDefinition.any().setValue(LEVEL, 1));
42
	}
43
44
	@Override
45
	public boolean isFull(final BlockState state) {
46
		return state.getValue(LEVEL) == 3;
47
	}
48
49
	@Override
50
	protected boolean canReceiveStalactiteDrip(final Fluid fluid) {
51
		return fluid == Fluids.WATER && this.precipitationType == Biome.Precipitation.RAIN;
52
	}
53
54
	@Override
55
	protected double getContentHeight(final BlockState state) {
56
		return getPixelContentHeight(state.getValue(LEVEL)) / 16.0;
57
	}
58
59
	private static double getPixelContentHeight(final int level) {
60
		return 6.0 + level * 3.0;
61
	}
62
63
	@Override
64
	protected VoxelShape getEntityInsideCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final Entity entity) {
65
		return FILLED_SHAPES[state.getValue(LEVEL) - 1];
66
	}
67
68
	@Override
69
	protected void entityInside(
70
		final BlockState state, final Level level, final BlockPos pos, final Entity entity, final InsideBlockEffectApplier effectApplier, final boolean isPrecise
71
	) {
72
		if (level instanceof ServerLevel serverLevel) {
73
			BlockPos blockPos = pos.immutable();
74
			effectApplier.runBefore(InsideBlockEffectType.EXTINGUISH, e -> {
75
				if (e.isOnFire() && e.mayInteract(serverLevel, blockPos)) {
76
					this.handleEntityOnFireInside(state, level, blockPos);
77
				}
78
			});
79
		}
80
81
		effectApplier.apply(InsideBlockEffectType.EXTINGUISH);
82
	}
83
84
	private void handleEntityOnFireInside(final BlockState state, final Level level, final BlockPos pos) {
85
		if (this.precipitationType == Biome.Precipitation.SNOW) {
86
			lowerFillLevel(Blocks.WATER_CAULDRON.defaultBlockState().setValue(LEVEL, state.getValue(LEVEL)), level, pos);
87
		} else {
88
			lowerFillLevel(state, level, pos);
89
		}
90
	}
91
92
	public static void lowerFillLevel(final BlockState state, final Level level, final BlockPos pos) {
93
		int newLevel = state.getValue(LEVEL) - 1;
94
		BlockState newState = newLevel == 0 ? Blocks.CAULDRON.defaultBlockState() : state.setValue(LEVEL, newLevel);
95
		level.setBlockAndUpdate(pos, newState);
96
		level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(newState));
97
	}
98
99
	@Override
100
	public void handlePrecipitation(final BlockState state, final Level level, final BlockPos pos, final Biome.Precipitation precipitation) {
101
		if (CauldronBlock.shouldHandlePrecipitation(level, precipitation) && state.getValue(LEVEL) != 3 && precipitation == this.precipitationType) {
102
			BlockState newState = state.cycle(LEVEL);
103
			level.setBlockAndUpdate(pos, newState);
104
			level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(newState));
105
		}
106
	}
107
108
	@Override
109
	protected int getAnalogOutputSignal(final BlockState state, final Level level, final BlockPos pos, final Direction direction) {
110
		return state.getValue(LEVEL);
111
	}
112
113
	@Override
114
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
115
		builder.add(LEVEL);
116
	}
117
118
	@Override
119
	protected void receiveStalactiteDrip(final BlockState state, final Level level, final BlockPos pos, final Fluid fluid) {
120
		if (!this.isFull(state)) {
121
			BlockState newState = state.setValue(LEVEL, state.getValue(LEVEL) + 1);
122
			level.setBlockAndUpdate(pos, newState);
123
			level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(newState));
124
			level.levelEvent(1047, pos, 0);
125
		}
126
	}
127
}
128

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