Jump to content

[1.8] Mob doesn't spawn minions (UNSOLVED)


DaryBob

Recommended Posts

Hey guy's! I was working on a boss mob which has multiple attacks. It shoots tree roots and spawns minions.

I have tried spawning the minions, first it worked, but now I doesn't work anymore. I think I accidentaly destroyed

one of the methods.. I can't find the problem, too me it seems correct but its not.. Heres the code:

 

EntityForestGuardian.java

 

 

package netcrafter.mods.aoto.entity.boss;

 

import java.util.ArrayList;

import java.util.List;

 

import com.google.common.base.Predicate;

import com.google.common.base.Predicates;

 

import net.minecraft.block.Block;

import net.minecraft.command.IEntitySelector;

import net.minecraft.enchantment.EnchantmentHelper;

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.EnumCreatureAttribute;

import net.minecraft.entity.IRangedAttackMob;

import net.minecraft.entity.SharedMonsterAttributes;

import net.minecraft.entity.ai.EntityAIArrowAttack;

import net.minecraft.entity.ai.EntityAIBase;

import net.minecraft.entity.ai.EntityAIHurtByTarget;

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.boss.IBossDisplayData;

import net.minecraft.entity.effect.EntityLightningBolt;

import net.minecraft.entity.item.EntityItem;

import net.minecraft.entity.item.EntityXPOrb;

import net.minecraft.entity.monster.EntityCaveSpider;

import net.minecraft.entity.monster.EntityEnderman;

import net.minecraft.entity.monster.EntityMob;

import net.minecraft.entity.monster.EntityZombie;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.projectile.EntitySmallFireball;

import net.minecraft.entity.projectile.EntitySnowball;

import net.minecraft.entity.projectile.EntityWitherSkull;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.potion.PotionEffect;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.BlockPos;

import net.minecraft.util.DamageSource;

import net.minecraft.util.EnumParticleTypes;

import net.minecraft.util.MathHelper;

import net.minecraft.util.WeightedRandomChestContent;

import net.minecraft.world.EnumDifficulty;

import net.minecraft.world.World;

import net.minecraftforge.common.ChestGenHooks;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import netcrafter.mods.aoto.entity.projectile.EntityTreeRoot;

import netcrafter.mods.aoto.init.AOTOItems;

 

public class EntityForestGuardian extends EntityMob implements IBossDisplayData, IRangedAttackMob {

   

/**The attack counter (0 = shoots tree roots

                      1 = spawns his minions)

*/

private int attackCounter = 0;

/**The ticks being counted when the mob is dead*/

    private int deathTicks = 0;

    /**Regenerates if regenTime equals 20*/

