Jump to content

Recommended Posts

Posted

Hey, I'm trying to execute this walking animation I created using MCAnimator ONLY when the entity is moving. But I'm having trouble achieving this

 

Model Code

package common.zeroquest.client.renderer.entity.model;

import java.util.HashMap;

import net.minecraft.client.model.ModelBase;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import common.zeroquest.client.mca.MCAModelRenderer;
import common.zeroquest.client.mca.libary.MCAVersionChecker;
import common.zeroquest.client.mca.libary.animation.AnimationHandler;
import common.zeroquest.client.mca.libary.math.Matrix4f;
import common.zeroquest.client.mca.libary.math.Quaternion;
import common.zeroquest.entity.EntityRowarn;

public class ModelRowarn extends ModelBase {
public final int MCA_MIN_REQUESTED_VERSION = 5;
public HashMap<String, MCAModelRenderer> parts = new HashMap<String, MCAModelRenderer>();

MCAModelRenderer neck1;
MCAModelRenderer torso1;
MCAModelRenderer tail1;
MCAModelRenderer leftHindLeg1;
MCAModelRenderer rightHindLeg1;
MCAModelRenderer leftFrontLeg;
MCAModelRenderer rightFrontLeg;
MCAModelRenderer neck2;
MCAModelRenderer torso2;
MCAModelRenderer tail2;
MCAModelRenderer leftHindLeg2;
MCAModelRenderer rightHindLeg2;
MCAModelRenderer leftFrontClaw1;
MCAModelRenderer leftFrontClaw2;
MCAModelRenderer rightFrontClaw1;
MCAModelRenderer rightFrontClaw2;
MCAModelRenderer topJaw;
MCAModelRenderer tail3;
MCAModelRenderer leftHindLeg3;
MCAModelRenderer rightHindLeg3;
MCAModelRenderer bottomJaw;
MCAModelRenderer tail4;
MCAModelRenderer leftHindClaw1;
MCAModelRenderer leftHindClaw2;
MCAModelRenderer rightHindClaw1;
MCAModelRenderer rightHindClaw2;
MCAModelRenderer fin1;
MCAModelRenderer fin2;

public ModelRowarn() {
	MCAVersionChecker.checkForLibraryVersion(getClass(), MCA_MIN_REQUESTED_VERSION);

	textureWidth = 256;
	textureHeight = 128;

	neck1 = new MCAModelRenderer(this, "Neck1", 21, 0);
	neck1.mirror = false;
	neck1.addBox(-2.0F, -2.0F, 1.0F, 4, 4, 6);
	neck1.setInitialRotationPoint(-0.5F, -11.0F, 9.0F);
	neck1.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(-0.16652437F, 0.0F, 0.0F, 0.9860373F)).transpose());
	neck1.setTextureSize(256, 128);
	parts.put(neck1.boxName, neck1);

	torso1 = new MCAModelRenderer(this, "Torso1", 69, 0);
	torso1.mirror = false;
	torso1.addBox(-2.5F, -2.5F, -9.0F, 5, 5, 9);
	torso1.setInitialRotationPoint(-0.5F, -10.5F, 4.0F);
	torso1.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(-0.055739015F, 0.0F, 0.0F, 0.9984454F)).transpose());
	torso1.setTextureSize(256, 128);
	parts.put(torso1.boxName, torso1);

	tail1 = new MCAModelRenderer(this, "Tail1", 99, 0);
	tail1.mirror = false;
	tail1.addBox(-2.0F, -2.0F, -10.0F, 4, 4, 10);
	tail1.setInitialRotationPoint(-0.5F, -11.5F, -4.0F);
	tail1.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(-0.055739015F, 0.0F, 0.0F, 0.9984454F)).transpose());
	tail1.setTextureSize(256, 128);
	parts.put(tail1.boxName, tail1);

	leftHindLeg1 = new MCAModelRenderer(this, "LeftHindLeg1", 11, 17);
	leftHindLeg1.mirror = false;
	leftHindLeg1.addBox(-1.0F, -5.0F, -2.0F, 2, 5, 3);
	leftHindLeg1.setInitialRotationPoint(1.5F, -11.0F, -3.0F);
	leftHindLeg1.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(-0.14816688F, 0.0F, 0.0F, 0.98896235F)).transpose());
	leftHindLeg1.setTextureSize(256, 128);
	parts.put(leftHindLeg1.boxName, leftHindLeg1);

	rightHindLeg1 = new MCAModelRenderer(this, "RightHindLeg1", 23, 17);
	rightHindLeg1.mirror = false;
	rightHindLeg1.addBox(-1.0F, -5.0F, -2.0F, 2, 5, 3);
	rightHindLeg1.setInitialRotationPoint(-2.5F, -11.0F, -3.0F);
	rightHindLeg1.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(-0.14816688F, 0.0F, 0.0F, 0.98896235F)).transpose());
	rightHindLeg1.setTextureSize(256, 128);
	parts.put(rightHindLeg1.boxName, rightHindLeg1);

	leftFrontLeg = new MCAModelRenderer(this, "LeftFrontLeg", 0, 17);
	leftFrontLeg.mirror = false;
	leftFrontLeg.addBox(-1.0F, -11.0F, -1.0F, 2, 11, 2);
	leftFrontLeg.setInitialRotationPoint(2.0F, -11.0F, 8.0F);
	leftFrontLeg.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, 0.0F, 0.0F, 1.0F)).transpose());
	leftFrontLeg.setTextureSize(256, 128);
	parts.put(leftFrontLeg.boxName, leftFrontLeg);

	rightFrontLeg = new MCAModelRenderer(this, "RightFrontLeg", 35, 17);
	rightFrontLeg.mirror = false;
	rightFrontLeg.addBox(-1.0F, -11.0F, -1.0F, 2, 11, 2);
	rightFrontLeg.setInitialRotationPoint(-3.0F, -11.0F, 8.0F);
	rightFrontLeg.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, 0.0F, 0.0F, 1.0F)).transpose());
	rightFrontLeg.setTextureSize(256, 128);
	parts.put(rightFrontLeg.boxName, rightFrontLeg);

	neck2 = new MCAModelRenderer(this, "Neck2", 0, 0);
	neck2.mirror = false;
	neck2.addBox(-2.0F, -2.0F, 1.0F, 4, 4, 6);
	neck2.setInitialRotationPoint(0.0F, -0.4F, 5.0F);
	neck2.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(-0.1478094F, 0.0F, 0.0F, 0.9890159F)).transpose());
	neck2.setTextureSize(256, 128);
	parts.put(neck2.boxName, neck2);
	neck1.addChild(neck2);

	torso2 = new MCAModelRenderer(this, "Torso2", 42, 0);
	torso2.mirror = false;
	torso2.addBox(-2.5F, -2.5F, -8.0F, 5, 5, ;
	torso2.setInitialRotationPoint(0.0F, -0.5F, 7.0F);
	torso2.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.043619387F, 0.0F, 0.0F, 0.99904823F)).transpose());
	torso2.setTextureSize(256, 128);
	parts.put(torso2.boxName, torso2);
	torso1.addChild(torso2);

	tail2 = new MCAModelRenderer(this, "Tail2", 129, 0);
	tail2.mirror = false;
	tail2.addBox(-1.5F, -1.5F, -10.0F, 3, 3, 10);
	tail2.setInitialRotationPoint(0.0F, 0.0F, -9.0F);
	tail2.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(-0.06104854F, 0.0F, 0.0F, 0.9981348F)).transpose());
	tail2.setTextureSize(256, 128);
	parts.put(tail2.boxName, tail2);
	tail1.addChild(tail2);

	leftHindLeg2 = new MCAModelRenderer(this, "LeftHindLeg2", 11, 27);
	leftHindLeg2.mirror = false;
	leftHindLeg2.addBox(-1.0F, -4.0F, -1.0F, 2, 4, 2);
	leftHindLeg2.setInitialRotationPoint(0.0F, -4.3F, 0.3F);
	leftHindLeg2.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.40673664F, 0.0F, 0.0F, 0.9135454F)).transpose());
	leftHindLeg2.setTextureSize(256, 128);
	parts.put(leftHindLeg2.boxName, leftHindLeg2);
	leftHindLeg1.addChild(leftHindLeg2);

	rightHindLeg2 = new MCAModelRenderer(this, "RightHindLeg2", 23, 27);
	rightHindLeg2.mirror = false;
	rightHindLeg2.addBox(-1.0F, -4.0F, -1.0F, 2, 4, 2);
	rightHindLeg2.setInitialRotationPoint(0.0F, -4.3F, 0.3F);
	rightHindLeg2.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.40673664F, 0.0F, 0.0F, 0.9135454F)).transpose());
	rightHindLeg2.setTextureSize(256, 128);
	parts.put(rightHindLeg2.boxName, rightHindLeg2);
	rightHindLeg1.addChild(rightHindLeg2);

	leftFrontClaw1 = new MCAModelRenderer(this, "LeftFrontClaw1", 11, 43);
	leftFrontClaw1.mirror = false;
	leftFrontClaw1.addBox(-0.5F, -1.0F, 0.0F, 1, 1, 3);
	leftFrontClaw1.setInitialRotationPoint(-0.5F, -10.0F, 0.0F);
	leftFrontClaw1.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, -0.09281317F, 0.0F, 0.99568355F)).transpose());
	leftFrontClaw1.setTextureSize(256, 128);
	parts.put(leftFrontClaw1.boxName, leftFrontClaw1);
	leftFrontLeg.addChild(leftFrontClaw1);

	leftFrontClaw2 = new MCAModelRenderer(this, "LeftFrontClaw2", 11, 43);
	leftFrontClaw2.mirror = false;
	leftFrontClaw2.addBox(-0.5F, -1.0F, 0.0F, 1, 1, 3);
	leftFrontClaw2.setInitialRotationPoint(0.5F, -10.0F, 0.0F);
	leftFrontClaw2.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, 0.09281374F, 0.0F, 0.9956835F)).transpose());
	leftFrontClaw2.setTextureSize(256, 128);
	parts.put(leftFrontClaw2.boxName, leftFrontClaw2);
	leftFrontLeg.addChild(leftFrontClaw2);

	rightFrontClaw1 = new MCAModelRenderer(this, "RightFrontClaw1", 23, 43);
	rightFrontClaw1.mirror = false;
	rightFrontClaw1.addBox(-0.5F, -1.0F, 0.0F, 1, 1, 3);
	rightFrontClaw1.setInitialRotationPoint(-0.5F, -10.0F, 0.0F);
	rightFrontClaw1.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, -0.09281317F, 0.0F, 0.99568355F)).transpose());
	rightFrontClaw1.setTextureSize(256, 128);
	parts.put(rightFrontClaw1.boxName, rightFrontClaw1);
	rightFrontLeg.addChild(rightFrontClaw1);

	rightFrontClaw2 = new MCAModelRenderer(this, "RightFrontClaw2", 23, 43);
	rightFrontClaw2.mirror = false;
	rightFrontClaw2.addBox(-0.5F, -1.0F, 0.0F, 1, 1, 3);
	rightFrontClaw2.setInitialRotationPoint(0.5F, -10.0F, 0.0F);
	rightFrontClaw2.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, 0.09281374F, 0.0F, 0.9956835F)).transpose());
	rightFrontClaw2.setTextureSize(256, 128);
	parts.put(rightFrontClaw2.boxName, rightFrontClaw2);
	rightFrontLeg.addChild(rightFrontClaw2);

	topJaw = new MCAModelRenderer(this, "TopJaw", 0, 54);
	topJaw.mirror = false;
	topJaw.addBox(-2.0F, -1.0F, 0.5F, 5, 3, ;
	topJaw.setInitialRotationPoint(-0.5F, 1.5F, 6.0F);
	topJaw.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.2923717F, 0.0F, 0.0F, 0.9563048F)).transpose());
	topJaw.setTextureSize(256, 128);
	parts.put(topJaw.boxName, topJaw);
	neck2.addChild(topJaw);

	tail3 = new MCAModelRenderer(this, "Tail3", 157, 0);
	tail3.mirror = false;
	tail3.addBox(-1.0F, -1.0F, -10.0F, 2, 2, 10);
	tail3.setInitialRotationPoint(0.0F, 0.0F, -8.0F);
	tail3.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(-0.02617695F, 0.0F, 0.0F, 0.99965733F)).transpose());
	tail3.setTextureSize(256, 128);
	parts.put(tail3.boxName, tail3);
	tail2.addChild(tail3);

	leftHindLeg3 = new MCAModelRenderer(this, "LeftHindLeg3", 11, 35);
	leftHindLeg3.mirror = false;
	leftHindLeg3.addBox(-1.0F, -4.0F, -1.0F, 2, 4, 2);
	leftHindLeg3.setInitialRotationPoint(0.0F, -3.4F, -0.2F);
	leftHindLeg3.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(-0.27563736F, 0.0F, 0.0F, 0.9612617F)).transpose());
	leftHindLeg3.setTextureSize(256, 128);
	parts.put(leftHindLeg3.boxName, leftHindLeg3);
	leftHindLeg2.addChild(leftHindLeg3);

	rightHindLeg3 = new MCAModelRenderer(this, "RightHindLeg3", 23, 35);
	rightHindLeg3.mirror = false;
	rightHindLeg3.addBox(-1.0F, -4.0F, -1.0F, 2, 4, 2);
	rightHindLeg3.setInitialRotationPoint(0.0F, -3.4F, -0.2F);
	rightHindLeg3.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(-0.27563736F, 0.0F, 0.0F, 0.9612617F)).transpose());
	rightHindLeg3.setTextureSize(256, 128);
	parts.put(rightHindLeg3.boxName, rightHindLeg3);
	rightHindLeg2.addChild(rightHindLeg3);

	bottomJaw = new MCAModelRenderer(this, "BottomJaw", 0, 68);
	bottomJaw.mirror = false;
	bottomJaw.addBox(-2.0F, -1.0F, 0.5F, 5, 2, 9);
	bottomJaw.setInitialRotationPoint(0.0F, -2.0F, 0.0F);
	bottomJaw.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, 0.0F, 0.0F, 1.0F)).transpose());
	bottomJaw.setTextureSize(256, 128);
	parts.put(bottomJaw.boxName, bottomJaw);
	topJaw.addChild(bottomJaw);

	tail4 = new MCAModelRenderer(this, "Tail4", 182, 0);
	tail4.mirror = false;
	tail4.addBox(-0.5F, -0.5F, -9.0F, 1, 1, 9);
	tail4.setInitialRotationPoint(0.0F, 0.0F, -8.0F);
	tail4.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(-0.02617695F, 0.0F, 0.0F, 0.99965733F)).transpose());
	tail4.setTextureSize(256, 128);
	parts.put(tail4.boxName, tail4);
	tail3.addChild(tail4);

	leftHindClaw1 = new MCAModelRenderer(this, "LeftHindClaw1", 11, 43);
	leftHindClaw1.mirror = false;
	leftHindClaw1.addBox(-0.5F, -1.0F, 0.0F, 1, 1, 3);
	leftHindClaw1.setInitialRotationPoint(-0.5F, -3.0F, 0.0F);
	leftHindClaw1.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, -0.09281317F, 0.0F, 0.99568355F)).transpose());
	leftHindClaw1.setTextureSize(256, 128);
	parts.put(leftHindClaw1.boxName, leftHindClaw1);
	leftHindLeg3.addChild(leftHindClaw1);

	leftHindClaw2 = new MCAModelRenderer(this, "LeftHindClaw2", 11, 43);
	leftHindClaw2.mirror = false;
	leftHindClaw2.addBox(-0.5F, -1.0F, 0.0F, 1, 1, 3);
	leftHindClaw2.setInitialRotationPoint(0.5F, -3.0F, 0.0F);
	leftHindClaw2.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, 0.09281276F, 0.0F, 0.99568355F)).transpose());
	leftHindClaw2.setTextureSize(256, 128);
	parts.put(leftHindClaw2.boxName, leftHindClaw2);
	leftHindLeg3.addChild(leftHindClaw2);

	rightHindClaw1 = new MCAModelRenderer(this, "RightHindClaw1", 23, 43);
	rightHindClaw1.mirror = false;
	rightHindClaw1.addBox(-0.5F, -1.0F, 0.0F, 1, 1, 3);
	rightHindClaw1.setInitialRotationPoint(-0.5F, -3.0F, 0.0F);
	rightHindClaw1.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, -0.09281317F, 0.0F, 0.99568355F)).transpose());
	rightHindClaw1.setTextureSize(256, 128);
	parts.put(rightHindClaw1.boxName, rightHindClaw1);
	rightHindLeg3.addChild(rightHindClaw1);

	rightHindClaw2 = new MCAModelRenderer(this, "RightHindClaw2", 23, 43);
	rightHindClaw2.mirror = false;
	rightHindClaw2.addBox(-0.5F, -1.0F, 0.0F, 1, 1, 3);
	rightHindClaw2.setInitialRotationPoint(0.5F, -3.0F, 0.0F);
	rightHindClaw2.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, 0.09281276F, 0.0F, 0.99568355F)).transpose());
	rightHindClaw2.setTextureSize(256, 128);
	parts.put(rightHindClaw2.boxName, rightHindClaw2);
	rightHindLeg3.addChild(rightHindClaw2);

	fin1 = new MCAModelRenderer(this, "Fin1", 182, 12);
	fin1.mirror = false;
	fin1.addBox(-5.0F, 0.0F, -8.0F, 5, 0, 7);
	fin1.setInitialRotationPoint(0.0F, 0.0F, -4.0F);
	fin1.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, 0.0F, 0.0F, 1.0F)).transpose());
	fin1.setTextureSize(256, 128);
	parts.put(fin1.boxName, fin1);
	tail4.addChild(fin1);

	fin2 = new MCAModelRenderer(this, "Fin2", 182, 21);
	fin2.mirror = false;
	fin2.addBox(-0.5F, 0.0F, -8.0F, 5, 0, 7);
	fin2.setInitialRotationPoint(0.0F, 0.0F, -4.0F);
	fin2.setInitialRotationMatrix(new Matrix4f().set(new Quaternion(0.0F, 0.0F, 0.0F, 1.0F)).transpose());
	fin2.setTextureSize(256, 128);
	parts.put(fin2.boxName, fin2);
	tail4.addChild(fin2);

}

