62 lines
3.0 KiB
Java
62 lines
3.0 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.phys.BlockHitResult;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.level.block.entity.JigsawBlockEntity;
|
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
public class JigsawBlock extends DirectionalBlock implements EntityBlock {
|
|
protected JigsawBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Direction>setValue((Property<Comparable>)JigsawBlock.FACING, Direction.UP));
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(JigsawBlock.FACING);
|
|
}
|
|
|
|
@Override
|
|
public BlockState rotate(final BlockState byg, final Rotation btr) {
|
|
return ((AbstractStateHolder<O, BlockState>)byg).<Comparable, Direction>setValue((Property<Comparable>)JigsawBlock.FACING, btr.rotate(byg.<Direction>getValue((Property<Direction>)JigsawBlock.FACING)));
|
|
}
|
|
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)JigsawBlock.FACING, bcn.getClickedFace());
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockEntity newBlockEntity(final BlockGetter bjd) {
|
|
return new JigsawBlockEntity();
|
|
}
|
|
|
|
@Override
|
|
public InteractionResult use(final BlockState byg, final Level bjt, final BlockPos fk, final Player ayg, final InteractionHand ajh, final BlockHitResult cvd) {
|
|
final BlockEntity bwi8 = bjt.getBlockEntity(fk);
|
|
if (bwi8 instanceof JigsawBlockEntity && ayg.canUseGameMasterBlocks()) {
|
|
ayg.openJigsawBlock((JigsawBlockEntity)bwi8);
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
return InteractionResult.PASS;
|
|
}
|
|
|
|
public static boolean canAttach(final StructureTemplate.StructureBlockInfo b1, final StructureTemplate.StructureBlockInfo b2) {
|
|
return b1.state.<Comparable>getValue((Property<Comparable>)JigsawBlock.FACING) == b2.state.<Direction>getValue((Property<Direction>)JigsawBlock.FACING).getOpposite() && b1.nbt.getString("attachement_type").equals(b2.nbt.getString("attachement_type"));
|
|
}
|
|
}
|