Mob Animation Problems

Started by LofiDemon on

Topic category: Help with Minecraft modding (Java Edition)

Joined May 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Mob Animation Problems

Before I begin I'd like to say I'm using v1.8.2 of MCreator!

So I've decided to begin working on creating custom mobs for my mod! Fun right? It actually, for the most part at least, is! I'm just having one issue, and it's with setting up the basic animation.

So when I first imported the .java model into my workspace, it asked me to set up the basic arm/head/leg movement! I did that and when I finally had my mob loaded into the game, I noticed a weird issue. Basically the arm "joints" (Where the arms were waving from, was at the bottom of the arm, at the paws, causing the shoulders to basically flail around as the creature moved around. I thought it may be because I used 3 different cubes to create the arm, but I also had the same issue with the legs (And they only had the single part to them). They were moving from the feet rather than from the "waist" area. I'd show a screenshot, but it's incredibly hard to get them in motion.

Here's My Mob's Code, the .java model was made with Blockbench! Arm2 is the left arm, and Arm1 is the right arm. Same format follows legs. I'm clueless as to why this issue is happening, so any explanations would be great. My one guess is that I have to manually change the 24 in the ".setrotationpoint" as shown in the snippet below, but I have no idea what I'd have to change it to for it to work properly!

package mod.mcreator;

import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.client.registry.RenderingRegistry;

import net.minecraft.world.biome.Biome;
import net.minecraft.world.World;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Item;
import net.minecraft.init.Items;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.EnumCreatureAttribute;
import net.minecraft.entity.Entity;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.model.ModelBox;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.Minecraft;

import java.util.Random;

public class mcreator_mobGemBeast extends thecrystallia.ModElement {

	public static int mobid = 1;
	public static int mobid2 = 2;

	@Override
	public void preInit(FMLPreInitializationEvent event) {
		EntityRegistry.registerModEntity(new ResourceLocation("thecrystallia:mobgembeast"), EntitymobGemBeast.class, "mobgembeast", mobid, instance,
				64, 1, true, -10092442, -16711681);
		Biome[] spawnBiomes = {mcreator_biomeObsidianForest.biome, mcreator_biomeCrystalliGrove.biome, mcreator_biomeEventideOrchard.biome,
				mcreator_biomeMidnightWoods.biome, mcreator_biomeLuminousAcres.biome, mcreator_biomeUmbralForest.biome,
				mcreator_biomeAuroraMeadows.biome, mcreator_biomeObsidianForest.biome,};
		EntityRegistry.addSpawn(EntitymobGemBeast.class, 5, 1, 3, EnumCreatureType.CREATURE, spawnBiomes);
	}

	@Override
	public void registerRenderers() {
		RenderLiving customRender = new RenderLiving(Minecraft.getMinecraft().getRenderManager(), new Modelmobgembeast(), 0) {

			protected ResourceLocation getEntityTexture(Entity par1Entity) {
				return new ResourceLocation("mobgembeast.png");
			}
		};
		RenderingRegistry.registerEntityRenderingHandler(EntitymobGemBeast.class, customRender);
	}

	public static class EntitymobGemBeast extends EntityWolf {

		public EntitymobGemBeast(World world) {
			super(world);
			setSize(0.6f, 1.8f);
			experienceValue = 5;
			this.isImmuneToFire = false;
			setNoAI(!true);
			this.tasks.addTask(1, new EntityAIWander(this, 1));
			this.tasks.addTask(2, new EntityAILookIdle(this));
			this.tasks.addTask(3, new EntityAISwimming(this));
			this.tasks.addTask(4, new EntityAILeapAtTarget(this, (float) 0.8));
			this.targetTasks.addTask(5, new EntityAIHurtByTarget(this, false));
		}

		@Override
		public EnumCreatureAttribute getCreatureAttribute() {
			return EnumCreatureAttribute.UNDEFINED;
		}

		@Override
		protected Item getDropItem() {
			return new ItemStack(mcreator_gemCrystalli.block, (int) (1)).getItem();
		}

		@Override
		public net.minecraft.util.SoundEvent getAmbientSound() {
			return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.rabbit.ambient"));
		}

		@Override
		public net.minecraft.util.SoundEvent getHurtSound(DamageSource ds) {
			return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.wolf.hurt"));
		}

		@Override
		public net.minecraft.util.SoundEvent getDeathSound() {
			return (net.minecraft.util.SoundEvent) net.minecraft.util.SoundEvent.REGISTRY.getObject(new ResourceLocation("entity.wolf.death"));
		}

		@Override
		protected float getSoundVolume() {
			return 1.0F;
		}

		protected void dropRareDrop(int par1) {
			this.dropItem(new ItemStack(Items.DIAMOND, (int) (1)).getItem(), 1);
		}

		public void onLivingUpdate() {
			super.onLivingUpdate();
			int i = (int) this.posX;
			int j = (int) this.posY;
			int k = (int) this.posZ;
			Random random = this.rand;
			if (true)
				for (int l = 0; l < 2; ++l) {
					double d0 = (double) ((float) i + random.nextFloat());
					double d1 = (double) ((float) j + random.nextFloat());
					double d2 = (double) ((float) k + random.nextFloat());
					int i1 = random.nextInt(2) * 2 - 1;
					double d3 = ((double) random.nextFloat() - 0.5D) * 0.5D;
					double d4 = ((double) random.nextFloat() - 0.5D) * 0.5D;
					double d5 = ((double) random.nextFloat() - 0.5D) * 0.5D;
					world.spawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, d0, d1, d2, d3, d4, d5);
				}
		}
	}

	// Made with Blockbench
	// Paste this code into your mod.
	public static class Modelmobgembeast extends ModelBase {

		private final ModelRenderer Head;
		private final ModelRenderer Ear2;
		private final ModelRenderer Ear1;
		private final ModelRenderer Body;
		private final ModelRenderer Arm2;
		private final ModelRenderer Arm1;
		private final ModelRenderer Leg1;
		private final ModelRenderer Leg2;

		public Modelmobgembeast() {
			textureWidth = 60;
			textureHeight = 41;
			Head = new ModelRenderer(this);
			Head.setRotationPoint(0.0F, 24.0F, 0.0F);
			Head.cubeList.add(new ModelBox(Head, 0, 0, -4.0F, -22.0F, -4.0F, 8, 8, 8, 0.0F, false));
			Head.cubeList.add(new ModelBox(Head, 32, 0, -2.0F, -17.0F, -5.0F, 4, 3, 1, 0.0F, false));
			Ear2 = new ModelRenderer(this);
			Ear2.setRotationPoint(0.0F, 0.0F, 0.0F);
			setRotationAngle(Ear2, 0.0F, -0.1745F, -0.3491F);
			Head.addChild(Ear2);
			Ear2.cubeList.add(new ModelBox(Ear2, 32, 9, -5.3473F, -21.2412F, 0.2376F, 9, 5, 0, 0.0F, true));
			Ear1 = new ModelRenderer(this);
			Ear1.setRotationPoint(0.0F, 0.0F, 0.0F);
			setRotationAngle(Ear1, 0.0F, 0.1745F, 0.3491F);
			Head.addChild(Ear1);
			Ear1.cubeList.add(new ModelBox(Ear1, 32, 4, -3.6527F, -21.2412F, 0.2376F, 9, 5, 0, 0.0F, false));
			Body = new ModelRenderer(this);
			Body.setRotationPoint(0.0F, 24.0F, 0.0F);
			Body.cubeList.add(new ModelBox(Body, 0, 29, -3.0F, -14.0F, -2.0F, 6, 8, 4, 0.0F, false));
			Body.cubeList.add(new ModelBox(Body, 42, 0, -1.0F, -9.0F, 2.0F, 2, 2, 1, 0.0F, false));
			Arm2 = new ModelRenderer(this);
			Arm2.setRotationPoint(0.0F, 24.0F, 0.0F);
			Arm2.cubeList.add(new ModelBox(Arm2, 0, 16, 3.0F, -14.0F, -1.0F, 2, 4, 2, 0.0F, true));
			Arm2.cubeList.add(new ModelBox(Arm2, 0, 22, 3.0F, -10.0F, -2.0F, 2, 3, 4, 0.0F, true));
			Arm2.cubeList.add(new ModelBox(Arm2, 12, 16, 3.0F, -7.0F, -3.0F, 3, 6, 6, 0.0F, true));
			Arm1 = new ModelRenderer(this);
			Arm1.setRotationPoint(0.0F, 24.0F, 0.0F);
			Arm1.cubeList.add(new ModelBox(Arm1, 0, 16, -5.0F, -14.0F, -1.0F, 2, 4, 2, 0.0F, false));
			Arm1.cubeList.add(new ModelBox(Arm1, 0, 22, -5.0F, -10.0F, -2.0F, 2, 3, 4, 0.0F, false));
			Arm1.cubeList.add(new ModelBox(Arm1, 12, 16, -6.0F, -7.0F, -3.0F, 3, 6, 6, 0.0F, false));
			Leg1 = new ModelRenderer(this);
			Leg1.setRotationPoint(0.0F, 24.0F, 0.0F);
			Leg1.cubeList.add(new ModelBox(Leg1, 50, 0, -3.0F, -6.0F, -1.0F, 3, 6, 2, 0.0F, true));
			Leg2 = new ModelRenderer(this);
			Leg2.setRotationPoint(0.0F, 24.0F, 0.0F);
			Leg2.cubeList.add(new ModelBox(Leg2, 50, 8, 0.0F, -6.0F, -1.0F, 3, 6, 2, 0.0F, true));
		}

		@Override
		public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
			Head.render(f5);
			Body.render(f5);
			Arm2.render(f5);
			Arm1.render(f5);
			Leg1.render(f5);
			Leg2.render(f5);
		}

		public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
			modelRenderer.rotateAngleX = x;
			modelRenderer.rotateAngleY = y;
			modelRenderer.rotateAngleZ = z;
		}

		public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity e) {
			super.setRotationAngles(f, f1, f2, f3, f4, f5, e);
			this.Head.rotateAngleY = f3 / (180F / (float) Math.PI);
			this.Head.rotateAngleX = f4 / (180F / (float) Math.PI);
			this.Leg2.rotateAngleX = MathHelper.cos(f * 1.0F) * -1.0F * f1;
			this.Leg1.rotateAngleX = MathHelper.cos(f * 1.0F) * 1.0F * f1;
			this.Arm1.rotateAngleX = MathHelper.cos(f * 0.6662F + (float) Math.PI) * 2.0F * f1 * 0.5F;
			this.Arm2.rotateAngleX = MathHelper.cos(f * 0.6662F) * 2.0F * f1 * 0.5F;
		}
	}
}

