return dead;
}
@Override
public void updateBurst(IManaBurst burst, ItemStack stack) {
EntityThrowable entity = (EntityThrowable) burst;
int storedColor = getStoredColor(stack);
if(storedColor == 16 && entity.worldObj.isRemote)
burst.setColor(getLensColor(stack));
boolean magnetized = entity.getEntityData().hasKey("Botania:Magnetized");
switch(stack.getItemDamage()) {
case DAMAGE : {
AxisAlignedBB axis = AxisAlignedBB.getBoundingBox(entity.posX, entity.posY, entity.posZ, entity.lastTickPosX, entity.lastTickPosY, entity.lastTickPosZ).expand(1, 1, 1);
List<EntityLivingBase> entities = entity.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axis);
for(EntityLivingBase living : entities) {
if(living instanceof EntityPlayer)
continue;
if(living.hurtTime == 0) {
int mana = burst.getMana();
if(mana >= 16) {
burst.setMana(mana - 16);
if(!burst.isFake() && !entity.worldObj.isRemote)
living.attackEntityFrom(DamageSource.magic, 4);
break;
}
}
}
break;
}
case MAGNET : {
int x = (int) entity.posX;
int y = (int) entity.posY;
int z = (int) entity.posZ;
int range = 3;
magnetize : {
for(int i = -range; i < range; i++)
for(int j = -range; j < range; j++)
for(int k = -range; k < range; k++)
if(entity.worldObj.getTileEntity(i + x, j + y, k + z) instanceof IManaReceiver) {
TileEntity tile = entity.worldObj.getTileEntity(i + x, j + y, k + z);
if(magnetized) {
int magX = entity.getEntityData().getInteger("Botania:MagnetizedX");
int magY = entity.getEntityData().getInteger("Botania:MagnetizedY");
int magZ = entity.getEntityData().getInteger("Botania:MagnetizedZ");
if(tile.xCoord != magX || tile.yCoord != magY || tile.zCoord != magZ)
continue;
}
IManaReceiver receiver = (IManaReceiver) tile;
ChunkCoordinates srcCoords = burst.getBurstSourceChunkCoordinates();
if(MathHelper.pointDistanceSpace(tile.xCoord, tile.yCoord, tile.zCoord, srcCoords.posX, srcCoords.posY, srcCoords.posZ) > 3 && receiver.canRecieveManaFromBursts() && !receiver.isFull()) {
Vector3 burstVec = Vector3.fromEntity(entity);
Vector3 tileVec = Vector3.fromTileEntityCenter(tile).add(0, -0.1, 0);
Vector3 motionVec = new Vector3(entity.motionX, entity.motionY, entity.motionZ);
Vector3 normalMotionVec = motionVec.copy().normalize();
Vector3 magnetVec = tileVec.sub(burstVec).normalize();
Vector3 differenceVec = normalMotionVec.sub(magnetVec).multiply(motionVec.mag() * 0.1);
Vector3 finalMotionVec = motionVec.sub(differenceVec);
if(!magnetized) {
finalMotionVec.multiply(0.75);
entity.getEntityData().setBoolean("Botania:Magnetized", true);
entity.getEntityData().setInteger("Botania:MagnetizedX", tile.xCoord);
entity.getEntityData().setInteger("Botania:MagnetizedY", tile.yCoord);
entity.getEntityData().setInteger("Botania:MagnetizedZ", tile.zCoord);
}
burst.setMotion(finalMotionVec.x, finalMotionVec.y, finalMotionVec.z);
break magnetize;
}