Jump to content

[1.10] Explosion Arrow [how to?]


terraya

Recommended Posts

Hello@All ,

 

i got my normal class from my Arrow, but how can i add a explosion?

 

i mean, i cannot use like on a "throwableEntity" , "OnImpact".

 

public class EntityArrow extends EntityTippedArrow implements IThrowableEntity {
public EntityArrow(World worldIn) {
	super(worldIn);
}

public EntityArrow(World worldIn, double x, double y, double z) {
	super(worldIn, x, y, z);
}

public EntityArrow(World worldIn, EntityLivingBase shooter) {
	super(worldIn, shooter);
}

@Override
public void setPotionEffect(ItemStack stack) {
	super.setPotionEffect(new ItemStack(ItemsUpdate.TestArrow)); 
}

@Override
protected ItemStack getArrowStack() {
	return new ItemStack(ItemsUpdate.TestArrow);
}

@Override
public Entity getThrower() {
	return shootingEntity;
}

@Override
public void setThrower(Entity entity) {
	shootingEntity = entity;
}

protected float getGravityVelocity()
{
  return 0F;
}
}

 

 

 

Link to comment
Share on other sites

This is what looking at your class hierarchy is good for.

 

protected void arrowHit(EntityLivingBase living)

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

This is what looking at your class hierarchy is good for.

 

protected void arrowHit(EntityLivingBase living)

 

tried it out now , somehow the arrow still doesnt make the "explosion" :S

 

thats my class:

 

public class EntityArrow extends EntityTippedArrow implements IThrowableEntity {
public EntityArrow(World worldIn) {
	super(worldIn);
}

public EntityArrow(World worldIn, double x, double y, double z) {
	super(worldIn, x, y, z);
}

public EntityArrow(World worldIn, EntityLivingBase shooter) {
	super(worldIn, shooter);
}

  public void onEntityUpdate()
  {
    if (this.ticks <= 0)
    {
      this.ticks = 200;
      setDead();
    }
    else
    {
      this.ticks -= 1;
    }
  }

  public int ticks = 200; 
  public int HitExplosionRadius = 10;  
  public int explosionRadius = 5;   


@SideOnly(Side.CLIENT)
    protected void arrowHit(EntityLivingBase living,RayTraceResult result)
    {
        super.arrowHit(living);
        {
            if (result.entityHit != null)
            {
                int i = 0;
                if (result.entityHit instanceof EntityLivingBase)
                {
                    i = 150;
                }
                result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
                worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 0.8F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F));
            	this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, this.HitExplosionRadius, true);
            }
            for (int j = 0; j < 1; ++j)
            {
              	this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, this.explosionRadius, true);
            }
            if (!this.worldObj.isRemote)
            {
                this.setDead();
                worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 0.7F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F));
            }
        }
    }
    
    
@Override
public void setPotionEffect(ItemStack stack) {
	super.setPotionEffect(new ItemStack(ItemsUpdate.TestArrow)); 
}

@Override
protected ItemStack getArrowStack() {
	return new ItemStack(ItemsUpdate.TestArrow);
}

@Override
public Entity getThrower() {
	return shootingEntity;
}

@Override
public void setThrower(Entity entity) {
	shootingEntity = entity;
}

protected float getGravityVelocity()
{
  return 0F;
}
}

Link to comment
Share on other sites

@SideOnly(Side.CLIENT)

 

Why is this here?

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

And why is this here?

protected void arrowHit(EntityLivingBase living,RayTraceResult result)

 

Seriously, use @Override and don't go dickering with things that you souldn't dicker with.

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

And why is this here?

protected void arrowHit(EntityLivingBase living,RayTraceResult result)

 

Seriously, use @Override and don't go dickering with things that you souldn't dicker with.

 

 

 

becouse if i do it like this:

 

    protected void arrowHit(EntityLivingBase living)
    {
        super.arrowHit(living);
        {
            if (living.entityHit != null)
            {
                int i = 0;
                if (living.entityHit instanceof EntityLivingBase)
                {
                    i = 150;
                }
                living.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
                worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 0.8F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F));
            	this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, this.HitExplosionRadius, true);
            }
            for (int j = 0; j < 1; ++j)
            {
              	this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, this.explosionRadius, true);
            }
            if (!this.worldObj.isRemote)
            {
                this.setDead();
                worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 0.7F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F));
            }
        }
    }

 

it says "entityHit cannot be resolved or is not a field" :/

Link to comment
Share on other sites

I have this:

