Animation in legs does not work.

Published by Neoelfeo on
Status
Fixed
Issue description

 There is an option to choose what piece is a leg, head or an arm

it use to work fine, even with custom models.

it used to work fine, even with custom models.

But now it doesn't work anymore, my Mcreator version is 1.7.3 for Minecraft 1.7.10

watch the legs

watch her legs, they are totaly still.

Here is the code, please check it out.

package mod.mcreator;

import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.World;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.init.Items;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.Entity;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.model.ModelBase;

import java.util.Random;

import cpw.mods.fml.relauncher.SideOnly;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.client.registry.RenderingRegistry;

@SuppressWarnings("unchecked")
public class mcreator_aldean2 {

	public static int mobid = 0;
	public Object instance;

	public void load() {
	}

	public void generateNether(World world, Random random, int chunkX, int chunkZ) {
	}

	public void generateSurface(World world, Random random, int chunkX, int chunkZ) {
	}

	public int addFuel(ItemStack fuel) {
		return 0;
	}

	@SideOnly(Side.CLIENT)
	public void registerRenderers() {
		RenderingRegistry.registerEntityRenderingHandler(mcreator_aldean2.Entityaldean2.class,
				new RenderLiving(new mcreator_aldean2.ModelAldean(), 0) {
					protected ResourceLocation getEntityTexture(Entity par1Entity) {
						return new ResourceLocation("Aldean.png");
					}
				});

	}

	public void serverLoad(FMLServerStartingEvent event) {
	}

	public void preInit(FMLPreInitializationEvent event) {
		int entityID = EntityRegistry.findGlobalUniqueEntityId();
		mobid = entityID;
		EntityRegistry.registerGlobalEntityID(mcreator_aldean2.Entityaldean2.class, "aldean2", entityID);
		EntityRegistry.registerModEntity(mcreator_aldean2.Entityaldean2.class, "aldean2", entityID, instance, 64, 1, true);
		EntityList.entityEggs.put(Integer.valueOf(entityID), new EntityList.EntityEggInfo(entityID, (0 << 16) + (61 << 8) + 86, (56 << 16)
				+ (45 << 8) + 26));
		EntityRegistry.addSpawn(mcreator_aldean2.Entityaldean2.class, 0, 1, 1, EnumCreatureType.creature, new BiomeGenBase[]{BiomeGenBase.ocean,
				BiomeGenBase.plains, BiomeGenBase.desert, BiomeGenBase.extremeHills, BiomeGenBase.forest, BiomeGenBase.taiga, BiomeGenBase.swampland,
				BiomeGenBase.river, BiomeGenBase.frozenOcean, BiomeGenBase.frozenRiver, BiomeGenBase.icePlains, BiomeGenBase.iceMountains,
				BiomeGenBase.mushroomIsland, BiomeGenBase.mushroomIslandShore, BiomeGenBase.beach, BiomeGenBase.desertHills,
				BiomeGenBase.forestHills, BiomeGenBase.taigaHills, BiomeGenBase.extremeHillsEdge, BiomeGenBase.jungle, BiomeGenBase.jungleHills,
				BiomeGenBase.jungleEdge, BiomeGenBase.deepOcean, BiomeGenBase.stoneBeach, BiomeGenBase.coldBeach, BiomeGenBase.birchForest,
				BiomeGenBase.birchForestHills, BiomeGenBase.roofedForest, BiomeGenBase.coldTaiga, BiomeGenBase.coldTaigaHills,
				BiomeGenBase.megaTaiga, BiomeGenBase.megaTaigaHills, BiomeGenBase.extremeHillsPlus, BiomeGenBase.savanna,
				BiomeGenBase.savannaPlateau, BiomeGenBase.mesa, BiomeGenBase.mesaPlateau_F, BiomeGenBase.mesaPlateau});

	}

	/*
	 * public Entity spawnEntity(int var1, World var2, double var3, double var5,
	 * double var7) { if(var1==mobid) return new
	 * mcreator_aldean2.Entityaldean2(var2); else return null; }
	 */

	public static class Entityaldean2 extends EntityVillager {
		World world = null;

