Jump to content

Recommended Posts

Posted (edited)

Hi, I am trying to render the bounding box of an entity with the code below. However, the rendered bounding box seems to be leading the actual bounding box. Is there something I'm missing out?

Spoiler
@Mod.EventBusSubscriber(modid = PRYmod.MODID, value = Dist.CLIENT)
public class TestRenderer {

    static double previousX;
    static double previousY;
    static double previousZ;

    @SubscribeEvent
    public static void onWorldRenderLast( RenderLevelStageEvent event ){
        if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_TRANSLUCENT_BLOCKS || PRYBlockEntity.target == null) {
            return;
        }

        Entity target = PRYBlockEntity.target;

        RenderSystem.disableDepthTest();
        PoseStack stack = event.getPoseStack();

        AABB aabb = target.getBoundingBox().move(-target.getX(), -target.getY(), -target.getZ());

        RenderSystem.depthMask(true);
        VertexConsumer vertexConsumer = Minecraft.getInstance().renderBuffers().bufferSource().getBuffer(RenderType.lines());

        double px = Mth.lerp(event.getPartialTick(), previousX, target.getX());
        double py = Mth.lerp(event.getPartialTick(), previousY, target.getY());
        double pz = Mth.lerp(event.getPartialTick(), previousZ, target.getZ());

        previousX = target.getX();
        previousY = target.getY();
        previousZ = target.getZ();

        Vec3 camvec = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
        double s0 = camvec.x;
        double s1 = camvec.y;
        double s2 = camvec.z;

        stack.pushPose();
        stack.translate(px-s0, py-s1, pz-s2);
        LevelRenderer.renderLineBox(stack, vertexConsumer, aabb, 255, 1, 1, 100);
        stack.popPose();
        RenderSystem.enableDepthTest();
    }
}

 

https://imgur.com/gallery/KLQvwPy

Edited by PRYtheSheep

I bang my head against the keyboard every time I code

Posted

The amount of offset seems to depend on the velocity of the entity, giving myself speed 99, the offset is greater when I'm running compared to crouching. Anyone have any ideas

I bang my head against the keyboard every time I code

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.