Search in sources :

Example 66 with Axis

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

the class BlockClusterOutline method renderBlockFace.

protected void renderBlockFace(PoseStack ms, VertexConsumer builder, BlockPos pos, Direction face) {
    Vec3 center = VecHelper.getCenterOf(pos);
    Vec3 offset = Vec3.atLowerCornerOf(face.getNormal());
    Vec3 plane = VecHelper.axisAlingedPlaneOf(offset);
    Axis axis = face.getAxis();
    offset = offset.scale(1 / 2f + 1 / 128d);
    plane = plane.scale(1 / 2f).add(offset);
    int deg = face.getAxisDirection().getStep() * 90;
    Vec3 a1 = plane.add(center);
    plane = VecHelper.rotate(plane, deg, axis);
    Vec3 a2 = plane.add(center);
    plane = VecHelper.rotate(plane, deg, axis);
    Vec3 a3 = plane.add(center);
    plane = VecHelper.rotate(plane, deg, axis);
    Vec3 a4 = plane.add(center);
    putQuad(ms, builder, a1, a2, a3, a4, face);
}
Also used : Vec3(net.minecraft.world.phys.Vec3) Axis(net.minecraft.core.Direction.Axis)

Example 67 with Axis

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

the class DeployerRenderer method renderInContraption.

public static void renderInContraption(MovementContext context, VirtualRenderWorld renderWorld, ContraptionMatrices matrices, MultiBufferSource buffer) {
    VertexConsumer builder = buffer.getBuffer(RenderType.solid());
    BlockState blockState = context.state;
    Mode mode = NBTHelper.readEnum(context.tileData, "Mode", Mode.class);
    PartialModel handPose = getHandPose(mode);
    float speed = (float) context.getAnimationSpeed();
    if (context.contraption.stalled)
        speed = 0;
    SuperByteBuffer shaft = CachedBufferer.block(AllBlocks.SHAFT.getDefaultState());
    SuperByteBuffer pole = CachedBufferer.partial(AllBlockPartials.DEPLOYER_POLE, blockState);
    SuperByteBuffer hand = CachedBufferer.partial(handPose, blockState);
    double factor;
    if (context.contraption.stalled || context.position == null || context.data.contains("StationaryTimer")) {
        factor = Mth.sin(AnimationTickHolder.getRenderTime() * .5f) * .25f + .25f;
    } else {
        Vec3 center = VecHelper.getCenterOf(new BlockPos(context.position));
        double distance = context.position.distanceTo(center);
        double nextDistance = context.position.add(context.motion).distanceTo(center);
        factor = .5f - Mth.clamp(Mth.lerp(AnimationTickHolder.getPartialTicks(), distance, nextDistance), 0, 1);
    }
    Vec3 offset = Vec3.atLowerCornerOf(blockState.getValue(FACING).getNormal()).scale(factor);
    PoseStack m = matrices.getModel();
    m.pushPose();
    m.pushPose();
    Axis axis = Axis.Y;
    if (context.state.getBlock() instanceof IRotate) {
        IRotate def = (IRotate) context.state.getBlock();
        axis = def.getRotationAxis(context.state);
    }
    float time = AnimationTickHolder.getRenderTime(context.world) / 20;
    float angle = (time * speed) % 360;
    TransformStack.cast(m).centre().rotateY(axis == Axis.Z ? 90 : 0).rotateZ(axis.isHorizontal() ? 90 : 0).unCentre();
    shaft.transform(m);
    shaft.rotateCentered(Direction.get(AxisDirection.POSITIVE, Axis.Y), angle);
    m.popPose();
    m.translate(offset.x, offset.y, offset.z);
    pole.transform(m);
    hand.transform(m);
    transform(pole, blockState, true);
    transform(hand, blockState, false);
    shaft.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)).renderInto(matrices.getViewProjection(), builder);
    pole.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)).renderInto(matrices.getViewProjection(), builder);
    hand.light(matrices.getWorld(), ContraptionRenderDispatcher.getContraptionWorldLight(context, renderWorld)).renderInto(matrices.getViewProjection(), builder);
    m.popPose();
}
Also used : IRotate(com.simibubi.create.content.contraptions.base.IRotate) BlockState(net.minecraft.world.level.block.state.BlockState) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Mode(com.simibubi.create.content.contraptions.components.deployer.DeployerTileEntity.Mode) Vec3(net.minecraft.world.phys.Vec3) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) BlockPos(net.minecraft.core.BlockPos) PartialModel(com.jozufozu.flywheel.core.PartialModel) Axis(net.minecraft.core.Direction.Axis)