@Override
public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7) {
	EntityRowarn entity = (EntityRowarn) par1Entity;

	AnimationHandler.performAnimationInModel(parts, entity);

	// Render every non-child part
	neck1.render(par7);
	torso1.render(par7);
	tail1.render(par7);
	leftHindLeg1.render(par7);
	rightHindLeg1.render(par7);
	leftFrontLeg.render(par7);
	rightFrontLeg.render(par7);
}

@Override
public void setLivingAnimations(EntityLivingBase par1EntityLivingBase, float par2, float par3, float par4) {
	EntityRowarn entityRowarn = (EntityRowarn) par1EntityLivingBase;
	if (par2 != 0 && par3 != 0) {
		entityRowarn.getAnimationHandler().activateAnimation("walking", 0);
	}
}

@Override
public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity) {}

public MCAModelRenderer getModelRendererFromName(String name) {
	return parts.get(name);
}
}

 

Entity Code

package common.zeroquest.entity;

import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import common.zeroquest.client.mca.animations.AnimationHandlerRowarn;
import common.zeroquest.client.mca.libary.IMCAnimatedEntity;
import common.zeroquest.client.mca.libary.animation.AnimationHandler;

public class EntityRowarn extends EntityAnimal implements IMCAnimatedEntity {
protected AnimationHandler animHandler = new AnimationHandlerRowarn(this);
private float field_175482_b;
private final float field_175484_c;
private float field_175483_bk;
private float field_175485_bl;
private float field_175486_bm;
private int field_175479_bo;
private boolean field_175480_bp;
private EntityAIWander wander;
private static final String __OBFID = "CL_00002213";

public EntityRowarn(World worldIn) {
	super(worldIn);
	this.experienceValue = 10;
	this.setSize(1F, 1F);
	EntityAIMoveTowardsRestriction entityaimovetowardsrestriction;
	this.tasks.addTask(5, entityaimovetowardsrestriction = new EntityAIMoveTowardsRestriction(this, 1.0D));
	this.tasks.addTask(7, this.wander = new EntityAIWander(this, 1.0D, 80));
	this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
	this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityRowarn.class, 12.0F, 0.01F));
	this.tasks.addTask(9, new EntityAILookIdle(this));
	this.wander.setMutexBits(3);
	entityaimovetowardsrestriction.setMutexBits(3);
	this.field_175484_c = this.field_175482_b = this.rand.nextFloat();
}

