Jump to content

Mob Entity Like to do....


Creepmander
 Share

Recommended Posts

Hi!

Mmm... I write an Entity and it looks like a Mermaid (Im isn't a perfect modeler xD).

Now i make it to can get air anywhere (It cant drowned => can move in the ground).

But it don't wanna go in the water xD. How i can make it to like to be in water?

 

The MobType class:

public abstract class EntityGyogyinMob extends EntityCreature implements IAnimals
{
    public EntityGyogyinMob(World par1World)
    {
        super(par1World);
    }

    public boolean canBreatheUnderwater()
    {
        return true;
    }

    /**
     * Checks if the entity's current position is a valid location to spawn this entity.
     */
    public boolean getCanSpawnHere()
    {
        return this.worldObj.checkNoEntityCollision(this.boundingBox);
    }

    /**
     * Get number of ticks, at least during which the living entity will be silent.
     */
    public int getTalkInterval()
    {
        return 120;
    }

    /**
     * Determines if an entity can be despawned, used on idle far away entities
     */
    protected boolean canDespawn()
    {
        return true;
    }

    /**
     * Get the experience points the entity currently has.
     */
    protected int getExperiencePoints(EntityPlayer par1EntityPlayer)
    {
        return 1 + this.worldObj.rand.nextInt(5);
    }
    public void onEntityUpdate()
    {
        int i = this.getAir();
        super.onEntityUpdate();
        
        if (this.isEntityAlive() && !this.isInsideOfMaterial(Material.water))
        {
            --i;
            this.setAir(i);
                        
            if (this.getAir() == -20)
            {
                this.setAir(0);
            }
        }
        else
        {
            this.setAir(300);
            //      [] <-- I Think i need to write here. (but i dont know)
        }
    }
}

 

This is the Entity's class:

public class EntitySelloOr1 extends EntityGyogyinMob
{
private int angerLevel = 0;

public EntitySelloOr1(World par1World)
{
	super(par1World);
	this.moveSpeed = 0.5F;
	this.texture = "/creepian/textures/SelloOr1.png";
}

@Override
public int getMaxHealth() {
	return 30;
}
public int getAttackStrength(Entity par1Entity)
    {
        ItemStack itemstack = this.getHeldItem();
        float f = (float)(this.getMaxHealth() - this.getHealth()) / (float)this.getMaxHealth();
        int i = 3 + MathHelper.floor_float(f * 4.0F);

        if (itemstack != null)
        {
            i += itemstack.getDamageVsEntity(this);
        }

        return i;
    }
protected String getLivingSound()
    {
        return null;
    }
    protected String getHurtSound()
    {
        return null;
    }
    protected String getDeathSound()
    {
        return null;
    }
    protected int getDropItemId()
    {
        return 0;
    }
    protected boolean isAIEnabled()
    {
        return false;
    }
    protected void dropFewItems(boolean par1, int par2)
    {
        int j = this.rand.nextInt(3 + par2) + 1;

        for (int k = 0; k < j; ++k)
        {
            this.entityDropItem(new ItemStack(creepian.creepian.silverCoin, 1, 0), 0.0F);
        }
    }
    public void onUpdate()
    {
    	if(this.isInWater() == true)
    	{
    		this.moveSpeed = 0.95F;
    	}
    	
        super.onUpdate();
    }
    public boolean isInWater()
    {
        return this.worldObj.handleMaterialAcceleration(this.boundingBox.expand(0.0D, -0.6000000238418579D, 0.0D), Material.water, this);
    }
    
    public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeEntityToNBT(par1NBTTagCompound);
        par1NBTTagCompound.setShort("Anger", (short)this.angerLevel);
    }
    public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readEntityFromNBT(par1NBTTagCompound);
        this.angerLevel = par1NBTTagCompound.getShort("Anger");
    }
    protected Entity findPlayerToAttack()
    {
        return this.angerLevel == 0 ? null : super.findPlayerToAttack();
    }
    public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
    {
        if (this.isEntityInvulnerable())
        {
            return false;
        }
        else
        {
            Entity entity = par1DamageSource.getEntity();

            if (entity instanceof EntityPlayer)
            {
                List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(32.0D, 32.0D, 32.0D));

                for (int j = 0; j < list.size(); ++j)
                {
                    Entity entity1 = (Entity)list.get(j);

                    if (entity1 instanceof EntitySelloOr1)
                    {
                        EntitySelloOr1 entityselloor1 = (EntitySelloOr1)entity1;
                        entityselloor1.becomeAngryAt(entity);
                    }
                }

                this.becomeAngryAt(entity);
            }

            return super.attackEntityFrom(par1DamageSource, par2);
        }
    }

    /**
     * Causes this PigZombie to become angry at the supplied Entity (which will be a player).
     */
    private void becomeAngryAt(Entity par1Entity)
    {
        this.entityToAttack = par1Entity;
        this.angerLevel = 400 + this.rand.nextInt(400);
    }
}

 

Yeah!, and i wanna make it can be agressive. (like zombie pig) You can see the code inside but it isn't completed, aaand I don't know what is the missing part.

Please help me in it.

 

Sorry for my English.

Link to comment
Share on other sites

I think you'll want to spawn it into the water at first...

Then...

public void onUpdate()
    {
    	if(this.isInWater())
    	{
    		this.moveSpeed = 0.95F;
    	}
        else
        {
          //search for water blocks and set it as a path target
    	}
        super.onUpdate();
    }

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.