Search in sources :

Example 26 with Axis

use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.

the class EncasedBeltBlock method updateShape.

@Override
public BlockState updateShape(BlockState stateIn, Direction face, BlockState neighbour, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) {
    Part part = stateIn.getValue(PART);
    Axis axis = stateIn.getValue(AXIS);
    boolean connectionAlongFirst = stateIn.getValue(CONNECTED_ALONG_FIRST_COORDINATE);
    Axis connectionAxis = connectionAlongFirst ? (axis == Axis.X ? Axis.Y : Axis.X) : (axis == Axis.Z ? Axis.Y : Axis.Z);
    Axis faceAxis = face.getAxis();
    boolean facingAlongFirst = axis == Axis.X ? faceAxis.isVertical() : faceAxis == Axis.X;
    boolean positive = face.getAxisDirection() == AxisDirection.POSITIVE;
    if (axis == faceAxis)
        return stateIn;
    if (!(neighbour.getBlock() instanceof EncasedBeltBlock)) {
        if (facingAlongFirst != connectionAlongFirst || part == Part.NONE)
            return stateIn;
        if (part == Part.MIDDLE)
            return stateIn.setValue(PART, positive ? Part.END : Part.START);
        if ((part == Part.START) == positive)
            return stateIn.setValue(PART, Part.NONE);
        return stateIn;
    }
    Part otherPart = neighbour.getValue(PART);
    Axis otherAxis = neighbour.getValue(AXIS);
    boolean otherConnection = neighbour.getValue(CONNECTED_ALONG_FIRST_COORDINATE);
    Axis otherConnectionAxis = otherConnection ? (otherAxis == Axis.X ? Axis.Y : Axis.X) : (otherAxis == Axis.Z ? Axis.Y : Axis.Z);
    if (neighbour.getValue(AXIS) == faceAxis)
        return stateIn;
    if (otherPart != Part.NONE && otherConnectionAxis != faceAxis)
        return stateIn;
    if (part == Part.NONE) {
        part = positive ? Part.START : Part.END;
        connectionAlongFirst = axis == Axis.X ? faceAxis.isVertical() : faceAxis == Axis.X;
    } else if (connectionAxis != faceAxis) {
        return stateIn;
    }
    if ((part == Part.START) != positive)
        part = Part.MIDDLE;
    return stateIn.setValue(PART, part).setValue(CONNECTED_ALONG_FIRST_COORDINATE, connectionAlongFirst);
}
Also used : Axis(net.minecraft.core.Direction.Axis)

Example 27 with Axis

use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.

the class EncasedBeltBlock method getStateForPlacement.

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
    Axis placedAxis = context.getNearestLookingDirection().getAxis();
    Axis axis = context.getPlayer() != null && context.getPlayer().isShiftKeyDown() ? placedAxis : getPreferredAxis(context);
    if (axis == null)
        axis = placedAxis;
    BlockState state = defaultBlockState().setValue(AXIS, axis);
    for (Direction facing : Iterate.directions) {
        if (facing.getAxis() == axis)
            continue;
        BlockPos pos = context.getClickedPos();
        BlockPos offset = pos.relative(facing);
        state = updateShape(state, facing, context.getLevel().getBlockState(offset), context.getLevel(), pos, offset);
    }
    return state;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Axis(net.minecraft.core.Direction.Axis)

Example 28 with Axis

use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.

the class EncasedBeltGenerator method getModelSuffix.

protected String getModelSuffix(BlockState state) {
    EncasedBeltBlock.Part part = state.getValue(EncasedBeltBlock.PART);
    Axis axis = state.getValue(EncasedBeltBlock.AXIS);
    if (part == Part.NONE)
        return "single";
    String orientation = axis == Axis.Y ? "vertical" : "horizontal";
    String section = part == Part.MIDDLE ? "middle" : "end";
    return section + "_" + orientation;
}
Also used : Part(com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock.Part) Axis(net.minecraft.core.Direction.Axis)

Example 29 with Axis

use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.

the class EncasedBeltGenerator method getXRotation.

@Override
protected int getXRotation(BlockState state) {
    EncasedBeltBlock.Part part = state.getValue(EncasedBeltBlock.PART);
    boolean connectedAlongFirst = state.getValue(EncasedBeltBlock.CONNECTED_ALONG_FIRST_COORDINATE);
    Axis axis = state.getValue(EncasedBeltBlock.AXIS);
    if (part == Part.NONE)
        return axis == Axis.Y ? 90 : 0;
    if (axis == Axis.X)
        return (connectedAlongFirst ? 90 : 0) + (part == Part.START ? 180 : 0);
    if (axis == Axis.Z)
        return (connectedAlongFirst ? 0 : (part == Part.START ? 270 : 90));
    return 0;
}
Also used : Part(com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock.Part) Axis(net.minecraft.core.Direction.Axis)

Example 30 with Axis

use of net.minecraft.core.Direction.Axis in project Create by Creators-of-Create.

the class EncasedCogCTBehaviour method connectsTo.

@Override
public boolean connectsTo(BlockState state, BlockState other, BlockAndTintGetter reader, BlockPos pos, BlockPos otherPos, Direction face) {
    Axis axis = state.getValue(AXIS);
    if (large || axis == face.getAxis())
        return super.connectsTo(state, other, reader, pos, otherPos, face);
    if (other.getBlock() == state.getBlock() && other.getValue(AXIS) == state.getValue(AXIS))
        return true;
    BlockState blockState = reader.getBlockState(otherPos.relative(face));
    if (!ICogWheel.isLargeCog(blockState))
        return false;
    return ((IRotate) blockState.getBlock()).getRotationAxis(blockState) == axis;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Axis(net.minecraft.core.Direction.Axis)

Aggregations

Axis (net.minecraft.core.Direction.Axis)85 Direction (net.minecraft.core.Direction)43 BlockPos (net.minecraft.core.BlockPos)39 BlockState (net.minecraft.world.level.block.state.BlockState)35 AxisDirection (net.minecraft.core.Direction.AxisDirection)24 Vec3 (net.minecraft.world.phys.Vec3)14 Level (net.minecraft.world.level.Level)13 IRotate (com.simibubi.create.content.contraptions.base.IRotate)9 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)7 Block (net.minecraft.world.level.block.Block)7 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)6 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)5 Player (net.minecraft.world.entity.player.Player)5 HashSet (java.util.HashSet)4 ItemStack (net.minecraft.world.item.ItemStack)4 KineticTileEntity (com.simibubi.create.content.contraptions.base.KineticTileEntity)3 Part (com.simibubi.create.content.contraptions.relays.encased.EncasedBeltBlock.Part)3 ArrayList (java.util.ArrayList)3 ServerLevel (net.minecraft.server.level.ServerLevel)3 StructureBlockInfo (net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate.StructureBlockInfo)3