Jump to content

Recommended Posts

Posted

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;

    }

 

}

 

 

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

    • Verified users can now unlock a $100 OFF Temu Coupon Code using the verified promo code [ALF401700]. This Temu $100 OFF code works for both new and existing customers and can be used to redeem up to 50% off your next order. Our exclusive Temu coupon code [ALF401700] delivers a flat $100 OFF on top of existing deals. First-time customers using code ALF401700 can save an extra 100% off select items. Returning users also qualify for an automatic $100 OFF discount just by applying this code at checkout. But wait—there’s more. With our Temu coupon codes for 2025, users can score up to 90% OFF on clearance items. Whether you’re shopping in the USA, Canada, UK, or elsewhere, Temu promo code ALF401700 unlocks extra discounts tailored to your account. Some users are saving 100% on items using this 2025 Temu promo code. 🔥 Temu Coupon Highlights Using Code [ALF401700]: Temu new user code – ALF401700: Save 50% off your first order + $100 OFF. Temu promo for existing customers – ALF401700: Enjoy flat $100 OFF instantly. Global availability: Works in the USA, UK, Canada, Germany, France, Japan, Chile, Colombia, Malaysia, Mexico, South Korea, Philippines, Saudi Arabia, Qatar, Pakistan, and more. Top 2025 Coupon Deal: Get $200 OFF plus 100% bonus discounts using code ALF401700. Top-Ranked Temu Deals for 2025 (Coupon Code: ALF401700): ✅ Temu $100 OFF Memorial Day Sale — Use ALF401700 ✅ Temu First Order Coupon — Use ALF401700 for 50% + $100 OFF ✅ Temu USA Coupon Code — Save $100 instantly with ALF401700 ✅ Temu Japan, Germany, Chile Codes — All support ALF401700 ✅ Temu Reddit Discount – $100 OFF: Valid for both new and old users ✅ Temu Coupon Bundle 2025 — $100 OFF + up to 50% slash ✅ 100% OFF Free Gift Code — Use ALF401700, no invite needed ✅ Temu Sign-Up Bonus Promo — Get a welcome $100 OFF instantly ✅ Free Temu Code for New Users — Use ALF401700, no referral required  Temu Clearance Codes 2025 — Use ALF401700 for 85–100% discounts Why ALF401700 is the Best Temu Code in 2025 Using Temu code ALF401700 is your ticket to massive savings, free shipping, first-order discounts, and stackable coupon bundles. Whether you're browsing electronics, fashion, home goods, or beauty products, this verified Temu discount code offers real savings—up to 90% OFF + $100 OFF on qualified orders. 💡 Pro Tip: Apply ALF401700 during checkout in the Temu app or website to activate your instant $100 discount, even if you’re not a new user. Temu $100 OFF Code by Country (All Use ALF401700): 🇺🇸 Temu USA – ALF401700 🇯🇵 Temu Japan – ALF401700 🇲🇽 Temu Mexico – ALF401700 🇨🇱 Temu Chile – ALF401700 🇨🇴 Temu Colombia – ALF401700 🇲🇾 Temu Malaysia – ALF401700 🇵🇭 Temu Philippines – ALF401700 🇰🇷 Temu Korea – ALF401700 🇵🇰 Temu Pakistan – ALF401700 🇫🇮 Temu Finland – ALF401700 🇸🇦 Temu Saudi Arabia – ALF401700 🇶🇦 Temu Qatar – ALF401700 🇫🇷 Temu France – ALF401700 🇩🇪 Temu Germany – ALF401700 🇮🇱 Temu Israel – ALF401700 Temu Coupon Code [ALF401700] Summary for SEO: Temu $100 OFF Code  Temu First Order Discount Code 2025  Temu Verified Promo Code ALF401700  Temu 50% OFF + $100 Bonus  Temu 100% OFF Code 2025  Temu App Promo ALF401700  Temu Working Discount Code 2025 
    • Hey there, nothing to do with the code, I am just suggesting you use Intelij IDEA. Trust me, it is the best.
    • Hey there, nothing to do with the code, I am just suggesting you use Intelij IDEA. Trust me, it is the best.
    • You can check the config of Geckolib and Mowzie's Mobs - maybe there is a way to disable some render features
    • You can use the .requires() function  the server also has a permission level of 4, which is the highest permission level.
  • Topics

×
×
  • Create New...

Important Information

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