@Override
public AnimationHandler getAnimationHandler() {
	return animHandler;
}

@Override
protected void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D);
	this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(16.0D);
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(30.0D);
}

@Override
public EntityAgeable createChild(EntityAgeable ageable) {
	// TODO Auto-generated method stub
	return null;
}
}

 

Rowarn Animation Handler

package common.zeroquest.client.mca.animations;

import java.util.HashMap;

import common.zeroquest.client.mca.libary.IMCAnimatedEntity;
import common.zeroquest.client.mca.libary.animation.AnimationHandler;
import common.zeroquest.client.mca.libary.animation.Channel;

public class AnimationHandlerRowarn extends AnimationHandler {
/** Map with all the animations. */
public static HashMap<String, Channel> animChannels = new HashMap<String, Channel>();
static {
	animChannels.put("swimming", new ChannelSwimming("swimming", 30.0F, 40, Channel.LINEAR));
	animChannels.put("leapinto", new ChannelLeapinto("leapinto", 20.0F, 50, Channel.LINEAR));
	animChannels.put("walking", new ChannelWalking("walking", 15.0F, 20, Channel.LINEAR));
}

public AnimationHandlerRowarn(IMCAnimatedEntity entity) {
	super(entity);
}

@Override
public void activateAnimation(String name, float startingFrame) {
	super.activateAnimation(animChannels, name, startingFrame);
}

@Override
public void stopAnimation(String name) {
	super.stopAnimation(animChannels, name);
}

@Override
public void fireAnimationEventClientSide(Channel anim, float prevFrame, float frame) {}

@Override
public void fireAnimationEventServerSide(Channel anim, float prevFrame, float frame) {}
}

 

