Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED][1.12.2] Custom snowballs sometimes hitting thrower


Sunser
 Share

Recommended Posts

Hi all. Before I start, know that I'm beginning with MC mod developing, plus my English is not always very clear. :/

 

I'm trying to create custom snowballs. I have met some issues with the

protected void onImpact(RayTraceResult result);

function. Sometimes, the thrower receives the snowball's effects, and obviously not want this. This does not append with all of my custom snowballs.

EntityFlintSnowball : working correctly (I haven't change that much the original code from the snowball entity)

Spoiler

 


@Override
protected void onImpact(RayTraceResult result) {
	if (result.entityHit != null) {
		int i = 0;
		if (result.entityHit instanceof EntityPlayer) {
			i=2; 
		}
		result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
	} 
	if (!this.world.isRemote) {
		this.world.setEntityState(this, (byte)3); this.setDead(); 
	} 
}

 

 

 

EntityTNTSnowball : working correctly (a bit more changes)

Spoiler

 


@Override
    protected void onImpact(RayTraceResult result)
    {
        if (!this.world.isRemote)
        {
            Explosion explosionIn = new Explosion(this.world,this.thrower,this.posX,this.posY,this.posZ,0.5F,false,true);
            EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(this.world, (double)((float)this.posX + 0.5F), this.posY, (double)((float)this.posZ + 0.5F), explosionIn.getExplosivePlacedBy());
            entitytntprimed.setFuse((short)(this.world.rand.nextInt(entitytntprimed.getFuse() / 4) + entitytntprimed.getFuse() / 8));
            this.world.createExplosion(entitytntprimed, this.posX, this.posY + (double)(this.height / 16.0F), this.posZ, 1.0F, true);

            this.world.setEntityState(this, (byte)3);
            this.setDead();
        }
    }

 

EntityPoisonSnowball : not working correctly (thrower hit by projectile)

Spoiler

@Override
    protected void onImpact(RayTraceResult result)
    {
        if (result.entityHit != null)
        {
            if (result.entityHit instanceof EntityPlayer)
            {
                PotionEffect eff = new PotionEffect(MobEffects.POISON,60);
                ((EntityPlayer) result.entityHit).addPotionEffect(eff);
                result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0.0F);

            }
        }

        if (!this.world.isRemote)
        {
            this.world.setEntityState(this, (byte)3);
            this.setDead();
        }
    }

 

EntityFireSnowball : not working correctly

Spoiler

@Override
    protected void onImpact(RayTraceResult result)
    {
        if (result.entityHit != null)
        {
            if (result.entityHit instanceof EntityPlayer)
            {
                result.entityHit.setFire(3);
            }
            result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0.0F);
        }

        if (!this.world.isRemote)
        {
            this.world.setEntityState(this, (byte)3);
            this.setDead();
        }
    }

 

All my snowballs are registered, rendered and working well apart from this problem. Please let me know if you have any idea. Thanks for reading.

 

Edited by Sunser
solved
Link to comment
Share on other sites

As far as I know this is an issue from vanilla, the EntityArrow has an if clause to check if the owner was hit and ignores him. YOu could do similar checks respecting the age to make it possible to hit yourself if you throw it straight up.

Edited by MCenderdragon

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

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.

Guest
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.