SculkShriekerBlock .java

net.minecraft.world.level.block.SculkShriekerBlock (class): members: TOP_Y, CAN_SUMMON, SHRIEKING, SHAPE_COLLISION, getOcclusionShape, stepOn, getTicker.

net.minecraft.world.level.blockclass139 linescommonextends BaseEntityBlock5.5 KB

Implements

API Surface (9)

void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
void stepOn(final Level level, final BlockPos pos, final BlockState onState, final Entity entity)
void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random)
VoxelShape getCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
VoxelShape getOcclusionShape(final BlockState state)
boolean useShapeForLightOcclusion(final BlockState state)
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)
FluidState getFluidState(final BlockState state)
void spawnAfterBreak(final BlockState state, final ServerLevel level, final BlockPos pos, final ItemStack tool, final boolean dropExperience)

Fields & Constants (12)

SHRIEKING
WATERLOGGED
CAN_SUMMON
SHAPE_COLLISION
TOP_Y
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

SculkShriekerBlock.java139 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.server.level.ServerLevel;
6
import net.minecraft.server.level.ServerPlayer;
7
import net.minecraft.util.RandomSource;
8
import net.minecraft.util.valueproviders.ConstantInt;
9
import net.minecraft.world.entity.Entity;
10
import net.minecraft.world.item.ItemStack;
11
import net.minecraft.world.item.context.BlockPlaceContext;
12
import net.minecraft.world.level.BlockGetter;
13
import net.minecraft.world.level.Level;
14
import net.minecraft.world.level.LevelReader;
15
import net.minecraft.world.level.ScheduledTickAccess;
16
import net.minecraft.world.level.block.entity.BlockEntity;
17
import net.minecraft.world.level.block.entity.BlockEntityTicker;
18
import net.minecraft.world.level.block.entity.BlockEntityType;
19
import net.minecraft.world.level.block.entity.BlockEntityTypes;
20
import net.minecraft.world.level.block.entity.SculkShriekerBlockEntity;
21
import net.minecraft.world.level.block.state.BlockBehaviour;
22
import net.minecraft.world.level.block.state.BlockState;
23
import net.minecraft.world.level.block.state.StateDefinition;
24
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
25
import net.minecraft.world.level.block.state.properties.BooleanProperty;
26
import net.minecraft.world.level.gameevent.vibrations.VibrationSystem;
27
import net.minecraft.world.level.material.FluidState;
28
import net.minecraft.world.level.material.Fluids;
29
import net.minecraft.world.phys.shapes.CollisionContext;
30
import net.minecraft.world.phys.shapes.VoxelShape;
31
import org.jspecify.annotations.Nullable;
32
33
public class SculkShriekerBlock extends BaseEntityBlock implements SimpleWaterloggedBlock {
34
	public static final BooleanProperty SHRIEKING = BlockStateProperties.SHRIEKING;
35
	public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
36
	public static final BooleanProperty CAN_SUMMON = BlockStateProperties.CAN_SUMMON;
37
	private static final VoxelShape SHAPE_COLLISION = Block.column(16.0, 0.0, 8.0);
38
	public static final double TOP_Y = SHAPE_COLLISION.max(Direction.Axis.Y);
39
40
	public SculkShriekerBlock(final BlockBehaviour.Properties properties) {
41
		super(properties);
42
		this.registerDefaultState(this.stateDefinition.any().setValue(SHRIEKING, false).setValue(WATERLOGGED, false).setValue(CAN_SUMMON, false));
43
	}
44
45
	@Override
46
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
47
		builder.add(SHRIEKING);
48
		builder.add(WATERLOGGED);
49
		builder.add(CAN_SUMMON);
50
	}
51
52
	@Override
53
	public void stepOn(final Level level, final BlockPos pos, final BlockState onState, final Entity entity) {
54
		if (level instanceof ServerLevel serverLevel) {
55
			ServerPlayer player = SculkShriekerBlockEntity.tryGetPlayer(entity);
56
			if (player != null) {
57
				serverLevel.getBlockEntity(pos, BlockEntityTypes.SCULK_SHRIEKER).ifPresent(shrieker -> shrieker.tryShriek(serverLevel, player));
58
			}
59
		}
60
61
		super.stepOn(level, pos, onState, entity);
62
	}
63
64
	@Override
65
	protected void tick(final BlockState state, final ServerLevel level, final BlockPos pos, final RandomSource random) {
66
		if (state.getValue(SHRIEKING)) {
67
			level.setBlockAndUpdate(pos, state.setValue(SHRIEKING, false));
68
			level.getBlockEntity(pos, BlockEntityTypes.SCULK_SHRIEKER).ifPresent(shrieker -> shrieker.tryRespond(level));
69
		}
70
	}
71
72
	@Override
73
	protected VoxelShape getCollisionShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
74
		return SHAPE_COLLISION;
75
	}
76
77
	@Override
78
	protected VoxelShape getOcclusionShape(final BlockState state) {
79
		return SHAPE_COLLISION;
80
	}
81
82
	@Override
83
	protected boolean useShapeForLightOcclusion(final BlockState state) {
84
		return true;
85
	}
86
87
	@Override
88
	public @Nullable BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
89
		return new SculkShriekerBlockEntity(worldPosition, blockState);
90
	}
91
92
	@Override
93
	protected BlockState updateShape(
94
		final BlockState state,
95
		final LevelReader level,
96
		final ScheduledTickAccess ticks,
97
		final BlockPos pos,
98
		final Direction directionToNeighbour,
99
		final BlockPos neighbourPos,
100
		final BlockState neighbourState,
101
		final RandomSource random
102
	) {
103
		if (state.getValue(WATERLOGGED)) {
104
			ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
105
		}
106
107
		return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
108
	}
109
110
	@Override
111
	public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
112
		return this.defaultBlockState().setValue(WATERLOGGED, context.getLevel().getFluidState(context.getClickedPos()).is(Fluids.WATER));
113
	}
114
115
	@Override
116
	protected FluidState getFluidState(final BlockState state) {
117
		return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
118
	}
119
120
	@Override
121
	protected void spawnAfterBreak(final BlockState state, final ServerLevel level, final BlockPos pos, final ItemStack tool, final boolean dropExperience) {
122
		super.spawnAfterBreak(state, level, pos, tool, dropExperience);
123
		if (dropExperience) {
124
			this.tryDropExperience(level, pos, tool, ConstantInt.of(5));
125
		}
126
	}
127
128
	@Override
129
	public <T extends BlockEntity> @Nullable BlockEntityTicker<T> getTicker(final Level level, final BlockState blockState, final BlockEntityType<T> type) {
130
		return !level.isClientSide()
131
			? BaseEntityBlock.createTickerHelper(
132
				type,
133
				BlockEntityTypes.SCULK_SHRIEKER,
134
				(innerLevel, pos, state, entity) -> VibrationSystem.Ticker.tick(innerLevel, entity.getVibrationData(), entity.getVibrationUser())
135
			)
136
			: null;
137
	}
138
}
139

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