Jump to content

Recommended Posts

Posted

hello guys it's again me with my entity :) now what i want to ask is if there is a specific code for if an entity projectile hits a block :) i wanna have that my entity projectile only explodes on block but now it's also exploding on entitys, so yeah... corect my code please :)

 

package invizzble.mods.nc.entities.projectiles;

import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.effect.EntityWeatherEffect;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;

public class EntityStaffODarknessAmmo extends EntityThrowable{

    public EntityStaffODarknessAmmo(World par1World)
    {
        super(par1World);
    }
    
    public EntityStaffODarknessAmmo(World par1World,EntityLivingBase par2EntityLivingBase) {
        super(par1World, par2EntityLivingBase);

    }
    
    private int explosionRadius= 3;
    
    @Override
    protected void onImpact(MovingObjectPosition par1Movingobjectposition) {
        
        if (par1Movingobjectposition.entityHit != null)
        {
            byte b0 = 30;
            par1Movingobjectposition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)b0);
            this.setDead();
        }
        if(!this.worldObj.isRemote){
            this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, explosionRadius, true);
            this.setDead();
        }
        
        
    }
    
    @Override
    protected float getGravityVelocity()
    {
        return 0F;
    }

}

Posted

Look at MovingObjectPosition.typeOfHit. Also, I don't believe you should be calling setDead on the client for an entity which exists on both the client and the server.

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.