Jump to content

How to make custom mob shoot fireballs?


MikeDark

Recommended Posts

I'm creating a mage that shoots balls of fire, however I can not do it and  need your help, please help me ...

 

My Entity Class:

 


package mike.bathicraft.mob;

import mike.bathicraft.items.GerenciadorDeItems;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIArrowAttack;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
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.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityLargeFireball;
import net.minecraft.entity.projectile.EntitySmallFireball;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class EntityMage extends EntityMob{

    public EntityMage(World world) {
	super(world);
	 isImmuneToFire = true;
	this.setSize(0.9F, 1.9F);
	this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(2, new EntityAIAttackOnCollide(this, EntityPlayer.class, 1.0D, false));
        this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
        this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 12.0F));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
}

  @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(120.0D);
        
    }
  
	protected boolean isAIEnabled()
    {
        return true;
    }

	@Override
	protected boolean isValidLightLevel()
	{
		 return true;
	}

	 @Override
	 public boolean getCanSpawnHere()
	 {
		 return true;		 
	 }

	 public ItemStack getHeldItem()
	 {
	 return heldItem;
	 }

	 private static final ItemStack heldItem = new ItemStack(GerenciadorDeItems.CetroDeFogo, 1);
	 		 		  
	 protected Item getDropItem(){
			return Items.blaze_powder;
		}

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

			case 0:
				this.dropItem(GerenciadorDeItems.CetroDeFogo, 1);
			}
		}

	    protected void playStepSound(int par1, int par2, int par3, int par4)
	        {
	           this.worldObj.playSoundAtEntity(this, null, 0.15F,  1.0F);
	        }
	}

Link to comment
Share on other sites

Show what you have tried.

 

I tried to adapt this code:

 


pprotected void attackEntity(Entity entity, float f)
    {
        if (f < 10F)
        {
            double d = entity.posX - posX;
            double d1 = entity.posZ - posZ;
            if (attackTime == 0)
            {
                EntitySnowball entitysnowball = new EntitySnowball(worldObj, this);
                double d2 = (entity.posY + (double)entity.getEyeHeight()) - 1.1000000238418579D - entitysnowball.posY;
                float f1 = MathHelper.sqrt_double(d * d + d1 * d1) * 0.2F;
                worldObj.playSoundAtEntity(this, "random.bow", 1.0F, 1.0F / (rand.nextFloat() * 0.4F + 0.8F));
                worldObj.spawnEntityInWorld(entitysnowball);
                entitysnowball.setThrowableHeading(d, d2 + (double)f1, d1, 1.6F, 12F);
                attackTime = 10;
            }
            rotationYaw = (float)((Math.atan2(d1, d) * 180D) / 3.1415927410125732D) - 90F;
            hasAttacked = true;
        }
    }

Link to comment
Share on other sites

You need an AI task to make your Entity actually do something. The snow golem for example uses EntityAIArrowAttack.

 

I used the following code, and it worked almost perfectly, the only problem is, the fireballs instead of being out of the mob are coming out of my player

 

@Override
		public void attackEntityWithRangedAttack(EntityLivingBase entity, float arg1) {

			Vec3 look = entity.getLookVec();
			EntityLargeFireball fireball2 = new EntityLargeFireball(worldObj);
			fireball2.setPosition(entity.posX + look.xCoord * 5, entity.posY + look.yCoord * 5, entity.posZ + look.zCoord * 5);
			fireball2.accelerationX = look.xCoord * 0.4;
			fireball2.accelerationY = look.yCoord * 0.4;
			fireball2.accelerationZ = look.zCoord * 0.4;
			this.worldObj.spawnEntityInWorld(fireball2);
		}

Link to comment
Share on other sites

You are using the entity being passed in as the "source" of the projectiles. But the entity you get as the parameter is the entity being attacked, not the entity that is doing the attack.

 

and how I could change to the entity that will make the attack, i tried to change some parts,however at the end, just did not work

Link to comment
Share on other sites

It is a method in your Entity. Thus

this

refers to your Entity.

 

I fix and now my body is firing fireballs, but after he started shooting for a part he did not "upgrade" and is always there to shoot, but if I get away and return back, he start shoot for one only direction, it returns with bug

 