Main Animation Handler

package common.zeroquest.client.mca.libary.animation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import net.minecraft.entity.Entity;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import common.zeroquest.client.mca.MCAModelRenderer;
import common.zeroquest.client.mca.libary.IMCAnimatedEntity;
import common.zeroquest.client.mca.libary.math.Quaternion;
import common.zeroquest.client.mca.libary.math.Vector3f;

public abstract class AnimationHandler {
public static AnimTickHandler animTickHandler;
/** Owner of this handler. */
private final IMCAnimatedEntity animatedEntity;
/** List of all the activate animations of this Entity. */
public ArrayList<Channel> animCurrentChannels = new ArrayList();
/** Previous time of every active animation. */
public HashMap<String, Long> animPrevTime = new HashMap<String, Long>();
/** Current frame of every active animation. */
public HashMap<String, Float> animCurrentFrame = new HashMap<String, Float>();
/**
 * Contains the unique names of the events that have been already fired
 * during each animation. It becomes empty at the end of every animation.
 * The key is the animation name and the value is the list of already-called
 * events.
 */
private final HashMap<String, ArrayList<String>> animationEvents = new HashMap<String, ArrayList<String>>();

public AnimationHandler(IMCAnimatedEntity entity) {
	if (animTickHandler == null) {
		animTickHandler = new AnimTickHandler();
	}
	animTickHandler.addEntity(entity);

	animatedEntity = entity;
}

public IMCAnimatedEntity getEntity() {
	return animatedEntity;
}

public void activateAnimation(HashMap<String, Channel> animChannels, String name, float startingFrame) {
	if (animChannels.get(name) != null) {
		Channel selectedChannel = animChannels.get(name);
		int indexToRemove = animCurrentChannels.indexOf(selectedChannel);
		if (indexToRemove != -1) {
			animCurrentChannels.remove(indexToRemove);
		}

		animCurrentChannels.add(selectedChannel);
		animPrevTime.put(name, System.nanoTime());
		animCurrentFrame.put(name, startingFrame);
		if (animationEvents.get(name) == null) {
			animationEvents.put(name, new ArrayList<String>());
		}
	}
	else {
		System.out.println("The animation called " + name + " doesn't exist!");
	}
}

public abstract void activateAnimation(String name, float startingFrame);

public void stopAnimation(HashMap<String, Channel> animChannels, String name) {
	Channel selectedChannel = animChannels.get(name);
	if (selectedChannel != null) {
		int indexToRemove = animCurrentChannels.indexOf(selectedChannel);
		if (indexToRemove != -1) {
			animCurrentChannels.remove(indexToRemove);
			animPrevTime.remove(name);
			animCurrentFrame.remove(name);
			animationEvents.get(name).clear();
		}
	}
	else {
		System.out.println("The animation called " + name + " doesn't exist!");
	}
}

public abstract void stopAnimation(String name);

public void animationsUpdate() {
	for (Iterator<Channel> it = animCurrentChannels.iterator(); it.hasNext() {
		Channel anim = it.next();
		float prevFrame = animCurrentFrame.get(anim.name);
		boolean animStatus = updateAnimation(animatedEntity, anim, animPrevTime, animCurrentFrame);
		if (animCurrentFrame.get(anim.name) != null) {
			fireAnimationEvent(anim, prevFrame, animCurrentFrame.get(anim.name));
		}
		if (!animStatus) {
			it.remove();
			animPrevTime.remove(anim.name);
			animCurrentFrame.remove(anim.name);
			animationEvents.get(anim.name).clear();
		}
	}
}

public boolean isAnimationActive(String name) {
	boolean animAlreadyUsed = false;
	for (Channel anim : animatedEntity.getAnimationHandler().animCurrentChannels) {
		if (anim.name.equals(name)) {
			animAlreadyUsed = true;
			break;
		}
	}

	return animAlreadyUsed;
}

private void fireAnimationEvent(Channel anim, float prevFrame, float frame) {
	if (isWorldRemote(animatedEntity)) {
		fireAnimationEventClientSide(anim, prevFrame, frame);
	}
	else {
		fireAnimationEventServerSide(anim, prevFrame, frame);
	}
}

@SideOnly(Side.CLIENT)
public abstract void fireAnimationEventClientSide(Channel anim, float prevFrame, float frame);

public abstract void fireAnimationEventServerSide(Channel anim, float prevFrame, float frame);

/** Check if the animation event has already been called. */
public boolean alreadyCalledEvent(String animName, String eventName) {
	if (animationEvents.get(animName) == null) {
		System.out.println("Cannot check for event " + eventName + "! Animation " + animName + "does not exist or is not active.");
		return true;
	}
	return animationEvents.get(animName).contains(eventName);
}

/** Set the animation event as "called", so it won't be fired again. */
public void setCalledEvent(String animName, String eventName) {
	if (animationEvents.get(animName) != null) {
		animationEvents.get(animName).add(eventName);
	}
	else {
		System.out.println("Cannot set event " + eventName + "! Animation " + animName + "does not exist or is not active.");
	}
}

/** Update animation values. Return false if the animation should stop. */
public static boolean updateAnimation(IMCAnimatedEntity entity, Channel channel, HashMap<String, Long> prevTimeAnim, HashMap<String, Float> prevFrameAnim) {
	if (FMLCommonHandler.instance().getEffectiveSide().isServer() || (FMLCommonHandler.instance().getEffectiveSide().isClient() && !isGamePaused())) {
		if (!(channel.mode == Channel.CUSTOM)) {
			long prevTime = prevTimeAnim.get(channel.name);
			float prevFrame = prevFrameAnim.get(channel.name);

			long currentTime = System.nanoTime();
			double deltaTime = (currentTime - prevTime) / 1000000000.0;
			float numberOfSkippedFrames = (float) (deltaTime * channel.fps);

			float currentFrame = prevFrame + numberOfSkippedFrames;

			if (currentFrame < channel.totalFrames - 1) // -1 as the first
														// frame mustn't be
														// "executed" as it
														// is the starting
														// situation
			{
				prevTimeAnim.put(channel.name, currentTime);
				prevFrameAnim.put(channel.name, currentFrame);
				return true;
			}
			else {
				if (channel.mode == Channel.LOOP) {
					prevTimeAnim.put(channel.name, currentTime);
					prevFrameAnim.put(channel.name, 0F);
					return true;
				}
				return false;
			}
		}
		else {
			return true;
		}
	}
	else {
		long currentTime = System.nanoTime();
		prevTimeAnim.put(channel.name, currentTime);
		return true;
	}
}

@SideOnly(Side.CLIENT)
private static boolean isGamePaused() {
	net.minecraft.client.Minecraft MC = net.minecraft.client.Minecraft.getMinecraft();
	return MC.isSingleplayer() && MC.currentScreen != null && MC.currentScreen.doesGuiPauseGame() && !MC.getIntegratedServer().getPublic();
}

/**
 * Apply animations if running or apply initial values. Must be called only
 * by the model class.
 */
@SideOnly(Side.CLIENT)
public static void performAnimationInModel(HashMap<String, MCAModelRenderer> parts, IMCAnimatedEntity entity) {
	for (Map.Entry<String, MCAModelRenderer> entry : parts.entrySet()) {
		String boxName = entry.getKey();
		MCAModelRenderer box = entry.getValue();

		boolean anyRotationApplied = false;
		boolean anyTranslationApplied = false;
		boolean anyCustomAnimationRunning = false;

		for (Channel channel : entity.getAnimationHandler().animCurrentChannels) {
			if (channel.mode != Channel.CUSTOM) {
				float currentFrame = entity.getAnimationHandler().animCurrentFrame.get(channel.name);

				// Rotations
				KeyFrame prevRotationKeyFrame = channel.getPreviousRotationKeyFrameForBox(boxName, entity.getAnimationHandler().animCurrentFrame.get(channel.name));
				int prevRotationKeyFramePosition = prevRotationKeyFrame != null
						? channel.getKeyFramePosition(prevRotationKeyFrame) : 0;

				KeyFrame nextRotationKeyFrame = channel.getNextRotationKeyFrameForBox(boxName, entity.getAnimationHandler().animCurrentFrame.get(channel.name));
				int nextRotationKeyFramePosition = nextRotationKeyFrame != null
						? channel.getKeyFramePosition(nextRotationKeyFrame) : 0;

				float SLERPProgress = (currentFrame - prevRotationKeyFramePosition) / (nextRotationKeyFramePosition - prevRotationKeyFramePosition);
				if (SLERPProgress > 1F || SLERPProgress < 0F) {
					SLERPProgress = 1F;
				}

				if (prevRotationKeyFramePosition == 0 && prevRotationKeyFrame == null && !(nextRotationKeyFramePosition == 0)) {
					Quaternion currentQuat = new Quaternion();
					currentQuat.slerp(parts.get(boxName).getDefaultRotationAsQuaternion(), nextRotationKeyFrame.modelRenderersRotations.get(boxName), SLERPProgress);
					box.getRotationMatrix().set(currentQuat).transpose();

					anyRotationApplied = true;
				}
				else if (prevRotationKeyFramePosition == 0 && prevRotationKeyFrame != null && !(nextRotationKeyFramePosition == 0)) {
					Quaternion currentQuat = new Quaternion();
					currentQuat.slerp(prevRotationKeyFrame.modelRenderersRotations.get(boxName), nextRotationKeyFrame.modelRenderersRotations.get(boxName), SLERPProgress);
					box.getRotationMatrix().set(currentQuat).transpose();

					anyRotationApplied = true;
				}
				else if (!(prevRotationKeyFramePosition == 0) && !(nextRotationKeyFramePosition == 0)) {
					Quaternion currentQuat = new Quaternion();
					currentQuat.slerp(prevRotationKeyFrame.modelRenderersRotations.get(boxName), nextRotationKeyFrame.modelRenderersRotations.get(boxName), SLERPProgress);
					box.getRotationMatrix().set(currentQuat).transpose();

					anyRotationApplied = true;
				}

				// Translations
				KeyFrame prevTranslationKeyFrame = channel.getPreviousTranslationKeyFrameForBox(boxName, entity.getAnimationHandler().animCurrentFrame.get(channel.name));
				int prevTranslationsKeyFramePosition = prevTranslationKeyFrame != null
						? channel.getKeyFramePosition(prevTranslationKeyFrame) : 0;

				KeyFrame nextTranslationKeyFrame = channel.getNextTranslationKeyFrameForBox(boxName, entity.getAnimationHandler().animCurrentFrame.get(channel.name));
				int nextTranslationsKeyFramePosition = nextTranslationKeyFrame != null
						? channel.getKeyFramePosition(nextTranslationKeyFrame) : 0;

				float LERPProgress = (currentFrame - prevTranslationsKeyFramePosition) / (nextTranslationsKeyFramePosition - prevTranslationsKeyFramePosition);
				if (LERPProgress > 1F) {
					LERPProgress = 1F;
				}

				if (prevTranslationsKeyFramePosition == 0 && prevTranslationKeyFrame == null && !(nextTranslationsKeyFramePosition == 0)) {
					Vector3f startPosition = parts.get(boxName).getPositionAsVector();
					Vector3f endPosition = nextTranslationKeyFrame.modelRenderersTranslations.get(boxName);
					Vector3f currentPosition = new Vector3f(startPosition);
					currentPosition.interpolate(endPosition, LERPProgress);
					box.setRotationPoint(currentPosition.x, currentPosition.y, currentPosition.z);

					anyTranslationApplied = true;
				}
				else if (prevTranslationsKeyFramePosition == 0 && prevTranslationKeyFrame != null && !(nextTranslationsKeyFramePosition == 0)) {
					Vector3f startPosition = prevTranslationKeyFrame.modelRenderersTranslations.get(boxName);
					Vector3f endPosition = nextTranslationKeyFrame.modelRenderersTranslations.get(boxName);
					Vector3f currentPosition = new Vector3f(startPosition);
					currentPosition.interpolate(endPosition, LERPProgress);
					box.setRotationPoint(currentPosition.x, currentPosition.y, currentPosition.z);
				}
				else if (!(prevTranslationsKeyFramePosition == 0) && !(nextTranslationsKeyFramePosition == 0)) {
					Vector3f startPosition = prevTranslationKeyFrame.modelRenderersTranslations.get(boxName);
					Vector3f endPosition = nextTranslationKeyFrame.modelRenderersTranslations.get(boxName);
					Vector3f currentPosition = new Vector3f(startPosition);
					currentPosition.interpolate(endPosition, LERPProgress);
					box.setRotationPoint(currentPosition.x, currentPosition.y, currentPosition.z);

					anyTranslationApplied = true;
				}
			}
			else {
				anyCustomAnimationRunning = true;

				((CustomChannel) channel).update(parts, entity);
			}
		}

		// Set the initial values for each box if necessary
		if (!anyRotationApplied && !anyCustomAnimationRunning) {
			box.resetRotationMatrix();
		}
		if (!anyTranslationApplied && !anyCustomAnimationRunning) {
			box.resetRotationPoint();
		}
	}
}

public static boolean isWorldRemote(IMCAnimatedEntity animatedEntity) {
	return ((Entity) animatedEntity).worldObj.isRemote;
}
}

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

I had massive, massive problems with MCAnimator and animations.  And not just in the "animate when" situation, but in a "does bad bad things and will crash the game" kind of way.  I was never able to fix it and instead rebuilt things using a standard quadruped.

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

Some people swear by it, but as I wanted to have an animation only play when my mob was walking, I did what looked like the only way to play and stop animations, which caused Concurrent Modification Exceptions.  Which no one was able to help me figure out.

 

So.

 

Yeah.  Don't use MCAnimator.  Good news, the model it creates is very easy to turn into a ModelBase.  You need to refactor some function names and work out the euler rotations from the quaternions (but as you created the model using eulers...) but it's pretty much a 1:1 port.

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

Well, I wanted to use the model from MCAnimator to have animations when my entity jumps and lands and swims in water, thats why I used MCAnimator. Since I can't use it, is there any alternative?

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

Quick and easy? Not that I know of.

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

Yeah, I'd given it a shot after I'd seen a lot of praise on these forums, but it turns out no one uses it for animation.  Surprise, surprise.

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

They custom built their animator. 

public class DragonAnimator { ... }

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

Haven't the faintest. :D

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

Hey,

 

I was strugling too with most programs like MCAnimator etc.. I don't know blender, you should try it to see if its working or not.

But the Link that helped me out (for Entities at least) is this:

 

http://jabelarminecraft.blogspot.nl/p/complex-entity-models-including.html

 

He explains some neat tips and tricks on how to create your own animatons.

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Posted

From what I hear It's better to code models and animations yourself, but I've been struggling with entity animation as well as soon as I tried to do it. :/

Posted

Yeah, it's pretty useful and easier to use for visualization, but should I at all, use it? Even just to use it to get the numbers to model them using the method jabelar recommends us using for animation?

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

It's useful for visualization, but I find modeling in techne to be a pain sometimes. Don't you?

 

Edit: Lol, I forgot we were talking about MCAnimator. It is a little easier and is useful for visualizing of animation, but still a pain to model in in my opinion. ;)

