Search in sources :

Example 1 with AxisDirection

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

the class BeltRenderer method renderSafe.

@Override
protected void renderSafe(BeltTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (!Backend.canUseInstancing(te.getLevel())) {
        BlockState blockState = te.getBlockState();
        if (!AllBlocks.BELT.has(blockState))
            return;
        BeltSlope beltSlope = blockState.getValue(BeltBlock.SLOPE);
        BeltPart part = blockState.getValue(BeltBlock.PART);
        Direction facing = blockState.getValue(BeltBlock.HORIZONTAL_FACING);
        AxisDirection axisDirection = facing.getAxisDirection();
        boolean downward = beltSlope == BeltSlope.DOWNWARD;
        boolean upward = beltSlope == BeltSlope.UPWARD;
        boolean diagonal = downward || upward;
        boolean start = part == BeltPart.START;
        boolean end = part == BeltPart.END;
        boolean sideways = beltSlope == BeltSlope.SIDEWAYS;
        boolean alongX = facing.getAxis() == Axis.X;
        PoseStack localTransforms = new PoseStack();
        TransformStack msr = TransformStack.cast(localTransforms);
        VertexConsumer vb = buffer.getBuffer(RenderType.solid());
        float renderTick = AnimationTickHolder.getRenderTime(te.getLevel());
        msr.centre().rotateY(AngleHelper.horizontalAngle(facing) + (upward ? 180 : 0) + (sideways ? 270 : 0)).rotateZ(sideways ? 90 : 0).rotateX(!diagonal && beltSlope != BeltSlope.HORIZONTAL ? 90 : 0).unCentre();
        if (downward || beltSlope == BeltSlope.VERTICAL && axisDirection == AxisDirection.POSITIVE) {
            boolean b = start;
            start = end;
            end = b;
        }
        DyeColor color = te.color.orElse(null);
        for (boolean bottom : Iterate.trueAndFalse) {
            PartialModel beltPartial = getBeltPartial(diagonal, start, end, bottom);
            SuperByteBuffer beltBuffer = CachedBufferer.partial(beltPartial, blockState).light(light);
            SpriteShiftEntry spriteShift = getSpriteShiftEntry(color, diagonal, bottom);
            // UV shift
            float speed = te.getSpeed();
            if (speed != 0 || te.color.isPresent()) {
                float time = renderTick * axisDirection.getStep();
                if (diagonal && (downward ^ alongX) || !sideways && !diagonal && alongX || sideways && axisDirection == AxisDirection.NEGATIVE)
                    speed = -speed;
                float scrollMult = diagonal ? 3f / 8f : 0.5f;
                float spriteSize = spriteShift.getTarget().getV1() - spriteShift.getTarget().getV0();
                double scroll = speed * time / (31.5 * 16) + (bottom ? 0.5 : 0.0);
                scroll = scroll - Math.floor(scroll);
                scroll = scroll * spriteSize * scrollMult;
                beltBuffer.shiftUVScrolling(spriteShift, (float) scroll);
            }
            beltBuffer.transform(localTransforms).renderInto(ms, vb);
            // Diagonal belt do not have a separate bottom model
            if (diagonal)
                break;
        }
        if (te.hasPulley()) {
            Direction dir = sideways ? Direction.UP : blockState.getValue(BeltBlock.HORIZONTAL_FACING).getClockWise();
            Supplier<PoseStack> matrixStackSupplier = () -> {
                PoseStack stack = new PoseStack();
                TransformStack stacker = TransformStack.cast(stack);
                stacker.centre();
                if (dir.getAxis() == Axis.X)
                    stacker.rotateY(90);
                if (dir.getAxis() == Axis.Y)
                    stacker.rotateX(90);
                stacker.rotateX(90);
                stacker.unCentre();
                return stack;
            };
            SuperByteBuffer superBuffer = CachedBufferer.partialDirectional(AllBlockPartials.BELT_PULLEY, blockState, dir, matrixStackSupplier);
            KineticTileEntityRenderer.standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb);
        }
    }
    renderItems(te, partialTicks, ms, buffer, light, overlay);
}
Also used : PoseStack(com.mojang.blaze3d.vertex.PoseStack) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) DyeColor(net.minecraft.world.item.DyeColor) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) BlockState(net.minecraft.world.level.block.state.BlockState) AxisDirection(net.minecraft.core.Direction.AxisDirection) TransformStack(com.jozufozu.flywheel.util.transform.TransformStack) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) PartialModel(com.jozufozu.flywheel.core.PartialModel) SpriteShiftEntry(com.simibubi.create.foundation.block.render.SpriteShiftEntry)

Example 2 with AxisDirection

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

the class BeltConnectorItem method getFacingFromTo.

