1

Custom projectile not colliding with objects

wakkytabbaky 9/6/14 6:42 am
191
9/6/2014 7:23 am
made a custom projectile and it will not collide and stop when it hits something it will go right through and keep going on forever, if it hits a entity it will dmg it but go through still and not stop any help is appreciated , not a very good modder so point the problem out if its clear as day


Click to reveal
package com.blockmanlegends.entity;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;


public class EntityEnergyBall
extends EntityThrowable
{
float power;

public EntityEnergyBall(World par1World)
{
super(par1World);
}

public EntityEnergyBall(World world, EntityLivingBase living, float f)
{
super(world, living);
this.power = f;
}

public EntityEnergyBall(World world, double x, double y, double z)
{
super(world, x, y, z);
}

protected float getGravityVelocity()
{
return 0.0F;
}

int fadeTimer = 0;

public void onUpdate(World world, EntityLivingBase living, EntityLivingBase livingbase, float f1_, float f2_)
{

this.posY = living.posY + (double)living.getEyeHeight() - 0.10000000149011612D;
double d0 = livingbase.posX - living.posX;
double d1 = livingbase.boundingBox.minY + (double)(livingbase.height / 3.0F) - this.posY;
double d2 = livingbase.posZ - living.posZ;
double d3 = (double)MathHelper.sqrt_double(d0 * d0 + d2 * d2);

if (d3 >= 1.0E-7D)
{
float f2 = (float)(Math.atan2(d2, d0) * 180.0D / Math.PI) - 90.0F;
float f3 = (float)(-(Math.atan2(d1, d3) * 180.0D / Math.PI));
double d4 = d0 / d3;
double d5 = d2 / d3;
this.setLocationAndAngles(living.posX + d4, this.posY, living.posZ + d5, f2, f3);
this.yOffset = 0.0F;
float f4 = (float)d3 * 0.2F;
this.setThrowableHeading(d0, d1 + (double)f4, d2, f1_, f2_);
}

this.fadeTimer += 1;
if (this.fadeTimer >= 100)
{
setDead();
}
}

protected void onImpact(MovingObjectPosition mop)
{
EntityLiving living;
if (mop.entityHit != null)
{
mop.entityHit.hurtResistantTime = 0;
mop.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, getThrower()), this.power);

mop.entityHit.worldObj.playSoundEffect(this.posX, this.posY, this.posZ, "pixelmoncore:energyHit", 1.0F, 1.0F);
if ((mop.entityHit instanceof EntityLiving))
{
living = (EntityLiving)mop.entityHit;

if (mop.entityHit != null)
{
float damage = 14;
mop.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), damage);
}

for (int l = 0; l < 5; ++l)
{
this.worldObj.spawnParticle("crit", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
if (!worldObj.isRemote)
{
setDead();
}
}
}
}

public void setIsCritical(boolean b)
{
float damage = 14;
}

}
Posted by
wakkytabbaky
Level 1 : New Miner
2

  Have something to say?

JoinSign in

1

TehDansorz
09/06/2014 7:23 am
Level 28 : Expert Nerd
Just check if a block or entity is in front of it and set it's velocity to 0.
1

Welcome