		public Entityaldean2(World var1) {
			super(var1);
			world = var1;
			experienceValue = 5;
			this.isImmuneToFire = false;
			addRandomArmor();
			this.tasks.addTask(0, new EntityAISwimming(this));
			this.tasks.addTask(6, new EntityAIWander(this, 1.0D));
			this.tasks.addTask(8, new EntityAILookIdle(this));

		}

		protected void addRandomArmor() {

		}

		protected void dropRareDrop(int par1) {
			this.dropItem(mcreator_goldCoin.block, 1);
		}

		public boolean isAIEnabled() {
			return true;
		}

		@Override
		protected Item getDropItem() {
			return new ItemStack(Items.rotten_flesh).getItem();
		}

		/**
		 * Returns the sound this mob makes while it's alive.
		 */
		protected String getLivingSound() {
			return "";
		}

		/**
		 * Returns the sound this mob makes when it is hurt.
		 */
		protected String getHurtSound() {
			return "";
		}

		/**
		 * Returns the sound this mob makes on death.
		 */
		protected String getDeathSound() {
			return "";
		}

		public void onStruckByLightning(EntityLightningBolt entityLightningBolt) {
			super.onStruckByLightning(entityLightningBolt);
			int i = (int) this.posX;
			int j = (int) this.posY;
			int k = (int) this.posZ;
			Entity entity = this;

		}

		protected void fall(float l) {
			super.fall(l);
			int i = (int) this.posX;
			int j = (int) this.posY;
			int k = (int) this.posZ;
			super.fall(l);
			Entity entity = this;

		}

		public void onDeath(DamageSource dsource) {
			super.onDeath(dsource);
			int i = (int) this.posX;
			int j = (int) this.posY;
			int k = (int) this.posZ;
			Entity entity = this;

		}

		public void onKillEntity(EntityLiving entityLiving) {
			super.onKillEntity(entityLiving);
			int i = (int) this.posX;
			int j = (int) this.posY;
			int k = (int) this.posZ;
			Entity entity = this;

		}

		public boolean interact(EntityPlayer entity) {
			super.interact(entity);
			int i = (int) this.posX;
			int j = (int) this.posY;
			int k = (int) this.posZ;

			return true;
		}

		public String getEntityName() {
			return "aldean2";
		}

	}

	// Date: 12/12/2017 3:06:07
	// Template version 1.1
	// Java generated by Techne
	// Keep in mind that you still need to fill in some blanks
	// - ZeuX

	public static class ModelAldean extends ModelBase {
		// fields
		ModelRenderer body;
		ModelRenderer arms;
		ModelRenderer rightleg;
		ModelRenderer leftleg;
		ModelRenderer body2;
		ModelRenderer headM;
          ModelRenderer head;
          ModelRenderer nose;
          ModelRenderer hair;

		public ModelAldean() {
			textureWidth = 128;
			textureHeight = 64;

			body = new ModelRenderer(this, 16, 16);
			body.addBox(-4F, 0F, -2F, 8, 6, 4);
			body.setRotationPoint(0F, 0F, 0F);
			body.setTextureSize(128, 64);
			body.mirror = true;
			setRotation(body, -0.1570796F, 0F, 0F);
			arms = new ModelRenderer(this, 40, 16);
			arms.addBox(-3F, -2F, -2F, 16, 7, 3);
			arms.setRotationPoint(-5F, 3F, -1F);
			arms.setTextureSize(128, 64);
			arms.mirror = true;
			setRotation(arms, -0.7102147F, 0F, 0F);
			rightleg = new ModelRenderer(this, 0, 16);
			rightleg.addBox(-2F, 0F, -2F, 4, 12, 4);
			rightleg.setRotationPoint(-2F, 12F, 0F);
			rightleg.setTextureSize(128, 64);
			rightleg.mirror = true;
			setRotation(rightleg, 0F, 0F, 0F);
			leftleg = new ModelRenderer(this, 0, 16);
			leftleg.addBox(-2F, 0F, -2F, 4, 12, 4);
			leftleg.setRotationPoint(2F, 12F, 0F);
			leftleg.setTextureSize(128, 64);
			leftleg.mirror = true;
			setRotation(leftleg, 0F, 0F, 0F);
			body2 = new ModelRenderer(this, 16, 27);
			body2.addBox(-4F, 6F, -3F, 8, 6, 4);
			body2.setRotationPoint(0F, 0F, -1F);
			body2.setTextureSize(128, 64);
			body2.mirror = true;
			setRotation(body2, 0.1532585F, 0F, 0F);
			headM = new ModelRenderer(this, "headM");
			headM.setRotationPoint(0F, 0F, 0F);
			setRotation(headM, 0F, 0F, 0F);
			headM.mirror = true;
			head = new ModelRenderer(this, 0, 0);
			head.addBox(-4F, -8F, -4F, 8, 8, 8);
			head.setRotationPoint(0F, 0F, 0F);
			head.setTextureSize(128, 64);
			head.mirror = true;
			setRotation(head, 0F, 0F, 0F);
			hair = new ModelRenderer(this, 0, 39);
			hair.addBox(-5F, -9F, -5F, 10, 12, 10);
			hair.setRotationPoint(0F, 0F, 0F);
			hair.setTextureSize(128, 64);
			hair.mirror = true;
			setRotation(hair, 0F, 0F, 0F);
			nose = new ModelRenderer(this, 17, 2);
			nose.addBox(-1F, 0F, 0F, 2, 2, 1);
			nose.setRotationPoint(0F, -3F, -5F);
			nose.setTextureSize(128, 64);
			nose.mirror = true;
			setRotation(nose, 0F, 0F, 0F);
			headM.addChild(head);
			headM.addChild(nose);
			headM.addChild(hair);
		}

