Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Need help with Partial Ticks and redering
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 0
gummby8

Need help with Partial Ticks and redering

By gummby8, May 21, 2016 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

gummby8    26

gummby8

gummby8    26

  • Diamond Finder
  • gummby8
  • Members
  • 26
  • 479 posts
Posted May 21, 2016

mixing math and partial ticks has been a weakness of mine. I understand what the variable is and how it works.

 

But math logic is not my strongest feature

 

Here is my model render method

 

    @Override
    public void render(Entity entity, float yaw, float partialTick, float f2, float f3, float f4, float f5) { 
    	EntityMoldormAlpha worm = (EntityMoldormAlpha) entity;
    	this.Part1.rotateAngleY = (float)Math.toRadians(yaw);
    	
    	this.Part2.rotationPointX = (float) (worm.moldormPart2.posX - worm.moldormPart1.posX) * 25;
    	this.Part2.rotationPointZ = (float) (worm.moldormPart2.posZ - worm.moldormPart1.posZ) * -25;
    	
    	this.Part3.rotationPointX = (float) (worm.moldormPart3.posX - worm.moldormPart1.posX) * 25;
    	this.Part3.rotationPointZ = (float) (worm.moldormPart3.posZ - worm.moldormPart1.posZ) * -25;

    	this.Part4.rotationPointX = (float) (worm.moldormPart4.posX - worm.moldormPart1.posX) * 22;
    	this.Part4.rotationPointZ = (float) (worm.moldormPart4.posZ - worm.moldormPart1.posZ) * -22;

    	this.Part5.rotationPointX = (float) (worm.moldormPart5.posX - worm.moldormPart1.posX) * 22;
    	this.Part5.rotationPointZ = (float) (worm.moldormPart5.posZ - worm.moldormPart1.posZ) * -22;
    	
    	this.Part1.render(f5);
    	this.Part2.render(f5);
        this.Part3.render(f5);
        this.Part4.render(f5);
        this.Part5.render(f5);
        
    }

 

I have made a lot of progress into getting multi part mobs to work for me. The parts of the model need to follow the hitboxes of the multi part mob, and they do now. The problem is that the hitboxes move per tick so 20 FPS and the FPS of a PC is probably going to be higher.

 

so the mob looks like this. The trailing tail parts jitter quite a bit

 

I know the answer is partial ticks, I just can't figure how to add partial ticks into the X and Z rotation point calculations

 

I have tried the following but the model part is still very jittery

 

    @Override
    public void render(Entity entity, float yaw, float partialTick, float f2, float f3, float f4, float f5) { 
    	EntityMoldormAlpha worm = (EntityMoldormAlpha) entity;
    	this.Part1.rotateAngleY = (float)Math.toRadians(yaw);
    	
    	this.Part2.rotationPointX = (float) (worm.moldormPart2.posX - worm.moldormPart1.posX) * 25;
    	this.Part2.rotationPointZ = (float) (worm.moldormPart2.posZ - worm.moldormPart1.posZ) * -25;
    	
    	this.Part3.rotationPointX = (float) (worm.moldormPart3.posX - worm.moldormPart1.posX) * 25;
    	this.Part3.rotationPointZ = (float) (worm.moldormPart3.posZ - worm.moldormPart1.posZ) * -25;

    	this.Part4.rotationPointX = (float) (worm.moldormPart4.posX - worm.moldormPart1.posX) * 22;
    	this.Part4.rotationPointZ = (float) (worm.moldormPart4.posZ - worm.moldormPart1.posZ) * -22;

    	float preX = (float) (worm.moldormPart5.prevPosX - worm.moldormPart1.prevPosX);
    	float preZ = (float) (worm.moldormPart5.prevPosZ - worm.moldormPart1.prevPosZ);
    	
    	float curX = (float) (worm.moldormPart5.posX - worm.moldormPart1.posX);
    	float curZ = (float) (worm.moldormPart5.posZ - worm.moldormPart1.posZ);
    	
    	this.Part5.rotationPointX = curX + ((curX - preX) * partialTick);
    	this.Part5.rotationPointZ = curZ + ((curZ - preZ) * partialTick);
    	
    	this.Part5.rotationPointX *= 22;
    	this.Part5.rotationPointZ *= -22;
    	
    	//this.Part5.rotationPointX = (float) (worm.moldormPart5.posX - worm.moldormPart1.posX) * 22;
    	//this.Part5.rotationPointZ = (float) (worm.moldormPart5.posZ - worm.moldormPart1.posZ) * -22;
    	
    	this.Part1.render(f5);
    	this.Part2.render(f5);
        this.Part3.render(f5);
        this.Part4.render(f5);
        this.Part5.render(f5);
        
    }

 

