Search in sources :

Example 1 with TransformStack

use of com.jozufozu.flywheel.util.transform.TransformStack in project Flywheel by Jozufozu.

the class MinecartInstance method beginFrame.

@Override
public void beginFrame() {
    TransformStack tstack = TransformStack.cast(stack);
    stack.setIdentity();
    float pt = AnimationTickHolder.getPartialTicks();
    Vec3i originCoordinate = materialManager.getOriginCoordinate();
    tstack.translate(Mth.lerp(pt, entity.xOld, entity.getX()) - originCoordinate.getX(), Mth.lerp(pt, entity.yOld, entity.getY()) - originCoordinate.getY(), Mth.lerp(pt, entity.zOld, entity.getZ()) - originCoordinate.getZ());
    float yaw = Mth.lerp(pt, entity.yRotO, entity.getYRot());
    long i = (long) entity.getId() * 493286711L;
    i = i * i * 4392167121L + i * 98761L;
    float f = (((float) (i >> 16 & 7L) + 0.5F) / 8 - 0.5F) * 0.004F;
    float f1 = (((float) (i >> 20 & 7L) + 0.5F) / 8 - 0.5F) * 0.004F;
    float f2 = (((float) (i >> 24 & 7L) + 0.5F) / 8 - 0.5F) * 0.004F;
    tstack.translate(f, f1, f2);
    tstack.nudge(entity.getId());
    double d0 = Mth.lerp(pt, entity.xOld, entity.getX());
    double d1 = Mth.lerp(pt, entity.yOld, entity.getY());
    double d2 = Mth.lerp(pt, entity.zOld, entity.getZ());
    Vec3 vector3d = entity.getPos(d0, d1, d2);
    float f3 = Mth.lerp(pt, entity.xRotO, entity.getXRot());
    if (vector3d != null) {
        Vec3 vector3d1 = entity.getPosOffs(d0, d1, d2, 0.3F);
        Vec3 vector3d2 = entity.getPosOffs(d0, d1, d2, -0.3F);
        if (vector3d1 == null) {
            vector3d1 = vector3d;
        }
        if (vector3d2 == null) {
            vector3d2 = vector3d;
        }
        tstack.translate(vector3d.x - d0, (vector3d1.y + vector3d2.y) / 2.0D - d1, vector3d.z - d2);
        Vec3 vector3d3 = vector3d2.add(-vector3d1.x, -vector3d1.y, -vector3d1.z);
        if (vector3d3.length() != 0.0D) {
            vector3d3 = vector3d3.normalize();
            yaw = (float) (Math.atan2(vector3d3.z, vector3d3.x) * 180.0D / Math.PI);
            f3 = (float) (Math.atan(vector3d3.y) * 73.0D);
        }
    }
    tstack.translate(0.0D, 0.375D, 0.0D);
    tstack.multiply(Vector3f.YP.rotationDegrees(180 - yaw));
    tstack.multiply(Vector3f.ZP.rotationDegrees(-f3));
    float f5 = (float) entity.getHurtTime() - pt;
    float f6 = entity.getDamage() - pt;
    if (f6 < 0) {
        f6 = 0;
    }
    if (f5 > 0) {
        tstack.multiply(Vector3f.XP.rotationDegrees(Mth.sin(f5) * f5 * f6 / 10 * (float) entity.getHurtDir()));
    }
    int j = entity.getDisplayOffset();
    if (contents != null) {
        tstack.pushPose();
        tstack.scale(0.75F);
        tstack.translate(-0.5D, (float) (j - 8) / 16, 0.5D);
        tstack.multiply(Vector3f.YP.rotationDegrees(90));
        contents.setTransform(stack);
        tstack.popPose();
    }
    body.setTransform(stack);
}
Also used : Vec3i(net.minecraft.core.Vec3i) Vec3(net.minecraft.world.phys.Vec3) TransformStack(com.jozufozu.flywheel.util.transform.TransformStack)

Example 2 with TransformStack

use of com.jozufozu.flywheel.util.transform.TransformStack in project Create by Creators-of-Create.

the class DeployerActorInstance method beginFrame.

@Override
public void beginFrame() {
    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(facing.getNormal()).scale(factor);
    TransformStack tstack = TransformStack.cast(stack);
    stack.setIdentity();
    tstack.translate(context.localPos).translate(offset);
    transformModel(stack, pole, hand, yRot, xRot, zRot);
}
Also used : Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) TransformStack(com.jozufozu.flywheel.util.transform.TransformStack)

Example 3 with TransformStack

use of com.jozufozu.flywheel.util.transform.TransformStack in project Create by Creators-of-Create.

the class DeployerActorInstance method transformModel.

static void transformModel(PoseStack stack, ModelData pole, ModelData hand, float yRot, float xRot, float zRot) {
    TransformStack tstack = TransformStack.cast(stack);
    tstack.centre();
    tstack.rotate(Direction.UP, (float) ((yRot) / 180 * Math.PI));
    tstack.rotate(Direction.EAST, (float) ((xRot) / 180 * Math.PI));
    stack.pushPose();
    tstack.rotate(Direction.SOUTH, (float) ((zRot) / 180 * Math.PI));
    tstack.unCentre();
    pole.setTransform(stack);
    stack.popPose();
    tstack.unCentre();
    hand.setTransform(stack);
}
Also used : TransformStack(com.jozufozu.flywheel.util.transform.TransformStack)

