Search in sources :

Example 26 with SuperByteBuffer

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

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

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

the class HandCrankRenderer 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();
    Block block = state.getBlock();
    PartialModel renderedHandle = null;
    if (block instanceof HandCrankBlock)
        renderedHandle = ((HandCrankBlock) block).getRenderedHandle();
    if (renderedHandle == null)
        return;
    Direction facing = state.getValue(FACING);
    SuperByteBuffer handle = CachedBufferer.partialFacing(renderedHandle, state, facing.getOpposite());
    HandCrankTileEntity crank = (HandCrankTileEntity) te;
    kineticRotationTransform(handle, te, facing.getAxis(), (crank.independentAngle + partialTicks * crank.chasingVelocity) / 360, light);
    handle.renderInto(ms, buffer.getBuffer(RenderType.solid()));
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) Block(net.minecraft.world.level.block.Block) Direction(net.minecraft.core.Direction) PartialModel(com.jozufozu.flywheel.core.PartialModel)

Example 29 with SuperByteBuffer

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

the class MechanicalMixerRenderer method renderSafe.

@Override
protected void renderSafe(KineticTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (Backend.canUseInstancing(te.getLevel()))
        return;
    BlockState blockState = te.getBlockState();
    MechanicalMixerTileEntity mixer = (MechanicalMixerTileEntity) te;
    VertexConsumer vb = buffer.getBuffer(RenderType.solid());
    SuperByteBuffer superBuffer = CachedBufferer.partial(AllBlockPartials.SHAFTLESS_COGWHEEL, blockState);
    standardKineticRotationTransform(superBuffer, te, light).renderInto(ms, vb);
    float renderedHeadOffset = mixer.getRenderedHeadOffset(partialTicks);
    float speed = mixer.getRenderedHeadRotationSpeed(partialTicks);
    float time = AnimationTickHolder.getRenderTime(te.getLevel());
    float angle = ((time * speed * 6 / 10f) % 360) / 180 * (float) Math.PI;
    SuperByteBuffer poleRender = CachedBufferer.partial(AllBlockPartials.MECHANICAL_MIXER_POLE, blockState);
    poleRender.translate(0, -renderedHeadOffset, 0).light(light).renderInto(ms, vb);
    SuperByteBuffer headRender = CachedBufferer.partial(AllBlockPartials.MECHANICAL_MIXER_HEAD, blockState);
    headRender.rotateCentered(Direction.UP, angle).translate(0, -renderedHeadOffset, 0).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)

Example 30 with SuperByteBuffer

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

the class SawRenderer method renderBlade.

protected void renderBlade(SawTileEntity te, PoseStack ms, MultiBufferSource buffer, int light) {
    BlockState blockState = te.getBlockState();
    PartialModel partial;
    float speed = te.getSpeed();
    boolean rotate = false;
    if (SawBlock.isHorizontal(blockState)) {
        if (speed > 0) {
            partial = AllBlockPartials.SAW_BLADE_HORIZONTAL_ACTIVE;
        } else if (speed < 0) {
            partial = AllBlockPartials.SAW_BLADE_HORIZONTAL_REVERSED;
        } else {
            partial = AllBlockPartials.SAW_BLADE_HORIZONTAL_INACTIVE;
        }
    } else {
        if (te.getSpeed() > 0) {
            partial = AllBlockPartials.SAW_BLADE_VERTICAL_ACTIVE;
        } else if (speed < 0) {
            partial = AllBlockPartials.SAW_BLADE_VERTICAL_REVERSED;
        } else {
            partial = AllBlockPartials.SAW_BLADE_VERTICAL_INACTIVE;
        }
        if (blockState.getValue(SawBlock.AXIS_ALONG_FIRST_COORDINATE))
            rotate = true;
    }
    SuperByteBuffer superBuffer = CachedBufferer.partialFacing(partial, blockState);
    if (rotate) {
        superBuffer.rotateCentered(Direction.UP, AngleHelper.rad(90));
    }
    superBuffer.color(0xFFFFFF).light(light).renderInto(ms, buffer.getBuffer(RenderType.cutoutMipped()));
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) 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