Search in sources :

Example 21 with SuperByteBuffer

use of com.simibubi.create.foundation.render.SuperByteBuffer in project Create by Creators-of-Create.

the class CouplingRenderer method renderCoupling.

public static void renderCoupling(PoseStack ms, MultiBufferSource buffer, Couple<AbstractMinecart> carts) {
    ClientLevel world = Minecraft.getInstance().level;
    if (carts.getFirst() == null || carts.getSecond() == null)
        return;
    Couple<Integer> lightValues = carts.map(c -> LevelRenderer.getLightColor(world, new BlockPos(c.getBoundingBox().getCenter())));
    Vec3 center = carts.getFirst().position().add(carts.getSecond().position()).scale(.5f);
    Couple<CartEndpoint> transforms = carts.map(c -> getSuitableCartEndpoint(c, center));
    BlockState renderState = Blocks.AIR.defaultBlockState();
    VertexConsumer builder = buffer.getBuffer(RenderType.solid());
    SuperByteBuffer attachment = CachedBufferer.partial(AllBlockPartials.COUPLING_ATTACHMENT, renderState);
    SuperByteBuffer ring = CachedBufferer.partial(AllBlockPartials.COUPLING_RING, renderState);
    SuperByteBuffer connector = CachedBufferer.partial(AllBlockPartials.COUPLING_CONNECTOR, renderState);
    Vec3 zero = Vec3.ZERO;
    Vec3 firstEndpoint = transforms.getFirst().apply(zero);
    Vec3 secondEndpoint = transforms.getSecond().apply(zero);
    Vec3 endPointDiff = secondEndpoint.subtract(firstEndpoint);
    double connectorYaw = -Math.atan2(endPointDiff.z, endPointDiff.x) * 180.0D / Math.PI;
    double connectorPitch = Math.atan2(endPointDiff.y, endPointDiff.multiply(1, 0, 1).length()) * 180 / Math.PI;
    TransformStack msr = TransformStack.cast(ms);
    carts.forEachWithContext((cart, isFirst) -> {
        CartEndpoint cartTransform = transforms.get(isFirst);
        ms.pushPose();
        cartTransform.apply(ms);
        attachment.light(lightValues.get(isFirst)).renderInto(ms, builder);
        msr.rotateY(connectorYaw - cartTransform.yaw);
        ring.light(lightValues.get(isFirst)).renderInto(ms, builder);
        ms.popPose();
    });
    int l1 = lightValues.getFirst();
    int l2 = lightValues.getSecond();
    int meanBlockLight = (((l1 >> 4) & 0xf) + ((l2 >> 4) & 0xf)) / 2;
    int meanSkyLight = (((l1 >> 20) & 0xf) + ((l2 >> 20) & 0xf)) / 2;
    ms.pushPose();
    msr.translate(firstEndpoint).rotateY(connectorYaw).rotateZ(connectorPitch);
    ms.scale((float) endPointDiff.length(), 1, 1);
    connector.light(meanSkyLight << 20 | meanBlockLight << 4).renderInto(ms, builder);
    ms.popPose();
}
Also used : ClientLevel(net.minecraft.client.multiplayer.ClientLevel) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) BlockState(net.minecraft.world.level.block.state.BlockState) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) TransformStack(com.jozufozu.flywheel.util.transform.TransformStack)

Example 22 with SuperByteBuffer

use of com.simibubi.create.foundation.render.SuperByteBuffer in project Create by Creators-of-Create.

the class GantryCarriageRenderer method renderSafe.

@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
    if (Backend.canUseInstancing(te.getLevel()))
        return;
    BlockState state = te.getBlockState();
    Direction facing = state.getValue(GantryCarriageBlock.FACING);
    Boolean alongFirst = state.getValue(GantryCarriageBlock.AXIS_ALONG_FIRST_COORDINATE);
    Axis rotationAxis = getRotationAxisOf(te);
    BlockPos visualPos = facing.getAxisDirection() == AxisDirection.POSITIVE ? te.getBlockPos() : te.getBlockPos().relative(facing.getOpposite());
    float angleForTe = getAngleForTe(te, visualPos, rotationAxis);
    Axis gantryAxis = Axis.X;
    for (Axis axis : Iterate.axes) if (axis != rotationAxis && axis != facing.getAxis())
        gantryAxis = axis;
    if (gantryAxis == Axis.X)
        if (facing == Direction.UP)
            angleForTe *= -1;
    if (gantryAxis == Axis.Y)
        if (facing == Direction.NORTH || facing == Direction.EAST)
            angleForTe *= -1;
    SuperByteBuffer cogs = CachedBufferer.partial(AllBlockPartials.GANTRY_COGS, state);
    cogs.centre().rotateY(AngleHelper.horizontalAngle(facing)).rotateX(facing == Direction.UP ? 0 : facing == Direction.DOWN ? 180 : 90).rotateY(alongFirst ^ facing.getAxis() == Axis.X ? 0 : 90).translate(0, -9 / 16f, 0).rotateX(-angleForTe).translate(0, 9 / 16f, 0).unCentre();
    cogs.light(light).renderInto(ms, buffer.getBuffer(RenderType.solid()));
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) Axis(net.minecraft.core.Direction.Axis)

