Jump to content

[1.12] Render what entity sees on screen

Spaceboy Ross

Recommended Posts

You would need to create a framebuffer, set it up correctly, bind a render texture to it, bind it as the active framebuffer and pretty much mimic the entire rendering of the game but with the Minecraft.renderViewEntity being the entity of your choice.

Then you would retrieve your texture, bind it and render a quad with it.

This is theoretical, I have never done anything like that and don't even know if this is possible. Look at minecraft's shaders, they might offer an insight at the issue.

Edit: If you simply want to change what the player sees on the screen(read: not add another texture on to of player's view) then you simply need to change Minecraft.renderViewEntity to the entity you wish to view the world from. However this was raised in an another topic and I believe the author of that topic had some frustrum culling issues with this approach.

Edited by V0idWa1k3r
Link to comment
Share on other sites

Yeah, pretty sure you'd have to do everything that the RenderGlobal class does but you'd set the camera and related frustum to be at the other entity position and in the direction it is looking. You could pretty much copy the code but that might not actually be easy because there is probably a lot of private stuff and concurrent modification issues you'd have to work through.


I know some people have implemented mirrors that use a similar idea in mods so maybe there is some tutorial or open source code that can give you ideas.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

6 minutes ago, jabelar said:

You could pretty much copy the code but that might not actually be easy because there is probably a lot of private stuff and concurrent modification issues you'd have to work through.

I actually don't think it's too challenging. As long as you change the renderViewEntity you can just do the same the game does when it renders everything. And it doesn't do much - it just calls a couple of public methods here and there.

I also don't think CMEs are going to be a thing. CME happens when a collection is modified while it is iterated. That shouldn't happen when the game simply renders the scene twice.

Link to comment
Share on other sites

A snippet of what? Setting the renderViewEntity? Creating a framebuffer? Rendering everything all over again?

Setting the renderViewEntity:


Creating a framebuffer(somewhat of a pseudo-code as I don't know if Minecraft allows using framebuffers directly like that(it might bind it's own framebuffer somewhere else) but I think for your purpose something like this should suffice - so don't use this code directly, it is meant to be an example)

int rbo = GL30.glGenRenderbuffers(); // Should be a field
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, rbo);
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_DEPTH24_STENCIL8, texWidth, texHeight);
int fbo = GL30.glGenFramebuffers(); // Should be a field
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, fbo);
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, tex, 0);


But I think the minecraft-way of doing framebuffers is in the net.minecraft.client.shader.Framebuffer class. However I have never used it and as such you need to figure it out yourself but I would imagine it's not too hard. Seems like it largely does the same my example code does but instead uses OpenGlHelper which is the correct way of doing it I suppose since it accounts for extensions.

Rendering everything:

Minecraft mc = Minecraft.getMinecraft();
mc.entityRenderer.updateCameraAndRender(mc.getRenderPartialTicks(), System.nanoTime());

Note that you will have to handle the case of the game being paused and supplying renderPartialTicksPaused from the game's timer to the updateCameraAndRender method and for that you will need refiection.


But you still haven't told us whether you even need all this framebuffer stuff. Do you just want to render the game from a different perspective or do you actually want to render a quad on the screen that shows what another entity is seeing?

Edited by V0idWa1k3r
Link to comment
Share on other sites

17 minutes ago, Spaceboy Ross said:

see what the entity sees on the screen.

This statement is ambiguous. Do you mean see as in see through the eyes of the entity(read: see the game from a different perspective) or see as in see a picture of the entity's vision on your HUD? If it's the former then you do not need the framebuffers, you simply need to change the renderViewEntity although I've heard that it is not quite that simple and causes frustrum culling issues.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now


  • Create New...

Important Information

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