Search in sources :

Example 36 with SuperByteBuffer

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

the class EjectorRenderer 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);
    EjectorTileEntity ejector = (EjectorTileEntity) te;
    VertexConsumer vertexBuilder = buffer.getBuffer(RenderType.solid());
    float lidProgress = ((EjectorTileEntity) te).getLidProgress(partialTicks);
    float angle = lidProgress * 70;
    if (!Backend.canUseInstancing(te.getLevel())) {
        SuperByteBuffer model = CachedBufferer.partial(AllBlockPartials.EJECTOR_TOP, te.getBlockState());
        applyLidAngle(te, angle, model);
        model.light(light).renderInto(ms, vertexBuilder);
    }
    TransformStack msr = TransformStack.cast(ms);
    float maxTime = (float) (ejector.earlyTarget != null ? ejector.earlyTargetTime : ejector.launcher.getTotalFlyingTicks());
    for (IntAttached<ItemStack> intAttached : ejector.launchedItems) {
        float time = intAttached.getFirst() + partialTicks;
        if (time > maxTime)
            continue;
        ms.pushPose();
        Vec3 launchedItemLocation = ejector.getLaunchedItemLocation(time);
        msr.translate(launchedItemLocation.subtract(Vec3.atLowerCornerOf(te.getBlockPos())));
        Vec3 itemRotOffset = VecHelper.voxelSpace(0, 3, 0);
        msr.translate(itemRotOffset);
        msr.rotateY(AngleHelper.horizontalAngle(ejector.getFacing()));
        msr.rotateX(time * 40);
        msr.translateBack(itemRotOffset);
        Minecraft.getInstance().getItemRenderer().renderStatic(intAttached.getValue(), TransformType.GROUND, light, overlay, ms, buffer, 0);
        ms.popPose();
    }
    DepotBehaviour behaviour = te.getBehaviour(DepotBehaviour.TYPE);
    if (behaviour == null || behaviour.isEmpty())
        return;
    ms.pushPose();
    applyLidAngle(te, angle, msr);
    msr.centre().rotateY(-180 - AngleHelper.horizontalAngle(te.getBlockState().getValue(EjectorBlock.HORIZONTAL_FACING))).unCentre();
    DepotRenderer.renderItemsOf(te, partialTicks, ms, buffer, light, overlay, behaviour);
    ms.popPose();
}
Also used : SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) Vec3(net.minecraft.world.phys.Vec3) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) TransformStack(com.jozufozu.flywheel.util.transform.TransformStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 37 with SuperByteBuffer

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

the class ArmRenderer method renderArm.

private void renderArm(VertexConsumer builder, PoseStack ms, PoseStack msLocal, TransformStack msr, BlockState blockState, int color, float baseAngle, float lowerArmAngle, float upperArmAngle, float headAngle, boolean hasItem, boolean isBlockItem, int light) {
    SuperByteBuffer base = CachedBufferer.partial(AllBlockPartials.ARM_BASE, blockState).light(light);
    SuperByteBuffer lowerBody = CachedBufferer.partial(AllBlockPartials.ARM_LOWER_BODY, blockState).light(light);
    SuperByteBuffer upperBody = CachedBufferer.partial(AllBlockPartials.ARM_UPPER_BODY, blockState).light(light);
    SuperByteBuffer head = CachedBufferer.partial(AllBlockPartials.ARM_HEAD, blockState).light(light);
    SuperByteBuffer claw = CachedBufferer.partial(AllBlockPartials.ARM_CLAW_BASE, blockState).light(light);
    SuperByteBuffer clawGrip = CachedBufferer.partial(AllBlockPartials.ARM_CLAW_GRIP, blockState);
    transformBase(msr, baseAngle);
    base.transform(msLocal).renderInto(ms, builder);
    transformLowerArm(msr, lowerArmAngle);
    lowerBody.color(color).transform(msLocal).renderInto(ms, builder);
    transformUpperArm(msr, upperArmAngle);
    upperBody.color(color).transform(msLocal).renderInto(ms, builder);
    transformHead(msr, headAngle);
    head.transform(msLocal).renderInto(ms, builder);
    transformClaw(msr);
    claw.transform(msLocal).renderInto(ms, builder);
    for (int flip : Iterate.positiveAndNegative) {
        msLocal.pushPose();
        transformClawHalf(msr, hasItem, isBlockItem, flip);
        clawGrip.light(light).transform(msLocal).renderInto(ms, builder);
        msLocal.popPose();
    }
}
Also used : SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer)

Example 38 with SuperByteBuffer

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

the class WorldSectionElement method buildStructureBuffer.