Example 23 with SuperByteBuffer

use of com.simibubi.create.foundation.render.SuperByteBuffer in project Create by Creators-of-Create.

the class AbstractPulleyRenderer method renderSafe.

@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (Backend.canUseInstancing(te.getLevel()))
        return;
    super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
    float offset = getOffset(te, partialTicks);
    boolean running = isRunning(te);
    Axis rotationAxis = ((IRotate) te.getBlockState().getBlock()).getRotationAxis(te.getBlockState());
    kineticRotationTransform(getRotatedCoil(te), te, rotationAxis, AngleHelper.rad(offset * 180), light).renderInto(ms, buffer.getBuffer(RenderType.solid()));
    Level world = te.getLevel();
    BlockState blockState = te.getBlockState();
    BlockPos pos = te.getBlockPos();
    SuperByteBuffer halfMagnet = CachedBufferer.partial(this.halfMagnet, blockState);
    SuperByteBuffer halfRope = CachedBufferer.partial(this.halfRope, blockState);
    SuperByteBuffer magnet = renderMagnet(te);
    SuperByteBuffer rope = renderRope(te);
    VertexConsumer vb = buffer.getBuffer(RenderType.solid());
    if (running || offset == 0)
        renderAt(world, offset > .25f ? magnet : halfMagnet, offset, pos, ms, vb);
    float f = offset % 1;
    if (offset > .75f && (f < .25f || f > .75f))
        renderAt(world, halfRope, f > .75f ? f - 1 : f, pos, ms, vb);
    if (!running)
        return;
    for (int i = 0; i < offset - 1.25f; i++) renderAt(world, rope, offset - i - 1, pos, ms, vb);
}
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) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) Axis(net.minecraft.core.Direction.Axis)

Example 24 with SuperByteBuffer

use of com.simibubi.create.foundation.render.SuperByteBuffer 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 25 with SuperByteBuffer

use of com.simibubi.create.foundation.render.SuperByteBuffer in project Create by Creators-of-Create.

the class GaugeRenderer method renderSafe.

@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (Backend.canUseInstancing(te.getLevel()))
        return;
    super.renderSafe(te, partialTicks, ms, buffer, light, overlay);
    BlockState gaugeState = te.getBlockState();
    GaugeTileEntity gaugeTE = (GaugeTileEntity) te;
    PartialModel partialModel = (type == Type.SPEED ? AllBlockPartials.GAUGE_HEAD_SPEED : AllBlockPartials.GAUGE_HEAD_STRESS);
    SuperByteBuffer headBuffer = CachedBufferer.partial(partialModel, gaugeState);
    SuperByteBuffer dialBuffer = CachedBufferer.partial(AllBlockPartials.GAUGE_DIAL, gaugeState);
    float dialPivot = 5.75f / 16;
    float progress = Mth.lerp(partialTicks, gaugeTE.prevDialState, gaugeTE.dialState);
    for (Direction facing : Iterate.directions) {
        if (!((GaugeBlock) gaugeState.getBlock()).shouldRenderHeadOnFace(te.getLevel(), te.getBlockPos(), gaugeState, facing))
            continue;
        VertexConsumer vb = buffer.getBuffer(RenderType.solid());
        rotateBufferTowards(dialBuffer, facing).translate(0, dialPivot, dialPivot).rotate(Direction.EAST, (float) (Math.PI / 2 * -progress)).translate(0, -dialPivot, -dialPivot).light(light).renderInto(ms, vb);
        rotateBufferTowards(headBuffer, facing).light(light).renderInto(ms, vb);
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) Direction(net.minecraft.core.Direction) PartialModel(com.jozufozu.flywheel.core.PartialModel)

Aggregations

SuperByteBuffer (com.simibubi.create.foundation.render.SuperByteBuffer)53 BlockState (net.minecraft.world.level.block.state.BlockState)30 Direction (net.minecraft.core.Direction)20 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)18 BlockPos (net.minecraft.core.BlockPos)12 PartialModel (com.jozufozu.flywheel.core.PartialModel)11 Axis (net.minecraft.core.Direction.Axis)7 Vec3 (net.minecraft.world.phys.Vec3)7 TransformStack (com.jozufozu.flywheel.util.transform.TransformStack)5 PoseStack (com.mojang.blaze3d.vertex.PoseStack)5 BlockState (net.minecraft.block.BlockState)5 AxisDirection (net.minecraft.core.Direction.AxisDirection)4 BufferBuilder (com.mojang.blaze3d.vertex.BufferBuilder)3 IRotate (com.simibubi.create.content.contraptions.base.IRotate)3 RenderType (net.minecraft.client.renderer.RenderType)3 Direction (net.minecraft.util.Direction)3 ShadeSeparatedBufferBuilder (com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder)2 ShadeSeparatingVertexConsumer (com.jozufozu.flywheel.core.model.ShadeSeparatingVertexConsumer)2 Random (java.util.Random)2 BlockRenderDispatcher (net.minecraft.client.renderer.block.BlockRenderDispatcher)2