Jump to content

Custom Rideable Entity Parts not Rotating


ctwagon

Recommended Posts

So I have a custom entity and almost everything is fine with it. It can be ridden and moved, but when it does, the parts don't rotate. Everything rotates fine when it is not being ridden. Here is the code for the mob.

 

EntityElephant.java

package com.ctwagon.testmod.entity.mobs;

import net.minecraft.block.Block;
import net.minecraft.block.BlockGrass;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IEntityLivingData;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

import com.ctwagon.testmod.items.ModItems;

public class EntityElephant extends EntityAnimal {
public boolean moveTrunk;

public EntityElephant(World par1World) {
	super(par1World);
	this.setSize(3.0F, 2.8F);
        this.getNavigator().setAvoidsWater(true);
	this.tasks.addTask(0, new EntityAISwimming(this));
        this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 1.0D, true));
	this.tasks.addTask(2, new EntityAIWander(this, 0.7D));
	this.tasks.addTask(3, new EntityAILookIdle(this));
        this.tasks.addTask(4, new EntityAIMate(this, 1.0D));
        this.targetTasks.addTask(0, new EntityAIHurtByTarget(this, true));
}

/**
     * Returns true if the newer Entity AI code should be run
     */
public boolean isAIEnabled() {
	return true;
}

protected void entityInit()
    {
        super.entityInit();
        this.dataWatcher.addObject(16, Byte.valueOf((byte)0));
    }

/**
     * (abstract) Protected helper method to write subclass entity data to NBT.
     */
    public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeEntityToNBT(par1NBTTagCompound);
        par1NBTTagCompound.setBoolean("Saddle", this.getSaddled());
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readEntityFromNBT(par1NBTTagCompound);
        this.setSaddled(par1NBTTagCompound.getBoolean("Saddle"));
    }
    
    public void setSaddled(boolean par1) {
    	if (par1)
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)1));
        }
        else
        {
            this.dataWatcher.updateObject(16, Byte.valueOf((byte)0));
        }
    }
    
    public boolean getSaddled() {
    	return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0;
    }

protected void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(40.0D);
	this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.3D);
}

/**
     * Called when the mob is falling. Calculates and applies fall damage.
     */
    protected void fall(float par1) {}
    
    protected Item getDropItem()
    {
        return ModItems.tusk;
    }

/**
     * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param
     * par2 - Level of Looting used to kill this mob.
     */
    protected void dropFewItems(boolean par1, int par2)
    {
    	int j = this.rand.nextInt(4) + this.rand.nextInt(1 + par2);
        int k;

        for (k = 0; k < j; ++k)
        {
            this.dropItem(Items.leather, 1);
        }
        
        int l = this.rand.nextInt(2);
        int m;
        
        for (m=0; m <= l; ++m) {
        	this.dropItem(ModItems.tusk, 1);
        }
        
    }
    
    public boolean interact(EntityPlayer par1EntityPlayer) {
    	ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem();
    	
    	if (itemstack != null && !this.getSaddled() && itemstack.getItem() == ModItems.largeSaddle) {
    		par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack)null);
    		this.setSaddled(true);
    		return true;
    	}
    	else if (this.getSaddled() && this.riddenByEntity == null) {
    		par1EntityPlayer.mountEntity(this);
            return true;
    	}
    	else {
    		return false;
    	}
    }
    
    /**
     * Moves the entity based on the specified heading.  Args: strafe, forward
     */
    public void moveEntityWithHeading(float par1, float par2) {
    	if (this.riddenByEntity != null && this.getSaddled())
        {
    		this.prevRotationYaw = this.rotationYaw = this.riddenByEntity.rotationYaw;
    		this.rotationPitch = this.riddenByEntity.rotationPitch * 0.5F;
    		this.setRotation(this.rotationYaw, this.rotationPitch);
            this.rotationYawHead = this.renderYawOffset = this.rotationYaw;
            par1 = ((EntityLivingBase)this.riddenByEntity).moveStrafing * 0.5F;
            par2 = ((EntityLivingBase)this.riddenByEntity).moveForward;
            this.stepHeight = 1.0F;
            
            if (!this.worldObj.isRemote)
            {
                this.setAIMoveSpeed((float)this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue() * 0.5F);
                super.moveEntityWithHeading(par1, par2);
            }
        }
        else
        {
            this.stepHeight = 0.5F;
            this.jumpMovementFactor = 0.02F;
            super.moveEntityWithHeading(par1, par2);
        }
    }