Example 68 with Axis

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

the class CrushingWheelBlock method updateControllers.

public void updateControllers(BlockState state, Level world, BlockPos pos, Direction side) {
    if (side.getAxis() == state.getValue(AXIS))
        return;
    if (world == null)
        return;
    BlockPos controllerPos = pos.relative(side);
    BlockPos otherWheelPos = pos.relative(side, 2);
    boolean controllerExists = AllBlocks.CRUSHING_WHEEL_CONTROLLER.has(world.getBlockState(controllerPos));
    boolean controllerIsValid = controllerExists && world.getBlockState(controllerPos).getValue(VALID);
    Direction controllerOldDirection = controllerExists ? world.getBlockState(controllerPos).getValue(CrushingWheelControllerBlock.FACING) : null;
    boolean controllerShouldExist = false;
    boolean controllerShouldBeValid = false;
    Direction controllerNewDirection = Direction.DOWN;
    BlockState otherState = world.getBlockState(otherWheelPos);
    if (AllBlocks.CRUSHING_WHEEL.has(otherState)) {
        controllerShouldExist = true;
        CrushingWheelTileEntity te = getTileEntity(world, pos);
        CrushingWheelTileEntity otherTe = getTileEntity(world, otherWheelPos);
        if (te != null && otherTe != null && (te.getSpeed() > 0) != (otherTe.getSpeed() > 0) && te.getSpeed() != 0) {
            Axis wheelAxis = state.getValue(AXIS);
            Axis sideAxis = side.getAxis();
            int controllerADO = Math.round(Math.signum(te.getSpeed())) * side.getAxisDirection().getStep();
            Vec3 controllerDirVec = new Vec3(wheelAxis == Axis.X ? 1 : 0, wheelAxis == Axis.Y ? 1 : 0, wheelAxis == Axis.Z ? 1 : 0).cross(new Vec3(sideAxis == Axis.X ? 1 : 0, sideAxis == Axis.Y ? 1 : 0, sideAxis == Axis.Z ? 1 : 0));
            controllerNewDirection = Direction.getNearest(controllerDirVec.x * controllerADO, controllerDirVec.y * controllerADO, controllerDirVec.z * controllerADO);
            controllerShouldBeValid = true;
        }
        if (otherState.getValue(AXIS) != state.getValue(AXIS))
            controllerShouldExist = false;
    }
    if (!controllerShouldExist) {
        if (controllerExists)
            world.setBlockAndUpdate(controllerPos, Blocks.AIR.defaultBlockState());
        return;
    }
    if (!controllerExists) {
        if (!world.getBlockState(controllerPos).getMaterial().isReplaceable())
            return;
        world.setBlockAndUpdate(controllerPos, AllBlocks.CRUSHING_WHEEL_CONTROLLER.getDefaultState().setValue(VALID, controllerShouldBeValid).setValue(CrushingWheelControllerBlock.FACING, controllerNewDirection));
    } else if (controllerIsValid != controllerShouldBeValid || controllerOldDirection != controllerNewDirection) {
        world.setBlockAndUpdate(controllerPos, world.getBlockState(controllerPos).setValue(VALID, controllerShouldBeValid).setValue(CrushingWheelControllerBlock.FACING, controllerNewDirection));
    }
    ((CrushingWheelControllerBlock) AllBlocks.CRUSHING_WHEEL_CONTROLLER.get()).updateSpeed(world.getBlockState(controllerPos), world, controllerPos);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis)