@Override
		public void attackEntityWithRangedAttack(EntityLivingBase entity, float arg1) {

			Vec3 look = this.getLookVec();
			EntityLargeFireball var3 = new EntityLargeFireball(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.3;
			var3.accelerationY = look.yCoord * 0.3;
			var3.accelerationZ = look.zCoord * 0.3;
	        this.worldObj.spawnEntityInWorld(var3);
		}

 

 

Link to comment
Share on other sites

Post your entire Entity class again please.

 

Entity Class:

 

package mike.bathicraft.mob;

import mike.bathicraft.items.GerenciadorDeItems;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IRangedAttackMob;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIArrowAttack;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
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.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityLargeFireball;
import net.minecraft.entity.projectile.EntitySmallFireball;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class EntityMage extends EntityMob implements IRangedAttackMob{

private int explosionStrength = 1;
  private Entity targetedEntity = null;

    public EntityMage(World world) {
	super(world);
	 isImmuneToFire = true;
	this.setSize(0.9F, 1.9F);
	this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(1, new EntityAIArrowAttack(this, 0.25F, 20, 10.0F));
        this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
        this.tasks.addTask(8, new EntityAIWatchClosest(this, EntityPlayer.class, 12.0F));
        this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true));
        this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, 0, true));
}
    
  @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(120.0D);
        
    }
  
	protected boolean isAIEnabled()
    {
        return true;
    }

	@Override
	protected boolean isValidLightLevel()
	{
		 return true;
	}

	 @Override
	 public boolean getCanSpawnHere()
	 {
		 return true;		 
	 }

	 public ItemStack getHeldItem()
	 {
	 return heldItem;
	 }

	 private static final ItemStack heldItem = new ItemStack(GerenciadorDeItems.CetroDeFogo, 1);
	 		 		  
	 protected Item getDropItem(){
			return Items.blaze_powder;
		}

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

			case 0:
				this.dropItem(GerenciadorDeItems.CetroDeFogo, 1);
			}
		}

	    protected void playStepSound(int par1, int par2, int par3, int par4)
	        {
	           this.worldObj.playSoundAtEntity(this, null, 0.15F,  1.0F);
	        }
	    
		@Override
		public void attackEntityWithRangedAttack(EntityLivingBase entity, float arg1) {

			Vec3 look = this.getLookVec();
			EntityLargeFireball var3 = new EntityLargeFireball(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.3;
			var3.accelerationY = look.yCoord * 0.3;
			var3.accelerationZ = look.zCoord * 0.3;
	        this.worldObj.spawnEntityInWorld(var3);

		}
}

Link to comment
Share on other sites

This is the code from EntityBlaze I put into my own mob. It works perfectly, as I will explain below. (Hopefully accurately.)

 

    @Override
    public void attackEntityWithRangedAttack(EntityLivingBase entity, float distance) {

        double d0 = entity.posX - this.posX;
        double d1 = entity.boundingBox.minY + (double)(entity.height / 2.0F) - (this.posY + (double)(this.height / 2.0F));
        double d2 = entity.posZ - this.posZ;

 

This calculates the x,y,z DISTANCE between the projectile and the target. getLook() only gives the DIRECTION.

 

        float f1 = MathHelper.sqrt_float(distance) * 0.5F;

 

This is calculating the accuracy (randomness) of the projectile. (The square root of the total distance divided by half. So, larger distances are more accurately fired.)

 

        this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1009, (int)this.posX, (int)this.posY, (int)this.posZ, 0);
        for (int i = 0; i < 1; ++i)
        {

 

This part has a for loop because the Blaze can fire three fireballs at a time, but it's not needed in this case.

 

            EntitySmallFireball entitysmallfireball = new EntitySmallFireball(this.worldObj, this, d0 + this.rand.nextGaussian() * (double)f1, d1, d2 + this.rand.nextGaussian() * (double)f1);

 

This is the important part. This sets the x,y,z vector of the projectile, it uses the distance numbers calculated above, times a random number. (Because the Blaze fires randomly), you can take out "this.rand.nextGaussian() * (double)f1" and the projectile will always hit you dead on.

 

            entitysmallfireball.posY = this.posY + (double)(this.height / 2.0F) + 0.5D;

 

This is where the projectile starts, the 0.5 is added to half the height to place it near the mobs mouth area.

 

            this.worldObj.spawnEntityInWorld(entitysmallfireball);
        }
    }

 