public boolean isBreedingItem(ItemStack par1ItemStack)
    {
    	return par1ItemStack != null && par1ItemStack.getItem() == Item.getItemFromBlock(Blocks.tallgrass);
    }

public boolean attackEntityAsMob(Entity par1Entity)
    {
        return par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), 6.0F);
    }

public EntityElephant createChild(EntityAgeable par1EntityAgeable) {
	return new EntityElephant(this.worldObj);
}

}

 

ModelElephant.java

package com.ctwagon.testmod.model;

import com.ctwagon.testmod.entity.mobs.EntityElephant;
import com.ctwagon.testmod.entity.mobs.EntityLion;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.util.MathHelper;

public class ModelElephant extends ModelBase
{
  //fields
    ModelRenderer Body1;
    ModelRenderer Body2;
    ModelRenderer Body3;
    ModelRenderer Body4;
    ModelRenderer Body5;
    ModelRenderer Saddle;
    ModelRenderer Leg1;
    ModelRenderer Leg2;
    ModelRenderer Leg3;
    ModelRenderer Leg4;
    ModelRenderer Head;
    ModelRenderer Ear1;
    ModelRenderer Ear2;
    ModelRenderer Trunk1;
    ModelRenderer Trunk2;
    ModelRenderer Trunk3;
    ModelRenderer Trunk4;
    ModelRenderer Tail;
    ModelRenderer Tusk1_1;
    ModelRenderer Tusk1_2;
    ModelRenderer Tusk1_3;
    ModelRenderer Tusk2_1;
    ModelRenderer Tusk2_2;
    ModelRenderer Tusk2_3;
  