private SuperByteBuffer buildStructureBuffer(PonderWorld world, RenderType layer) {
    BlockRenderDispatcher dispatcher = ModelUtil.VANILLA_RENDERER;
    ThreadLocalObjects objects = THREAD_LOCAL_OBJECTS.get();
    PoseStack poseStack = objects.poseStack;
    Random random = objects.random;
    ShadeSeparatingVertexConsumer shadeSeparatingWrapper = objects.shadeSeparatingWrapper;
    ShadeSeparatedBufferBuilder builder = new ShadeSeparatedBufferBuilder(512);
    BufferBuilder unshadedBuilder = objects.unshadedBuilder;
    builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
    unshadedBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.BLOCK);
    shadeSeparatingWrapper.prepare(builder, unshadedBuilder);
    world.setMask(this.section);
    ForgeHooksClient.setRenderType(layer);
    ModelBlockRenderer.enableCaching();
    section.forEach(pos -> {
        BlockState state = world.getBlockState(pos);
        FluidState fluidState = world.getFluidState(pos);
        poseStack.pushPose();
        poseStack.translate(pos.getX(), pos.getY(), pos.getZ());
        if (state.getRenderShape() == RenderShape.MODEL && ItemBlockRenderTypes.canRenderInLayer(state, layer)) {
            BlockEntity tileEntity = world.getBlockEntity(pos);
            dispatcher.renderBatched(state, pos, world, poseStack, shadeSeparatingWrapper, true, random, tileEntity != null ? tileEntity.getModelData() : EmptyModelData.INSTANCE);
        }
        if (!fluidState.isEmpty() && ItemBlockRenderTypes.canRenderInLayer(fluidState, layer))
            dispatcher.renderLiquid(pos, world, builder, fluidState);
        poseStack.popPose();
    });
    ModelBlockRenderer.clearCache();
    ForgeHooksClient.setRenderType(null);
    world.clearMask();
    shadeSeparatingWrapper.clear();
    unshadedBuilder.end();
    builder.appendUnshadedVertices(unshadedBuilder);
    builder.end();
    return new SuperByteBuffer(builder);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) PoseStack(com.mojang.blaze3d.vertex.PoseStack) Random(java.util.Random) SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer) BlockRenderDispatcher(net.minecraft.client.renderer.block.BlockRenderDispatcher) ShadeSeparatingVertexConsumer(com.jozufozu.flywheel.core.model.ShadeSeparatingVertexConsumer) BufferBuilder(com.mojang.blaze3d.vertex.BufferBuilder) ShadeSeparatedBufferBuilder(com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder) ShadeSeparatedBufferBuilder(com.jozufozu.flywheel.core.model.ShadeSeparatedBufferBuilder) FluidState(net.minecraft.world.level.material.FluidState) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 39 with SuperByteBuffer

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

the class MechanicalCrafterRenderer method renderAndTransform.

private SuperByteBuffer renderAndTransform(PartialModel renderBlock, BlockState crafterState) {
    SuperByteBuffer buffer = CachedBufferer.partial(renderBlock, crafterState);
    float xRot = crafterState.getValue(MechanicalCrafterBlock.POINTING).getXRotation();
    float yRot = AngleHelper.horizontalAngle(crafterState.getValue(HORIZONTAL_FACING));
    buffer.rotateCentered(Direction.UP, (float) ((yRot + 90) / 180 * Math.PI));
    buffer.rotateCentered(Direction.EAST, (float) ((xRot) / 180 * Math.PI));
    return buffer;
}
Also used : SuperByteBuffer(com.simibubi.create.foundation.render.SuperByteBuffer)

Example 40 with SuperByteBuffer

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

the class MechanicalCrafterRenderer method renderFast.

public void renderFast(MechanicalCrafterTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light) {
    BlockState blockState = te.getBlockState();
    VertexConsumer vb = buffer.getBuffer(RenderType.solid());
    if (!Backend.canUseInstancing(te.getLevel())) {
        SuperByteBuffer superBuffer = CachedBufferer.partial(AllBlockPartials.SHAFTLESS_COGWHEEL, blockState);
        standardKineticRotationTransform(superBuffer, te, light);
        superBuffer.rotateCentered(Direction.UP, (float) (blockState.getValue(HORIZONTAL_FACING).getAxis() != Direction.Axis.X ? 0 : Math.PI / 2));
        superBuffer.rotateCentered(Direction.EAST, (float) (Math.PI / 2));
        superBuffer.renderInto(ms, vb);
    }
    Direction targetDirection = MechanicalCrafterBlock.getTargetDirection(blockState);
    BlockPos pos = te.getBlockPos();
    if ((te.covered || te.phase != Phase.IDLE) && te.phase != Phase.CRAFTING && te.phase != Phase.INSERTING) {
        SuperByteBuffer lidBuffer = renderAndTransform(AllBlockPartials.MECHANICAL_CRAFTER_LID, blockState);
        lidBuffer.light(light).renderInto(ms, vb);
    }
    if (MechanicalCrafterBlock.isValidTarget(te.getLevel(), pos.relative(targetDirection), blockState)) {
        SuperByteBuffer beltBuffer = renderAndTransform(AllBlockPartials.MECHANICAL_CRAFTER_BELT, blockState);
        SuperByteBuffer beltFrameBuffer = renderAndTransform(AllBlockPartials.MECHANICAL_CRAFTER_BELT_FRAME, blockState);
        if (te.phase == Phase.EXPORTING) {
            int textureIndex = (int) ((te.getCountDownSpeed() / 128f * AnimationTickHolder.getTicks()));
            beltBuffer.shiftUVtoSheet(AllSpriteShifts.CRAFTER_THINGIES, (textureIndex % 4) / 4f, 0, 1);
        }
        beltBuffer.light(light).renderInto(ms, vb);
        beltFrameBuffer.light(light).renderInto(ms, vb);
    } else {
        SuperByteBuffer arrowBuffer = renderAndTransform(AllBlockPartials.MECHANICAL_CRAFTER_ARROW, blockState);
        arrowBuffer.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) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

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