Done. My class extends EntitySkeleton and nothing but this method is in it. I spawned it in, and now I have a skelington that shoots (Inaccurate) fireballs instead of arrows.

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I want to make a tree decorator that will generate a beehive under branches of my tree. I have no idea how to check for branches and make beehives generate because TreeDecorator.Context.logs() is just a block pos and i dont understand how it works. i hope ill get an answer here.
    • Imagine this: you've painstakingly accumulated $97,000 worth of Bitcoin, only to see it vanish into the digital abyss at the hands of cunning scammers. It's a devastating blow, leaving you feeling helpless and betrayed. But fear not, for Lee Ultimate Hacker is here to turn the tide in your favor. After conducting extensive research on cryptocurrency recovery options, I stumbled upon Lee Ultimate Hacker, and it proved to be the most suitable choice for the daunting task at hand. Despite my initial skepticism, they shattered my doubts by successfully retrieving $92,000 of the lost Bitcoin—a feat I once deemed impossible. From the moment I reached out to Lee Ultimate Hacker and provided them with all the pertinent information about the fraudulent transaction, they sprang into action with unwavering determination. True to their word, they delivered on their promise to recover the lost Bitcoin within an impressive timeframe of 24 to 72 hours. Their professionalism, expertise, and commitment to their clients were truly commendable, transforming what seemed like an insurmountable ordeal into a resounding triumph. In my eyes, the investment of both time and money was more than justified by the remarkable outcome achieved by Lee Ultimate Hacker. So, if you've fallen victim to cryptocurrency scams and are grappling with the anguish of lost funds, don't despair. Reach out to Lee Ultimate Hacker and let them work their magic. Their track record of success speaks for itself, and with their assistance, you can reclaim what's rightfully yours and emerge stronger than ever before. Don't let the darkness of cybercrime overshadow your financial future. Take a stand against fraudsters with the help of Lee Ultimate Hacker, and witness the transformation from despair to triumph. Your journey to recovery starts here. LEEULTIMATEHACKER@ AOL. COM or Support @ leeultimatehacker . com. telegram:LEEULTIMATE or wh@tsapp +1  (715) 314  -  9248 https://leeultimatehacker.com Thank you.
    • There's a scheme I got into where they promised to trade Bitcoin for me and take a cut as a commission. Seemed like a good idea at the time. But then, things went south real fast. They ended up transferring   $190,000 worth of my Bitcoin. I was devastated and felt completely helpless. That's when I stumbled upon the Wizard Web Recovery Tool. It was like a beacon of hope amid chaos. With this tool, I could finally start digging into what went wrong and hopefully get my Bitcoin back. Using Wizard Web was surprisingly easy. I just had to plug in some details about my Bitcoin account and let it do its thing. It started scanning the internet, looking for any clues about what happened to my Bitcoin. It felt like having a detective on my side, searching for answers. And guess what? Wizard Web found some leads. It uncovered evidence of the scheme's shady dealings and helped me track down the people responsible for losing my Bitcoin. Armed with this information, I took the case to court. After a long and hard-fought legal battle, the court ruled in my favor. The perpetrators were held accountable for their actions and faced criminal charges for their involvement in the scheme. It was a victory not just for me, but for anyone who's been taken advantage of by these kinds of scams. Thanks to Wizard Web Recovery, I was able to get justice and reclaim what was rightfully mine. It showed me that even in the face of adversity, there's always a way to fight back. And with the right tools and determination, anything is possible.   The following is the contact information for Wizard Web Recovery.   Email: wizard web recovery((@))programmer . net
    • Hello, good morning. I know some programming and I'm interested in mod creation. That's why I've decided to follow a tutorial guide on YouTube by TurtyWurty. https://www.youtube.com/watch?v=DhoX9cmAZqA&t=160s&ab_channel=TurtyWurty I've followed the tutorial perfectly. The problem is that when checking the food, the texture doesn't load for me. However, everything seems fine no matter how much I check. I'm sure it's something trivial, the problem is that I can't find it. Could you help me solve it, please? I leave a zip of my file so you can edit it freely. forge-1.20-Civicraft.rar
    • If you have nvidia graphics, it's important that you make sure Minecraft (and anything Minecraft-related) is set to prefer high performance graphics first. If you only update your AMD drivers it might fix the issue but cause severe performance loss vs Vanilla as it'll be running on the integrated graphics instead of dedicated nvidia graphics
  • Topics

×
×
  • Create New...

Important Information

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