For anyone wondering I render the hitboxes with the following in the mob renderer

 

 

package com.Splosions.ModularBosses.client.render.entity;

import java.util.logging.Level;

import org.lwjgl.opengl.GL11;

import com.Splosions.ModularBosses.client.models.entity.ModelMoldormAlpha;
import com.Splosions.ModularBosses.client.models.entity.ModelTeleportBiped;
import com.Splosions.ModularBosses.entity.EntityMoldormAlpha;
import com.Splosions.ModularBosses.entity.EntityParagon;
import com.Splosions.ModularBosses.entity.EntityTeleportBiped;

import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderEntity;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.EntityDragonPart;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Vec3;

public class RenderMoldormAlpha extends Render {

protected ModelBase model;

    public RenderMoldormAlpha(RenderManager renderManager, ModelBase model, float shadowSize) {
	super(renderManager);
	this.model = new ModelMoldormAlpha();
    }

    
    @Override
public void doRender(Entity entity, double x, double y, double z, float yaw, float partialTicks) {
    	EntityMoldormAlpha ent = (EntityMoldormAlpha) entity;

    	GL11.glPushMatrix();
	bindTexture(getEntityTexture(ent));
	GL11.glTranslated(x, y + 1, z);
	GL11.glScalef(1, 1, 1);
	GL11.glRotatef(180, 1, 0, 0);
	model.render(ent, yaw, partialTicks, 0.0F, 0.0F, 0.0F, 0.0475F);
	GL11.glPopMatrix();

	if (ent.debugHitboxes) {
		renderDebugBoundingBox(ent.moldormPart1, x, y, z, yaw, partialTicks, ent.moldormPart1.posX - ent.posX, ent.moldormPart1.posY - ent.posY, ent.moldormPart1.posZ - ent.posZ);
		renderDebugBoundingBox(ent.moldormPart2, x, y, z, yaw, partialTicks, ent.moldormPart2.posX - ent.posX, ent.moldormPart2.posY - ent.posY, ent.moldormPart2.posZ - ent.posZ);
		renderDebugBoundingBox(ent.moldormPart3, x, y, z, yaw, partialTicks, ent.moldormPart3.posX - ent.posX, ent.moldormPart3.posY - ent.posY, ent.moldormPart3.posZ - ent.posZ);
		renderDebugBoundingBox(ent.moldormPart4, x, y, z, yaw, partialTicks, ent.moldormPart4.posX - ent.posX, ent.moldormPart4.posY - ent.posY, ent.moldormPart4.posZ - ent.posZ);
		renderDebugBoundingBox(ent.moldormPart5, x, y, z, yaw, partialTicks, ent.moldormPart5.posX - ent.posX, ent.moldormPart5.posY - ent.posY, ent.moldormPart5.posZ - ent.posZ);
	}
}
    
    
    
private void renderDebugBoundingBox(EntityDragonPart part, double x, double y, double z, float yaw, float partialTicks, double xOff, double yOff, double zOff) {

	GlStateManager.depthMask(false);
	GlStateManager.disableTexture2D();
	GlStateManager.disableLighting();
	GlStateManager.disableCull();
	GlStateManager.disableBlend();
	float f2 = part.width / 2.0F;
	AxisAlignedBB axisalignedbb = part.getEntityBoundingBox();
	AxisAlignedBB axisalignedbb1 = new AxisAlignedBB(axisalignedbb.minX - part.posX + x + xOff, axisalignedbb.minY - part.posY + y + yOff, axisalignedbb.minZ - part.posZ + z + zOff, axisalignedbb.maxX - part.posX + x + xOff, axisalignedbb.maxY - part.posY + y + yOff, axisalignedbb.maxZ - part.posZ + z + zOff);
	RenderGlobal.drawOutlinedBoundingBox(axisalignedbb1, 0);
	Tessellator tessellator = Tessellator.getInstance();
	WorldRenderer worldrenderer = tessellator.getWorldRenderer();
	Vec3 vec3 = part.getLook(partialTicks);
	worldrenderer.startDrawing(3);
	worldrenderer.setColorOpaque_I(255);
	tessellator.draw();
	GlStateManager.enableTexture2D();
	GlStateManager.enableLighting();
	GlStateManager.enableCull();
	GlStateManager.disableBlend();
	GlStateManager.depthMask(true);
}

    
@Override
protected ResourceLocation getEntityTexture(Entity entity) {
	return new ResourceLocation("mb:textures/mobs/Moldorm.png");
}

}

 

 

 

