Jump to content

Recommended Posts

Posted

I would make my flying mob attack colliding with the player, but I can not do since we can not use artificial intelligence because the movements do not work if I use, so I used a code that makes my death attack, but did not work and he is flying out there...

 

Part of my class attack death:

 


@Override
		        public void attackEntity(Entity entity, float arg1) {
		               
		                this.arrowHitTimer++;
		               
		                if (this.arrowHitTimer == 20) {
		                       
		                        if(entity instanceof EntityPlayer) {
		                        				                        	
		                                Vec3 look = this.getLookVec();
		                                if(!(arg1 <= 2)){
		                                
		                                EntityWitherSkull var3 = new EntityWitherSkull(this.worldObj, this, 1, 1, 1);
		                                var3.setPosition(this.posX + look.xCoord * 1, this.posY + look.yCoord * 1, this.posZ + look.zCoord * 1);
		                                var3.accelerationX = look.xCoord * 0.1;
		                                var3.accelerationY = look.yCoord * 0.1;
		                                var3.accelerationZ = look.zCoord * 0.1;
		                                this.worldObj.spawnEntityInWorld(var3);
		                                this.arrowHitTimer = -40;
		                        	}else{
		                        		this.arrowHitTimer = -20;
		                        		attackEntityAsMob(entity);
		                        	}
		                        }
		                }
			 }
}

 

Part of my class attack ghost:

 

public void attackEntity(Entity entity, float arg1) {
	               
                this.arrowHitTimer++;
               
                if (this.arrowHitTimer == 20) {
                       
                        if(entity instanceof EntityPlayer) {
                        	
                        	this.arrowHitTimer = -20;
                        		attackEntityAsMob(entity);
                        	}
                        }
                }	

 

My Ghost Class:

 

package mike.bathicraft.mob;

import mike.bathicraft.entity.EntityFlyingMob;
import mike.bathicraft.items.GerenciadorDeItems;
import net.minecraft.entity.Entity;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFleeSun;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIRestrictSun;
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.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityWitherSkull;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class EntityFantasma extends EntityFlyingMob {

	public int courseChangeCooldown;

	public double waypointX;

	public double waypointY;

	public double waypointZ;

	public EntityFantasma(World world) {
		super(world);
		this.setSize(0.9F, 1.9F);
	}

	  @Override
	    protected void applyEntityAttributes()
	    {
	        
	        super.applyEntityAttributes();
	        this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(3.0D);
	        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(20.0D);
	        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.4D);
	        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(15.0D);
	        
	    }
		 		 		  
		 protected Item getDropItem(){
				return Items.iron_ingot;
			}

			protected void dropRareDrop(int par1){
				switch (this.rand.nextInt(3)){

				case 0:
					this.dropItem(Items.iron_sword, 1);
				}
			}

			@Override
			protected void updateEntityActionState()
		    {
		        double var1 = this.waypointX - this.posX;
		        double var3 = this.waypointY - this.posY;
		        double var5 = this.waypointZ - this.posZ;
		        double var7 = var1 * var1 + var3 * var3 + var5 * var5;

		        if (var7 < 1.0D || var7 > 3600.0D)
		        {
		            this.waypointX = this.posX + (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F);
		            this.waypointY = this.posY + (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F);
		            this.waypointZ = this.posZ + (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 16.0F);
		        }

		        if (this.courseChangeCooldown-- <= 0)
		        {
		            this.courseChangeCooldown += this.rand.nextInt(5) + 2;
		            var7 = (double)MathHelper.sqrt_double(var7);

		            if (this.isCourseTraversable(this.waypointX, this.waypointY, this.waypointZ, var7))
		            {
		                this.motionX += var1 / var7 * 0.1D;
		                this.motionY += var3 / var7 * 0.1D;
		                this.motionZ += var5 / var7 * 0.1D;
		            }
		            else
		            {
		                this.waypointX = this.posX;
		                this.waypointY = this.posY;
		                this.waypointZ = this.posZ;
		            }
		        }
		            this.renderYawOffset = this.rotationYaw = -((float)Math.atan2(this.motionX, this.motionZ)) * 180.0F / (float)Math.PI;
		    }

			private boolean isCourseTraversable(double par1, double par3, double par5, double par7)
			    {
			        double var9 = (this.waypointX - this.posX) / par7;
			        double var11 = (this.waypointY - this.posY) / par7;
			        double var13 = (this.waypointZ - this.posZ) / par7;
			        AxisAlignedBB var15 = this.boundingBox.copy();

			        for (int var16 = 1; (double)var16 < par7; ++var16)
			        {
			            var15.offset(var9, var11, var13);

			            if (!this.worldObj.getCollidingBoundingBoxes(this, var15).isEmpty())
			            {
			                return false;
			            }
			        }

			        return true;
			    }

			public void attackEntity(Entity entity, float arg1) {
	               
                this.arrowHitTimer++;
               
                if (this.arrowHitTimer == 20) {
                       
                        if(entity instanceof EntityPlayer) {
                        	
                        	this.arrowHitTimer = -20;
                        		attackEntityAsMob(entity);
                        	}
                        }
                }			                      
}


 

