JigsawBlock .java

net.minecraft.world.level.block.JigsawBlock (class): members: getFrontFacing, getTopFacing, canAttach, ORIENTATION, newBlockEntity, useWithoutItem, mirror.

net.minecraft.world.level.blockclass95 linescommonextends Block3.8 KB

Implements

API Surface (9)

void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder)
BlockState rotate(final BlockState state, final Rotation rotation)
BlockState mirror(final BlockState state, final Mirror mirror)
BlockState getStateForPlacement(final BlockPlaceContext context)
BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState)
InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult)
boolean canAttach(final StructureTemplate.JigsawBlockInfo source, final StructureTemplate.JigsawBlockInfo target)
Direction getFrontFacing(final BlockState state)
Direction getTopFacing(final BlockState state)

Fields & Constants (1)

ORIENTATION

Full Source

JigsawBlock.java95 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.FrontAndTop;
6
import net.minecraft.world.InteractionResult;
7
import net.minecraft.world.entity.player.Player;
8
import net.minecraft.world.item.context.BlockPlaceContext;
9
import net.minecraft.world.level.Level;
10
import net.minecraft.world.level.block.entity.BlockEntity;
11
import net.minecraft.world.level.block.entity.JigsawBlockEntity;
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.EnumProperty;
17
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
18
import net.minecraft.world.phys.BlockHitResult;
19
20
/**
21
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
22
 */
23
public class JigsawBlock extends Block implements EntityBlock, GameMasterBlock {
24
	public static final EnumProperty<FrontAndTop> ORIENTATION = BlockStateProperties.ORIENTATION;
25
26
	/**
27
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
28
	 */
29
	public JigsawBlock(final BlockBehaviour.Properties properties) {
30
		super(properties);
31
		this.registerDefaultState(this.stateDefinition.any().setValue(ORIENTATION, FrontAndTop.NORTH_UP));
32
	}
33
34
	@Override
35
	protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> builder) {
36
		builder.add(ORIENTATION);
37
	}
38
39
	@Override
40
	protected BlockState rotate(final BlockState state, final Rotation rotation) {
41
		return state.setValue(ORIENTATION, rotation.rotation().rotate(state.getValue(ORIENTATION)));
42
	}
43
44
	@Override
45
	protected BlockState mirror(final BlockState state, final Mirror mirror) {
46
		return state.setValue(ORIENTATION, mirror.rotation().rotate(state.getValue(ORIENTATION)));
47
	}
48
49
	@Override
50
	public BlockState getStateForPlacement(final BlockPlaceContext context) {
51
		Direction front = context.getClickedFace();
52
		Direction top;
53
		if (front.getAxis() == Direction.Axis.Y) {
54
			top = context.getHorizontalDirection().getOpposite();
55
		} else {
56
			top = Direction.UP;
57
		}
58
59
		return this.defaultBlockState().setValue(ORIENTATION, FrontAndTop.fromFrontAndTop(front, top));
60
	}
61
62
	@Override
63
	public BlockEntity newBlockEntity(final BlockPos worldPosition, final BlockState blockState) {
64
		return new JigsawBlockEntity(worldPosition, blockState);
65
	}
66
67
	@Override
68
	protected InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult) {
69
		if (level.getBlockEntity(pos) instanceof JigsawBlockEntity jigsawBlockEntity && player.canUseGameMasterBlocks()) {
70
			player.openJigsawBlock(jigsawBlockEntity);
71
			return InteractionResult.SUCCESS;
72
		} else {
73
			return InteractionResult.PASS;
74
		}
75
	}
76
77
	public static boolean canAttach(final StructureTemplate.JigsawBlockInfo source, final StructureTemplate.JigsawBlockInfo target) {
78
		Direction sourceFront = getFrontFacing(source.state());
79
		Direction targetFront = getFrontFacing(target.state());
80
		Direction sourceTop = getTopFacing(source.state());
81
		Direction targetTop = getTopFacing(target.state());
82
		JigsawBlockEntity.JointType jointType = source.jointType();
83
		boolean rollable = jointType == JigsawBlockEntity.JointType.ROLLABLE;
84
		return sourceFront == targetFront.getOpposite() && (rollable || sourceTop == targetTop) && (target.name() == null || source.target().equals(target.name()));
85
	}
86
87
	public static Direction getFrontFacing(final BlockState state) {
88
		return state.getValue(ORIENTATION).front();
89
	}
90
91
	public static Direction getTopFacing(final BlockState state) {
92
		return state.getValue(ORIENTATION).top();
93
	}
94
}
95

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