PotentSulfurBlock .java

net.minecraft.world.level.block.PotentSulfurBlock (class, 161 lines): members: ALLOWED_WATER_BLOCKS_ABOVE, STATE, triggerEvent, getTicker, onPlace, ticks.

net.minecraft.world.level.blockclass161 linescommonextends BaseEntityBlock6.9 KB

API Surface (5)

void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
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 onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston)
void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random)
boolean triggerEvent(final BlockState state, final Level level, final BlockPos pos, final int b0, final int b1)

Fields & Constants (9)

ALLOWED_WATER_BLOCKS_ABOVE
STATE
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

PotentSulfurBlock.java161 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.sounds.SoundEvents;
7
import net.minecraft.sounds.SoundSource;
8
import net.minecraft.tags.BlockTags;
9
import net.minecraft.util.RandomSource;
10
import net.minecraft.world.item.context.BlockPlaceContext;
11
import net.minecraft.world.level.Level;
12
import net.minecraft.world.level.LevelReader;
13
import net.minecraft.world.level.ScheduledTickAccess;
14
import net.minecraft.world.level.block.entity.BlockEntity;
15
import net.minecraft.world.level.block.entity.BlockEntityTicker;
16
import net.minecraft.world.level.block.entity.BlockEntityType;
17
import net.minecraft.world.level.block.entity.BlockEntityTypes;
18
import net.minecraft.world.level.block.entity.PotentSulfurBlockEntity;
19
import net.minecraft.world.level.block.state.BlockBehaviour;
20
import net.minecraft.world.level.block.state.BlockState;
21
import net.minecraft.world.level.block.state.StateDefinition;
22
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
23
import net.minecraft.world.level.block.state.properties.EnumProperty;
24
import net.minecraft.world.level.block.state.properties.PotentSulfurState;
25
import net.minecraft.world.level.gameevent.GameEvent;
26
import net.minecraft.world.level.material.FluidState;
27
import net.minecraft.world.level.material.Fluids;
28
import org.jspecify.annotations.Nullable;
29
30
public class PotentSulfurBlock extends BaseEntityBlock {
31
	public static final int ALLOWED_WATER_BLOCKS_ABOVE = 4;
32
	public static final EnumProperty<PotentSulfurState> STATE = BlockStateProperties.POTENT_SULFUR_STATE;
33
34
	public PotentSulfurBlock(final BlockBehaviour.Properties properties) {
35
		super(properties);
36
		this.registerDefaultState(this.defaultBlockState().setValue(STATE, PotentSulfurState.DRY));
37
	}
38
39
	@Override
40
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
41
		builder.add(STATE);
42
	}
43
44
	@Override
45
	public @Nullable BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
46
		return new PotentSulfurBlockEntity(worldPosition, blockState);
47
	}
48
49
	@Override
50
	protected BlockState updateShape(
51
		final BlockState state,
52
		final LevelReader level,
53
		final ScheduledTickAccess ticks,
54
		final BlockPos pos,
55
		final Direction directionToNeighbour,
56
		final BlockPos neighbourPos,
57
		final BlockState neighbourState,
58
		final RandomSource random
59
	) {
60
		return validBlockState(state, level, pos);
61
	}
62
63
	@Override
64
	public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
65
		return validBlockState(this.defaultBlockState(), context.getLevel(), context.getClickedPos());
66
	}
67
68
	private static BlockState validBlockState(final BlockState state, final LevelReader level, final BlockPos pos) {
69
		if (!level.getFluidState(pos.above()).isSourceOfType(Fluids.WATER)) {
70
			return state.setValue(STATE, PotentSulfurState.DRY);
71
		}
72
73
		BlockState belowState = level.getBlockState(pos.below());
74
		if (belowState.is(BlockTags.CAUSES_CONTINUOUS_GEYSER_ERUPTIONS) && isSourceIfFluid(belowState)) {
75
			return state.setValue(STATE, PotentSulfurState.CONTINUOUS);
76
		}
77
78
		if (belowState.is(BlockTags.CAUSES_PERIODIC_GEYSER_ERUPTIONS) && isSourceIfFluid(belowState)) {
79
			boolean isGeyser = state.getValue(STATE) == PotentSulfurState.ERUPTING || state.getValue(STATE) == PotentSulfurState.DORMANT;
80
			if (!isGeyser && level.getBlockEntity(pos) instanceof PotentSulfurBlockEntity potentSulfurEntity) {
81
				potentSulfurEntity.resetCountdown();
82
			}
83
84
			return state.getValue(STATE) == PotentSulfurState.ERUPTING ? state : state.setValue(STATE, PotentSulfurState.DORMANT);
85
		} else {
86
			return state.setValue(STATE, PotentSulfurState.WET);
87
		}
88
	}