Any help is appreciated.

 

Thank you

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45596 posts
Posted May 21, 2016

Instead of using pos{XYZ} directly, calculate the interpolated position for each like so:

actual{XYZ} = prev{XYZ} + ({XYZ} - prev{XYZ}) * partialTicks

.

Then use

actual{XYZ}

in place of where you used {XYZ} before.

  • Quote

Share this post


Link to post
Share on other sites

gummby8    26

gummby8

gummby8    26

  • Diamond Finder
  • gummby8
  • Members
  • 26
  • 479 posts
Posted May 21, 2016

Instead of using pos{XYZ} directly, calculate the interpolated position for each like so:

actual{XYZ} = prev{XYZ} + ({XYZ} - prev{XYZ}) * partialTicks

.

Then use

actual{XYZ}

in place of where you used {XYZ} before.

 

Not sure I understand what you mean......actually positive I don't understand because I wrote this, and it definitely does not work :)

 

    	float actualX = (float) (worm.moldormPart5.posX - worm.moldormPart5.prevPosX) * partialTick;
    	this.Part5.rotationPointX = (float) (actualX - worm.moldormPart5.prevPosX) * partialTick;
    	
    	float actualZ = (float) (worm.moldormPart5.posZ - worm.moldormPart5.prevPosZ) * partialTick;
    	this.Part5.rotationPointZ = (float) (actualZ - worm.moldormPart5.prevPosZ) * partialTick;
    	
    	this.Part5.rotationPointX *= 22;
    	this.Part5.rotationPointZ *= -22;

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45596 posts
Posted May 21, 2016

That's not using the formula I posted.

Put the calculation for actual{XYZ} at the top of your method. Do NOT use partial ticks, posX or prevPosX anywhere else except in that calculation.

  • Quote

Share this post


Link to post
Share on other sites

gummby8    26

gummby8

gummby8    26

  • Diamond Finder
  • gummby8
  • Members
  • 26
  • 479 posts
Posted May 21, 2016

That's not using the formula I posted.

Put the calculation for actual{XYZ} at the top of your method. Do NOT use partial ticks, posX or prevPosX anywhere else except in that calculation.

 

I am getting confused because I am not sure which of your variables correlate to the variable names I am using

 

the position of part5 needs to have part1's position subtracted from it otherwise part5 appears a mile away

    	//actual{XYZ} = prev{XYZ} + ({XYZ} - prev{XYZ}) * partialTicks.
    	float p1actualX =  (float) ((worm.moldormPart1.prevPosX + (worm.moldormPart1.posX - worm.moldormPart1.prevPosX) * partialTick));
    	float p1actualZ =  (float) ((worm.moldormPart1.prevPosZ + (worm.moldormPart1.posZ - worm.moldormPart1.prevPosZ) * partialTick));
    	
    	float p5actualX =  (float) ((worm.moldormPart5.prevPosX + (worm.moldormPart5.posX - worm.moldormPart5.prevPosX) * partialTick));
    	float p5actualZ =  (float) ((worm.moldormPart5.prevPosZ + (worm.moldormPart5.posZ - worm.moldormPart5.prevPosZ) * partialTick));
    	
    	this.Part5.rotationPointX = p5actualX - p1actualX;
    	this.Part5.rotationPointZ = p5actualZ - p1actualZ;
    	
    	this.Part5.rotationPointX *= 22;
    	this.Part5.rotationPointZ *= -22;

 

this still has part5 vibrating very bad

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6671

diesieben07

diesieben07    6671

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6671
  • 45596 posts
Posted May 21, 2016

Not sure then...

  • Quote

Share this post


Link to post
Share on other sites

gummby8    26

gummby8

gummby8    26

  • Diamond Finder
  • gummby8
  • Members
  • 26
  • 479 posts
Posted May 22, 2016

Perhaps it is something in the entity when it sets the hitbox locations.

 