  public ModelElephant()
  {
    textureWidth = 512;
    textureHeight = 256;
    
      Body1 = new ModelRenderer(this, 0, 17);
      Body1.addBox(-12F, -12F, -24F, 24, 20, 48);
      Body1.setRotationPoint(0F, -2F, 0F);
      Body1.setTextureSize(512, 256);
      Body1.mirror = true;
      setRotation(Body1, 0F, 0F, 0F);
      Body2 = new ModelRenderer(this, 0, 85);
      Body2.addBox(-11F, -13F, -23F, 22, 1, 46);
      Body2.setRotationPoint(0F, -2F, 0F);
      Body2.setTextureSize(512, 256);
      Body2.mirror = true;
      setRotation(Body2, 0F, 0F, 0F);
      Body3 = new ModelRenderer(this, 0, 132);
      Body3.addBox(-10F, -14F, -22F, 20, 1, 44);
      Body3.setRotationPoint(0F, -2F, 0F);
      Body3.setTextureSize(512, 256);
      Body3.mirror = true;
      setRotation(Body3, 0F, 0F, 0F);
      Body4 = new ModelRenderer(this, 0, 177);
      Body4.addBox(-8F, -15F, -20F, 16, 1, 40);
      Body4.setRotationPoint(0F, -2F, 0F);
      Body4.setTextureSize(512, 256);
      Body4.mirror = true;
      setRotation(Body4, 0F, 0F, 0F);
      Body5 = new ModelRenderer(this, 0, 218);
      Body5.addBox(-6F, -16F, -18F, 12, 1, 36);
      Body5.setRotationPoint(0F, -2F, 0F);
      Body5.setTextureSize(512, 256);
      Body5.mirror = true;
      setRotation(Body5, 0F, 0F, 0F);
      Saddle = new ModelRenderer(this, 176, 0);
      Saddle.addBox(-6F, -18F, -10F, 12, 3, 20);
      Saddle.setRotationPoint(0F, -2F, 0F);
      Saddle.setTextureSize(512, 256);
      Saddle.mirror = true;
      setRotation(Saddle, 0F, 0F, 0F);
      Leg1 = new ModelRenderer(this, 144, 17);
      Leg1.addBox(-3F, 0F, -3F, 6, 18, 6);
      Leg1.setRotationPoint(8F, 6F, -20F);
      Leg1.setTextureSize(512, 256);
      Leg1.mirror = true;
      setRotation(Leg1, 0F, 0F, 0F);
      Leg2 = new ModelRenderer(this, 144, 17);
      Leg2.addBox(-3F, 0F, -3F, 6, 18, 6);
      Leg2.setRotationPoint(-8F, 6F, -20F);
      Leg2.setTextureSize(512, 256);
      Leg2.mirror = true;
      setRotation(Leg2, 0F, 0F, 0F);
      Leg3 = new ModelRenderer(this, 144, 17);
      Leg3.addBox(-3F, 0F, -3F, 6, 18, 6);
      Leg3.setRotationPoint(8F, 6F, 20F);
      Leg3.setTextureSize(512, 256);
      Leg3.mirror = true;
      setRotation(Leg3, 0F, 0F, 0F);
      Leg4 = new ModelRenderer(this, 144, 17);
      Leg4.addBox(-3F, 0F, -3F, 6, 18, 6);
      Leg4.setRotationPoint(-8F, 6F, 20F);
      Leg4.setTextureSize(512, 256);
      Leg4.mirror = true;
      setRotation(Leg4, 0F, 0F, 0F);
      Head = new ModelRenderer(this, 0, 0);
      Head.addBox(-5F, -4F, -9F, 10, 8, 9);
      Head.setRotationPoint(0F, -6F, -24F);
      Head.setTextureSize(512, 256);
      Head.mirror = true;
      setRotation(Head, 0F, 0F, 0F);
      Ear1 = new ModelRenderer(this, 38, 0);
      Ear1.addBox(0F, -5F, 0F, 7, 13, 1);
      Ear1.setRotationPoint(5F, -6F, -27F);
      Ear1.setTextureSize(512, 256);
      Ear1.mirror = true;
      setRotation(Ear1, 0F, 0F, 0F);
      Ear2 = new ModelRenderer(this, 38, 0);
      Ear2.addBox(-7F, -5F, 0F, 7, 13, 1);
      Ear2.setRotationPoint(-5F, -6F, -27F);
      Ear2.setTextureSize(512, 256);
      Ear2.mirror = true;
      setRotation(Ear2, 0F, 0F, 0F);
      Trunk1 = new ModelRenderer(this, 54, 0);
      Trunk1.addBox(-2F, -1F, -2F, 4, 6, 4);
      Trunk1.setRotationPoint(0F, -3F, -35F);
      Trunk1.setTextureSize(512, 256);
      Trunk1.mirror = true;
      setRotation(Trunk1, 0F, 0F, 0F);
      Trunk2 = new ModelRenderer(this, 54, 0);
      Trunk2.addBox(-2F, 2F, -2F, 4, 6, 4);
      Trunk2.setRotationPoint(0F, -1F, -35F);
      Trunk2.setTextureSize(512, 256);
      Trunk2.mirror = true;
      setRotation(Trunk2, 0F, 0F, 0F);
      Trunk3 = new ModelRenderer(this, 54, 0);
      Trunk3.addBox(-2F, 4F, -2F, 4, 6, 4);
      Trunk3.setRotationPoint(0F, 2F, -35F);
      Trunk3.setTextureSize(512, 256);
      Trunk3.mirror = true;
      setRotation(Trunk3, 0F, 0F, 0F);
      Trunk4 = new ModelRenderer(this, 54, 0);
      Trunk4.addBox(-2F, 6F, -2F, 4, 6, 4);
      Trunk4.setRotationPoint(0F, 5F, -35F);
      Trunk4.setTextureSize(512, 256);
      Trunk4.mirror = true;
      setRotation(Trunk4, 0F, 0F, 0F);
      Tail = new ModelRenderer(this, 168, 17);
      Tail.addBox(-1F, 0F, 0F, 2, 10, 2);
      Tail.setRotationPoint(0F, -12F, 24F);
      Tail.setTextureSize(512, 256);
      Tail.mirror = true;
      setRotation(Tail, 0F, 0F, 0F);
      Tusk1_1 = new ModelRenderer(this, 70, 0);
      Tusk1_1.addBox(5F, 3F, -11F, 2, 2, 4);
      Tusk1_1.setRotationPoint(0F, -6F, -24F);
      Tusk1_1.setTextureSize(512, 256);
      Tusk1_1.mirror = true;
      setRotation(Tusk1_1, 0F, 0F, 0F);
      Tusk1_2 = new ModelRenderer(this, 82, 0);
      Tusk1_2.addBox(5F, 4F, -16F, 2, 2, 5);
      Tusk1_2.setRotationPoint(0F, -6F, -24F);
      Tusk1_2.setTextureSize(512, 256);
      Tusk1_2.mirror = true;
      setRotation(Tusk1_2, 0F, 0F, 0F);
      Tusk1_3 = new ModelRenderer(this, 96, 0);
      Tusk1_3.addBox(4F, 3F, -18F, 2, 2, 2);
      Tusk1_3.setRotationPoint(0F, -6F, -24F);
      Tusk1_3.setTextureSize(512, 256);
      Tusk1_3.mirror = true;
      setRotation(Tusk1_3, 0F, 0F, 0F);
      Tusk2_1 = new ModelRenderer(this, 70, 0);
      Tusk2_1.addBox(-7F, 3F, -11F, 2, 2, 4);
      Tusk2_1.setRotationPoint(0F, -6F, -24F);
      Tusk2_1.setTextureSize(512, 256);
      Tusk2_1.mirror = true;
      setRotation(Tusk2_1, 0F, 0F, 0F);
      Tusk2_2 = new ModelRenderer(this, 82, 0);
      Tusk2_2.addBox(-7F, 4F, -16F, 2, 2, 5);
      Tusk2_2.setRotationPoint(0F, -6F, -24F);
      Tusk2_2.setTextureSize(512, 256);
      Tusk2_2.mirror = true;
      setRotation(Tusk2_2, 0F, 0F, 0F);
      Tusk2_3 = new ModelRenderer(this, 96, 0);
      Tusk2_3.addBox(-6F, 3F, -18F, 2, 2, 2);
      Tusk2_3.setRotationPoint(0F, -6F, -24F);
      Tusk2_3.setTextureSize(512, 256);
      Tusk2_3.mirror = true;
      setRotation(Tusk2_3, 0F, 0F, 0F);
  }
  
  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);
    
    EntityElephant entityelephant = (EntityElephant)entity;
    
    setRotationAngles(f, f1, f2, f3, f4, f5, entity);
    Body1.render(f5);
    Body2.render(f5);
    Body3.render(f5);
    Body4.render(f5);
    Body5.render(f5);
    Leg1.render(f5);
    Leg2.render(f5);
    Leg3.render(f5);
    Leg4.render(f5);
    Head.render(f5);
    Ear1.render(f5);
    Ear2.render(f5);
    Trunk1.render(f5);
    Trunk2.render(f5);
    Trunk3.render(f5);
    Trunk4.render(f5);
    Tail.render(f5);
    Tusk1_1.render(f5);
    Tusk1_2.render(f5);
    Tusk1_3.render(f5);
    Tusk2_1.render(f5);
    Tusk2_2.render(f5);
    Tusk2_3.render(f5);
    
    if (entityelephant.getSaddled()) {
    	Saddle.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.Leg1.rotateAngleX = MathHelper.cos(f * 0.6662F) * 1.4F * f1;
    this.Leg2.rotateAngleX = MathHelper.cos(f * 0.6662F + (float)Math.PI) * 1.4F * f1;
    this.Leg3.rotateAngleX = MathHelper.cos(f * 0.6662F + (float)Math.PI) * 1.4F * f1;
    this.Leg4.rotateAngleX = MathHelper.cos(f * 0.6662F) * 1.4F * f1;
    this.Tail.rotateAngleZ = MathHelper.cos(f * 0.6662F) * 1.4F * f1;
    this.Ear1.rotateAngleY = MathHelper.cos(f * 0.3332F) * 1.4F * f1;
    this.Ear2.rotateAngleY = -MathHelper.cos(f * 0.3332F) * 1.4F * f1;
    this.Trunk1.rotateAngleZ = MathHelper.cos(f * 0.6662F) * 1.05F * f1;
    this.Trunk2.rotateAngleZ = MathHelper.cos(f * 0.6662F) * 1.1F * f1;
    this.Trunk3.rotateAngleZ = MathHelper.cos(f * 0.6662F) * 1.15F * f1;
    this.Trunk4.rotateAngleZ = MathHelper.cos(f * 0.6662F) * 1.2F * f1;
  }

}

 

RenderElephant.java

package com.ctwagon.testmod.render;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;

import com.ctwagon.testmod.Testmod;
import com.ctwagon.testmod.entity.mobs.EntityElephant;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class RenderElephant extends RenderLiving {
    private static final ResourceLocation mobTextures = new ResourceLocation(Testmod.MODID + ":textures/entity/Elephant.png");
    private static final String __OBFID = "CL_00000984";

    public RenderElephant(ModelBase par1ModelBase, float par2)
    {
        super(par1ModelBase, par2);
    }
    
    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(EntityElephant par1EntityElephant)
    {
        return mobTextures;
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(Entity par1Entity)
    {
        return this.getEntityTexture((EntityElephant)par1Entity);
    }
}

Link to comment
Share on other sites

I don't know what the issue is, but if you copy vanilla classes, you MUST remove the

__OBFID

lines, as that will screw up the building of the mod and make it not work.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.