Jump to content

(Solved) [1.8.9] TESR Animation is smooth but speed changes depending on FPS


mr_crayfish

Recommended Posts

Hello,

 

I'm currently working on a flip animation for a grill block I am creating. The problem I am facing is that the animaton speed varies depending on the FPS. I have read that multiplying your values by partialTicks will solve this issue but this doesn't seem to be the case. I'm wonder if you guys what I am doing wrong, and how it can be fixed? Thanks

 

GrillRenderer

package com.mrcrayfish.furniture.render.tileentity;

import com.mrcrayfish.furniture.blocks.BlockGrill;
import com.mrcrayfish.furniture.tileentity.TileEntityGrill;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;

public class GrillRenderer extends TileEntitySpecialRenderer 
{
private ItemStack coal = new ItemStack(Items.coal, 1, 1);
private EntityItem entityItem = new EntityItem(Minecraft.getMinecraft().theWorld, 0D, 0D, 0D, coal);

private final float MAX_ANIM_TIME = 100F;
private final float FLIP_HEIGHT = 0.5F;

@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTicks, int destroyStage) 
{
	entityItem.hoverStart = 0;

	if(!(te.getBlockType() instanceof BlockGrill))
		return;

	BlockGrill grill = (BlockGrill) te.getBlockType();
	TileEntityGrill tileEntityGrill = (TileEntityGrill) te;

	int rotation = grill.getMetaFromState(te.getWorld().getBlockState(te.getPos()));

	GlStateManager.pushMatrix();
	{
		GlStateManager.translate(x, y, z);
		GlStateManager.translate(0.5, 0.85, 0.5);
		GlStateManager.rotate(rotation * -90F, 0, 1, 0);
		GlStateManager.translate(0.18, 0, -0.35);
		GlStateManager.rotate(90F, 1, 0, 0);
		for(int i = 0; i < tileEntityGrill.getCoal(); i++)
		{
			GlStateManager.pushMatrix();
			{
				GlStateManager.rotate(15F, 0, 1, 0);
				entityItem.setEntityItemStack(coal);
				Minecraft.getMinecraft().getRenderManager().renderEntityWithPosYaw(entityItem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);
			}
			GlStateManager.popMatrix();
			GlStateManager.translate(-0.2, 0, 0);
		}
	}
	GlStateManager.popMatrix();

	GlStateManager.pushMatrix();
	{
		GlStateManager.translate(x, y, z);
		GlStateManager.translate(0.5, 1, 0.5);
		GlStateManager.rotate(rotation * -90F, 0, 1, 0);
		GlStateManager.translate(0.2, 0, -0.32);
		GlStateManager.rotate(90F, 1, 0, 0);

		/* Left */
		if(tileEntityGrill.getItem(0) != null)
		{
			GlStateManager.pushMatrix();
			{
				if(tileEntityGrill.flippedLeft)
				{
					if(tileEntityGrill.leftFlippingCount < MAX_ANIM_TIME / 2)
					{
						tileEntityGrill.leftCurrentHeight += (FLIP_HEIGHT / (MAX_ANIM_TIME / 2)) * partialTicks;
					}
					else if(tileEntityGrill.leftCurrentHeight > 0F)
					{
						tileEntityGrill.leftCurrentHeight -= (FLIP_HEIGHT / (MAX_ANIM_TIME / 2)) * partialTicks;
					}

					if(tileEntityGrill.leftCurrentHeight >= 0F)
					{
						GlStateManager.translate(0, 0, -Math.sqrt(tileEntityGrill.leftCurrentHeight));
					}
					else
					{
						tileEntityGrill.leftCurrentHeight = 0F;
					}
				}

				GlStateManager.rotate((tileEntityGrill.leftFlippingCount / MAX_ANIM_TIME * 180F), 0, 1, 0);

				entityItem.setEntityItemStack(tileEntityGrill.getItem(0));
				Minecraft.getMinecraft().getRenderManager().renderEntityWithPosYaw(entityItem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);

				if(tileEntityGrill.flippedLeft && tileEntityGrill.leftFlippingCount < MAX_ANIM_TIME)
				{
					tileEntityGrill.leftFlippingCount += partialTicks;
				}
			}
			GlStateManager.popMatrix();
		}
		else
		{
			tileEntityGrill.leftFlippingCount = 0F;
		}

		GlStateManager.translate(-0.4, 0, 0);

		/* Right */
		if(tileEntityGrill.getItem(1) != null)
		{
			GlStateManager.pushMatrix();
			{
				if(tileEntityGrill.flippedRight)
				{
					if(tileEntityGrill.rightFlippingCount < MAX_ANIM_TIME / 2)
					{
						tileEntityGrill.rightCurrentHeight += (FLIP_HEIGHT / (MAX_ANIM_TIME / 2)) * partialTicks;
					}
					else if(tileEntityGrill.rightCurrentHeight > 0F)
					{
						tileEntityGrill.rightCurrentHeight -= (FLIP_HEIGHT / (MAX_ANIM_TIME / 2)) * partialTicks;
					}

					if(tileEntityGrill.rightCurrentHeight >= 0F)
					{
						GlStateManager.translate(0, 0, -Math.sqrt(tileEntityGrill.rightCurrentHeight));
					}
					else
					{
						tileEntityGrill.rightCurrentHeight = 0F;
					}
				}

				//System.out.println("Right Flip Count:" + tileEntityGrill.rightFlippingCount);
				//System.out.println("Right Current Height:" + tileEntityGrill.rightCurrentHeight);

				GlStateManager.rotate(tileEntityGrill.rightFlippingCount / MAX_ANIM_TIME * 180F, 0, 1, 0);

				entityItem.setEntityItemStack(tileEntityGrill.getItem(1));
				Minecraft.getMinecraft().getRenderManager().renderEntityWithPosYaw(entityItem, 0.0D, 0.0D, 0.0D, 0.0F, 0.0F);

				if(tileEntityGrill.flippedRight && tileEntityGrill.rightFlippingCount < MAX_ANIM_TIME)
				{
					tileEntityGrill.rightFlippingCount += partialTicks;
				}
			}
			GlStateManager.popMatrix();
		}
		else
		{
			tileEntityGrill.rightFlippingCount = 0F;
		}
	}
	GlStateManager.popMatrix();
}
}

  • Like 1
Link to comment
Share on other sites

Partial ticks is what happens when you take "1.73489 ticks elapsed" (13ms left until next tick) and express it as "1 tick" (plus a little bit).

 

So you add, not multiply.

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.

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.