89
90
	private static boolean isSourceIfFluid(final BlockState belowState) {
91
		FluidState fluidState = belowState.getFluidState();
92
		return fluidState.isEmpty() || fluidState.isSource();
93
	}
94
95
	@Override
96
	protected void onPlace(final BlockState state, final Level level, final BlockPos pos, final BlockState oldState, final boolean movedByPiston) {
97
		super.onPlace(state, level, pos, oldState, movedByPiston);
98
		if (state.getValue(STATE) == PotentSulfurState.ERUPTING || state.getValue(STATE) == PotentSulfurState.CONTINUOUS) {
99
			level.blockEvent(pos, this, 0, 0);
100
			level.playSound(
101
				null,
102
				pos,
103
				state.getValue(STATE) == PotentSulfurState.CONTINUOUS ? SoundEvents.GEYSER_CONTINUOUS_START : SoundEvents.GEYSER_ERUPTION_START,
104
				SoundSource.BLOCKS,
105
				1.0F,
106
				1.0F
107
			);
108
			level.gameEvent(GameEvent.BLOCK_ACTIVATE, pos, GameEvent.Context.of(state));
109
		}
110
	}
111
112
	@Override
113
	public void animateTick(final BlockState state, final Level level, final BlockPos pos, final RandomSource random) {
114
		if (state.getValue(STATE) != PotentSulfurState.DRY) {
115
			if (level.getFluidState(pos.above()).isSourceOfType(Fluids.WATER)) {
116
				spawnBubbleParticlesAt(level, random, pos.getX(), pos.getY() + 1, pos.getZ());
117
				spawnBubbleParticlesAt(level, random, pos.getX(), pos.getY() + 1, pos.getZ());
118
				if (random.nextInt(10) == 0) {
119
					level.playLocalSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.NOXIOUS_GAS, SoundSource.AMBIENT, 1.0F, 1.0F, false);
120
				}
121
			}
122
		}
123
	}
124
125
	private static void spawnBubbleParticlesAt(final Level level, final RandomSource random, final double x, final double y, final double z) {
126
		level.addAlwaysVisibleParticle(ParticleTypes.SULFUR_BUBBLES, x + random.nextFloat(), y + random.nextFloat(), z + random.nextFloat(), 0.0, 0.0, 0.0);
127
	}
128
129
	@Override
130
	protected boolean triggerEvent(final BlockState state, final Level level, final BlockPos pos, final int b0, final int b1) {
131
		if (level.getBlockEntity(pos) instanceof PotentSulfurBlockEntity entity) {
132
			entity.eruptionTick = level.getGameTime();
133
		}
134
135
		return true;
136
	}
137
138
	@Override
139
	public <T extends BlockEntity> @Nullable BlockEntityTicker<T> getTicker(final Level level, final BlockState blockState, final BlockEntityType<T> type) {
140
		boolean client = level.isClientSide();
141
142
		return createTickerHelper(
143
			type,
144
			BlockEntityTypes.POTENT_SULFUR,
145
			switch ((PotentSulfurState)blockState.getValue(STATE)) {
146
				case DRY -> null;
147
				case WET -> client ? PotentSulfurBlockEntity.CLIENT_NOXIOUS_GAS_TICKER : PotentSulfurBlockEntity.SERVER_NAUSEA_EFFECT_TICKER;
148
				case DORMANT -> client
149
					? PotentSulfurBlockEntity.CLIENT_NOXIOUS_GAS_TICKER
150
					: PotentSulfurBlockEntity.SERVER_WAITING_COUNTDOWN_TICKER.andThen(PotentSulfurBlockEntity.SERVER_NAUSEA_EFFECT_TICKER);
151
				case ERUPTING -> client
152
					? PotentSulfurBlockEntity.CLIENT_GEYSER_PLUME_TICKER.apply(SoundEvents.GEYSER_ERUPTION_ACTIVE).andThen(PotentSulfurBlockEntity.LAUNCH_ENTITY_TICKER)
153
					: PotentSulfurBlockEntity.LAUNCH_ENTITY_TICKER.andThen(PotentSulfurBlockEntity.SERVER_WAITING_COUNTDOWN_TICKER);
154
				case CONTINUOUS -> client
155
					? PotentSulfurBlockEntity.CLIENT_GEYSER_PLUME_TICKER.apply(SoundEvents.GEYSER_CONTINUOUS_ACTIVE).andThen(PotentSulfurBlockEntity.LAUNCH_ENTITY_TICKER)
156
					: PotentSulfurBlockEntity.LAUNCH_ENTITY_TICKER;
157
			}
158
		);
159
	}
160
}
161

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