Jump to content

[1.7.10][solved] spawnEntityInWorld producing unresponsive mobs


salvestrom

Recommended Posts

 

 

 

public void wakeTheDamned() {

 

if(!this.worldObj.isRemote)

{

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

 

//"Wake the Dead"

EntitySacrificialSkeleton aid = new EntitySacrificialSkeleton(this.worldObj);

aid.setLocationAndAngles((double)this.posX-5+this.rand.nextInt(10), (double)this.posY+1, (double)this.posZ-5+this.rand.nextInt(10), 0.0F, 0.0F);

aid.onSpawnWithEgg((IEntityLivingData)null);

aid.setCurrentItemOrArmor(0, new ItemStack(w2theJungle.boneGripBow));

aid.setCurrentItemOrArmor(4, new ItemStack(w2theJungle.obshelmet));

 

this.worldObj.spawnEntityInWorld(aid);

this.playSound("mob.skeleton.hurt", 0.5f, 1);

aid.spawnExplosionParticle();

}

}

}

 

 

 

 

This code is part of a boss entity. He summons these adds and can pass his attack target to them. But the mobs summoned in this code are largely idle,  don't fight back and won't respond to passed threat. In contrast the same skeletons summoned using an egg will happily attack anything that they're told to by the boss.

 

According to the system.out i used, the constructor  for the sacrifical skeletons is run, so presumably the super [which calls EntitySkeleton] is too, yet, it's like it isn't.

 

 

Link to comment
Share on other sites

The problem predates the inclusion of aid.onspawnwithegg. I added that today after seeing it used in similar circumstances for vanilla code. it made no difference. the sac. skel entity has no implimentation of onspawn, anyway. also note that my skeleton, when spawned by other means, behaves correctly. it is only the version summoned by the boss code that is not working correctly.

 

the class:

 

 

 

public class EntitySacrificialSkeleton extends EntitySkeleton {

 

public EntitySacrificialSkeleton(World p_i1741_1_) {

super(p_i1741_1_);

 

System.out.println("i been made");

 

}

 

protected boolean isValidLightLevel()

    {

        int i = MathHelper.floor_double(this.posX);

        int j = MathHelper.floor_double(this.boundingBox.minY);

        int k = MathHelper.floor_double(this.posZ);

 

        if (this.worldObj.getSavedLightValue(EnumSkyBlock.Sky, i, j, k) > this.rand.nextInt(32))

        {

            return false;

        }

        else

        {

            int l = this.worldObj.getBlockLightValue(i, j, k);

 

            if (this.worldObj.isThundering())

            {

                int i1 = this.worldObj.skylightSubtracted;

                this.worldObj.skylightSubtracted = 10;

                l = this.worldObj.getBlockLightValue(i, j, k);

                this.worldObj.skylightSubtracted = i1;

            }

 

            return true; //l <= this.rand.nextInt(13);

           

//            return l >= this.rand.nextInt(12) + 6;

        }

    }

 

    public void onLivingUpdate() {

   

    //this.setDead();

    super.onLivingUpdate();

    }

   

    public void updateRidden()

    {

    //this.renderYawOffset = 1.5f;

    super.updateRidden();

   

    }

   

    @Override   

    public boolean attackEntityFrom(DamageSource ds, float f0)

    {

    if(ds == DamageSource.onFire) {

    return false;

    }

   

    if(this.ridingEntity != null && ds.getEntity() == this.ridingEntity)

    {

    return false;

    }

   

    return super.attackEntityFrom(ds, f0);

    }

   

    public void attackEntityWithRangedAttack(EntityLivingBase p_82196_1_, float p_82196_2_)

    {

    if(this.ridingEntity != null && p_82196_1_ == this.ridingEntity)

    {

    }

   

    this.height = this.isRiding() ? 1.8f * 1.25f : 1.8f;

   

        EntityArrow entityarrow = new EntityArrow(this.worldObj, this, p_82196_1_, 1.6F, (float)(14 - this.worldObj.difficultySetting.getDifficultyId() * 4));

        int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, this.getHeldItem());

        int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, this.getHeldItem());

        entityarrow.setDamage((double)(p_82196_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.worldObj.difficultySetting.getDifficultyId() * 0.11F));

 

        if (i > 0)

        {

            entityarrow.setDamage(entityarrow.getDamage() + (double)i * 0.5D + 0.5D);

        }

 

        if (j > 0)

        {

            entityarrow.setKnockbackStrength(j);

        }

 

        if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, this.getHeldItem()) > 0 || this.getSkeletonType() == 1)

        {

            entityarrow.setFire(100);

        }

 

        this.playSound("random.bow", 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));

        this.worldObj.spawnEntityInWorld(entityarrow);

    }

 

    protected Item getDropItem()

    {

        return Items.arrow;

    }

   

   

 

    protected void dropFewItems(boolean p_70628_1_, int p_70628_2_)

    {

        int j;

        int k;

 

        j = this.rand.nextInt(3 + p_70628_2_);

 

        for (k = 0; k < j; ++k)

        {

        this.dropItem(Items.arrow, 1);

      }

 

        j = this.rand.nextInt(1 + p_70628_2_);

 

        for (k = 0; k < j; ++k)

        {

            this.dropItem(w2theJungle.carvedBone, 1);

        }

    }

 

    protected void dropRareDrop(int p_70600_1_)

    {

    this.entityDropItem(new ItemStack(w2theJungle.ancientSkull, 1, 1), 0.0F);

    }

}

 

 

 

 

as you can see, theres nothing here but tweaks to code for loot and valid light checks. if it wasn't for an issue with mounted shooting and an abandoned interest in upping their dmg, the ranged attack method wouldn't even be here.

 

is there a chance this is due to an issue with an older forge? my 1.7.10 is a year old, i think.

Link to comment
Share on other sites

Hm, the Forge version shouldn't affect it, no. Are you getting any interesting messages in your console log?

 

Are your skeleton aids stuck in the ground at all? I notice you don't really adjust the y position other than +1, but with the random x/z position, that may not be enough.

 

Otherwise, your spawn code looks pretty standard, especially if your entity is working as expected otherwise... I dunno, maybe show the code that calls the #wakeTheDamned method?

Link to comment
Share on other sites

so, yeah. ID-10T issue.

 

the wakeTheDamned() method gives the skeletons a custom bow. the combat tasks method in EntitySkeleton only checks against Items.bow, so the aid has no ranged attack task. eliminating the appropriate line fixed everything, even if i have new stuff to deal with. :) I will most likely overwrite the combat task method to allow a check for the custom bow.

 

i was staring at it only yesterday and am kicking myself for not managing to put 2 and 2 together.

 

thanks for the troubleshooting.

Link to comment
Share on other sites

Do note that in order to add AI tasks, you need to wait until after the entity has spawned in the world.  EntityLivingBase#tasks is null until then.

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.

Link to comment
Share on other sites

Do note that in order to add AI tasks, you need to wait until after the entity has spawned in the world.  EntityLivingBase#tasks is null until then.

 

EntityLiving#tasks

is initialised in the

EntityLiving

constructor, so you can add tasks in the constructor of your entity class (if you're spawning your own entity) or after the entity has been constructed (if you're spawning an existing entity with new AI tasks).

 

If you're dealing with entities being spawned from external code (e.g. vanilla or other mods), you can't add tasks in

EntityEvent.EntityConstructing

as it's called from the

Entity

constructor before the

EntityLiving

constructor has run. The first event fired after the

EntityLiving

constructor has run is

EntityJoinWorldEvent

, which is the earliest you can add tasks in this situation.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.