    private int regenTime = 0;

 

public EntityForestGuardian(World worldIn) {

super(worldIn);

this.setSize(1.5F, 7.0F);

    this.tasks.addTask(1, new EntityAISwimming(this));

    this.tasks.addTask(2, new EntityAIWander(this, 1.0D));

        this.tasks.addTask(2, new EntityAIArrowAttack(this, 1.0D, 40, 20.0F));

    this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));

    this.tasks.addTask(3, new EntityAILookIdle(this));

    this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, false));

    this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));

}

   

    @Override

    protected void applyEntityAttributes() {

        super.applyEntityAttributes();

        this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(160.0F);

        this.getEntityAttribute(SharedMonsterAttributes.followRange).setBaseValue(35.0D);

        this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.23000000417232513D);

        this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(12.0D);

    }

 

    //Can't be pushed (No knockback)

    @Override

    public boolean canBePushed() {

        return false;

    }

 

    /** Sounds in progress

    @Override

    protected String getLivingSound() {

        return null;

    }

 

    @Override

    protected String getHurtSound() {

        return null;

    }

 

    @Override

    protected String getDeathSound() {

        return null;

    }

    */

   

    /** Calls this method if the mob is dead */

    @SuppressWarnings("unchecked")

    @Override

    protected void onDeathUpdate() {

    //Increments deathTicks every tick

    ++this.deathTicks;

 

    //Creates a huge explosion if the value of deathTicks is between 180 and 200

        if (this.deathTicks >= 180 && this.deathTicks <= 200) {

            final float f = (this.rand.nextFloat() - 0.5F) * 1.5F;

            final float f1 = (this.rand.nextFloat() - 0.5F) * 2.0F;

            final float f2 = (this.rand.nextFloat() - 0.5F) * 1.5F;

            //Spawns the explosion into the world

            this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.posX + f, this.posY + 2.0D + f1, this.posZ + f2, 0.0D, 0.0D, 0.0D);

        }

 

        int i;

        int j;

 

        if (!this.worldObj.isRemote) {

       

        if (this.deathTicks > 150 && this.deathTicks % 5 == 0) {

                i = 30;

 

                while (i > 0) {

                    j = EntityXPOrb.getXPSplit(i);

                    i -= j;

                    //Spawns xp orbs while i is bigger than zero

                    this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));

                }

            }

 

        }

 

        //Rotates the mob

        this.moveEntity(0.0D, 0.10000000149011612D, 0.0D);

        this.renderYawOffset = this.rotationYaw += 20.0F;

 

        //Checks if the death ticks reached 200

        if (this.deathTicks == 200 && !this.worldObj.isRemote) {

            i = 20;

 

            while (i > 0) {

                j = EntityXPOrb.getXPSplit(i);

                i -= j;

                //Spawns xp orbs while i is bigger than 0

                this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));

            }

 

            //Drops an item

            this.entityDropItem(new ItemStack(AOTOItems.gem, 1, 1), 0.5F);

           

            //Spawns a lighting bolt into the world

            this.worldObj.addWeatherEffect(new EntityLightningBolt(worldObj, this.posX + 6, this.posY + 6, this.posZ));

           

            //Sets this mob dead

            super.setDead();

        }

    }

 

    @Override

    protected void dropFewItems(boolean par1, int par2) {

    final ItemStack var2 = new ItemStack(Items.diamond_axe);

    //Adds a random enchantment to our item

        EnchantmentHelper.addRandomEnchantment(this.rand, var2, 5);

        //Drops this item

        this.entityDropItem(var2, 0.0F);

    }

   

    @Override

    public EntityItem entityDropItem(ItemStack par1ItemStack, float par2) {

        final EntityItem entityitem = new EntityItem(this.worldObj, this.posX, this.posY + par2, this.posZ, par1ItemStack);

        entityitem.motionY = -2.0D;

        //After 60 ticks you can pickup the item

        entityitem.setPickupDelay(60);

        if (this.captureDrops) {

        //Adds a captured drop to the array

            this.capturedDrops.add(entityitem);

        }else{

        //Spawns the entity item into the world

            this.worldObj.spawnEntityInWorld(entityitem);

        }

        return entityitem;

    }

   

    @Override

    public void onLivingUpdate() {

   

    //If the regentime is higher than 20, heal him (increases the regenTime on every check)

    if(regenTime++ > 20) {

    regenTime = 0;

    this.heal(4);

    } 

    super.onLivingUpdate();

    }

   

    @Override

    public boolean attackEntityFrom(DamageSource dmgSource, float dmgValue) {

   

    //Amount of damage equals 4 if it gets fire dmg

    if(dmgSource.isFireDamage()) {

    dmgValue = 4;

    }

   

    if(super.attackEntityFrom(dmgSource, dmgValue)) {

    if(dmgSource.getEntity() != null) {

    Entity entity = dmgSource.getEntity();

   

    }

   

        //Checks the value of health and switches the attacks

        if(this.getHealth() < this.getMaxHealth() * 0.62 && attackCounter == 0) {

        attackCounter++;

        spawnMinions();

        System.out.println("Health:" + this.getHealth() + " Attack:" + attackCounter);

        }else if(attackCounter == 1 && this.getHealth() < this.getMaxHealth() * 0.25) {

        attackCounter++;

        spawnMinions();

        System.out.println("Health:" + this.getHealth() + " Attack:" + attackCounter);

        }

        return true;

        }

   

return false;

    }

   

    @Override

    public void attackEntityWithRangedAttack(EntityLivingBase entity, float distance) {

   

    if(attackCounter == 0) {

        rootAttack(entity, distance);

    }else if(attackCounter == 1) {

    rootAttack(entity, distance);

    }else if(attackCounter == 2) {

    super.attackEntityAsMob(entity);

    }

    }

   

    public void rootAttack(EntityLivingBase entity, float distance) {

    //Checks if the attack counter is 0 (Shoots tree roots)

    if(this.attackCounter == 0) {

    //Calculates the width

            double d0 = entity.posX - this.posX;

            //Calculates the height

            double d1 = entity.getEntityBoundingBox().minY + (double)(entity.height / 2.0F) - (this.posY + (double)(this.height / 2.0F));

            //Calculates the depth

            double d2 = entity.posZ - this.posZ;

            //Calculates the root of distance and multiplies it with 0.5F

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

            //Plays the sound effect

            this.worldObj.playAuxSFXAtEntity((EntityPlayer)null, 1009, new BlockPos((int)this.posX, (int)this.posY, (int)this.posZ), 0);

            for (int i = 0; i < 1; ++i) {

            /**d0 + this.rand.nextGaussian() * (double)f1, d1, d2 + this.rand.nextGaussian() * (double)f1*/

            //Creates the tree root and calculates the accels

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

                //Calculares the height

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

            //Spawns the tree root

                this.worldObj.spawnEntityInWorld(treeroot);

            }

        }

    }

   

    private void spawnMinions() {

   

    //Number of mobs spawned

    int numSpawned = 0;

   

    //Trys to spawn minion. If true, increment the number of mobs

    if(trySpawnMinion((int) this.posX + 1, (int) this.posY, (int) this.posZ)) { numSpawned++; }

    //Returns back

    if(numSpawned >= 2) return;

    if(trySpawnMinion((int) this.posX - 1, (int) this.posY, (int) this.posZ - 1)) { numSpawned++; }

    if(numSpawned >= 2) return;

    if(trySpawnMinion((int) this.posX, (int) this.posY, (int) this.posZ + 1)) { numSpawned++; }

    if(numSpawned >= 2) return;

    if(trySpawnMinion((int) this.posX, (int) this.posY, (int) this.posZ - 1)) { numSpawned++; }

    if(numSpawned >= 2) return;

    if(trySpawnMinion((int) this.posX + 1, (int) this.posY, (int) this.posZ + 1)) { numSpawned++; }

    if(numSpawned >= 2) return;

    if(trySpawnMinion((int) this.posX - 1, (int) this.posY, (int) this.posZ - 1)) { numSpawned++; }

    if(numSpawned >= 2) return;

    if(trySpawnMinion((int) this.posX - 1, (int) this.posY, (int) this.posZ + 1)) { numSpawned++; }

    if(numSpawned >= 2) return;

    if(trySpawnMinion((int) this.posX + 1, (int) this.posY, (int) this.posZ - 1)) { numSpawned++; }

    if(numSpawned >= 2) return;

    }

   

    private boolean trySpawnMinion(int x, int y, int z) {

   

    EntityZombie minion = new EntityZombie(this.worldObj);

    minion.setPosition(x, y, z);

   

    //Checks if the minion can spawn here

    if(minion.getCanSpawnHere()) {

    if(!this.worldObj.isRemote) {

    //Spawns entity and explosion particle in world

    this.worldObj.spawnEntityInWorld(minion);

    minion.spawnExplosionParticle();

    System.out.println("Spawned minion at: " + x + " " + y + " " + z);

    return true;

    }

    }

   

    return false;

    }

 

}

 

 

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.