My Flying Mob Class:

 

package mike.bathicraft.entity;

import net.minecraft.block.Block;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class EntityFlyingMob extends EntityMob{

public EntityFlyingMob(World world) {
	super(world);
}

protected void fall(float par1) {}

/**
* Takes in the distance the entity has fallen this tick and whether its on the ground to update the fall distance
* and deal fall damage if landing on the ground.  Args: distanceFallenThisTick, onGround
*/
protected void updateFallState(double par1, boolean par3) {}

/**
* Moves the entity based on the specified heading.  Args: strafe, forward
*/
public void moveEntityWithHeading(float par1, float par2)
{
    if (this.isInWater())
    {
        this.moveFlying(par1, par2, 0.02F);
        this.moveEntity(this.motionX, this.motionY, this.motionZ);
        this.motionX *= 0.800000011920929D;
        this.motionY *= 0.800000011920929D;
        this.motionZ *= 0.800000011920929D;
    }
    else if (this.handleLavaMovement())
    {
        this.moveFlying(par1, par2, 0.02F);
        this.moveEntity(this.motionX, this.motionY, this.motionZ);
        this.motionX *= 0.5D;
        this.motionY *= 0.5D;
        this.motionZ *= 0.5D;
    }
    else
    {
        float var3 = 0.91F;

        if (this.onGround)
        {
            var3 = 0.54600006F;
            Block var4 = this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.boundingBox.minY) - 1, MathHelper.floor_double(this.posZ));

        }

        float var8 = 0.16277136F / (var3 * var3 * var3);
        this.moveFlying(par1, par2, this.onGround ? 0.1F * var8 : 0.02F);
        var3 = 0.91F;

        if (this.onGround)
        {
            var3 = 0.54600006F;
            Block var5 = this.worldObj.getBlock(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.boundingBox.minY) - 1, MathHelper.floor_double(this.posZ));

        }

        this.moveEntity(this.motionX, this.motionY, this.motionZ);
        this.motionX *= (double)var3;
        this.motionY *= (double)var3;
        this.motionZ *= (double)var3;
    }

    this.prevLimbSwingAmount = this.limbSwingAmount;
    double var10 = this.posX - this.prevPosX;
    double var9 = this.posZ - this.prevPosZ;
    float var7 = MathHelper.sqrt_double(var10 * var10 + var9 * var9) * 4.0F;

    if (var7 > 1.0F)
    {
        var7 = 1.0F;
    }

    this.limbSwingAmount += (var7 - this.limbSwingAmount) * 0.4F;
    this.limbSwing += this.limbSwingAmount;
}

/**
* returns true if this entity is by a ladder, false otherwise
*/
public boolean isOnLadder()
{
    return false;
}
}

Posted

Use the method onUpdate(), don't forget to call super.onUpdate().

Than test if the distance to the closest player is very short.

than use player.attackEntityFrom(DamageSource source, float damage);

Posted

Before you can attack a player, you need a player to attack.

Try worldObj.getClosestPlayer to find methods for getting players.

For getting a good damagesource:

use DamageSource.causeMobDamage(this)

use the ammount of damage you want instead of "par2".

and like diesieben said:

if you would know basic java, you would be finished allready!

Posted

Also use @Override so that your IDE will yell at you when you aren't actually overriding something.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.