Thank ya for the help! I'm hoping this isn't a bug with this version of MCreator so that I can get some crazy cool mobs working right into my mod asap!

You need to set the proper…
Sun, 03/17/2019 - 12:00

You need to set the proper rotation points in the modeler. MCreator just imports the code from the modeler so any model related bugs are in fact issues with the modeler and not MCreator.

Joined May 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Would you happen to know how…
Sun, 03/17/2019 - 20:40

Would you happen to know how to set rotation points in Blockbench? Totally fine if not, but thank you for letting me know <333

Joined Feb 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
When you set up the…
Wed, 03/20/2019 - 02:21

When you set up the animation wizard for your mob, make sure that the element doesn't have an offset or a rotation because it won't import them in and won't accept them when animating... Basically, the animation ignores the fact the rotation and the offset exist and animates without them...

Joined May 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Well, the arms and legs both…
Thu, 03/21/2019 - 04:26

Well, the arms and legs both don't have any rotated parts or offsets so there should be no problems there, I am however having trouble figuring out how to set a proper pivot point with BlockBench haha, I'm sure I'll figure it out eventually but for now thanks for letting me know for future reference!

Joined Sep 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I also use Blockbench, make…
Mon, 03/25/2019 - 17:50

I also use Blockbench, make sure you set the origin of the bone to where you want it to rotate from.