Jump to content

Summoning another entity on impact at thrown entity?


gurujive

Recommended Posts

Say if I'd like to summon a lightningbolt as I smash a creeper in the face with something...

 

What would that look like?

 

so far my on impact looks like so (it is a thrown entity):

protected void onImpact(RayTraceResult result)
    {
    	if (!this.isWet() && result.entityHit instanceof EntityCreeper)
        {
        	((EntityCreeper) result.entityHit).ignite();	
        }
        if (result.entityHit != null)
        {
            int i = 0;
            if (result.entityHit instanceof EntityLivingBase)
            {
                i = 0;
            }
            result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
            result.entityHit.addVelocity(this.motionX * (double)this.knockbackStrength * 10.0D, 0.4D, this.motionZ * (double)this.knockbackStrength * 10.0D);
            result.entityHit.setFire(;
            result.entityHit.attackEntityFrom(DamageSource.drown, 3.0F);
            result.entityHit.attackEntityFrom(DamageSource.lightningBolt, 4.0F);
            float f = 0.0F;
            this.worldObj.createExplosion(this, this.posX, this.posY + (double)(this.height / 16.0F), this.posZ, (float)this.explosionPower, true);
            worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 0.8F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F));           
        }
        for (int j = 0; j < 8; ++j)
        {
            this.worldObj.spawnParticle(EnumParticleTypes.BLOCK_CRACK, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[] {Block.getIdFromBlock(Blocks.FIRE)});
        }
        ++ticksExisted;
        if (this.ticksExisted >= 100)
        {
        	this.setDead();
        }
        if (!this.worldObj.isRemote)
        {	
        	this.pushOutOfBlocks(0, 0, 0);
        	this.addVelocity(this.motionX * (double)this.knockbackStrength * 0.01D, 0.7D, this.motionZ * (double)this.knockbackStrength * 0.01D);
            worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.ENTITY_BLAZE_BURN, SoundCategory.NEUTRAL, 0.7F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F));
        }        
    }

 

 

However I would like to add a small possibility of when it makes impact that it will summon a lightningbolt from the sky to strike the entity that it hits.

 

Possible? (I sure hope it is)

Link to comment
Share on other sites

Do you have a world object to spawn the entity into?

Yes.

Do you have the ability to call

new

?

Yes.

Can you do this?

Yes.

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

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.