AmethystClusterBlock .java

net.minecraft.world.level.block.AmethystClusterBlock (class): members: shapes, WATERLOGGED, FACING, getFluidState, canSurvive, mirror, rotate, width.

net.minecraft.world.level.blockclass99 linescommonextends AmethystBlock3.9 KB

Implements

API Surface (7)

VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context)
boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos)
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)
BlockState rotate(final BlockState state, final Rotation rotation)
BlockState mirror(final BlockState state, final Mirror mirror)
FluidState getFluidState(final BlockState state)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)

Fields & Constants (12)

WATERLOGGED
FACING
height
width
shapes
state
level
ticks
pos
directionToNeighbour
neighbourPos
neighbourState

Full Source

AmethystClusterBlock.java99 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import java.util.Map;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Direction;
6
import net.minecraft.util.RandomSource;
7
import net.minecraft.world.item.context.BlockPlaceContext;
8
import net.minecraft.world.level.BlockGetter;
9
import net.minecraft.world.level.LevelAccessor;
10
import net.minecraft.world.level.LevelReader;
11
import net.minecraft.world.level.ScheduledTickAccess;
12
import net.minecraft.world.level.block.state.BlockBehaviour;
13
import net.minecraft.world.level.block.state.BlockState;
14
import net.minecraft.world.level.block.state.StateDefinition;
15
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
16
import net.minecraft.world.level.block.state.properties.BooleanProperty;
17
import net.minecraft.world.level.block.state.properties.EnumProperty;
18
import net.minecraft.world.level.material.FluidState;
19
import net.minecraft.world.level.material.Fluids;
20
import net.minecraft.world.phys.shapes.CollisionContext;
21
import net.minecraft.world.phys.shapes.Shapes;
22
import net.minecraft.world.phys.shapes.VoxelShape;
23
import org.jspecify.annotations.Nullable;
24
25
public class AmethystClusterBlock extends AmethystBlock implements SimpleWaterloggedBlock {
26
	public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
27
	public static final EnumProperty<Direction> FACING = BlockStateProperties.FACING;
28
	private final float height;
29
	private final float width;
30
	private final Map<Direction, VoxelShape> shapes;
31
32
	public AmethystClusterBlock(final float height, final float width, final BlockBehaviour.Properties props) {
33
		super(props);
34
		this.registerDefaultState(this.defaultBlockState().setValue(WATERLOGGED, false).setValue(FACING, Direction.UP));
35
		this.shapes = Shapes.rotateAll(Block.boxZ(width, 16.0F - height, 16.0));
36
		this.height = height;
37
		this.width = width;
38
	}
39
40
	@Override
41
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
42
		return this.shapes.get(state.getValue(FACING));
43
	}
44
45
	@Override
46
	protected boolean canSurvive(final BlockState state, final LevelReader level, final BlockPos pos) {
47
		Direction direction = state.getValue(FACING);
48
		BlockPos adjacentPos = pos.relative(direction.getOpposite());
49
		return level.getBlockState(adjacentPos).isFaceSturdy(level, adjacentPos, direction);
50
	}
51
52
	@Override
53
	protected BlockState updateShape(
54
		final BlockState state,
55
		final LevelReader level,
56
		final ScheduledTickAccess ticks,
57
		final BlockPos pos,
58
		final Direction directionToNeighbour,
59
		final BlockPos neighbourPos,
60
		final BlockState neighbourState,
61
		final RandomSource random
62
	) {
63
		if (state.getValue(WATERLOGGED)) {
64
			ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level));
65
		}
66
67
		return directionToNeighbour == state.getValue(FACING).getOpposite() && !state.canSurvive(level, pos)
68
			? Blocks.AIR.defaultBlockState()
69
			: super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
70
	}
71
72
	@Override
73
	public @Nullable BlockState getStateForPlacement(final BlockPlaceContext context) {
74
		LevelAccessor level = context.getLevel();
75
		BlockPos pos = context.getClickedPos();
76
		return this.defaultBlockState().setValue(WATERLOGGED, level.getFluidState(pos).is(Fluids.WATER)).setValue(FACING, context.getClickedFace());
77
	}
78
79
	@Override
80
	protected BlockState rotate(final BlockState state, final Rotation rotation) {
81
		return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
82
	}
83
84
	@Override
85
	protected BlockState mirror(final BlockState state, final Mirror mirror) {
86
		return state.rotate(mirror.getRotation(state.getValue(FACING)));
87
	}
88
89
	@Override
90
	protected FluidState getFluidState(final BlockState state) {
91
		return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
92
	}
93
94
	@Override
95
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
96
		builder.add(WATERLOGGED, FACING);
97
	}
98
}
99

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