Jump to content

Water walking entity


I_Iz_Shahid

Recommended Posts

Hey guys,

 

I have been trying to figure out a way to allow my custom mob to walk over water, but all of my attempts have failed. I am getting stuck on how to check what block is the entity standing on top of, I seems like the method I am looking for got removed in the recent version of minecraft.

 

Secondly, I would like know how to make any damage the entity receives be sent back to the aggressor, Like if I hit it I would take the damage not the entity.

 

Any Ideas?

if(pain == 0)

{

   gain = 0;

}

Link to comment
Share on other sites

For the first concern, the mob is just supposed to be ABLE to walk. It doesn't matter if it doesn't like to wander over it, it just needs to be able to walk on top of it if it somehow goes into water. Is there a method that returns the block under the entities feet at the given moment?

if(pain == 0)

{

   gain = 0;

}

Link to comment
Share on other sites

I got another random issue not related to whatever I just changed, apparently my entity is now frozen in place quivering his head oh so slightly. When I hit it, he just turns red and waves his arms like crazy. I have no idea what is going on, I commented out AI parts and the waterwalking code and the problem still prevails

 

Code:

package com.Accelerator.Entity;

import net.minecraft.block.Block;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;

public class EntityAccelerator
extends EntityMob
{

public EntityAccelerator(World worldIn)
{
	super(worldIn);
	this.isImmuneToFire = true;/*
        this.tasks.addTask(2, new EntityAILeapAtTarget(this, 1.0F));
        this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityMob.class, 1.0D, false));
        this.tasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityZombie.class, true));
        this.tasks.addTask(4, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(4, new EntityAILookIdle(this));
	this.tasks.addTask(5, new EntityAIWander(this, 1.0D));
        this.tasks.addTask(4, new EntityAISwimming(this));*/
}

public boolean isAIEnabled()
{
	return true;
}

public void onUpdate()
{/*
	BlockPos pos = new BlockPos((int) this.posX, (int) this.posY - 1, (int) this.posZ);
	if (this.worldObj.getBlockState(pos).getBlock() == Blocks.water)
	{
		this.motionY = 0;
	}*/
}

public void applyEntityAtributes()
{
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(20.0D);
        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D);
        this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(10.0D);
        this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setBaseValue(1.0D);
        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(256.0D);
}

protected void updateAITasks()
    {
        super.updateAITasks();
    }
/**
 * Returns the sound this mob makes while it's alive. I'll be teaching how to add custom sounds a little bit later.
 */
protected String getLivingSound()
{
	return "mob.cow.say";
}

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

/**
 * Returns the sound this mob makes on death.
 */
protected String getDeathSound()
{
	return "mob.cow.hurt";
}
/**
 * Plays step sound at it's coordinates
 */
protected void playStepSound(int par1, int par2, int par3, int par4)
{
	this.playSound("mob.cow.step", 0.15F, 1.0F);
}

/**
 * Returns the volume for the sounds this mob makes.
 */
protected float getSoundVolume()
{
	return 0.4F;
}
/**
     * Checks if the entity's current position is a valid location to spawn this entity.
     */
    public boolean getCanSpawnHere()
    {
        return this.worldObj.getDifficulty() != EnumDifficulty.PEACEFUL;
    }
    
    private void explode()
    {
        if (!this.worldObj.isRemote)
        {
            boolean flag = this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing");
            this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 2.0F, flag);
            this.setDead();
        }
    }
}

if(pain == 0)

{

   gain = 0;

}

Link to comment
Share on other sites

You could just try to make it always move to the surface and it might work okay. You'd just check if the block at the position of the entity's feet is a fluid and if it is you'd move the entity up to point where it would be on top. I don't know how glitchy that would look, and as mentioned you might need to modify the AI and navigator to make it move in a sensible way while on the water.

 

If that doesn't work you might, to make your entity to "walk" on water it might be easiest to actually make it technically a flying entity (extend EntityFlying like a Ghast) and prevent it from flying above the ground. That would be a fair bit of work, but probably more straight-forward than trying to prevent the normal sinking into water since that involves gravity and the navigator and things like that. You have a lot more control over the movement of an EntityFlying than an EntityMob or EntityCreature.

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.