Jump to content

[1.7.10] RenderPlayerPre Event - How to smooth out model jitter


Thornack

Recommended Posts

Hi everyone,

 

I have a mod where the player can morph into entities that he "owns". He can call upon them whenever and all that. i do have an issue however in multiplayer. The models seem to "jitter" when a second player logs in and sees the morphed player (his new model shows up) but it jitters which is odd. I was wondering if there is any way to smooth out this jitter.

 

here is my event

 

@SubscribeEvent
public void onRenderPlayerPre(RenderPlayerEvent.Pre pre) {

	BattlePlayerProperties bpp = BattlePlayerProperties.get(pre.entityPlayer); // Client Side Player
	if (bpp == null) {
		return;
	}

	if(bpp.isMorphed()) {
		pre.setCanceled(true); // this stops the player from rendering
		EntityPlayer thePlayer = Minecraft.getMinecraft().thePlayer;
		float modelYOffset;
		if(pre.entityPlayer.equals(thePlayer)){
		modelYOffset = -1.625F;
		} else{
		modelYOffset = 0F;
		}
		int modelId = bpp.getModelId();	//default is -1 which is steve model
		double x = pre.entityPlayer.posX - thePlayer.posX;
		double y = pre.entityPlayer.posY - thePlayer.posY;
		double z = pre.entityPlayer.posZ - thePlayer.posZ;


		Render renderPlayerModel = PlayerRenderingRegistry.getRendererByModelId(modelId);
		renderPlayerMode.doRender(pre.entityPlayer, x, y + modelYOffset, z, 0F, 0.0625F);
	}
}

 

it seems the issue has to do with the x, y, and z x coordinates that I calculate so that the new model renders in the correct spot for the player. Any ideas how to fix the jitter? it only seems to happen when the second player sees the morphed player and this second player moves around  while the morphed player is stationary. I think it may also be happening when the morphed player moves around but it isn't as noticeable I don't think.

Link to comment
Share on other sites

I solved it, this is the math and yes its sucky

//Actual entity position equation is actualPos = lastTickPos + (currentTicPos - lastTickPos) * partialTicks - Thanks to diesieben07 for this
//But you have to calculate the lastTicPos and currentTicPos based on the past/present positions of the two players to put the model in the right spot

double x = (pre.entityPlayer.prevPosX - thePlayer.prevPosX) + ((pre.entityPlayer.posX - thePlayer.posX) - (pre.entityPlayer.prevPosX - thePlayer.prevPosX))*pre.partialRenderTick;
double y = (pre.entityPlayer.prevPosY - thePlayer.prevPosY) + ((pre.entityPlayer.posY - thePlayer.posY) - (pre.entityPlayer.prevPosY - thePlayer.prevPosY))*pre.partialRenderTick;
double z = (pre.entityPlayer.prevPosZ - thePlayer.prevPosZ) + ((pre.entityPlayer.posZ - thePlayer.posZ) - (pre.entityPlayer.prevPosZ - thePlayer.prevPosZ))*pre.partialRenderTick;

Link to comment
Share on other sites

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.