Posted

I know right? I never did figure that addChild stuff out...

Posted

Here, I used this tutorial to master the addChild methods: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571589-modding-animation-guide

 

I also did trial and error and finally got them correct.. but still need help with advanced animations

Main Developer and Owner of Zero Quest

Visit the Wiki for more information

If I helped anyone, please give me a applaud and a thank you!

Posted

I do recommend it indeed, because it supports childmodelParts. But keep in mind that it aint perfect.

I experianced an slight offset in the dimensions. but it shouldnt be disturbing if you don't need a model to be moving punctual at the single degree.

(I only discoveres it cause I wanted a model to move exactualy across certain lines)

 

If you need an example, I made an animated tileEntity in my mechanicalCraftingTable mod.(Link below) Feel free to take a look at it.

 

Keep in mind though, my mod and the tutorial is for mc 1.7.10!

So you probably need to dig into the .jons files etc. But apart from that, it should look similar.

Anyway good luck, and please share the results! Im curious.

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Posted

Here, I used this tutorial to master the addChild methods: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571589-modding-animation-guide

 

I also did trial and error and finally got them correct.. but still need help with advanced animations

 

Cool. I think next time I work with entities I'll try to do it in Java. I tried to work with animation in Java but I couldn't figure out how to convert from degrees to radians. This tutorial helps though, http://jabelarminecraft.blogspot.ca/p/introduction-first-of-all-to-understand.html. In fact, I didn't even know they were called radians before today, all I knew was somehow I needed to convert degrees to the stupid huge decimal number format thingy. :D

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.