Search in sources :

Example 51 with Axis

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

the class BeltConnectorItem method canConnect.

public static boolean canConnect(Level world, BlockPos first, BlockPos second) {
    if (!world.isAreaLoaded(first, 1))
        return false;
    if (!world.isAreaLoaded(second, 1))
        return false;
    if (!second.closerThan(first, maxLength()))
        return false;
    BlockPos diff = second.subtract(first);
    Axis shaftAxis = world.getBlockState(first).getValue(BlockStateProperties.AXIS);
    int x = diff.getX();
    int y = diff.getY();
    int z = diff.getZ();
    int sames = ((Math.abs(x) == Math.abs(y)) ? 1 : 0) + ((Math.abs(y) == Math.abs(z)) ? 1 : 0) + ((Math.abs(z) == Math.abs(x)) ? 1 : 0);
    if (shaftAxis.choose(x, y, z) != 0)
        return false;
    if (sames != 1)
        return false;
    if (shaftAxis != world.getBlockState(second).getValue(BlockStateProperties.AXIS))
        return false;
    if (shaftAxis == Axis.Y && x != 0 && z != 0)
        return false;
    BlockEntity tileEntity = world.getBlockEntity(first);
    BlockEntity tileEntity2 = world.getBlockEntity(second);
    if (!(tileEntity instanceof KineticTileEntity))
        return false;
    if (!(tileEntity2 instanceof KineticTileEntity))
        return false;
    float speed1 = ((KineticTileEntity) tileEntity).getTheoreticalSpeed();
    float speed2 = ((KineticTileEntity) tileEntity2).getTheoreticalSpeed();
    if (Math.signum(speed1) != Math.signum(speed2) && speed1 != 0 && speed2 != 0)
        return false;
    BlockPos step = new BlockPos(Math.signum(diff.getX()), Math.signum(diff.getY()), Math.signum(diff.getZ()));
    int limit = 1000;
    for (BlockPos currentPos = first.offset(step); !currentPos.equals(second) && limit-- > 0; currentPos = currentPos.offset(step)) {
        BlockState blockState = world.getBlockState(currentPos);
        if (ShaftBlock.isShaft(blockState) && blockState.getValue(AbstractShaftBlock.AXIS) == shaftAxis)
            continue;
        if (!blockState.getMaterial().isReplaceable())
            return false;
    }
    return true;
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) BlockPos(net.minecraft.core.BlockPos) Axis(net.minecraft.core.Direction.Axis) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 52 with Axis

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

the class BeltShapes method getBeltShape.

private static VoxelShape getBeltShape(BlockState state) {
    Direction facing = state.getValue(BeltBlock.HORIZONTAL_FACING);
    Axis axis = facing.getAxis();
    BeltPart part = state.getValue(BeltBlock.PART);
    BeltSlope slope = state.getValue(BeltBlock.SLOPE);
    // vertical
    if (slope == BeltSlope.VERTICAL) {
        if (part == BeltPart.MIDDLE || part == BeltPart.PULLEY)
            return VERTICAL_FULL.get(axis);
        // vertical ending
        return (part == BeltPart.START ? VERTICAL_START : VERTICAL_END).get(facing);
    }
    // flat part
    if (slope == BeltSlope.HORIZONTAL) {
        if (part == BeltPart.MIDDLE || part == BeltPart.PULLEY)
            return FLAT_FULL.get(axis);
        // flat ending
        return (part == BeltPart.START ? FLAT_START : FLAT_END).get(facing);
    }
    // sideways part
    if (slope == BeltSlope.SIDEWAYS) {
        if (part == BeltPart.MIDDLE || part == BeltPart.PULLEY)
            return SIDE_FULL.get(axis);
        // flat ending
        return (part == BeltPart.START ? SIDE_START : SIDE_END).get(facing);
    }
    // slope
    if (part == BeltPart.MIDDLE || part == BeltPart.PULLEY)
        return (slope == BeltSlope.DOWNWARD ? SLOPE_DESC : SLOPE_ASC).get(facing);
    // sloped ending
    if (part == BeltPart.START)
        return (slope == BeltSlope.DOWNWARD ? SLOPE_DESC_START : SLOPE_ASC_START).get(facing);
    if (part == BeltPart.END)
        return (slope == BeltSlope.DOWNWARD ? SLOPE_DESC_END : SLOPE_ASC_END).get(facing);
    // bad state
    return Shapes.empty();
}
Also used : Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis)

