RotatedPillarBlock .java

net.minecraft.world.level.block.RotatedPillarBlock (class, 51 lines): members: rotatePillar, AXIS, rotate, getStateForPlacement. imports: EnumProperty.

net.minecraft.world.level.blockclass51 linescommonextends Block1.6 KB

API Surface (4)

BlockState rotate(final BlockState state, final Rotation rotation)
BlockState rotatePillar(final BlockState state, final Rotation rotation)
void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
BlockState getStateForPlacement(final BlockPlaceContext context)

Fields & Constants (1)

AXIS

Full Source

RotatedPillarBlock.java51 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.block;
2
3
import net.minecraft.core.Direction;
4
import net.minecraft.world.item.context.BlockPlaceContext;
5
import net.minecraft.world.level.block.state.BlockBehaviour;
6
import net.minecraft.world.level.block.state.BlockState;
7
import net.minecraft.world.level.block.state.StateDefinition;
8
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
9
import net.minecraft.world.level.block.state.properties.EnumProperty;
10
11
public class RotatedPillarBlock extends Block {
12
	public static final EnumProperty<Direction.Axis> AXIS = BlockStateProperties.AXIS;
13
14
	public RotatedPillarBlock(final BlockBehaviour.Properties properties) {
15
		super(properties);
16
		this.registerDefaultState(this.defaultBlockState().setValue(AXIS, Direction.Axis.Y));
17
	}
18
19
	@Override
20
	protected BlockState rotate(final BlockState state, final Rotation rotation) {
21
		return rotatePillar(state, rotation);
22
	}
23
24
	public static BlockState rotatePillar(final BlockState state, final Rotation rotation) {
25
		switch (rotation) {
26
			case COUNTERCLOCKWISE_90:
27
			case CLOCKWISE_90:
28
				switch ((Direction.Axis)state.getValue(AXIS)) {
29
					case X:
30
						return state.setValue(AXIS, Direction.Axis.Z);
31
					case Z:
32
						return state.setValue(AXIS, Direction.Axis.X);
33
					default:
34
						return state;
35
				}
36
			default:
37
				return state;
38
		}
39
	}
40
41
	@Override
42
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
43
		builder.add(AXIS);
44
	}
45
46
	@Override
47
	public BlockState getStateForPlacement(final BlockPlaceContext context) {
48
		return this.defaultBlockState().setValue(AXIS, context.getClickedFace().getAxis());
49
	}
50
}
51

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