private static Direction getFacingFromTo(BlockPos start, BlockPos end) {
    Axis beltAxis = start.getX() == end.getX() ? Axis.Z : Axis.X;
    BlockPos diff = end.subtract(start);
    AxisDirection axisDirection = AxisDirection.POSITIVE;
    if (diff.getX() == 0 && diff.getZ() == 0)
        axisDirection = diff.getY() > 0 ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE;
    else
        axisDirection = beltAxis.choose(diff.getX(), 0, diff.getZ()) > 0 ? AxisDirection.POSITIVE : AxisDirection.NEGATIVE;
    return Direction.get(axisDirection, beltAxis);
}
Also used : AxisDirection(net.minecraft.core.Direction.AxisDirection) BlockPos(net.minecraft.core.BlockPos) Axis(net.minecraft.core.Direction.Axis)

Example 3 with AxisDirection

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

the class BlockClusterOutline method render.

@Override
public void render(PoseStack ms, SuperRenderTypeBuffer buffer, float pt) {
    cluster.visibleEdges.forEach(edge -> {
        Vec3 start = Vec3.atLowerCornerOf(edge.pos);
        Direction direction = Direction.get(AxisDirection.POSITIVE, edge.axis);
        renderAACuboidLine(ms, buffer, start, Vec3.atLowerCornerOf(edge.pos.relative(direction)));
    });
    Optional<AllSpecialTextures> faceTexture = params.faceTexture;
    if (!faceTexture.isPresent())
        return;
    RenderType translucentType = RenderTypes.getOutlineTranslucent(faceTexture.get().getLocation(), true);
    VertexConsumer builder = buffer.getLateBuffer(translucentType);
    cluster.visibleFaces.forEach((face, axisDirection) -> {
        Direction direction = Direction.get(axisDirection, face.axis);
        BlockPos pos = face.pos;
        if (axisDirection == AxisDirection.POSITIVE)
            pos = pos.relative(direction.getOpposite());
        renderBlockFace(ms, builder, pos, direction);
    });
}
Also used : AllSpecialTextures(com.simibubi.create.AllSpecialTextures) Vec3(net.minecraft.world.phys.Vec3) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) RenderType(net.minecraft.client.renderer.RenderType)

Example 4 with AxisDirection

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

the class SchematicAndQuillHandler method mouseScrolled.

public boolean mouseScrolled(double delta) {
    if (!isActive())
        return false;
    if (!AllKeys.ctrlDown())
        return false;
    if (secondPos == null)
        range = (int) Mth.clamp(range + delta, 1, 100);
    if (selectedFace == null)
        return true;
    AABB bb = new AABB(firstPos, secondPos);
    Vec3i vec = selectedFace.getNormal();
    Vec3 projectedView = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
    if (bb.contains(projectedView))
        delta *= -1;
    int x = (int) (vec.getX() * delta);
    int y = (int) (vec.getY() * delta);
    int z = (int) (vec.getZ() * delta);
    AxisDirection axisDirection = selectedFace.getAxisDirection();
    if (axisDirection == AxisDirection.NEGATIVE)
        bb = bb.move(-x, -y, -z);
    double maxX = Math.max(bb.maxX - x * axisDirection.getStep(), bb.minX);
    double maxY = Math.max(bb.maxY - y * axisDirection.getStep(), bb.minY);
    double maxZ = Math.max(bb.maxZ - z * axisDirection.getStep(), bb.minZ);
    bb = new AABB(bb.minX, bb.minY, bb.minZ, maxX, maxY, maxZ);
    firstPos = new BlockPos(bb.minX, bb.minY, bb.minZ);
    secondPos = new BlockPos(bb.maxX, bb.maxY, bb.maxZ);
    Lang.sendStatus(Minecraft.getInstance().player, "schematicAndQuill.dimensions", (int) bb.getXsize() + 1, (int) bb.getYsize() + 1, (int) bb.getZsize() + 1);
    return true;
}
Also used : Vec3i(net.minecraft.core.Vec3i) Vec3(net.minecraft.world.phys.Vec3) AxisDirection(net.minecraft.core.Direction.AxisDirection) BlockPos(net.minecraft.core.BlockPos) AABB(net.minecraft.world.phys.AABB)

Aggregations

AxisDirection (net.minecraft.core.Direction.AxisDirection)4 BlockPos (net.minecraft.core.BlockPos)3 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)2 Direction (net.minecraft.core.Direction)2 Vec3 (net.minecraft.world.phys.Vec3)2 PartialModel (com.jozufozu.flywheel.core.PartialModel)1 TransformStack (com.jozufozu.flywheel.util.transform.TransformStack)1 PoseStack (com.mojang.blaze3d.vertex.PoseStack)1 AllSpecialTextures (com.simibubi.create.AllSpecialTextures)1 SpriteShiftEntry (com.simibubi.create.foundation.block.render.SpriteShiftEntry)1 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)1 RenderType (net.minecraft.client.renderer.RenderType)1 Axis (net.minecraft.core.Direction.Axis)1 Vec3i (net.minecraft.core.Vec3i)1 DyeColor (net.minecraft.world.item.DyeColor)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 AABB (net.minecraft.world.phys.AABB)1