2016-07-13 17:19:02 -04:00
|
|
|
package WayofTime.bloodmagic.entity.projectile;
|
|
|
|
|
|
|
|
import lombok.Setter;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.projectile.EntityThrowable;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.util.DamageSource;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.fml.common.registry.IThrowableEntity;
|
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
|
|
|
import WayofTime.bloodmagic.meteor.MeteorRegistry;
|
|
|
|
|
|
|
|
public class EntityMeteor extends EntityThrowable implements IThrowableEntity
|
|
|
|
{
|
|
|
|
protected int ticksInAir = 0;
|
|
|
|
protected int maxTicksInAir = 600;
|
|
|
|
|
2016-11-05 11:14:56 -04:00
|
|
|
protected double radiusModifier = 1;
|
|
|
|
protected double explosionModifier = 1;
|
|
|
|
protected double fillerChance = 0;
|
|
|
|
|
2016-07-13 17:19:02 -04:00
|
|
|
@Setter
|
|
|
|
public ItemStack meteorStack;
|
|
|
|
|
|
|
|
public EntityMeteor(World world)
|
|
|
|
{
|
|
|
|
super(world);
|
|
|
|
}
|
|
|
|
|
2016-11-05 11:14:56 -04:00
|
|
|
public EntityMeteor(World world, double x, double y, double z, double velX, double velY, double velZ, double radiusModifier, double explosionModifier, double fillerChance)
|
2016-07-13 17:19:02 -04:00
|
|
|
{
|
|
|
|
super(world);
|
|
|
|
this.setSize(1F, 1F);
|
|
|
|
this.setPosition(x, y, z);
|
|
|
|
motionX = velX;
|
|
|
|
motionY = velY;
|
|
|
|
motionZ = velZ;
|
2016-11-05 11:14:56 -04:00
|
|
|
this.radiusModifier = radiusModifier;
|
|
|
|
this.explosionModifier = explosionModifier;
|
|
|
|
this.fillerChance = fillerChance;
|
2016-07-13 17:19:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected float getGravityVelocity()
|
|
|
|
{
|
|
|
|
return 0.03F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
|
|
|
super.onUpdate();
|
|
|
|
if (this.ticksExisted > this.maxTicksInAir)
|
|
|
|
{
|
|
|
|
setDead();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onImpact(RayTraceResult mop)
|
|
|
|
{
|
|
|
|
if (mop.typeOfHit == RayTraceResult.Type.ENTITY && mop.entityHit != null)
|
|
|
|
{
|
|
|
|
this.onImpact(mop.entityHit);
|
|
|
|
} else if (mop.typeOfHit == RayTraceResult.Type.BLOCK)
|
|
|
|
{
|
|
|
|
generateMeteor(mop.getBlockPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setDead();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void onImpact(Entity mop)
|
|
|
|
{
|
|
|
|
if (mop instanceof EntityLivingBase)
|
|
|
|
{
|
|
|
|
doDamage(100, mop);
|
|
|
|
}
|
|
|
|
|
|
|
|
generateMeteor(mop.getPosition());
|
|
|
|
|
|
|
|
// spawnHitParticles("magicCrit", 8);
|
|
|
|
this.setDead();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void doDamage(int i, Entity mop)
|
|
|
|
{
|
|
|
|
mop.attackEntityFrom(this.getDamageSource(), i);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void generateMeteor(BlockPos pos)
|
|
|
|
{
|
2016-11-05 11:14:56 -04:00
|
|
|
MeteorRegistry.generateMeteorForItem(meteorStack, worldObj, pos, Blocks.STONE.getDefaultState(), radiusModifier, explosionModifier, fillerChance);
|
2016-07-13 17:19:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public DamageSource getDamageSource()
|
|
|
|
{
|
|
|
|
return DamageSource.anvil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeEntityToNBT(NBTTagCompound nbt)
|
|
|
|
{
|
|
|
|
super.writeEntityToNBT(nbt);
|
|
|
|
nbt.setInteger(Constants.NBT.PROJECTILE_TICKS_IN_AIR, ticksInAir);
|
|
|
|
nbt.setInteger(Constants.NBT.PROJECTILE_MAX_TICKS_IN_AIR, maxTicksInAir);
|
2016-11-05 11:14:56 -04:00
|
|
|
nbt.setDouble("radiusModifier", radiusModifier);
|
|
|
|
nbt.setDouble("explosionModifier", explosionModifier);
|
|
|
|
nbt.setDouble("fillerChance", fillerChance);
|
2016-07-13 17:19:02 -04:00
|
|
|
if (meteorStack != null)
|
|
|
|
{
|
|
|
|
meteorStack.writeToNBT(nbt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readEntityFromNBT(NBTTagCompound nbt)
|
|
|
|
{
|
|
|
|
super.readEntityFromNBT(nbt);
|
|
|
|
ticksInAir = nbt.getInteger(Constants.NBT.PROJECTILE_TICKS_IN_AIR);
|
|
|
|
maxTicksInAir = nbt.getInteger(Constants.NBT.PROJECTILE_MAX_TICKS_IN_AIR);
|
2016-11-05 11:14:56 -04:00
|
|
|
radiusModifier = nbt.getDouble("radiusModifier");
|
|
|
|
explosionModifier = nbt.getDouble("explosionModifier");
|
|
|
|
fillerChance = nbt.getDouble("fillerChance");
|
2016-07-13 17:19:02 -04:00
|
|
|
meteorStack = ItemStack.loadItemStackFromNBT(nbt);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean canTriggerWalking()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canBeCollidedWith()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setThrower(Entity entity)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|