| 1 | package net.minecraft.world.item.context;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Direction;
|
| 5 | import net.minecraft.world.InteractionHand;
|
| 6 | import net.minecraft.world.item.ItemStack;
|
| 7 | import net.minecraft.world.level.Level;
|
| 8 | import net.minecraft.world.phys.BlockHitResult;
|
| 9 | import net.minecraft.world.phys.Vec3;
|
| 10 |
|
| 11 | public class DirectionalPlaceContext extends BlockPlaceContext {
|
| 12 | private final Direction direction;
|
| 13 |
|
| 14 | public DirectionalPlaceContext(final Level level, final BlockPos pos, final Direction direction, final ItemStack dispensed, final Direction clickedFace) {
|
| 15 | super(level, null, InteractionHand.MAIN_HAND, dispensed, new BlockHitResult(Vec3.atBottomCenterOf(pos), clickedFace, pos, false));
|
| 16 | this.direction = direction;
|
| 17 | }
|
| 18 |
|
| 19 | @Override
|
| 20 | public BlockPos getClickedPos() {
|
| 21 | return this.getHitResult().getBlockPos();
|
| 22 | }
|
| 23 |
|
| 24 | @Override
|
| 25 | public boolean canPlace() {
|
| 26 | return this.getLevel().getBlockState(this.getHitResult().getBlockPos()).canBeReplaced(this);
|
| 27 | }
|
| 28 |
|
| 29 | @Override
|
| 30 | public boolean replacingClickedOnBlock() {
|
| 31 | return this.canPlace();
|
| 32 | }
|
| 33 |
|
| 34 | @Override
|
| 35 | public Direction getNearestLookingDirection() {
|
| 36 | return Direction.DOWN;
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | public Direction[] getNearestLookingDirections() {
|
| 41 | switch (this.direction) {
|
| 42 | case DOWN:
|
| 43 | default:
|
| 44 | return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP};
|
| 45 | case UP:
|
| 46 | return new Direction[]{Direction.DOWN, Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
|
| 47 | case NORTH:
|
| 48 | return new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.SOUTH};
|
| 49 | case SOUTH:
|
| 50 | return new Direction[]{Direction.DOWN, Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.NORTH};
|
| 51 | case WEST:
|
| 52 | return new Direction[]{Direction.DOWN, Direction.WEST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.EAST};
|
| 53 | case EAST:
|
| 54 | return new Direction[]{Direction.DOWN, Direction.EAST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.WEST};
|
| 55 | }
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | public Direction getHorizontalDirection() {
|
| 60 | return this.direction.getAxis() == Direction.Axis.Y ? Direction.NORTH : this.direction;
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | public boolean isSecondaryUseActive() {
|
| 65 | return false;
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | public float getRotation() {
|
| 70 | return this.direction.get2DDataValue() * 90;
|
| 71 | }
|
| 72 | }
|
| 73 |
|