		public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
			super.render(entity, f, f1, f2, f3, f4, f5);
			setRotationAngles(f, f1, f2, f3, f4, f5, entity);
			body.render(f5);
			arms.render(f5);
			rightleg.render(f5);
			leftleg.render(f5);
			body2.render(f5);
			headM.render(f5);
		}

		private void setRotation(ModelRenderer model, float x, float y, float z) {
			model.rotateAngleX = x;
			model.rotateAngleY = y;
			model.rotateAngleZ = z;
		}

		public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity) {
			super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
			this.headM.rotateAngleY = f3 / (180F / (float)Math.PI);
			this.headM.rotateAngleX = f4 / (180F / (float)Math.PI);
		}

	}

}

 

I also try adding this lines of code:

 

this.leftleg.rotateAngleX = MathHelper.cos(f * 1.0F) * -1.0F * f1;
this.rightleg.rotateAngleX = MathHelper.cos(f * 1.0F) * 1.0F * f1;

But this error comes up:

Hate this

Issue comments

This is rather strange. Did you put the code you provided inside the proper method?

public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity) {

Could you send me the modified method you made? I have checked myself and defining legs and arms worked for me. Are you sure you selected all the parts?

Oh, you mean the rotation points for her legs, it ended up looking like this:

 

          public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity) {
               super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
               this.headM.rotateAngleY = f3 / (180F / (float)Math.PI);
               this.headM.rotateAngleX = f4 / (180F / (float)Math.PI);
               this.leftleg.rotateAngleX = MathHelper.cos(f * 1.0F) * -1.0F * f1;
               this.rightleg.rotateAngleX = MathHelper.cos(f * 1.0F) * 1.0F * f1;
          }

     }

}

 

I'll show what I do.

just give me some time to upload it to youtube.

Oh, I see the problem. After you add the legs animation code, you need to import MathHelper class. You can do this by pressing the Fix and organise imports button in the code editor. This will import it for you. After you click this button, recompile and test again.

I will also check why MCreator doesn't automatically add leg animation parts, but using your code and by organising imports you should be able to fix this. Please report back. Thanks!

And a pro tip: Use Ctrl + Shift + M to save, build and run Minecraft from the console. It will save you a time of building the whole thing twice.

Great! I am glad it works now. I will also make sure that this bug will be fixed in a future release so there won't be a need for manual coding in order to achieve this.

I have no intentions to sound impatient, but what sort of timescale do you think until the next version of the program?

I'm useless with code, I think I'll hang tight and wait for the update - mucking around with it even following this thread left me lost. I'll stick to the other features of the program in the mean time while I continue to learn more about modding. :)

I have checked version 1.7.7 and animations work. As the next 1.7.10 update is planned as a generator option inside MCreator 2, I am closing this issue and suggest to use MCreator 1.7.7 in case this is an issue or use the provided fix found in this issue.