Example 53 with Axis

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

the class SplitShaftRenderer method renderSafe.

@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (Backend.canUseInstancing(te.getLevel()))
        return;
    Block block = te.getBlockState().getBlock();
    final Axis boxAxis = ((IRotate) block).getRotationAxis(te.getBlockState());
    final BlockPos pos = te.getBlockPos();
    float time = AnimationTickHolder.getRenderTime(te.getLevel());
    for (Direction direction : Iterate.directions) {
        Axis axis = direction.getAxis();
        if (boxAxis != axis)
            continue;
        float offset = getRotationOffsetForPosition(te, pos, axis);
        float angle = (time * te.getSpeed() * 3f / 10) % 360;
        float modifier = 1;
        if (te instanceof SplitShaftTileEntity)
            modifier = ((SplitShaftTileEntity) te).getRotationSpeedModifier(direction);
        angle *= modifier;
        angle += offset;
        angle = angle / 180f * (float) Math.PI;
        SuperByteBuffer superByteBuffer = CachedBufferer.partialFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState(), direction);
        kineticRotationTransform(superByteBuffer, te, axis, angle, light);
        superByteBuffer.renderInto(ms, buffer.getBuffer(RenderType.solid()));
    }
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis)

Example 54 with Axis

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

the class GearboxRenderer method renderSafe.

@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (Backend.canUseInstancing(te.getLevel()))
        return;
    final Axis boxAxis = te.getBlockState().getValue(BlockStateProperties.AXIS);
    final BlockPos pos = te.getBlockPos();
    float time = AnimationTickHolder.getRenderTime(te.getLevel());
    for (Direction direction : Iterate.directions) {
        final Axis axis = direction.getAxis();
        if (boxAxis == axis)
            continue;
        SuperByteBuffer shaft = CachedBufferer.partialFacing(AllBlockPartials.SHAFT_HALF, te.getBlockState(), direction);
        float offset = getRotationOffsetForPosition(te, pos, axis);
        float angle = (time * te.getSpeed() * 3f / 10) % 360;
        if (te.getSpeed() != 0 && te.hasSource()) {
            BlockPos source = te.source.subtract(te.getBlockPos());
            Direction sourceFacing = Direction.getNearest(source.getX(), source.getY(), source.getZ());
            if (sourceFacing.getAxis() == direction.getAxis())
                angle *= sourceFacing == direction ? 1 : -1;
            else if (sourceFacing.getAxisDirection() == direction.getAxisDirection())
                angle *= -1;
        }
        angle += offset;
        angle = angle / 180f * (float) Math.PI;
        kineticRotationTransform(shaft, te, axis, angle, light);
        shaft.renderInto(ms, buffer.getBuffer(RenderType.solid()));
    }
}
Also used : SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis)

Example 55 with Axis

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

the class EncasedBeltBlock method updateAfterWrenched.

@Override
public BlockState updateAfterWrenched(BlockState newState, UseOnContext context) {
    // Blocks.AIR.getDefaultState()
    // .updateNeighbors(context.getWorld(), context.getPos(), 1);
    Axis axis = newState.getValue(AXIS);
    newState = defaultBlockState().setValue(AXIS, axis);
    if (newState.hasProperty(BlockStateProperties.POWERED))
        newState = newState.setValue(BlockStateProperties.POWERED, context.getLevel().hasNeighborSignal(context.getClickedPos()));
    for (Direction facing : Iterate.directions) {
        if (facing.getAxis() == axis)
            continue;
        BlockPos pos = context.getClickedPos();
        BlockPos offset = pos.relative(facing);
        newState = updateShape(newState, facing, context.getLevel().getBlockState(offset), context.getLevel(), pos, offset);
    }
    // newState.updateNeighbors(context.getWorld(), context.getPos(), 1 | 2);
    return newState;
}
Also used : 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