Example 4 with TransformStack

use of com.jozufozu.flywheel.util.transform.TransformStack 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 5 with TransformStack

use of com.jozufozu.flywheel.util.transform.TransformStack in project Create by Creators-of-Create.

the class ExtendoGripItemRenderer method render.

@Override
protected void render(ItemStack stack, ExtendoGripModel model, PartialItemModelRenderer renderer, TransformType transformType, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    TransformStack stacker = TransformStack.cast(ms);
    float animation = 0.25f;
    boolean leftHand = transformType == TransformType.FIRST_PERSON_LEFT_HAND;
    boolean rightHand = transformType == TransformType.FIRST_PERSON_RIGHT_HAND;
    if (leftHand || rightHand)
        animation = Mth.lerp(AnimationTickHolder.getPartialTicks(), ExtendoGripRenderHandler.lastMainHandAnimation, ExtendoGripRenderHandler.mainHandAnimation);
    animation = animation * animation * animation;
    float extensionAngle = Mth.lerp(animation, 24f, 156f);
    float halfAngle = extensionAngle / 2;
    float oppositeAngle = 180 - extensionAngle;
    // grip
    renderer.renderSolid(model.getOriginalModel(), light);
    // bits
    ms.pushPose();
    ms.translate(0, 1 / 16f, -7 / 16f);
    ms.scale(1, 1, 1 + animation);
    ms.pushPose();
    stacker.rotateX(-halfAngle).translate(rotationOffset);
    renderer.renderSolid(model.getPartial("thin_short"), light);
    stacker.translateBack(rotationOffset);
    ms.translate(0, 5.5f / 16f, 0);
    stacker.rotateX(-oppositeAngle).translate(rotationOffset);
    renderer.renderSolid(model.getPartial("wide_long"), light);
    stacker.translateBack(rotationOffset);
    ms.translate(0, 11 / 16f, 0);
    stacker.rotateX(oppositeAngle).translate(rotationOffset);
    ms.translate(0, 0.5f / 16f, 0);
    renderer.renderSolid(model.getPartial("thin_short"), light);
    stacker.translateBack(rotationOffset);
    ms.popPose();
    ms.pushPose();
    stacker.rotateX(-180 + halfAngle).translate(rotationOffset);
    renderer.renderSolid(model.getPartial("wide_short"), light);
    stacker.translateBack(rotationOffset);
    ms.translate(0, 5.5f / 16f, 0);
    stacker.rotateX(oppositeAngle).translate(rotationOffset);
    renderer.renderSolid(model.getPartial("thin_long"), light);
    stacker.translateBack(rotationOffset);
    ms.translate(0, 11 / 16f, 0);
    stacker.rotateX(-oppositeAngle).translate(rotationOffset);
    ms.translate(0, 0.5f / 16f, 0);
    renderer.renderSolid(model.getPartial("wide_short"), light);
    stacker.translateBack(rotationOffset);
    // hand
    ms.translate(0, 5.5f / 16f, 0);
    stacker.rotateX(180 - halfAngle).rotateY(180);
    ms.translate(0, 0, -4 / 16f);
    ms.scale(1, 1, 1 / (1 + animation));
    renderer.renderSolid((leftHand || rightHand) ? ExtendoGripRenderHandler.pose.get() : AllBlockPartials.DEPLOYER_HAND_POINTING.get(), light);
    ms.popPose();
    ms.popPose();
    // cog
    ms.pushPose();
    float angle = AnimationTickHolder.getRenderTime() * -2;
    if (leftHand || rightHand)
        angle += 360 * animation;
    angle %= 360;
    stacker.translate(cogRotationOffset).rotateZ(angle).translateBack(cogRotationOffset);
    renderer.renderSolid(model.getPartial("cog"), light);
    ms.popPose();
}
Also used : TransformStack(com.jozufozu.flywheel.util.transform.TransformStack)

Aggregations

TransformStack (com.jozufozu.flywheel.util.transform.TransformStack)24 Vec3 (net.minecraft.world.phys.Vec3)9 PoseStack (com.mojang.blaze3d.vertex.PoseStack)7 ItemStack (net.minecraft.world.item.ItemStack)7 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)6 SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)5 ItemRenderer (net.minecraft.client.renderer.entity.ItemRenderer)5 Direction (net.minecraft.core.Direction)5 BlockState (net.minecraft.world.level.block.state.BlockState)4 TransformType (net.minecraft.client.renderer.block.model.ItemTransforms.TransformType)3 BlockItem (net.minecraft.world.item.BlockItem)3 PartialModel (com.jozufozu.flywheel.core.PartialModel)2 TransportedItemStack (com.simibubi.create.content.contraptions.relays.belt.transport.TransportedItemStack)2 Random (java.util.Random)2 Minecraft (net.minecraft.client.Minecraft)2 BlockPos (net.minecraft.core.BlockPos)2 Entity (net.minecraft.world.entity.Entity)2 Quaternion (com.mojang.math.Quaternion)1 SpriteShiftEntry (com.simibubi.create.foundation.block.render.SpriteShiftEntry)1 PartialItemModelRenderer (com.simibubi.create.foundation.item.render.PartialItemModelRenderer)1