Do you see anything wrong here?

 

public void onLivingUpdate() {
	super.onLivingUpdate();

	if (this.ticksExisted % this.ranTicks== (20 - 1) && !this.worldObj.isRemote){
	this.ranTicks = getRandomNumberInRange(20, 40);
	this.ranPosX = getRandomNumberInRange(-20, 20);
	this.ranPosZ = getRandomNumberInRange(-20, 20);
	}

	if (this.isCollidedHorizontally && !this.worldObj.isRemote && this.flip == 0){
		this.ranPosX *= -1;
		this.ranPosZ *= -1;
		this.flip = 10;
	} 

	if (!this.worldObj.isRemote){
		this.flip -=(this.flip <= 0)? 0 : 1;
	}

	this.moveHelper.setMoveTo(this.posX + ranPosX, this.posY, this.posZ + ranPosZ, 0.70D);
	setHitBoxes();

}



private void setHitBoxes() {
	if(this.ticksExisted == 1){
		this.moldormPart2.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0);
		this.moldormPart3.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0);
		this.moldormPart4.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0);
		this.moldormPart5.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0);
	}


	this.moldormPart1.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0);
        	movePiecePos(this.moldormPart2, this.moldormPart1, 6, 1);
    	        movePiecePos(this.moldormPart3, this.moldormPart2, 6, 1);
        	movePiecePos(this.moldormPart4, this.moldormPart3, 7, 1);
        	movePiecePos(this.moldormPart5, this.moldormPart4, 7, 1);

}

    
    
public static void movePiecePos(EntityDragonPart targetPart, EntityDragonPart destinationPart, float speed, float yawSpeed){
	targetPart.posX += ((destinationPart.posX - targetPart.posX) / speed);
	targetPart.posY += ((destinationPart.posY - targetPart.posY) / speed);
	targetPart.posZ += ((destinationPart.posZ - targetPart.posZ) / speed);
	targetPart.rotationYaw += ((destinationPart.rotationYaw - targetPart.rotationYaw) / yawSpeed);

	targetPart.setLocationAndAngles(targetPart.posX, targetPart.posY, targetPart.posZ, targetPart.rotationYaw, 0);



}

 

 

 

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • plugsmustard
      on/off button for custom furnace

      By plugsmustard · Posted 24 minutes ago

    • anothertime
      1.14 - hot swap fails in IDEA

      By anothertime · Posted 24 minutes ago

      I usually rebuild the module with build\build module but I've also tried run\reload changes after looking for a solution on the web but the result is the same
    • DaemonUmbra
      1.14 - hot swap fails in IDEA

      By DaemonUmbra · Posted 26 minutes ago

      Are you running the build manually with a gradle task or are you clicking run -> reload changed classes?
    • Draco18s
      on/off button for custom furnace

      By Draco18s · Posted 27 minutes ago

      You linked to a specific commit, so when I looked at it, it was the old commit where it wasn't changed. As far as I can tell, it should work. Can you post a screenshot of the error?   As for what you put here, you put the code that does whatever you want the button to do.
    • anothertime
      1.14 - hot swap fails in IDEA

      By anothertime · Posted 29 minutes ago

      Changes to the body of an existing method
  • Topics

    • plugsmustard
      55
      on/off button for custom furnace

      By plugsmustard
      Started Wednesday at 03:11 PM

    • anothertime
      4
      1.14 - hot swap fails in IDEA

      By anothertime
      Started 9 hours ago

    • matt1999rd
      4
      [1.14-newer] how to keep value when closing minecraft

      By matt1999rd
      Started 2 hours ago

    • matt1999rd
      15
      [1.14-newer] deprecated method onBlockActivated

      By matt1999rd
      Started November 1

    • JetCobblestone
      9
      [1.14] moving item assignment to a separate function

      By JetCobblestone
      Started 3 hours ago

  • Who's Online (See full list)

    • RoboShark1019
    • Yanny7
    • anothertime
    • loordgek
    • plugsmustard
    • oitsjustjose
    • Nuparu00
    • sobrinth
    • Gnaux
    • DaemonUmbra
    • FaxeeK
    • Cerandior
    • LTNightshade
    • matt1999rd
    • kuririn
    • diesieben07
    • Lea9ue
    • Ommina
    • Simon_kungen
    • CactusCoffee
    • Iterator
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Need help with Partial Ticks and redering
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community