Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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

  • Author

I found what the problem was : conflict between sides... Just had to check first if !world.isRemote and all worked perfectly.

Thanks anyway for your quick answer. :D

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.