Example 69 with Axis

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

the class GantryShaftBlock method updateShape.

@Override
public BlockState updateShape(BlockState state, Direction direction, BlockState neighbour, LevelAccessor world, BlockPos pos, BlockPos neighbourPos) {
    Direction facing = state.getValue(FACING);
    Axis axis = facing.getAxis();
    if (direction.getAxis() != axis)
        return state;
    boolean connect = AllBlocks.GANTRY_SHAFT.has(neighbour) && neighbour.getValue(FACING) == facing;
    Part part = state.getValue(PART);
    if (direction.getAxisDirection() == facing.getAxisDirection()) {
        if (connect) {
            if (part == Part.END)
                part = Part.MIDDLE;
            if (part == Part.SINGLE)
                part = Part.START;
        } else {
            if (part == Part.MIDDLE)
                part = Part.END;
            if (part == Part.START)
                part = Part.SINGLE;
        }
    } else {
        if (connect) {
            if (part == Part.START)
                part = Part.MIDDLE;
            if (part == Part.SINGLE)
                part = Part.END;
        } else {
            if (part == Part.MIDDLE)
                part = Part.START;
            if (part == Part.END)
                part = Part.SINGLE;
        }
    }
    return state.setValue(PART, part);
}
Also used : Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis)

Example 70 with Axis

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

the class GantryShaftBlock method neighborChanged.

@Override
public void neighborChanged(BlockState state, Level worldIn, BlockPos pos, Block p_220069_4_, BlockPos p_220069_5_, boolean p_220069_6_) {
    if (worldIn.isClientSide)
        return;
    boolean previouslyPowered = state.getValue(POWERED);
    // shouldBePowered(state, worldIn, pos);
    boolean shouldPower = worldIn.hasNeighborSignal(pos);
    if (!previouslyPowered && !shouldPower && shouldBePowered(state, worldIn, pos)) {
        worldIn.setBlock(pos, state.setValue(POWERED, true), 3);
        return;
    }
    if (previouslyPowered == shouldPower)
        return;
    // Collect affected gantry shafts
    List<BlockPos> toUpdate = new ArrayList<>();
    Direction facing = state.getValue(FACING);
    Axis axis = facing.getAxis();
    for (Direction d : Iterate.directionsInAxis(axis)) {
        BlockPos currentPos = pos.relative(d);
        while (true) {
            if (!worldIn.isLoaded(currentPos))
                break;
            BlockState currentState = worldIn.getBlockState(currentPos);
            if (!(currentState.getBlock() instanceof GantryShaftBlock))
                break;
            if (currentState.getValue(FACING) != facing)
                break;
            if (!shouldPower && currentState.getValue(POWERED) && worldIn.hasNeighborSignal(currentPos))
                return;
            if (currentState.getValue(POWERED) == shouldPower)
                break;
            toUpdate.add(currentPos);
            currentPos = currentPos.relative(d);
        }
    }
    toUpdate.add(pos);
    for (BlockPos blockPos : toUpdate) {
        BlockState blockState = worldIn.getBlockState(blockPos);
        BlockEntity te = worldIn.getBlockEntity(blockPos);
        if (te instanceof KineticTileEntity)
            ((KineticTileEntity) te).detachKinetics();
        if (blockState.getBlock() instanceof GantryShaftBlock)
            worldIn.setBlock(blockPos, blockState.setValue(POWERED, shouldPower), 2);
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) KineticTileEntity(com.simibubi.create.content.contraptions.base.KineticTileEntity) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) Axis(net.minecraft.core.Direction.Axis) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

Axis (net.minecraft.core.Direction.Axis)87 Direction (net.minecraft.core.Direction)43 BlockPos (net.minecraft.core.BlockPos)39 BlockState (net.minecraft.world.level.block.state.BlockState)37 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