Search in sources :

Example 21 with Axis

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

the class VerticalGearboxItem method updateCustomBlockEntityTag.

@Override
protected boolean updateCustomBlockEntityTag(BlockPos pos, Level world, Player player, ItemStack stack, BlockState state) {
    Axis prefferedAxis = null;
    for (Direction side : Iterate.horizontalDirections) {
        BlockState blockState = world.getBlockState(pos.relative(side));
        if (blockState.getBlock() instanceof IRotate) {
            if (((IRotate) blockState.getBlock()).hasShaftTowards(world, pos.relative(side), blockState, side.getOpposite()))
                if (prefferedAxis != null && prefferedAxis != side.getAxis()) {
                    prefferedAxis = null;
                    break;
                } else {
                    prefferedAxis = side.getAxis();
                }
        }
    }
    Axis axis = prefferedAxis == null ? player.getDirection().getClockWise().getAxis() : prefferedAxis == Axis.X ? Axis.Z : Axis.X;
    world.setBlockAndUpdate(pos, state.setValue(BlockStateProperties.AXIS, axis));
    return super.updateCustomBlockEntityTag(pos, world, player, stack, state);
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) BlockState(net.minecraft.world.level.block.state.BlockState) Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis)

Example 22 with Axis

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

the class BeltTunnelShapes method getShape.

public static VoxelShape getShape(BlockState state) {
    BeltTunnelBlock.Shape shape = state.getValue(BeltTunnelBlock.SHAPE);
    Direction.Axis axis = state.getValue(BeltTunnelBlock.HORIZONTAL_AXIS);
    if (shape == BeltTunnelBlock.Shape.CROSS)
        return CROSS;
    if (BeltTunnelBlock.isStraight(state))
        return STRAIGHT.get(axis);
    if (shape == BeltTunnelBlock.Shape.T_LEFT)
        return TEE.get(axis == Direction.Axis.Z ? Direction.EAST : Direction.NORTH);
    if (shape == BeltTunnelBlock.Shape.T_RIGHT)
        return TEE.get(axis == Direction.Axis.Z ? Direction.WEST : Direction.SOUTH);
    // something went wrong
    return Shapes.block();
}
Also used : Axis(net.minecraft.core.Direction.Axis) Direction(net.minecraft.core.Direction)

Example 23 with Axis

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

the class ItemVaultCTBehaviour method get.

@Override
public CTSpriteShiftEntry get(BlockState state, Direction direction) {
    Axis vaultBlockAxis = ItemVaultBlock.getVaultBlockAxis(state);
    boolean small = !ItemVaultBlock.isLarge(state);
    if (vaultBlockAxis == null)
        return null;
    if (direction.getAxis() == vaultBlockAxis)
        return AllSpriteShifts.VAULT_FRONT.get(small);
    if (direction == Direction.UP)
        return AllSpriteShifts.VAULT_TOP.get(small);
    if (direction == Direction.DOWN)
        return AllSpriteShifts.VAULT_BOTTOM.get(small);
    return AllSpriteShifts.VAULT_SIDE.get(small);
}
Also used : Axis(net.minecraft.core.Direction.Axis)

Example 24 with Axis

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

the class CogWheelBlock method getAxisForPlacement.

protected Axis getAxisForPlacement(BlockPlaceContext context) {
    if (context.getPlayer() != null && context.getPlayer().isShiftKeyDown())
        return context.getClickedFace().getAxis();
    Level world = context.getLevel();
    BlockState stateBelow = world.getBlockState(context.getClickedPos().below());
    if (AllBlocks.ROTATION_SPEED_CONTROLLER.has(stateBelow) && isLargeCog())
        return stateBelow.getValue(SpeedControllerBlock.HORIZONTAL_AXIS) == Axis.X ? Axis.Z : Axis.X;
    BlockPos placedOnPos = context.getClickedPos().relative(context.getClickedFace().getOpposite());
    BlockState placedAgainst = world.getBlockState(placedOnPos);
    Block block = placedAgainst.getBlock();
    if (ICogWheel.isSmallCog(placedAgainst))
        return ((IRotate) block).getRotationAxis(placedAgainst);
    Axis preferredAxis = getPreferredAxis(context);
    return preferredAxis != null ? preferredAxis : context.getClickedFace().getAxis();
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) EncasedCogwheelBlock(com.simibubi.create.content.contraptions.relays.encased.EncasedCogwheelBlock) SpeedControllerBlock(com.simibubi.create.content.contraptions.relays.advanced.SpeedControllerBlock) Block(net.minecraft.world.level.block.Block) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) Axis(net.minecraft.core.Direction.Axis)

Example 25 with Axis

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

the class CogwheelBlockItem method triggerShiftingGearsAdvancement.

protected void triggerShiftingGearsAdvancement(Level world, BlockPos pos, BlockState state, Player player) {
    if (world.isClientSide || player == null)
        return;
    Axis axis = state.getValue(CogWheelBlock.AXIS);
    for (Axis perpendicular1 : Iterate.axes) {
        if (perpendicular1 == axis)
            continue;
        Direction d1 = Direction.get(AxisDirection.POSITIVE, perpendicular1);
        for (Axis perpendicular2 : Iterate.axes) {
            if (perpendicular1 == perpendicular2)
                continue;
            if (axis == perpendicular2)
                continue;
            Direction d2 = Direction.get(AxisDirection.POSITIVE, perpendicular2);
            for (int offset1 : Iterate.positiveAndNegative) {
                for (int offset2 : Iterate.positiveAndNegative) {
                    BlockPos connectedPos = pos.relative(d1, offset1).relative(d2, offset2);
                    BlockState blockState = world.getBlockState(connectedPos);
                    if (!(blockState.getBlock() instanceof CogWheelBlock))
                        continue;
                    if (blockState.getValue(CogWheelBlock.AXIS) != axis)
                        continue;
                    if (ICogWheel.isLargeCog(blockState) == large)
                        continue;
                    AllTriggers.triggerFor(AllTriggers.SHIFTING_GEARS, player);
                }
            }
        }
    }
}
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)

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