public class EntityCheeseArrow extends EntityArrow {
private int duration = 200;

public EntityCheeseArrow(World worldIn) {
	super(worldIn);
}

public EntityCheeseArrow(World worldIn, EntityLivingBase shooter) {
	super(worldIn, shooter);
}

public EntityCheeseArrow(World worldIn, double x, double y, double z) {
	super(worldIn, x, y, z);
}

@Override
public void onUpdate() {
	super.onUpdate();
	if (this.worldObj.isRemote && !this.inGround) {
		this.worldObj.spawnParticle(EnumParticleTypes.END_ROD, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
	} else if (!this.worldObj.isRemote && this.inGround) {
		worldObj.createExplosion(shootingEntity, this.posX, this.posY, this.posZ, 1.0F, true);
		this.setDead();
	}
}

@Override
public ItemStack getArrowStack() {
	return new ItemStack(CheeseItems.CHEESE_ARROW);
}

@Override
public void arrowHit(EntityLivingBase living) {
	super.arrowHit(living);
	World world = living.getEntityWorld();
	if(living != shootingEntity) {
		world.createExplosion(shootingEntity, living.posX, living.posY, living.posZ, 1.0F, true);
	}
}
}

That works for me...

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Link to comment
Share on other sites

I have this:

public class EntityCheeseArrow extends EntityArrow {
private int duration = 200;

public EntityCheeseArrow(World worldIn) {
	super(worldIn);
}

public EntityCheeseArrow(World worldIn, EntityLivingBase shooter) {
	super(worldIn, shooter);
}

public EntityCheeseArrow(World worldIn, double x, double y, double z) {
	super(worldIn, x, y, z);
}

@Override
public void onUpdate() {
	super.onUpdate();
	if (this.worldObj.isRemote && !this.inGround) {
		this.worldObj.spawnParticle(EnumParticleTypes.END_ROD, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
	} else if (!this.worldObj.isRemote && this.inGround) {
		worldObj.createExplosion(shootingEntity, this.posX, this.posY, this.posZ, 1.0F, true);
		this.setDead();
	}
}

@Override
public ItemStack getArrowStack() {
	return new ItemStack(CheeseItems.CHEESE_ARROW);
}

@Override
public void arrowHit(EntityLivingBase living) {
	super.arrowHit(living);
	World world = living.getEntityWorld();
	if(living != shootingEntity) {
		world.createExplosion(shootingEntity, living.posX, living.posY, living.posZ, 1.0F, true);
	}
}
}

That works for me...

 

sure that it is for 1.10?

 

it shows up a bunch of errors :S

Link to comment
Share on other sites

1. Make sure to import the right things

2. CheeseItems.CHEESE_ARROW is just my arrow item, you need to put your own there

3. Can you post the errors?

 

ok i got all i think,

 

but somehow the problem is , that he is using my arrow (yes) but i dont know why (or is it normal?) that the customarrow (without textures etc) has automaticaly the form/texture of the vanila arrow?

 

and ye it work without errors , it just dont want to explode ... O.o idk what am i doing wrong :x

 

public class EntityArrow extends EntityTippedArrow  {
private int duration = 200;

public EntityArrow(World worldIn) {
	super(worldIn);
}

public EntityArrow(World worldIn, EntityLivingBase shooter) {
	super(worldIn, shooter);
}

public EntityArrow(World worldIn, double x, double y, double z) {
	super(worldIn, x, y, z);
}

@Override
public void onUpdate() {
	super.onUpdate();
	if (this.worldObj.isRemote && !this.inGround) {
		this.worldObj.spawnParticle(EnumParticleTypes.END_ROD, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
	} else if (!this.worldObj.isRemote && this.inGround) {
		worldObj.createExplosion(shootingEntity, this.posX, this.posY, this.posZ, 1.0F, true);
		this.setDead();
	}
}

@Override
public ItemStack getArrowStack() {
	return new ItemStack(ItemsUpdate.TestArrow);
}

@Override
public void arrowHit(EntityLivingBase living) {
	super.arrowHit(living);
	World world = living.getEntityWorld();
	if(living != shootingEntity) {
		world.createExplosion(shootingEntity, living.posX, living.posY, living.posZ, 1.0F, true);
	}
}
}

Link to comment
Share on other sites

Don't call your arrow class EntityArrow, it makes things pretty confusing, and extends EntityArrow, not EntityTippedArrow

 

 

ok i did a new class but it still doesnt work ... id ont understand why it doesnt work ...

 

here we go:

 

public static Item TestArrow;
	TestArrow = new CustomArrow().setUnlocalizedName("TestArrow");
	GameRegistry.registerItem(TestArrow, "TestArrow");
	registerRender(TestArrow);

 

 

the customarrow.class

 

public class CustomArrow extends ItemArrow{

    public EntityArrow createArrow(World worldIn, ItemStack stack, EntityLivingBase shooter)
    {
        EntityTippedArrow entitytippedarrow = new EntityTippedArrow(worldIn, shooter);
        entitytippedarrow.setPotionEffect(stack);
        return entitytippedarrow;
    }
    
}

 

      EntityRegistry.registerModEntity(ExplosionArrow.class, "TestArrow", 14, this, 80, 3, true);

 

public class ExplosionArrow extends EntityTippedArrow  {
private int duration = 200;

public ExplosionArrow(World worldIn) {
	super(worldIn);
}

public ExplosionArrow(World worldIn, EntityLivingBase shooter) {
	super(worldIn, shooter);
}

public ExplosionArrow(World worldIn, double x, double y, double z) {
	super(worldIn, x, y, z);
}

@Override
public void onUpdate() {
	super.onUpdate();
	if (this.worldObj.isRemote && !this.inGround) {
		this.worldObj.spawnParticle(EnumParticleTypes.END_ROD, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
	} else if (!this.worldObj.isRemote && this.inGround) {
		worldObj.createExplosion(shootingEntity, this.posX, this.posY, this.posZ, 1.0F, true);
		this.setDead();
	}
}

@Override
public ItemStack getArrowStack() {
	return new ItemStack(ItemsUpdate.TestArrow);
}

@Override
public void arrowHit(EntityLivingBase living) {
	super.arrowHit(living);
	World world = living.getEntityWorld();
	if(living != shootingEntity) {
		world.createExplosion(shootingEntity, living.posX, living.posY, living.posZ, 1.0F, true);
	}
}
}

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.