Posted January 30, 20187 yr 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 January 30, 20187 yr by Sunser solved
January 30, 20187 yr 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 January 30, 20187 yr by MCenderdragon catch(Exception e) { } Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).
January 30, 20187 yr 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.
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.