Jump to content

Recommended Posts

Posted

Code is a bit messy, but essentially I'm waiting for an event, then calling readyTickHandler().  It waits a specified number of ticks (renderDelay) before performing the render.  This is to allow time for the world to load.

 

However, due to the delay, I do not want to render from the player's location after the delay, but rather from their original location and orientation.

 

Here's the problem:

Even though I'm setting the temporary entity's orientation, it's being ignored when the render happens, it's treated as always 0, regardless of its actual value.  If I use the actual player as the temporary agent, then it gets rendered with the correct orientation values (that is, where the player is looking at the time).

 

What do I need to change in order for the temporary entity to make it render correctly?

 

public void readyTickHandler(World w, EntityPlayer pl) {
	world = w;
	p = new EntityRenderNode(world);
	world.spawnEntityInWorld(p);
	p.posX = pl.posX;
	p.posY = pl.posY;
	p.posZ = pl.posZ;
	p.rotationPitch = 0;
	p.rotationYaw = pl.rotationYaw;
	System.out.println("Yaw: " + pl.rotationYaw);
	renderDelay = 20*30;
}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
	if(renderDelay > 0) {
		renderDelay--;
	}
	if(renderDelay == 0) {
		renderDelay = -1;
		System.out.println("Render Yaw: " + p.rotationYaw);

		//this is the function that handles the rendering.
		int[] data = renderWorldToTexture(p, 0.01F);
		//now we save the data.
    		ByteArrayOutputStream bt = new ByteArrayOutputStream();
		DataOutputStream out = new DataOutputStream(bt);
		try
		{
			//omitted for irrelevancy.
		}
		catch (IOException ex)
		{
		}
		//remove the temporary entity
		p.attackEntityFrom(DamageSource.outOfWorld,	100);
	}
}

private final int[] renderWorldToTexture(EntityLivingBase player, float renderTime) {
        GameSettings settings = mc.gameSettings; // dont want to access these fields every time
        EntityRenderer entityRenderer = mc.entityRenderer;
        
        RenderGlobal renderGlobalBackup = mc.renderGlobal;
        EntityLivingBase viewportBackup = mc.renderViewEntity;
        int heightBackup = mc.displayHeight;
        int widthBackup = mc.displayWidth;
        int thirdPersonBackup = settings.thirdPersonView;
        boolean hideGuiBackup = settings.hideGUI;
        int particleBackup = mc.gameSettings.particleSetting;
        mc.gameSettings.particleSetting = 2;

        int width = 128;
        int height = 128;
        
        mc.renderGlobal = mc.renderGlobal;
        mc.renderViewEntity = player;
        mc.displayHeight = height;
        mc.displayWidth = width;
        
        settings.thirdPersonView = 0;
        settings.hideGUI = true;
        
        int fps = EntityRenderer.performanceToFps(mc.gameSettings.limitFramerate);
        
        if (settings.limitFramerate == 0) {
                entityRenderer.renderWorld(renderTime, 0L);
        } else {
                entityRenderer.renderWorld(renderTime, (1000000000 / fps));
        }
        
        int k = width * height;
        int[] dataarray = new int[k];
        IntBuffer databuffer = BufferUtils.createIntBuffer(k);

        GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
        databuffer.clear();
        GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, databuffer);
        databuffer.get(dataarray);
        reconfigureArray(dataarray, width, height);
        
        settings.thirdPersonView = thirdPersonBackup;
        settings.hideGUI = hideGuiBackup;
        
        mc.displayHeight = heightBackup;
        mc.displayWidth = widthBackup;
        mc.renderGlobal = renderGlobalBackup;
        mc.renderViewEntity = viewportBackup;
        mc.gameSettings.particleSetting = particleBackup;
        
        return dataarray;
    }

//I actually have no idea what purpose this function serves, but Vanilla uses it with screenshots.
private void reconfigureArray(int[] dataarray, int width, int height) {
	int[] aint1 = new int[width];
        int k = height / 2;

        for (int l = 0; l < k; ++l)
        {
            System.arraycopy(dataarray, l * width, aint1, 0, width);
            System.arraycopy(dataarray, (height - 1 - l) * width, dataarray, l * width, width);
            System.arraycopy(aint1, 0, dataarray, (height - 1 - l) * width, width);
        }
}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Hi

 

Beats me!

 

Have you tried looking in

EntityRenderer.orientCamera() to see if you can figure it out using breakpoints?

 

I also notice an interesting setting

this.mc.gameSettings.debugCamEnable

which might get you the control you need?

 

-TGG

 

 

Posted

I figured it out yesterday, pure guess.

 

The rendered YAW is based on entity.rotationYawHead.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.